@lwc/template-compiler 2.45.2 → 2.45.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +2 -2
  2. package/dist/index.cjs.js +5313 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/{types/index.d.ts → index.d.ts} +1 -0
  5. package/dist/index.js +5286 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +33 -30
  8. package/dist/commonjs/codegen/codegen.js +0 -330
  9. package/dist/commonjs/codegen/codegen.js.map +0 -1
  10. package/dist/commonjs/codegen/expression.js +0 -176
  11. package/dist/commonjs/codegen/expression.js.map +0 -1
  12. package/dist/commonjs/codegen/formatters/module.js +0 -91
  13. package/dist/commonjs/codegen/formatters/module.js.map +0 -1
  14. package/dist/commonjs/codegen/helpers.js +0 -233
  15. package/dist/commonjs/codegen/helpers.js.map +0 -1
  16. package/dist/commonjs/codegen/index.js +0 -549
  17. package/dist/commonjs/codegen/index.js.map +0 -1
  18. package/dist/commonjs/codegen/optimize.js +0 -119
  19. package/dist/commonjs/codegen/optimize.js.map +0 -1
  20. package/dist/commonjs/codegen/static-element-serializer.js +0 -122
  21. package/dist/commonjs/codegen/static-element-serializer.js.map +0 -1
  22. package/dist/commonjs/config.js +0 -78
  23. package/dist/commonjs/config.js.map +0 -1
  24. package/dist/commonjs/index.js +0 -66
  25. package/dist/commonjs/index.js.map +0 -1
  26. package/dist/commonjs/parser/attribute.js +0 -237
  27. package/dist/commonjs/parser/attribute.js.map +0 -1
  28. package/dist/commonjs/parser/constants.js +0 -155
  29. package/dist/commonjs/parser/constants.js.map +0 -1
  30. package/dist/commonjs/parser/expression-complex/html.js +0 -222
  31. package/dist/commonjs/parser/expression-complex/html.js.map +0 -1
  32. package/dist/commonjs/parser/expression-complex/index.js +0 -26
  33. package/dist/commonjs/parser/expression-complex/index.js.map +0 -1
  34. package/dist/commonjs/parser/expression-complex/types.js +0 -9
  35. package/dist/commonjs/parser/expression-complex/types.js.map +0 -1
  36. package/dist/commonjs/parser/expression-complex/validate.js +0 -141
  37. package/dist/commonjs/parser/expression-complex/validate.js.map +0 -1
  38. package/dist/commonjs/parser/expression.js +0 -130
  39. package/dist/commonjs/parser/expression.js.map +0 -1
  40. package/dist/commonjs/parser/html.js +0 -112
  41. package/dist/commonjs/parser/html.js.map +0 -1
  42. package/dist/commonjs/parser/index.js +0 -1181
  43. package/dist/commonjs/parser/index.js.map +0 -1
  44. package/dist/commonjs/parser/parse5Errors.js +0 -77
  45. package/dist/commonjs/parser/parse5Errors.js.map +0 -1
  46. package/dist/commonjs/parser/parser.js +0 -309
  47. package/dist/commonjs/parser/parser.js.map +0 -1
  48. package/dist/commonjs/parser/utils/html-element-attributes.js +0 -411
  49. package/dist/commonjs/parser/utils/html-element-attributes.js.map +0 -1
  50. package/dist/commonjs/parser/utils/html-elements.js +0 -141
  51. package/dist/commonjs/parser/utils/html-elements.js.map +0 -1
  52. package/dist/commonjs/parser/utils/javascript.js +0 -25
  53. package/dist/commonjs/parser/utils/javascript.js.map +0 -1
  54. package/dist/commonjs/parser/utils/svg-elements.js +0 -42
  55. package/dist/commonjs/parser/utils/svg-elements.js.map +0 -1
  56. package/dist/commonjs/shared/ast.js +0 -496
  57. package/dist/commonjs/shared/ast.js.map +0 -1
  58. package/dist/commonjs/shared/constants.js +0 -33
  59. package/dist/commonjs/shared/constants.js.map +0 -1
  60. package/dist/commonjs/shared/estree.js +0 -325
  61. package/dist/commonjs/shared/estree.js.map +0 -1
  62. package/dist/commonjs/shared/naming.js +0 -32
  63. package/dist/commonjs/shared/naming.js.map +0 -1
  64. package/dist/commonjs/shared/parse5.js +0 -20
  65. package/dist/commonjs/shared/parse5.js.map +0 -1
  66. package/dist/commonjs/shared/renderer-hooks.js +0 -55
  67. package/dist/commonjs/shared/renderer-hooks.js.map +0 -1
  68. package/dist/commonjs/shared/types.js +0 -49
  69. package/dist/commonjs/shared/types.js.map +0 -1
  70. package/dist/commonjs/shared/utils.js +0 -45
  71. package/dist/commonjs/shared/utils.js.map +0 -1
  72. package/dist/commonjs/state.js +0 -24
  73. package/dist/commonjs/state.js.map +0 -1
  74. /package/dist/{types/codegen → codegen}/codegen.d.ts +0 -0
  75. /package/dist/{types/codegen → codegen}/expression.d.ts +0 -0
  76. /package/dist/{types/codegen → codegen}/formatters/module.d.ts +0 -0
  77. /package/dist/{types/codegen → codegen}/helpers.d.ts +0 -0
  78. /package/dist/{types/codegen → codegen}/index.d.ts +0 -0
  79. /package/dist/{types/codegen → codegen}/optimize.d.ts +0 -0
  80. /package/dist/{types/codegen → codegen}/static-element-serializer.d.ts +0 -0
  81. /package/dist/{types/config.d.ts → config.d.ts} +0 -0
  82. /package/dist/{types/parser → parser}/attribute.d.ts +0 -0
  83. /package/dist/{types/parser → parser}/constants.d.ts +0 -0
  84. /package/dist/{types/parser → parser}/expression-complex/html.d.ts +0 -0
  85. /package/dist/{types/parser → parser}/expression-complex/index.d.ts +0 -0
  86. /package/dist/{types/parser → parser}/expression-complex/types.d.ts +0 -0
  87. /package/dist/{types/parser → parser}/expression-complex/validate.d.ts +0 -0
  88. /package/dist/{types/parser → parser}/expression.d.ts +0 -0
  89. /package/dist/{types/parser → parser}/html.d.ts +0 -0
  90. /package/dist/{types/parser → parser}/index.d.ts +0 -0
  91. /package/dist/{types/parser → parser}/parse5Errors.d.ts +0 -0
  92. /package/dist/{types/parser → parser}/parser.d.ts +0 -0
  93. /package/dist/{types/parser → parser}/utils/html-element-attributes.d.ts +0 -0
  94. /package/dist/{types/parser → parser}/utils/html-elements.d.ts +0 -0
  95. /package/dist/{types/parser → parser}/utils/javascript.d.ts +0 -0
  96. /package/dist/{types/parser → parser}/utils/svg-elements.d.ts +0 -0
  97. /package/dist/{types/shared → shared}/ast.d.ts +0 -0
  98. /package/dist/{types/shared → shared}/constants.d.ts +0 -0
  99. /package/dist/{types/shared → shared}/estree.d.ts +0 -0
  100. /package/dist/{types/shared → shared}/naming.d.ts +0 -0
  101. /package/dist/{types/shared → shared}/parse5.d.ts +0 -0
  102. /package/dist/{types/shared → shared}/renderer-hooks.d.ts +0 -0
  103. /package/dist/{types/shared → shared}/types.d.ts +0 -0
  104. /package/dist/{types/shared → shared}/utils.d.ts +0 -0
  105. /package/dist/{types/state.d.ts → state.d.ts} +0 -0
