@@ -10,7 +10,7 @@ import {
10
10
} from '@vue-macros/common'
11
11
import { walkAST } from 'ast-walker-scope'
12
12
import { filterMacro , hasPropsOrEmits } from './utils'
13
- import type { ExportDefaultDeclaration , Statement } from '@babel/types'
13
+ import type { ExportDefaultDeclaration , Program , Statement } from '@babel/types'
14
14
15
15
export function transformDefineOptions ( code : string , id : string ) {
16
16
if ( ! code . includes ( DEFINE_OPTIONS ) ) return
@@ -70,7 +70,7 @@ export function transformDefineOptions(code: string, id: string) {
70
70
return getTransformResult ( s , id )
71
71
}
72
72
73
- const checkDefaultExport = ( stmts : Statement [ ] ) => {
73
+ export const checkDefaultExport = ( stmts : Statement [ ] ) => {
74
74
const hasDefaultExport = stmts . some (
75
75
( node ) : node is ExportDefaultDeclaration =>
76
76
node . type === 'ExportDefaultDeclaration'
@@ -81,28 +81,26 @@ const checkDefaultExport = (stmts: Statement[]) => {
81
81
)
82
82
}
83
83
84
- const getIdentifiers = ( stmts : Statement [ ] ) => {
84
+ export const getIdentifiers = ( stmts : Statement [ ] ) => {
85
85
let ids : string [ ] = [ ]
86
- walkAST (
87
- {
88
- type : 'Program' ,
89
- body : stmts ,
90
- directives : [ ] ,
91
- sourceType : 'module' ,
92
- sourceFile : '' ,
86
+ const program : Program = {
87
+ type : 'Program' ,
88
+ body : stmts ,
89
+ directives : [ ] ,
90
+ sourceType : 'module' ,
91
+ sourceFile : '' ,
92
+ }
93
+ walkAST ( program , {
94
+ enter ( node ) {
95
+ if ( node . type === 'BlockStatement' ) {
96
+ this . skip ( )
97
+ }
93
98
} ,
94
- {
95
- enter ( node ) {
96
- if ( node . type === 'BlockStatement' ) {
97
- this . skip ( )
98
- }
99
- } ,
100
- leave ( node ) {
101
- if ( node . type !== 'Program' ) return
102
- ids = Object . keys ( this . scope )
103
- } ,
104
- }
105
- )
99
+ leave ( node ) {
100
+ if ( node . type !== 'Program' ) return
101
+ ids = Object . keys ( this . scope )
102
+ } ,
103
+ } )
106
104
107
105
return ids
108
106
}
0 commit comments