@@ -259,13 +259,26 @@ export function* generateComponent(
259
259
yield endOfLine ;
260
260
}
261
261
262
- yield * generateVScope ( options , ctx , node , props ) ;
262
+ const refName = yield * generateVScope ( options , ctx , node , props ) ;
263
263
264
264
ctx . usedComponentCtxVars . add ( componentCtxVar ) ;
265
265
const usedComponentEventsVar = yield * generateElementEvents ( options , ctx , node , var_functionalComponent , var_componentInstance , var_componentEmit , var_componentEvents ) ;
266
266
267
267
if ( var_defineComponentCtx && ctx . usedComponentCtxVars . has ( var_defineComponentCtx ) ) {
268
268
yield `const ${ componentCtxVar } = __VLS_nonNullable(__VLS_pickFunctionalComponentCtx(${ var_originalComponent } , ${ var_componentInstance } ))${ endOfLine } ` ;
269
+ if ( refName ) {
270
+ yield `// @ts-ignore${ newLine } ` ;
271
+ if ( node . codegenNode ?. type === CompilerDOM . NodeTypes . VNODE_CALL
272
+ && node . codegenNode . props ?. type === CompilerDOM . NodeTypes . JS_OBJECT_EXPRESSION
273
+ && node . codegenNode . props . properties . find ( ( { key } ) => key . type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION && key . content === 'ref_for' )
274
+ ) {
275
+ yield `(${ refName } ??= []).push(${ var_defineComponentCtx } )` ;
276
+ } else {
277
+ yield `${ refName } = ${ var_defineComponentCtx } ` ;
278
+ }
279
+
280
+ yield endOfLine ;
281
+ }
269
282
}
270
283
if ( usedComponentEventsVar ) {
271
284
yield `let ${ var_componentEmit } !: typeof ${ componentCtxVar } .emit${ endOfLine } ` ;
@@ -350,7 +363,17 @@ export function* generateElement(
350
363
yield endOfLine ;
351
364
}
352
365
353
- yield * generateVScope ( options , ctx , node , node . props ) ;
366
+ const refName = yield * generateVScope ( options , ctx , node , node . props ) ;
367
+ if ( refName ) {
368
+ yield `// @ts-ignore${ newLine } ` ;
369
+ yield `${ refName } = __VLS_intrinsicElements` ;
370
+ yield * generatePropertyAccess (
371
+ options ,
372
+ ctx ,
373
+ node . tag
374
+ ) ;
375
+ yield endOfLine ;
376
+ }
354
377
355
378
const slotDir = node . props . find ( p => p . type === CompilerDOM . NodeTypes . DIRECTIVE && p . name === 'slot' ) as CompilerDOM . DirectiveNode ;
356
379
if ( slotDir && componentCtxVar ) {
@@ -397,13 +420,14 @@ function* generateVScope(
397
420
}
398
421
399
422
yield * generateElementDirectives ( options , ctx , node ) ;
400
- yield * generateReferencesForElements ( options , ctx , node ) ; // <el ref="foo" />
423
+ const refName = yield * generateReferencesForElements ( options , ctx , node ) ; // <el ref="foo" />
401
424
yield * generateReferencesForScopedCssClasses ( options , ctx , node ) ;
402
425
403
426
if ( inScope ) {
404
427
yield `}${ newLine } ` ;
405
428
ctx . blockConditions . length = originalConditionsNum ;
406
429
}
430
+ return refName ;
407
431
}
408
432
409
433
export function getCanonicalComponentName ( tagText : string ) {
@@ -571,6 +595,10 @@ function* generateReferencesForElements(
571
595
')'
572
596
) ;
573
597
yield endOfLine ;
598
+
599
+ const refName = CompilerDOM . toValidAssetId ( prop . value . content , '_VLS_refs' as any ) ;
600
+ options . templateRefNames . set ( prop . value . content , refName ) ;
601
+ return refName ;
574
602
}
575
603
}
576
604
}
0 commit comments