@@ -17,7 +17,6 @@ export function* generateScriptSetupImports(
17
17
0 ,
18
18
codeFeatures . all ,
19
19
] ;
20
- yield newLine ;
21
20
}
22
21
23
22
export function * generateScriptSetup (
@@ -96,16 +95,6 @@ function* generateSetupFunction(
96
95
scriptSetupRanges : ScriptSetupRanges ,
97
96
syntax : 'return' | 'export default' | undefined
98
97
) : Generator < Code > {
99
- if ( options . vueCompilerOptions . target >= 3.3 ) {
100
- yield `const { ` ;
101
- for ( const macro of Object . keys ( options . vueCompilerOptions . macros ) ) {
102
- if ( ! ctx . bindingNames . has ( macro ) && macro !== 'templateRef' ) {
103
- yield macro + `, ` ;
104
- }
105
- }
106
- yield `} = await import('${ options . vueCompilerOptions . lib } ')${ endOfLine } ` ;
107
- }
108
-
109
98
ctx . scriptSetupGeneratedOffset = options . getGeneratedLength ( ) - scriptSetupRanges . importSectionEndOffset ;
110
99
111
100
let setupCodeModifies : [ Code [ ] , number , number ] [ ] = [ ] ;
@@ -280,6 +269,8 @@ function* generateSetupFunction(
280
269
yield generateSfcBlockSection ( scriptSetup , nextStart , scriptSetup . content . length , codeFeatures . all ) ;
281
270
282
271
yield * generateScriptSectionPartiallyEnding ( scriptSetup . name , scriptSetup . content . length , '#3632/scriptSetup.vue' ) ;
272
+ yield * generateMacros ( options , ctx ) ;
273
+ yield * generateDefineProp ( options , scriptSetup ) ;
283
274
284
275
if ( scriptSetupRanges . defineProps ?. typeArg && scriptSetupRanges . withDefaults ?. arg ) {
285
276
// fix https://github.com/vuejs/language-tools/issues/1187
@@ -317,6 +308,42 @@ function* generateSetupFunction(
317
308
}
318
309
}
319
310
311
+ function * generateMacros (
312
+ options : ScriptCodegenOptions ,
313
+ ctx : ScriptCodegenContext
314
+ ) : Generator < Code > {
315
+ if ( options . vueCompilerOptions . target >= 3.3 ) {
316
+ yield `declare const { ` ;
317
+ for ( const macro of Object . keys ( options . vueCompilerOptions . macros ) ) {
318
+ if ( ! ctx . bindingNames . has ( macro ) ) {
319
+ yield `${ macro } , ` ;
320
+ }
321
+ }
322
+ yield `}: typeof import('${ options . vueCompilerOptions . lib } ')${ endOfLine } ` ;
323
+ }
324
+ }
325
+
326
+ function * generateDefineProp (
327
+ options : ScriptCodegenOptions ,
328
+ scriptSetup : NonNullable < Sfc [ 'scriptSetup' ] >
329
+ ) : Generator < Code > {
330
+ const definePropProposalA = scriptSetup . content . trimStart ( ) . startsWith ( '// @experimentalDefinePropProposal=kevinEdition' ) || options . vueCompilerOptions . experimentalDefinePropProposal === 'kevinEdition' ;
331
+ const definePropProposalB = scriptSetup . content . trimStart ( ) . startsWith ( '// @experimentalDefinePropProposal=johnsonEdition' ) || options . vueCompilerOptions . experimentalDefinePropProposal === 'johnsonEdition' ;
332
+
333
+ if ( definePropProposalA || definePropProposalB ) {
334
+ yield `type __VLS_PropOptions<T> = Exclude<import('${ options . vueCompilerOptions . lib } ').Prop<T>, import('${ options . vueCompilerOptions . lib } ').PropType<T>>${ endOfLine } ` ;
335
+ if ( definePropProposalA ) {
336
+ yield `declare function defineProp<T>(name: string, options: ({ required: true } | { default: T }) & __VLS_PropOptions<T>): import('${ options . vueCompilerOptions . lib } ').ComputedRef<T>${ endOfLine } ` ;
337
+ yield `declare function defineProp<T>(name?: string, options?: __VLS_PropOptions<T>): import('${ options . vueCompilerOptions . lib } ').ComputedRef<T | undefined>${ endOfLine } ` ;
338
+ }
339
+ if ( definePropProposalB ) {
340
+ yield `declare function defineProp<T>(value: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${ options . vueCompilerOptions . lib } ').ComputedRef<T>${ endOfLine } ` ;
341
+ yield `declare function defineProp<T>(value: T | (() => T) | undefined, required: true, options?: __VLS_PropOptions<T>): import('${ options . vueCompilerOptions . lib } ').ComputedRef<T>${ endOfLine } ` ;
342
+ yield `declare function defineProp<T>(value?: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${ options . vueCompilerOptions . lib } ').ComputedRef<T | undefined>${ endOfLine } ` ;
343
+ }
344
+ }
345
+ }
346
+
320
347
function * generateDefineWithType (
321
348
scriptSetup : NonNullable < Sfc [ 'scriptSetup' ] > ,
322
349
statement : TextRange ,
0 commit comments