@lwc/template-compiler 6.3.1 → 6.3.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.
package/dist/index.cjs.js CHANGED
@@ -10685,7 +10685,10 @@ class TemplateHtmlTokenizer extends Tokenizer {
10685
10685
  errors.invariant(html.codePointAt(idxOfClosingBracket) === CLOSING_CURLY_BRACKET, errors.ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR, ['expression must end with curly brace.']);
10686
10686
  // Parsed expressions that are cached here will be later retrieved when the
10687
10687
  // LWC template AST is being constructed.
10688
- this.parser.preparsedJsExpressions.set(expressionStart, estreeNode);
10688
+ this.parser.preparsedJsExpressions.set(expressionStart, {
10689
+ parsedExpression: estreeNode,
10690
+ rawText: expressionTextNodeValue,
10691
+ });
10689
10692
  return expressionTextNodeValue;
10690
10693
  }
10691
10694
  // ATTRIBUTE_VALUE_UNQUOTED_STATE is entered when an opening tag is being parsed,
@@ -10978,6 +10981,22 @@ function validateSourceIsParsedExpression(source, parsedExpression) {
10978
10981
  'Unexpected end of expression',
10979
10982
  ]);
10980
10983
  }
10984
+ function validatePreparsedJsExpressions(ctx) {
10985
+ ctx.preparsedJsExpressions?.forEach(({ parsedExpression, rawText }) => {
10986
+ const acornLoc = parsedExpression.loc;
10987
+ const parse5Loc = {
10988
+ startLine: acornLoc.start.line,
10989
+ startCol: acornLoc.start.column,
10990
+ startOffset: parsedExpression.start,
10991
+ endLine: acornLoc.end.line,
10992
+ endCol: acornLoc.end.column,
10993
+ endOffset: parsedExpression.end,
10994
+ };
10995
+ ctx.withErrorWrapping(() => {
10996
+ validateExpressionAst(parsedExpression);
10997
+ }, errors.ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR, sourceLocation(parse5Loc), (err) => `Invalid expression ${rawText} - ${err.message}`);
10998
+ });
10999
+ }
10981
11000
  function parseExpression(ctx, source, location) {
10982
11001
  const { ecmaVersion } = ctx;
10983
11002
  return ctx.withErrorWrapping(() => {
@@ -11265,6 +11284,7 @@ function parse$1(source, state) {
11265
11284
  return { warnings: ctx.warnings };
11266
11285
  }
11267
11286
  const root = ctx.withErrorRecovery(() => {
11287
+ validatePreparsedJsExpressions(ctx);
11268
11288
  const templateRoot = getTemplateRoot(ctx, fragment);
11269
11289
  return parseRoot(ctx, templateRoot);
11270
11290
  });
@@ -11527,12 +11547,12 @@ function parseText(ctx, parse5Text) {
11527
11547
  // Implementation of the lexer ensures that each text-node template expression
11528
11548
  // will be contained in its own text node. Adjacent static text will be in
11529
11549
  // separate text nodes.
11530
- const preparsedExpression = ctx.preparsedJsExpressions.get(location.startOffset);
11531
- if (!preparsedExpression) {
11550
+ const entry = ctx.preparsedJsExpressions.get(location.startOffset);
11551
+ if (!entry?.parsedExpression) {
11532
11552
  throw new Error('Implementation error: cannot find preparsed template expression');
11533
11553
  }
11534
11554
  const value = {
11535
- ...preparsedExpression,
11555
+ ...entry.parsedExpression,
11536
11556
  location: sourceLocation(location),
11537
11557
  };
11538
11558
  return [text(rawText, value, location)];
@@ -12805,13 +12825,13 @@ function bindComplexExpression(expression, codeGen) {
12805
12825
  },
12806
12826
  leave(node, parent) {
12807
12827
  if (isArrowFunctionExpression(node)) {
12808
- expressionScopes.exitScope(node);
12828
+ return expressionScopes.exitScope(node);
12809
12829
  }
12810
- else if (parent !== null &&
12811
- isIdentifier(node) &&
12812
- // Acorn parses `undefined` as an Identifier.
12813
- node.name !== 'undefined' &&
12814
- !(isMemberExpression(parent) && parent.property === node) &&
12830
+ // Acorn parses `undefined` as an Identifier.
12831
+ const isIdentifier$1 = isIdentifier(node) && node.name !== 'undefined';
12832
+ if (parent !== null &&
12833
+ isIdentifier$1 &&
12834
+ !(isMemberExpression(parent) && parent.property === node && !parent.computed) &&
12815
12835
  !(isProperty$1(parent) && parent.key === node) &&
12816
12836
  !codeGen.isLocalIdentifier(node) &&
12817
12837
  !expressionScopes.isScopedToExpression(node)) {
@@ -14039,5 +14059,5 @@ function compile(source, config) {
14039
14059
  exports.compile = compile;
14040
14060
  exports.default = compile;
14041
14061
  exports.parse = parse;
14042
- /** version: 6.3.1 */
14062
+ /** version: 6.3.3 */
14043
14063
  //# sourceMappingURL=index.cjs.js.map