File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
packages/@lwc/template-compiler/src/parser Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ export function validateComplexExpression(
201201 expression: Expression;
202202 raw: string;
203203} {
204- const leadingChars = source.slice(expressionStart + 1 , expression.start);
204+ const leadingChars = source.slice(expressionStart + OPENING_CURLY_LEN , expression.start);
205205 const trailingChars = getTrailingChars(source.slice(expression.end));
206206 const idxOfClosingBracket = expression.end + trailingChars.length;
207207 // Capture text content between the outer curly braces, inclusive.
@@ -239,7 +239,7 @@ export function validateComplexExpression(
239239 invariant(
240240 expression.end === templateExpression.end,
241241 ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR,
242- ['Expression incorrectly formed']
242+ ['expression incorrectly formed']
243243 );
244244
245245 return {
Original file line number Diff line number Diff line change @@ -518,14 +518,16 @@ function parseTextComplex(
518518 index
519519 );
520520 parsedTextNodes.push(ast.text(parsed.raw, parsed.expression, location));
521+
522+ // Parse the remainder of the text node for expressions
521523 index += parsed.raw.length;
522524 start = index;
523525 continue;
524526 }
525527 index++;
526528 }
527529
528- // Parse any literal that followed the expression
530+ // Parse any remaining literal
529531 if (start < rawText.length) {
530532 const literalToken = rawText.slice(start, index);
531533 parsedTextNodes.push(
@@ -1914,6 +1916,13 @@ function getTemplateAttribute(
19141916
19151917 let attrValue: Literal | Expression;
19161918
1919+ /*
1920+ A complex attribute expression should only be parsed as a complex expression if it has been quoted.
1921+ Quoting complex expressions ensures that the expression is valid HTML. If the complex expression
1922+ has not been quoted, then it is parsed as a legacy expression and it will fail with an appropriate explanation.
1923+ This ensures backward compatibility with legacy expressions which do not require, or currently permit quotes
1924+ to be used.
1925+ */
19171926 const isPotentialComplexExpression =
19181927 quotedExpression && !escapedExpression && value.startsWith(EXPRESSION_SYMBOL_START);
19191928 if (ctx.config.experimentalComplexExpressions && isPotentialComplexExpression) {
You can’t perform that action at this time.
0 commit comments