string_literal.js 905 B

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