Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@lwc/errors/src/compiler/error-info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
/**
* Next error code: 1211
* Next error code: 1212
*/

export * from './compiler';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,4 +1020,11 @@ export const ParserDiagnostics = {
level: DiagnosticLevel.Error,
url: '',
},

RESERVED_KEYWORD_AS_IDENTIFIER: {
code: 1211,
message: '{0} is a reserved keyword and cannot be used as an identifier.',
level: DiagnosticLevel.Error,
url: '',
},
} as const satisfies Record<string, LWCErrorInfo>;
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
}
},
{
"code": 1059,
"message": "LWC1059: const is not a valid identifier",
"code": 1211,
"message": "LWC1211: const is a reserved keyword and cannot be used as an identifier.",
"level": 1,
"location": {
"line": 3,
Expand Down
7 changes: 6 additions & 1 deletion packages/@lwc/template-compiler/src/parser/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ export function parseIdentifier(
isValid = isIdentifierChar(source.charCodeAt(i));
}

if (isValid && !isReservedES6Keyword(source)) {
if (isValid) {
if (isReservedES6Keyword(source)) {
ctx.throwAtLocation(ParserDiagnostics.RESERVED_KEYWORD_AS_IDENTIFIER, location, [
source,
]);
}
return {
...t.identifier(source),
location,
Expand Down