@@ -1,155 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TMPL_EXPR_ECMASCRIPT_EDITION = exports.TEMPLATE_DIRECTIVES = exports.ATTR_NAME = exports.HTML_TAG = exports.KNOWN_HTML_AND_SVG_ELEMENTS = exports.HTML_ATTRIBUTES_REVERSE_LOOKUP = exports.DISALLOWED_HTML_TAGS = exports.ATTRS_PROPS_TRANFORMS = exports.DISALLOWED_MATHML_TAGS = exports.SUPPORTED_SVG_TAGS = exports.DATA_RE = exports.LWC_DIRECTIVE_SET = exports.EVENT_HANDLER_NAME_RE = exports.EVENT_HANDLER_RE = exports.ITERATOR_RE = exports.VALID_IF_MODIFIER = exports.LWC_RE = exports.IF_RE = exports.EXPRESSION_RE = void 0;
4
- /*
5
- * Copyright (c) 2018, salesforce.com, inc.
6
- * All rights reserved.
7
- * SPDX-License-Identifier: MIT
8
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
9
- */
10
- const shared_1 = require("@lwc/shared");
11
- const types_1 = require("../shared/types");
12
- const html_element_attributes_1 = require("./utils/html-element-attributes");
13
- const html_elements_1 = require("./utils/html-elements");
14
- const svg_elements_1 = require("./utils/svg-elements");
15
- exports.EXPRESSION_RE = /(\{(?:.)+?\})/g;
16
- exports.IF_RE = /^if:/;
17
- exports.LWC_RE = /^lwc:/;
18
- exports.VALID_IF_MODIFIER = new Set(['true', 'false', 'strict-true']);
19
- exports.ITERATOR_RE = /^iterator:.*$/;
20
- exports.EVENT_HANDLER_RE = /^on/;
21
- exports.EVENT_HANDLER_NAME_RE = /^on[a-z][a-z0-9_]*$/;
22
- exports.LWC_DIRECTIVE_SET = new Set(Object.values(types_1.ElementDirectiveName));
23
- const ATTRIBUTE_NAME_CHAR = [
24
- ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-',
25
- '\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD',
26
- '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040',
27
- ].join('');
28
- // eslint-disable-next-line no-misleading-character-class
29
- exports.DATA_RE = new RegExp('^(data)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
30
- exports.SUPPORTED_SVG_TAGS = new Set([
31
- 'svg',
32
- 'a',
33
- 'altGlyph',
34
- 'altglyphDef',
35
- 'altGlyphItem',
36
- 'animate',
37
- 'animateColor',
38
- 'animateMotion',
39
- 'animateTransform',
40
- 'audio',
41
- 'canvas',
42
- 'circle',
43
- 'clipPath',
44
- 'defs',
45
- 'desc',
46
- 'ellipse',
47
- 'feBlend',
48
- 'feColorMatrix',
49
- 'feComponentTransfer',
50
- 'feFuncR',
51
- 'feFuncG',
52
- 'feFuncB',
53
- 'feFuncA',
54
- 'feComposite',
55
- 'feConvolveMatrix',
56
- 'feDiffuseLighting',
57
- 'feDisplacementMap',
58
- 'feDropShadow',
59
- 'feFlood',
60
- 'feGaussianBlur',
61
- 'feMerge',
62
- 'feMergeNode',
63
- 'feMorphology',
64
- 'feOffset',
65
- 'feSpecularLighting',
66
- 'feTile',
67
- 'feTurbulence',
68
- 'fePointLight',
69
- 'filter',
70
- 'font',
71
- 'foreignObject',
72
- 'g',
73
- 'glyph',
74
- 'glyphRef',
75
- 'hkern',
76
- 'image',
77
- 'line',
78
- 'linearGradient',
79
- 'marker',
80
- 'mask',
81
- 'mpath',
82
- 'path',
83
- 'pattern',
84
- 'polygon',
85
- 'polyline',
86
- 'radialGradient',
87
- 'rect',
88
- 'stop',
89
- 'switch',
90
- 'symbol',
91
- 'text',
92
- 'textPath',
93
- 'title',
94
- 'tref',
95
- 'tspan',
96
- 'video',
97
- 'view',
98
- 'vkern',
99
- 'use',
100
- ]);
101
- exports.DISALLOWED_MATHML_TAGS = new Set([
102
- 'script',
103
- 'link',
104
- 'base',
105
- 'object',
106
- 'embed',
107
- 'meta',
108
- ]);
109
- exports.ATTRS_PROPS_TRANFORMS = {
110
- accesskey: 'accessKey',
111
- readonly: 'readOnly',
112
- tabindex: 'tabIndex',
113
- bgcolor: 'bgColor',
114
- colspan: 'colSpan',
115
- rowspan: 'rowSpan',
116
- contenteditable: 'contentEditable',
117
- crossorigin: 'crossOrigin',
118
- datetime: 'dateTime',
119
- formaction: 'formAction',
120
- ismap: 'isMap',
121
- maxlength: 'maxLength',
122
- minlength: 'minLength',
123
- novalidate: 'noValidate',
124
- usemap: 'useMap',
125
- for: 'htmlFor',
126
- ...shared_1.AriaAttrNameToPropNameMap,
127
- };
128
- exports.DISALLOWED_HTML_TAGS = new Set(['base', 'link', 'meta', 'script', 'title']);
129
- exports.HTML_ATTRIBUTES_REVERSE_LOOKUP = html_element_attributes_1.HTML_ATTRIBUTE_ELEMENT_MAP;
130
- exports.KNOWN_HTML_AND_SVG_ELEMENTS = new Set([...html_elements_1.HTML_ELEMENTS, ...svg_elements_1.SVG_ELEMENTS]);
131
- exports.HTML_TAG = {
132
- A: 'a',
133
- AREA: 'area',
134
- BODY: 'body',
135
- CAPTION: 'caption',
136
- COL: 'col',
137
- COLGROUP: 'colgroup',
138
- HEAD: 'head',
139
- HTML: 'html',
140
- TBODY: 'tbody',
141
- TD: 'td',
142
- TFOOT: 'tfoot',
143
- TH: 'th',
144
- THEAD: 'thead',
145
- TR: 'tr',
146
- USE: 'use',
147
- };
148
- exports.ATTR_NAME = {
149
- HREF: 'href',
150
- XLINK_HREF: 'xlink:href',
151
- };
152
- exports.TEMPLATE_DIRECTIVES = [/^key$/, /^lwc:*/, /^if:*/, /^for:*/, /^iterator:*/];
153
- // TODO [#3370]: remove experimental template expression flag
154
- exports.TMPL_EXPR_ECMASCRIPT_EDITION = 2022;
155
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/parser/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,wCAAwD;AACxD,2CAAuD;AACvD,6EAA6E;AAC7E,yDAAsD;AACtD,uDAAoD;AAEvC,QAAA,aAAa,GAAG,gBAAgB,CAAC;AAEjC,QAAA,KAAK,GAAG,MAAM,CAAC;AACf,QAAA,MAAM,GAAG,OAAO,CAAC;AACjB,QAAA,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;AAE9D,QAAA,WAAW,GAAG,eAAe,CAAC;AAE9B,QAAA,gBAAgB,GAAG,KAAK,CAAC;AACzB,QAAA,qBAAqB,GAAG,qBAAqB,CAAC;AAE9C,QAAA,iBAAiB,GAAgB,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,4BAAoB,CAAC,CAAC,CAAC;AAE3F,MAAM,mBAAmB,GAAG;IACxB,6FAA6F;IAC7F,oFAAoF;IACpF,8CAA8C;CACjD,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAEX,yDAAyD;AAC5C,QAAA,OAAO,GAAG,IAAI,MAAM,CAAC,WAAW,GAAG,mBAAmB,GAAG,KAAK,CAAC,CAAC;AAEhE,QAAA,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACtC,KAAK;IACL,GAAG;IACH,UAAU;IACV,aAAa;IACb,cAAc;IACd,SAAS;IACT,cAAc;IACd,eAAe;IACf,kBAAkB;IAClB,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,MAAM;IACN,MAAM;IACN,SAAS;IACT,SAAS;IACT,eAAe;IACf,qBAAqB;IACrB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,aA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AC,CAAC,CAAC;AAE5E,QAAA,8BAA8B,GAEvC,oDAA0B,CAAC;AAElB,QAAA,2BAA2B,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,6BAAa,EAAE,GAAG,2BAAY,CAAC,CAAC,CAAC;AAE3E,QAAA,QAAQ,GAAG;IACpB,CAAC,EAAE,GAAG;IACN,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,IAAI;IACR,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,IAAI;IACR,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;CACb,CAAC;AACW,QAAA,SAAS,GAAG;IACrB,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,YAAY;CAC3B,CAAC;AACW,QAAA,mBAAmB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAEzF,6DAA6D;AAChD,QAAA,4BAA4B,GAAG,IAAI,CAAC"}
@@ -1,222 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023, salesforce.com, inc.
4
- * All rights reserved.
5
- * SPDX-License-Identifier: MIT
6
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7
- */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.parseFragment = void 0;
13
- const acorn_1 = require("acorn");
14
- const errors_1 = require("@lwc/errors");
15
- const parser_1 = __importDefault(require("parse5/lib/parser"));
16
- const tokenizer_1 = __importDefault(require("parse5/lib/tokenizer"));
17
- const constants_1 = require("../constants");
18
- const OPENING_CURLY_LEN = 1;
19
- const CLOSING_CURLY_LEN = 1;
20
- const OPENING_CURLY_BRACKET = 0x7b;
21
- const CLOSING_CURLY_BRACKET = 0x7d;
22
- const WHITESPACE = /\s*/;
23
- const TRAILING_SPACES_AND_PARENS = /[\s)]*/;
24
- function getWhitespaceLen(str) {
25
- return WHITESPACE.exec(str)[0].length;
26
- }
27
- function getTrailingChars(str) {
28
- return TRAILING_SPACES_AND_PARENS.exec(str)[0];
29
- }
30
- /**
31
- * This function checks for "unbalanced" extraneous parentheses surrounding the expression.
32
- *
33
- * Examples of balanced extraneous parentheses (validation passes):
34
- * {(foo.bar)} <-- the MemberExpressions does not account for the surrounding parens
35
- * {(foo())} <-- the CallExpression does not account for the surrounding parens
36
- * {((foo ?? bar)())} <-- the CallExpression does not account for the surrounding parens
37
- *
38
- * Examples of unbalanced extraneous parentheses (validation fails):
39
- * {(foo.bar))} <-- there is an extraneous trailing paren
40
- * {foo())} <-- there is an extraneous trailing paren
41
- *
42
- * Examples of no extraneous parentheses (validation passes):
43
- * {foo()} <-- the CallExpression accounts for the trailing paren
44
- * {(foo ?? bar).baz} <-- the outer MemberExpression accounts for the leading paren
45
- * {(foo).bar} <-- the outer MemberExpression accounts for the leading paren
46
- *
47
- * Notably, no examples of extraneous leading parens could be found - these result in a
48
- * parsing error in Acorn. However, this function still checks, in case there is an
49
- * unknown expression that would parse with an extraneous leading paren.
50
- */
51
- function validateMatchingExtraParens(leadingChars, trailingChars) {
52
- const numLeadingParens = leadingChars.split('(').length - 1;
53
- const numTrailingParens = trailingChars.split(')').length - 1;
54
- (0, errors_1.invariant)(numLeadingParens === numTrailingParens, errors_1.ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR, ['expression must have balanced parentheses.']);
55
- }
56
- /**
57
- * This class extends `parse5`'s internal tokenizer.
58
- *
59
- * Its behavior diverges from that specified in the WHATWG HTML spec
60
- * in two places:
61
- * - 13.2.5.38 - unquoted attribute values
62
- * - 13.2.5.1 - the "data" state, which corresponds to parsing outside of tags
63
- *
64
- * Specifically, this tokenizer defers to Acorn's JavaScript parser when
65
- * encountering a `{` character for an attribute value or within a text
66
- * node. Acorn parses the expression, and the tokenizer continues its work
67
- * following the closing `}`.
68
- *
69
- * The tokenizer itself is a massive state machine - code points are consumed one at
70
- * a time and, when certain conditions are met, sequences of those code points are
71
- * emitted as tokens. The tokenizer will also transition to new states, under conditions
72
- * specified by the HTML spec.
73
- */
74
- class TemplateHtmlTokenizer extends tokenizer_1.default {
75
- constructor(parser) {
76
- super();
77
- // We track which attribute values are in-progess so that we can defer
78
- // to the default tokenizer's behavior after the first character of
79
- // an unquoted attr value has been checked for an opening curly brace.
80
- this.checkedAttrs = new WeakSet();
81
- this.parser = parser;
82
- }
83
- // Move the lexer's cursor forward by the indicated number of positions. This
84
- // mechanism is superior to setting `this.preprocessor.pos` because it allows
85
- // parse5's location mixin to count new lines and columns, resulting in correct
86
- // AST location information.
87
- advanceBy(numChars) {
88
- for (let i = 0; i < numChars; i++) {
89
- this.preprocessor.advance();
90
- }
91
- }
92
- parseTemplateExpression() {
93
- const expressionStart = this.preprocessor.pos;
94
- const html = this.preprocessor.html;
95
- const leadingWhitespaceLen = getWhitespaceLen(html.slice(expressionStart + 1));
96
- const javascriptExprStart = expressionStart + leadingWhitespaceLen + OPENING_CURLY_LEN;
97
- // Start parsing after the opening curly brace and any leading whitespace.
98
- const estreeNode = (0, acorn_1.parseExpressionAt)(html, javascriptExprStart, {
99
- ecmaVersion: constants_1.TMPL_EXPR_ECMASCRIPT_EDITION,
100
- allowAwaitOutsideFunction: true,
101
- locations: true,
102
- ranges: true,
103
- onComment: () => (0, errors_1.invariant)(false, errors_1.ParserDiagnostics.INVALID_EXPR_COMMENTS_DISALLOWED),
104
- });
105
- const leadingChars = html.slice(expressionStart + 1, estreeNode.start);
106
- const trailingChars = getTrailingChars(html.slice(estreeNode.end));
107
- validateMatchingExtraParens(leadingChars, trailingChars);
108
- const idxOfClosingBracket = estreeNode.end + trailingChars.length;
109
- // Capture text content between the outer curly braces, inclusive.
110
- const expressionTextNodeValue = html.slice(expressionStart, idxOfClosingBracket + CLOSING_CURLY_LEN);
111
- (0, errors_1.invariant)(html.codePointAt(idxOfClosingBracket) === CLOSING_CURLY_BRACKET, errors_1.ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR, ['expression must end with curly brace.']);
112
- this.advanceBy(expressionTextNodeValue.length);
113
- // Parsed expressions that are cached here will be later retrieved when the
114
- // LWC template AST is being constructed.
115
- this.parser.preparsedJsExpressions.set(expressionStart, estreeNode);
116
- return expressionTextNodeValue;
117
- }
118
- // ATTRIBUTE_VALUE_UNQUOTED_STATE is entered when an opening tag is being parsed,
119
- // after an attribute name is parsed, and after the `=` character is parsed. The
120
- // next character determines whether the lexer enters the ATTRIBUTE_VALUE_QUOTED_STATE
121
- // or ATTRIBUTE_VALUE_UNQUOTED_STATE. Customizations required to support template
122
- // expressions are only in effect when parsing an unquoted attribute value.
123
- ATTRIBUTE_VALUE_UNQUOTED_STATE(codePoint) {
124
- if (codePoint === OPENING_CURLY_BRACKET && !this.checkedAttrs.has(this.currentAttr)) {
125
- this.checkedAttrs.add(this.currentAttr);
126
- this.currentAttr.value = this.parseTemplateExpression();
127
- // Moving the cursor back by one allows the state machine to correctly detect
128
- // the state into which it should next transition.
129
- this._unconsume();
130
- }
131
- else {
132
- // If the first character in an unquoted-attr-value is not an opening
133
- // curly brace, it isn't a template expression. Opening curly braces
134
- // coming later in an unquoted attr value should not be considered
135
- // the beginning of a template expression.
136
- this.checkedAttrs.add(this.currentAttr);
137
- super.ATTRIBUTE_VALUE_UNQUOTED_STATE(codePoint);
138
- }
139
- }
140
- // DATA_STATE is the initial & default state of the lexer. It can be thought of as the
141
- // state when the cursor is outside of an (opening or closing) tag, and outside of
142
- // special parts of an HTML document like the contents of a <style> or <script> tag.
143
- // In other words, we're parsing a text node when in DATA_STATE.
144
- DATA_STATE(codePoint) {
145
- if (codePoint === OPENING_CURLY_BRACKET) {
146
- // An opening curly brace may be the first character in a text node.
147
- // If that is not the case, we need to emit the text node characters
148
- // that come before the curly brace.
149
- if (this.currentCharacterToken) {
150
- // Emit the text segment preceding the curly brace.
151
- this._emitCurrentCharacterToken();
152
- }
153
- const expressionTextNodeValue = this.parseTemplateExpression();
154
- // Create a new text-node token to contain our `{expression}`
155
- this._createCharacterToken(tokenizer_1.default.CHARACTER_TOKEN, expressionTextNodeValue);
156
- // Emit the text node token containing the `{expression}`
157
- this._emitCurrentCharacterToken();
158
- // Moving the cursor back by one allows the state machine to correctly detect
159
- // the state into which it should next transition.
160
- this._unconsume();
161
- }
162
- else {
163
- super.DATA_STATE(codePoint);
164
- }
165
- }
166
- }
167
- /**
168
- * This class extends `parse5`'s internal parser. The heavy lifting is
169
- * done in the tokenizer. This class is only present to facilitate use
170
- * of that tokenizer when parsing expressions.
171
- */
172
- class TemplateHtmlParser extends parser_1.default {
173
- constructor(_options) {
174
- const { preparsedJsExpressions, ...options } = _options;
175
- super(options);
176
- this.preparsedJsExpressions = preparsedJsExpressions;
177
- }
178
- _bootstrap(document, fragmentContext) {
179
- super._bootstrap(document, fragmentContext);
180
- // The default `_bootstrap` method creates a new Tokenizer; here, we ensure that our
181
- // customized tokenizer is used.
182
- this.tokenizer = new TemplateHtmlTokenizer(this);
183
- }
184
- // The parser will try to concatenate adjacent text tokens into a single
185
- // text node. Template expressions should be encapsulated in their own
186
- // text node, and not combined with adjacent text or whitespace. To avoid
187
- // that, we create a new text node for the template expression rather than
188
- // allowing the concatenation to proceed.
189
- _insertCharacters(token) {
190
- if (token.chars[0] !== '{') {
191
- return super._insertCharacters(token);
192
- }
193
- const parentNode = this.openElements.current;
194
- const textNode = {
195
- nodeName: '#text',
196
- value: token.chars,
197
- sourceCodeLocation: token.location,
198
- parentNode,
199
- };
200
- parentNode.childNodes.push(textNode);
201
- }
202
- }
203
- /**
204
- * Parse the LWC template using a customized parser & lexer that allow
205
- * for template expressions to be parsed correctly.
206
- *
207
- * @param {string} source raw template markup
208
- * @param {ParseFragmentConfig} config
209
- *
210
- * @return {DocumentFragment} the parsed document
211
- */
212
- function parseFragment(source, config) {
213
- const { ctx, sourceCodeLocationInfo = true, onParseError } = config;
214
- const parser = new TemplateHtmlParser({
215
- sourceCodeLocationInfo,
216
- onParseError,
217
- preparsedJsExpressions: ctx.preparsedJsExpressions,
218
- });
219
- return parser.parseFragment(source);
220
- }
221
- exports.parseFragment = parseFragment;
222
- //# sourceMappingURL=html.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"html.js","sourceRoot":"","sources":["../../../../src/parser/expression-complex/html.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,iCAA0C;AAE1C,wCAA2D;AAC3D,+DAAuC;AACvC,qEAA6C;AAC7C,4CAA4D;AAI5D,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,UAAU,GAAG,KAAK,CAAC;AACzB,MAAM,0BAA0B,GAAG,QAAQ,CAAC;AAE5C,SAAS,gBAAgB,CAAC,GAAW;IACjC,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC3C,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAW;IACjC,OAAO,0BAA0B,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,2BAA2B,CAAC,YAAoB,EAAE,aAAqB;IAC5E,MAAM,gBAAgB,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5D,MAAM,iBAAiB,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,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,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,wEAAwE;IACxE,sEAAsE;IACtE,yEAAyE;IACzE,0EAA0E;IAC1E,yCAAyC;IACzC,iBAAiB,CAAC,KAAU;QACxB,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YACxB,OAAO,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;SACzC;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;QAC7C,MAAM,QAAQ,GAAa;YACvB,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,kBAAkB,EAAE,KAAK,CAAC,QAAQ;YAClC,UAAU;SACb,CAAC;QACF,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;CACJ;AAQD;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,MAAc,EAAE,MAA2B;IACrE,MAAM,EAAE,GAAG,EAAE,sBAAsB,GAAG,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEpE,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC;QAClC,sBAAsB;QACtB,YAAY;QACZ,sBAAsB,EAAE,GAAG,CAAC,sBAAuB;KACtD,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAVD,sCAUC"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023, salesforce.com, inc.
4
- * All rights reserved.
5
- * SPDX-License-Identifier: MIT
6
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./types"), exports);
24
- __exportStar(require("./validate"), exports);
25
- __exportStar(require("./html"), exports);
26
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/parser/expression-complex/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023, salesforce.com, inc.
4
- * All rights reserved.
5
- * SPDX-License-Identifier: MIT
6
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/parser/expression-complex/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -1,141 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023, salesforce.com, inc.
4
- * All rights reserved.
5
- * SPDX-License-Identifier: MIT
6
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.validateExpressionAst = void 0;
33
- const errors_1 = require("@lwc/errors");
34
- const estree_walker_1 = require("estree-walker");
35
- const t = __importStar(require("../../shared/estree"));
36
- const ALWAYS_INVALID_TYPES = new Map(Object.entries({
37
- AwaitExpression: 'await expressions',
38
- ClassExpression: 'classes',
39
- FunctionExpression: 'function expressions',
40
- ImportExpression: 'imports',
41
- MetaProperty: 'import.meta',
42
- NewExpression: 'object instantiation',
43
- RegExpLiteral: 'regular expression literals',
44
- SequenceExpression: 'comma operators',
45
- Super: '`super`',
46
- ThisExpression: '`this`',
47
- YieldExpression: '`yield`',
48
- }));
49
- const STATEMENT_TYPES = new Set([
50
- 'BlockStatement',
51
- 'BreakStatement',
52
- 'ClassDeclaration',
53
- 'ContinueStatement',
54
- 'DebuggerStatement',
55
- 'DeclareClass',
56
- 'DeclareExportAllDeclaration',
57
- 'DeclareExportDeclaration',
58
- 'DeclareFunction',
59
- 'DeclareInterface',
60
- 'DeclareModule',
61
- 'DeclareModuleExports',
62
- 'DeclareOpaqueType',
63
- 'DeclareTypeAlias',
64
- 'DeclareVariable',
65
- 'DoWhileStatement',
66
- 'EmptyStatement',
67
- 'ExportAllDeclaration',
68
- 'ExportDefaultDeclaration',
69
- 'ExportNamedDeclaration',
70
- 'ExpressionStatement',
71
- 'ForInStatement',
72
- 'ForOfStatement',
73
- 'ForStatement',
74
- 'FunctionDeclaration',
75
- 'IfStatement',
76
- 'ImportDeclaration',
77
- 'LabeledStatement',
78
- 'ReturnStatement',
79
- 'Statement',
80
- 'SwitchStatement',
81
- 'ThrowStatement',
82
- 'TryStatement',
83
- 'VariableDeclaration',
84
- 'WhileStatement',
85
- 'WithStatement',
86
- ]);
87
- const MUTATION_TYPES = new Set(['AssignmentExpression', 'UpdateExpression']);
88
- function validateArrowFunction(node) {
89
- (0, errors_1.invariant)(node.body.type !== 'BlockStatement', errors_1.ParserDiagnostics.INVALID_EXPR_ARROW_FN_BODY);
90
- (0, errors_1.invariant)(!node.async, errors_1.ParserDiagnostics.INVALID_EXPR_ARROW_FN_KIND, ['async']);
91
- // This condition should never occur, unless the spec changes. However, it is
92
- // permitted by the ESTree representation, so we'll check for it just in case.
93
- (0, errors_1.invariant)(!node.generator, errors_1.ParserDiagnostics.INVALID_EXPR_ARROW_FN_KIND, ['generators']);
94
- }
95
- function validateUnaryExpression(node) {
96
- (0, errors_1.invariant)(node.operator !== 'delete', errors_1.ParserDiagnostics.INVALID_EXPR_DELETE_OP);
97
- }
98
- function validateLiteral(node) {
99
- // Because there may be a need for a polyfill in older browsers, and because there
100
- // isn't an obvious need for their inclusion, big ints are disallowed in template
101
- // expressions.
102
- (0, errors_1.invariant)(node.bigint === undefined, errors_1.ParserDiagnostics.INVALID_EXPR_PROHIBITED_NODE_TYPE, ['BigInts']);
103
- // Regular expression literals are difficult to visually parse, and
104
- // may be difficult to programatically parse with future parsing methods. For those
105
- // reasons, they are also disallowed.
106
- (0, errors_1.invariant)(node.regex === undefined, errors_1.ParserDiagnostics.INVALID_EXPR_PROHIBITED_NODE_TYPE, ['regular expression literals']);
107
- }
108
- function validateNode(node, _parent, isWithinArrowFn) {
109
- var _a, _b;
110
- (0, errors_1.invariant)(!((_a = node.leadingComments) === null || _a === void 0 ? void 0 : _a.length) && !((_b = node.trailingComments) === null || _b === void 0 ? void 0 : _b.length), errors_1.ParserDiagnostics.INVALID_EXPR_COMMENTS_DISALLOWED);
111
- (0, errors_1.invariant)(!STATEMENT_TYPES.has(node.type), errors_1.ParserDiagnostics.INVALID_EXPR_STATEMENTS_PROHIBITED);
112
- (0, errors_1.invariant)(!(MUTATION_TYPES.has(node.type) && !isWithinArrowFn), errors_1.ParserDiagnostics.INVALID_EXPR_MUTATION_OUTSIDE_ARROW);
113
- (0, errors_1.invariant)(!ALWAYS_INVALID_TYPES.has(node.type), errors_1.ParserDiagnostics.INVALID_EXPR_PROHIBITED_NODE_TYPE, [ALWAYS_INVALID_TYPES.get(node.type)]);
114
- if (t.isArrowFunctionExpression(node)) {
115
- validateArrowFunction(node);
116
- }
117
- else if (t.isUnaryExpression(node)) {
118
- validateUnaryExpression(node);
119
- }
120
- else if (t.isLiteral(node)) {
121
- validateLiteral(node);
122
- }
123
- }
124
- function validateExpressionAst(rootNode) {
125
- let arrowFnScopeDepth = 0;
126
- (0, estree_walker_1.walk)(rootNode, {
127
- enter(node, parent) {
128
- validateNode(node, parent, !!arrowFnScopeDepth);
129
- if (t.isArrowFunctionExpression(node)) {
130
- arrowFnScopeDepth++;
131
- }
132
- },
133
- leave(node) {
134
- if (t.isArrowFunctionExpression(node)) {
135
- arrowFnScopeDepth--;
136
- }
137
- },
138
- });
139
- }
140
- exports.validateExpressionAst = validateExpressionAst;
141
- //# sourceMappingURL=validate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/parser/expression-complex/validate.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,wCAA2D;AAC3D,iDAAqC;AACrC,uDAAyC;AAGzC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAChC,MAAM,CAAC,OAAO,CAAC;IACX,eAAe,EAAE,mBAAmB;IACpC,eAAe,EAAE,SAAS;IAC1B,kBAAkB,EAA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