@@ -332,7 +332,7 @@ ${commandLine.vueOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}
332
332
333
333
const vueFile = language . scripts . get ( componentPath ) ?. generated ?. root ;
334
334
const vueDefaults = vueFile && exportName === 'default'
335
- ? ( vueFile instanceof vue . VueVirtualCode ? readVueComponentDefaultProps ( vueFile , printer , ts , commandLine . vueOptions ) : { } )
335
+ ? ( vueFile instanceof vue . VueVirtualCode ? readVueComponentDefaultProps ( vueFile , printer , ts ) : { } )
336
336
: { } ;
337
337
const tsDefaults = ! vueFile ? readTsComponentDefaultProps (
338
338
componentPath . slice ( componentPath . lastIndexOf ( '.' ) + 1 ) , // ts | js | tsx | jsx
@@ -707,10 +707,9 @@ function createSchemaResolvers(
707
707
}
708
708
709
709
function readVueComponentDefaultProps (
710
- vueSourceFile : vue . VueVirtualCode ,
710
+ root : vue . VueVirtualCode ,
711
711
printer : ts . Printer | undefined ,
712
- ts : typeof import ( 'typescript' ) ,
713
- vueCompilerOptions : vue . VueCompilerOptions
712
+ ts : typeof import ( 'typescript' )
714
713
) {
715
714
let result : Record < string , { default ?: string , required ?: boolean ; } > = { } ;
716
715
@@ -721,13 +720,14 @@ function readVueComponentDefaultProps(
721
720
722
721
function scriptSetupWorker ( ) {
723
722
724
- const descriptor = vueSourceFile . _sfc ;
725
- const scriptSetupRanges = descriptor . scriptSetup ? vue . parseScriptSetupRanges ( ts , descriptor . scriptSetup . ast , vueCompilerOptions ) : undefined ;
723
+ const sfc = root . _sfc ;
724
+ const codegen = vue . tsCodegen . get ( sfc ) ;
725
+ const scriptSetupRanges = codegen ?. scriptSetupRanges . get ( ) ;
726
726
727
- if ( descriptor . scriptSetup && scriptSetupRanges ?. withDefaults ?. arg ) {
727
+ if ( sfc . scriptSetup && scriptSetupRanges ?. withDefaults ?. arg ) {
728
728
729
- const defaultsText = descriptor . scriptSetup . content . slice ( scriptSetupRanges . withDefaults . arg . start , scriptSetupRanges . withDefaults . arg . end ) ;
730
- const ast = ts . createSourceFile ( '/tmp.' + descriptor . scriptSetup . lang , '(' + defaultsText + ')' , ts . ScriptTarget . Latest ) ;
729
+ const defaultsText = sfc . scriptSetup . content . slice ( scriptSetupRanges . withDefaults . arg . start , scriptSetupRanges . withDefaults . arg . end ) ;
730
+ const ast = ts . createSourceFile ( '/tmp.' + sfc . scriptSetup . lang , '(' + defaultsText + ')' , ts . ScriptTarget . Latest ) ;
731
731
const obj = findObjectLiteralExpression ( ast ) ;
732
732
733
733
if ( obj ) {
@@ -743,9 +743,9 @@ function readVueComponentDefaultProps(
743
743
}
744
744
}
745
745
}
746
- } else if ( descriptor . scriptSetup && scriptSetupRanges ?. defineProps ?. arg ) {
747
- const defaultsText = descriptor . scriptSetup . content . slice ( scriptSetupRanges . defineProps . arg . start , scriptSetupRanges . defineProps . arg . end ) ;
748
- const ast = ts . createSourceFile ( '/tmp.' + descriptor . scriptSetup . lang , '(' + defaultsText + ')' , ts . ScriptTarget . Latest ) ;
746
+ } else if ( sfc . scriptSetup && scriptSetupRanges ?. defineProps ?. arg ) {
747
+ const defaultsText = sfc . scriptSetup . content . slice ( scriptSetupRanges . defineProps . arg . start , scriptSetupRanges . defineProps . arg . end ) ;
748
+ const ast = ts . createSourceFile ( '/tmp.' + sfc . scriptSetup . lang , '(' + defaultsText + ')' , ts . ScriptTarget . Latest ) ;
749
749
const obj = findObjectLiteralExpression ( ast ) ;
750
750
751
751
if ( obj ) {
@@ -754,8 +754,8 @@ function readVueComponentDefaultProps(
754
754
...resolvePropsOption ( ast , obj , printer , ts ) ,
755
755
} ;
756
756
}
757
- } else if ( descriptor . scriptSetup && scriptSetupRanges ?. defineProps ?. destructured ) {
758
- const ast = descriptor . scriptSetup . ast ;
757
+ } else if ( sfc . scriptSetup && scriptSetupRanges ?. defineProps ?. destructured ) {
758
+ const ast = sfc . scriptSetup . ast ;
759
759
for ( const [ prop , initializer ] of scriptSetupRanges . defineProps . destructured ) {
760
760
if ( initializer ) {
761
761
const expText = printer ?. printNode ( ts . EmitHint . Expression , initializer , ast ) ?? initializer . getText ( ast ) ;
@@ -780,7 +780,7 @@ function readVueComponentDefaultProps(
780
780
781
781
function scriptWorker ( ) {
782
782
783
- const descriptor = vueSourceFile . _sfc ;
783
+ const descriptor = root . _sfc ;
784
784
785
785
if ( descriptor . script ) {
786
786
const scriptResult = readTsComponentDefaultProps ( descriptor . script . lang , descriptor . script . content , 'default' , printer , ts ) ;
0 commit comments