@@ -74,10 +74,12 @@ const visitors: Visitors = {
7474 return ;
7575 }
7676 const source = path . node ! . source ! ;
77- // 1. insert `import { load as __load } from '${loader}'` at top of program
78- importManager . add ( { load : '__load' } , loader ) ;
79- // 2. replace this import with `__load(${source})`
80- path . replaceWith ( b . callExpression ( b . identifier ( '__load' ) , [ structuredClone ( source ) ] ) ) ;
77+ // 1. insert `import { load as __lwcLoad } from '${loader}'` at top of program
78+ importManager . add ( { load : '__lwcLoad' } , loader ) ;
79+ // 2. replace this `import(source)` with `__lwcLoad(source)`
80+ const load = b . identifier ( '__lwcLoad' ) ;
81+ state . trustedLwcIdentifiers . add ( load ) ;
82+ path . replaceWith ( b . callExpression ( load , [ structuredClone ( source ) ] ) ) ;
8183 } ,
8284 ClassDeclaration ( path , state ) {
8385 const { node } = path ;
@@ -246,9 +248,9 @@ const visitors: Visitors = {
246248 }
247249 } ,
248250 } ,
249- Identifier ( path , _state ) {
251+ Identifier ( path , state ) {
250252 const { node } = path ;
251- if ( node ?. name . startsWith ( '__lwc' ) ) {
253+ if ( node ?. name . startsWith ( '__lwc' ) && ! state . trustedLwcIdentifiers . has ( node ) ) {
252254 throw generateError ( node , SsrCompilerErrors . RESERVED_IDENTIFIER_PREFIX ) ;
253255 }
254256 } ,
@@ -286,6 +288,7 @@ export default function compileJS(
286288 wireAdapters : [ ] ,
287289 experimentalDynamicComponent : options . experimentalDynamicComponent ,
288290 importManager : new ImportManager ( ) ,
291+ trustedLwcIdentifiers : new WeakSet ( ) ,
289292 } ;
290293
291294 traverse ( ast , visitors , state ) ;
0 commit comments