@@ -6,6 +6,7 @@ import type {
66 NamedImportSpecifier ,
77 ImportDefaultSpecifier ,
88 ImportSpecifier ,
9+ BlockStatement ,
910} from "@swc/core" ;
1011
1112import { Config , SetupAst } from "../constants" ;
@@ -22,7 +23,7 @@ function transformEmits(
2223 setupAst : SetupAst ,
2324 config : Config ,
2425) {
25- const { script, offset, setupScript , fileAbsolutePath } = config ;
26+ const { script, offset, fileAbsolutePath } = config ;
2627 const name = getSetupSecondParams ( "emit" , setupAst , fileAbsolutePath ) ;
2728 if ( ! name ) {
2829 return ;
@@ -106,15 +107,15 @@ function transformEmits(
106107 }
107108
108109 let emitNames : string [ ] = [ ] ;
109- if ( setupScript ) {
110+ if ( ( setupAst . body as BlockStatement ) ?. stmts ?. length ) {
110111 const visitor = new GetCallExpressionFirstArg ( name ) ;
111112 visitor . visitFn ( setupAst ) ;
112113
113- const setupOffset = setupAst . span . start ;
114114 emitNames = ( visitor . firstArgAst as Identifier [ ] ) . map ( ( ast ) => {
115- const { start, end } = getRealSpan ( ast . span , setupOffset ) ;
116- return setupScript . slice ( start , end ) ;
115+ const { start, end } = getRealSpan ( ast . span , offset ) ;
116+ return script . slice ( start , end ) ;
117117 } ) ;
118+ console . log ( emitNames ) ;
118119 }
119120
120121 str = `${ preCode } defineEmits([${ [ ...new Set ( [ ...keys , ...emitNames ] ) ] . join (
0 commit comments