string_literal.mjs 737 B

12345678910111213141516171819
  1. /**
  2. * @license
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. /**
  6. * An object of type TemplateStringsArray represents the literal part(s) of a
  7. * template literal. This function checks if a TemplateStringsArray object is
  8. * actually from a template literal.
  9. *
  10. * @param templateObj This contains the literal part of the template literal.
  11. * @param hasExprs If true, the input template may contain embedded expressions.
  12. * @param errorMsg The custom error message in case any checks fail.
  13. */
  14. export function assertIsTemplateObject(templateObj, hasExprs, errorMsg) {
  15. if (!Array.isArray(templateObj) || !Array.isArray(templateObj.raw) ||
  16. (!hasExprs && templateObj.length !== 1)) {
  17. throw new TypeError(errorMsg);
  18. }
  19. }