Skip to content
Merged
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/ssr-compiler/src/compile-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The placeholder variables all end in a number, rather than __, and it's easier to eliminate this arbitrary constraint than refactor the placeholder code.

// TODO [#5032]: Harmonize errors thrown in `@lwc/ssr-compiler`
throw new Error(`LWCTODO: identifier name '${node.name}' cannot start with '__lwc'`);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/@lwc/ssr-compiler/src/estemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends EsNode | null = EsNode | null> = (
node: EsNode | null | undefined
Expand Down Expand Up @@ -65,8 +71,6 @@ type ToReplacementParameters<Arr extends unknown[]> = Arr extends [infer Head, .
[ValidatedType<Head>, ...ToReplacementParameters<Rest>]
: []; // `Arr` is an empty array -- nothing to transform

const PLACEHOLDER_PREFIX = `__ESTEMPLATE_${Math.random().toString().slice(2)}_PLACEHOLDER__`;

interface TraversalState {
placeholderToValidator: Map<number, Validator>;
replacementNodes: Array<EsNode | EsNode[] | null>;
Expand Down