Skip to content

Commit cbbddf5

Browse files
chore: add comments
1 parent fe7a030 commit cbbddf5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/@lwc/template-compiler/src/parser/expression-complex/validate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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 {

packages/@lwc/template-compiler/src/parser/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)