@@ -3,7 +3,7 @@ import { camelize, capitalize } from '@vue/shared';
3
3
import type { Code , VueCodeInformation } from '../../types' ;
4
4
import { getSlotsPropertyName , hyphenateTag } from '../../utils/shared' ;
5
5
import { createVBindShorthandInlayHintInfo } from '../inlayHints' ;
6
- import { collectVars , createTsAst , endOfLine , newLine , normalizeAttributeValue , variableNameRegex , wrapWith } from '../utils' ;
6
+ import { endOfLine , newLine , normalizeAttributeValue , variableNameRegex , wrapWith } from '../utils' ;
7
7
import { generateCamelized } from '../utils/camelized' ;
8
8
import type { TemplateCodegenContext } from './context' ;
9
9
import { generateElementChildren } from './elementChildren' ;
@@ -12,10 +12,9 @@ import { generateElementEvents } from './elementEvents';
12
12
import { type FailedPropExpression , generateElementProps } from './elementProps' ;
13
13
import type { TemplateCodegenOptions } from './index' ;
14
14
import { generateInterpolation } from './interpolation' ;
15
- import { generateObjectProperty } from './objectProperty' ;
16
15
import { generatePropertyAccess } from './propertyAccess' ;
17
16
import { collectStyleScopedClassReferences } from './styleScopedClasses' ;
18
- import { generateTemplateChild } from './templateChild ' ;
17
+ import { generateVSlot } from './vSlot ' ;
19
18
20
19
const colonReg = / : / g;
21
20
@@ -43,7 +42,6 @@ export function* generateComponent(
43
42
const isComponentTag = node . tag . toLowerCase ( ) === 'component' ;
44
43
45
44
ctx . currentComponent = {
46
- node,
47
45
ctxVar : var_defineComponentCtx ,
48
46
used : false
49
47
} ;
@@ -285,10 +283,10 @@ export function* generateComponent(
285
283
286
284
const slotDir = node . props . find ( p => p . type === CompilerDOM . NodeTypes . DIRECTIVE && p . name === 'slot' ) as CompilerDOM . DirectiveNode ;
287
285
if ( slotDir ) {
288
- yield * generateComponentSlot ( options , ctx , node , slotDir ) ;
286
+ yield * generateVSlot ( options , ctx , node , slotDir ) ;
289
287
}
290
288
else {
291
- yield * generateElementChildren ( options , ctx , node ) ;
289
+ yield * generateElementChildren ( options , ctx , node , true ) ;
292
290
}
293
291
294
292
if ( ctx . currentComponent . used ) {
@@ -308,7 +306,7 @@ export function* generateElement(
308
306
: undefined ;
309
307
const failedPropExps : FailedPropExpression [ ] = [ ] ;
310
308
311
- yield `__VLS_elementAsFunction (__VLS_intrinsicElements` ;
309
+ yield `__VLS_asFunctionalElement (__VLS_intrinsicElements` ;
312
310
yield * generatePropertyAccess (
313
311
options ,
314
312
ctx ,
@@ -351,17 +349,11 @@ export function* generateElement(
351
349
ctx . singleRootElType = `typeof __VLS_nativeElements['${ node . tag } ']` ;
352
350
}
353
351
354
- const slotDir = node . props . find ( p => p . type === CompilerDOM . NodeTypes . DIRECTIVE && p . name === 'slot' ) as CompilerDOM . DirectiveNode ;
355
- if ( slotDir && ctx . currentComponent ) {
356
- yield * generateComponentSlot ( options , ctx , node , slotDir ) ;
357
- }
358
- else {
359
- yield * generateElementChildren ( options , ctx , node ) ;
360
- }
361
-
362
352
if ( hasVBindAttrs ( options , ctx , node ) ) {
363
353
ctx . inheritedAttrVars . add ( `__VLS_intrinsicElements.${ node . tag } ` ) ;
364
354
}
355
+
356
+ yield * generateElementChildren ( options , ctx , node ) ;
365
357
}
366
358
367
359
function * generateFailedPropExps (
@@ -479,105 +471,6 @@ function* generateComponentGeneric(
479
471
ctx . lastGenericComment = undefined ;
480
472
}
481
473
482
- function * generateComponentSlot (
483
- options : TemplateCodegenOptions ,
484
- ctx : TemplateCodegenContext ,
485
- node : CompilerDOM . ElementNode ,
486
- slotDir : CompilerDOM . DirectiveNode
487
- ) : Generator < Code > {
488
- yield `{${ newLine } ` ;
489
- if ( ctx . currentComponent ) {
490
- ctx . currentComponent . used = true ;
491
- ctx . hasSlotElements . add ( ctx . currentComponent . node ) ;
492
- }
493
- const slotBlockVars : string [ ] = [ ] ;
494
- yield `const {` ;
495
- if ( slotDir ?. arg ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION && slotDir . arg . content ) {
496
- yield * generateObjectProperty (
497
- options ,
498
- ctx ,
499
- slotDir . arg . loc . source ,
500
- slotDir . arg . loc . start . offset ,
501
- slotDir . arg . isStatic ? ctx . codeFeatures . withoutHighlight : ctx . codeFeatures . all ,
502
- slotDir . arg . loc ,
503
- false ,
504
- true
505
- ) ;
506
- }
507
- else {
508
- yield * wrapWith (
509
- slotDir . loc . start . offset ,
510
- slotDir . loc . start . offset + ( slotDir . rawName ?. length ?? 0 ) ,
511
- ctx . codeFeatures . withoutHighlightAndCompletion ,
512
- `default`
513
- ) ;
514
- }
515
- yield `: __VLS_thisSlot } = ${ ctx . currentComponent ! . ctxVar } .slots!${ endOfLine } ` ;
516
-
517
- if ( slotDir ?. exp ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION ) {
518
- const slotAst = createTsAst ( options . ts , slotDir , `(${ slotDir . exp . content } ) => {}` ) ;
519
- collectVars ( options . ts , slotAst , slotAst , slotBlockVars ) ;
520
- if ( ! slotDir . exp . content . includes ( ':' ) ) {
521
- yield `const [` ;
522
- yield [
523
- slotDir . exp . content ,
524
- 'template' ,
525
- slotDir . exp . loc . start . offset ,
526
- ctx . codeFeatures . all ,
527
- ] ;
528
- yield `] = __VLS_getSlotParams(__VLS_thisSlot)${ endOfLine } ` ;
529
- }
530
- else {
531
- yield `const ` ;
532
- yield [
533
- slotDir . exp . content ,
534
- 'template' ,
535
- slotDir . exp . loc . start . offset ,
536
- ctx . codeFeatures . all ,
537
- ] ;
538
- yield ` = __VLS_getSlotParam(__VLS_thisSlot)${ endOfLine } ` ;
539
- }
540
- }
541
-
542
- for ( const varName of slotBlockVars ) {
543
- ctx . addLocalVariable ( varName ) ;
544
- }
545
-
546
- yield * ctx . resetDirectiveComments ( 'end of slot children start' ) ;
547
-
548
- let prev : CompilerDOM . TemplateChildNode | undefined ;
549
- for ( const childNode of node . children ) {
550
- yield * generateTemplateChild ( options , ctx , childNode , prev ) ;
551
- prev = childNode ;
552
- }
553
-
554
- for ( const varName of slotBlockVars ) {
555
- ctx . removeLocalVariable ( varName ) ;
556
- }
557
- let isStatic = true ;
558
- if ( slotDir ?. arg ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION ) {
559
- isStatic = slotDir . arg . isStatic ;
560
- }
561
- if ( isStatic && slotDir && ! slotDir . arg ) {
562
- yield `${ ctx . currentComponent ! . ctxVar } .slots!['` ;
563
- yield [
564
- '' ,
565
- 'template' ,
566
- slotDir . loc . start . offset + (
567
- slotDir . loc . source . startsWith ( '#' )
568
- ? '#' . length : slotDir . loc . source . startsWith ( 'v-slot:' )
569
- ? 'v-slot:' . length
570
- : 0
571
- ) ,
572
- ctx . codeFeatures . completion ,
573
- ] ;
574
- yield `'/* empty slot name completion */]${ newLine } ` ;
575
- }
576
-
577
- yield * ctx . generateAutoImportCompletion ( ) ;
578
- yield `}${ newLine } ` ;
579
- }
580
-
581
474
function * generateReferencesForElements (
582
475
options : TemplateCodegenOptions ,
583
476
ctx : TemplateCodegenContext ,
0 commit comments