template-literals.js 837 B

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.TaggedTemplateExpression = TaggedTemplateExpression;
  4. exports.TemplateElement = TemplateElement;
  5. exports.TemplateLiteral = TemplateLiteral;
  6. function TaggedTemplateExpression(node) {
  7. this.print(node.tag, node);
  8. this.print(node.quasi, node);
  9. }
  10. function TemplateElement(node, parent) {
  11. var isFirst = parent.quasis[0] === node;
  12. var isLast = parent.quasis[parent.quasis.length - 1] === node;
  13. var value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${");
  14. if (!isFirst) this.space();
  15. this.token(value);
  16. if (!isLast) this.space();
  17. }
  18. function TemplateLiteral(node) {
  19. var quasis = node.quasis;
  20. for (var i = 0; i < quasis.length; i++) {
  21. this.print(quasis[i], node);
  22. if (i + 1 < quasis.length) {
  23. this.print(node.expressions[i], node);
  24. }
  25. }
  26. }