diff --git a/packages/@lwc/ssr-compiler/src/compile-js/index.ts b/packages/@lwc/ssr-compiler/src/compile-js/index.ts index 5263e77680..eecb39860a 100644 --- a/packages/@lwc/ssr-compiler/src/compile-js/index.ts +++ b/packages/@lwc/ssr-compiler/src/compile-js/index.ts @@ -244,7 +244,7 @@ const visitors: Visitors = { }, Identifier(path, _state) { const { node } = path; - if (node?.name.startsWith('__lwc') && node.name.endsWith('__')) { + if (node?.name.startsWith('__lwc')) { // TODO [#5032]: Harmonize errors thrown in `@lwc/ssr-compiler` throw new Error(`LWCTODO: identifier name '${node.name}' cannot start with '__lwc'`); } diff --git a/packages/@lwc/ssr-compiler/src/estemplate.ts b/packages/@lwc/ssr-compiler/src/estemplate.ts index 6df0148fa0..3bceadec0d 100644 --- a/packages/@lwc/ssr-compiler/src/estemplate.ts +++ b/packages/@lwc/ssr-compiler/src/estemplate.ts @@ -20,6 +20,12 @@ import type { Checker } from 'estree-toolkit/dist/generated/is-type'; /** Placeholder value to use to opt out of validation. */ const NO_VALIDATION = false; +/** + * `esTemplate` generates JS code with "holes" to be filled later. In order to have a valid AST, + * it uses identifiers with this prefix at the location of the holes. + */ +const PLACEHOLDER_PREFIX = '__lwc_ESTEMPLATE_PLACEHOLDER__'; + /** A function that accepts a node and checks that it is a particular type of node. */ type Validator = ( node: EsNode | null | undefined @@ -65,8 +71,6 @@ type ToReplacementParameters = Arr extends [infer Head, . [ValidatedType, ...ToReplacementParameters] : []; // `Arr` is an empty array -- nothing to transform -const PLACEHOLDER_PREFIX = `__ESTEMPLATE_${Math.random().toString().slice(2)}_PLACEHOLDER__`; - interface TraversalState { placeholderToValidator: Map; replacementNodes: Array;