@@ -2,11 +2,11 @@ import { types as t } from '@babel/core'
2
2
import { camelize , capitalize } from '@vue/shared'
3
3
import traverse from '@babel/traverse'
4
4
import generate from '@babel/generator'
5
- import { ParsedSFC } from './types'
5
+ import { ParsedSFC , ScriptSetupTransformOptions } from '. ./types'
6
6
import { applyMacros } from './macros'
7
7
import { getIdentifierDeclarations } from './identifiers'
8
8
9
- export function transformScriptSetup ( sfc : ParsedSFC ) {
9
+ export function transformScriptSetup ( sfc : ParsedSFC , options ?: ScriptSetupTransformOptions ) {
10
10
const { scriptSetup, script, template } = sfc
11
11
12
12
const imports = scriptSetup . ast . body . filter ( n => n . type === 'ImportDeclaration' )
@@ -31,7 +31,7 @@ export function transformScriptSetup(sfc: ParsedSFC) {
31
31
)
32
32
33
33
// append `<script setup>` imports to `<script>`
34
- const ast = t . program ( [
34
+ let ast = t . program ( [
35
35
...imports ,
36
36
...script . ast . body ,
37
37
] )
@@ -139,7 +139,7 @@ export function transformScriptSetup(sfc: ParsedSFC) {
139
139
)
140
140
}
141
141
142
- if ( ! hasBody ) {
142
+ if ( ! hasBody && ! options ?. astTransforms ) {
143
143
return {
144
144
ast : null ,
145
145
code : '' ,
@@ -152,6 +152,8 @@ export function transformScriptSetup(sfc: ParsedSFC) {
152
152
t . exportDefaultDeclaration ( __sfc ) as any ,
153
153
)
154
154
155
+ ast = options ?. astTransforms ?. post ?.( ast , sfc ) || ast
156
+
155
157
return {
156
158
ast,
157
159
code : generate ( ast ) . code ,
0 commit comments