@@ -39,6 +39,10 @@ import type {
3939} from '@lwc/template-compiler' ;
4040import type { TransformerContext } from '../../types' ;
4141
42+ // This function will be defined once and hoisted to the top of the template function. It'll be
43+ // referenced deeper in the call stack where the function is called or passed as a parameter.
44+ // It is a higher-order function that curries local variables that may be referenced by the
45+ // shadow slot content.
4246const bGenerateShadowSlottedContent = esTemplateWithYield `
4347 const ${ /* function name */ is . identifier } = (${ /* local vars */ is . identifier } ) => async function* ${ /* function name */ 0 } (contextfulParent) {
4448 // The 'contextfulParent' variable is shadowed here so that a contextful relationship
@@ -47,17 +51,20 @@ const bGenerateShadowSlottedContent = esTemplateWithYield`
4751 ${ /* shadow slot content */ is . statement }
4852 };
4953` < EsVariableDeclaration > ;
54+ // By passing in the set of local variables (which correspond 1:1 to the variables expected by
55+ // the referenced function), `shadowSlottedContent` will be curried function that can generate
56+ // shadow-slotted content.
5057const bGenerateShadowSlottedContentRef = esTemplateWithYield `
5158 const shadowSlottedContent = ${ /* reference to hoisted fn */ is . identifier } (${ /* local vars */ is . identifier } );
5259` < EsVariableDeclaration > ;
5360const bNullishGenerateShadowSlottedContent = esTemplateWithYield `
5461 const shadowSlottedContent = null;
5562` < EsVariableDeclaration > ;
5663
57- const bContentMap = esTemplateWithYield `
64+ const blightSlottedContentMap = esTemplateWithYield `
5865 const ${ /* name of the content map */ is . identifier } = Object.create(null);
5966` < EsVariableDeclaration > ;
60- const bNullishContentMap = esTemplateWithYield `
67+ const bNullishLightSlottedContentMap = esTemplateWithYield `
6168 const ${ /* name of the content map */ is . identifier } = null;
6269` < EsVariableDeclaration > ;
6370
@@ -298,11 +305,11 @@ export function getSlottedContent(
298305 )
299306 : bNullishGenerateShadowSlottedContent ( ) ;
300307 const lightSlottedContentMap = hasLightSlottedContent
301- ? bContentMap ( b . identifier ( 'lightSlottedContentMap' ) )
302- : bNullishContentMap ( b . identifier ( 'lightSlottedContentMap' ) ) ;
308+ ? blightSlottedContentMap ( b . identifier ( 'lightSlottedContentMap' ) )
309+ : bNullishLightSlottedContentMap ( b . identifier ( 'lightSlottedContentMap' ) ) ;
303310 const scopedSlottedContentMap = hasScopedSlottedContent
304- ? bContentMap ( b . identifier ( 'scopedSlottedContentMap' ) )
305- : bNullishContentMap ( b . identifier ( 'scopedSlottedContentMap' ) ) ;
311+ ? blightSlottedContentMap ( b . identifier ( 'scopedSlottedContentMap' ) )
312+ : bNullishLightSlottedContentMap ( b . identifier ( 'scopedSlottedContentMap' ) ) ;
306313
307314 return bGenerateSlottedContent (
308315 shadowSlottedContentFn ,
0 commit comments