@@ -2,31 +2,26 @@ import * as CompilerDOM from '@vue/compiler-dom';
22import type * as ts from 'typescript' ;
33import type { Code , Sfc , VueCompilerOptions } from '../../types' ;
44import { endOfLine , newLine , wrapWith } from '../common' ;
5- import { createTemplateCodegenContext } from './context' ;
5+ import { TemplateCodegenContext , createTemplateCodegenContext } from './context' ;
66import { getCanonicalComponentName , getPossibleOriginalComponentNames } from './element' ;
77import { generateObjectProperty } from './objectProperty' ;
8- import { generateStringLiteralKey } from './stringLiteralKey' ;
98import { generateTemplateChild , getVForNode } from './templateChild' ;
109
1110export interface TemplateCodegenOptions {
1211 ts : typeof ts ;
1312 compilerOptions : ts . CompilerOptions ;
1413 vueCompilerOptions : VueCompilerOptions ;
1514 template : NonNullable < Sfc [ 'template' ] > ;
16- shouldGenerateScopedClasses ?: boolean ;
17- stylesScopedClasses : Set < string > ;
1815 scriptSetupBindingNames : Set < string > ;
1916 scriptSetupImportComponentNames : Set < string > ;
2017 hasDefineSlots ?: boolean ;
2118 slotsAssignName ?: string ;
2219 propsAssignName ?: string ;
2320}
2421
25- export function * generateTemplate ( options : TemplateCodegenOptions ) : Generator < Code > {
22+ export function * generateTemplate ( options : TemplateCodegenOptions ) : Generator < Code , TemplateCodegenContext > {
2623 const ctx = createTemplateCodegenContext ( options . scriptSetupBindingNames ) ;
2724
28- let hasSlot = false ;
29-
3025 if ( options . slotsAssignName ) {
3126 ctx . addLocalVariable ( options . slotsAssignName ) ;
3227 }
@@ -50,19 +45,16 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
5045
5146 yield * ctx . generateAutoImportCompletion ( ) ;
5247
53- return {
54- ctx,
55- hasSlot,
56- } ;
48+ return ctx ;
5749
5850 function * generateSlotsType ( ) : Generator < Code > {
5951 for ( const { expVar, varName } of ctx . dynamicSlots ) {
60- hasSlot = true ;
52+ ctx . hasSlot = true ;
6153 yield `Partial<Record<NonNullable<typeof ${ expVar } >, (_: typeof ${ varName } ) => any>> &${ newLine } ` ;
6254 }
6355 yield `{${ newLine } ` ;
6456 for ( const slot of ctx . slots ) {
65- hasSlot = true ;
57+ ctx . hasSlot = true ;
6658 if ( slot . name && slot . loc !== undefined ) {
6759 yield * generateObjectProperty (
6860 options ,
@@ -96,14 +88,26 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
9688 yield `if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {${ newLine } ` ;
9789 for ( const { className, offset } of ctx . scopedClasses ) {
9890 yield `__VLS_styleScopedClasses[` ;
99- yield * generateStringLiteralKey (
91+ yield [
92+ '' ,
93+ 'template' ,
94+ offset ,
95+ ctx . codeFeatures . navigationWithoutRename ,
96+ ] ;
97+ yield `'` ;
98+ yield [
10099 className ,
100+ 'template' ,
101101 offset ,
102- {
103- ...ctx . codeFeatures . navigationAndCompletion ,
104- __displayWithLink : options . stylesScopedClasses . has ( className ) ,
105- } ,
106- ) ;
102+ ctx . codeFeatures . navigationAndCompletion ,
103+ ] ;
104+ yield `'` ;
105+ yield [
106+ '' ,
107+ 'template' ,
108+ offset + className . length ,
109+ ctx . codeFeatures . navigationWithoutRename ,
110+ ] ;
107111 yield `]${ endOfLine } ` ;
108112 }
109113 yield `}${ newLine } ` ;
0 commit comments