Skip to content

Commit

Permalink
chore: add TMPL_EXPR_ECMASCRIPT_EDITION constant
Browse files Browse the repository at this point in the history
  • Loading branch information
divmain committed Mar 6, 2023
1 parent ae5fc8c commit 9b9fc3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/@lwc/template-compiler/src/parser/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@ export const ATTR_NAME = {
XLINK_HREF: 'xlink:href',
};
export const TEMPLATE_DIRECTIVES = [/^key$/, /^lwc:*/, /^if:*/, /^for:*/, /^iterator:*/];

// TODO [#3370]: remove experimental template expression flag
export const TMPL_EXPR_ECMASCRIPT_EDITION = 2022;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Document, DocumentFragment, ParsingError, ParserOptions } from 'parse5'
import { ParserDiagnostics, invariant } from '@lwc/errors';
import Parser from 'parse5/lib/parser';
import Tokenizer from 'parse5/lib/tokenizer';
import { TMPL_EXPR_ECMASCRIPT_EDITION } from '../constants';
import type ParserCtx from '../parser';
import type { PreparsedExpressionMap } from './types';

Expand Down Expand Up @@ -55,7 +56,7 @@ class TemplateHtmlTokenizer extends Tokenizer {

// Start parsing immediately after the opening curly brace.
const estreeNode = parseExpressionAt(html, javascriptExprStart, {
ecmaVersion: 2022,
ecmaVersion: TMPL_EXPR_ECMASCRIPT_EDITION,
locations: true,
ranges: true,
onComment: () => invariant(false, ParserDiagnostics.INVALID_EXPR_COMMENTS_DISALLOWED),
Expand Down
5 changes: 4 additions & 1 deletion packages/@lwc/template-compiler/src/parser/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as t from '../shared/estree';
import { NormalizedConfig } from '../config';
import { Expression, Identifier, SourceLocation } from '../shared/types';
import { validateExpressionAst } from './expression-complex';
import { TMPL_EXPR_ECMASCRIPT_EDITION } from './constants';

import ParserCtx from './parser';
import { isReservedES6Keyword } from './utils/javascript';
Expand Down Expand Up @@ -103,7 +104,9 @@ export function parseExpression(
source: string,
location: SourceLocation
): Expression {
const ecmaVersion = ctx.config.experimentalComplexExpressions ? 2022 : 2020;
const ecmaVersion = ctx.config.experimentalComplexExpressions
? TMPL_EXPR_ECMASCRIPT_EDITION
: 2020;
return ctx.withErrorWrapping(
() => {
const parsed = parseExpressionAt(source, 1, { ecmaVersion });
Expand Down

0 comments on commit 9b9fc3d

Please sign in to comment.