@@ -2,11 +2,11 @@ import { types as t } from '@babel/core'
22import { camelize , capitalize } from '@vue/shared'
33import traverse from '@babel/traverse'
44import generate from '@babel/generator'
5- import { ParsedSFC } from './types'
5+ import { ParsedSFC , ScriptSetupTransformOptions } from '. ./types'
66import { applyMacros } from './macros'
77import { getIdentifierDeclarations } from './identifiers'
88
9- export function transformScriptSetup ( sfc : ParsedSFC ) {
9+ export function transformScriptSetup ( sfc : ParsedSFC , options ?: ScriptSetupTransformOptions ) {
1010 const { scriptSetup, script, template } = sfc
1111
1212 const imports = scriptSetup . ast . body . filter ( n => n . type === 'ImportDeclaration' )
@@ -31,7 +31,7 @@ export function transformScriptSetup(sfc: ParsedSFC) {
3131 )
3232
3333 // append `<script setup>` imports to `<script>`
34- const ast = t . program ( [
34+ let ast = t . program ( [
3535 ...imports ,
3636 ...script . ast . body ,
3737 ] )
@@ -139,7 +139,7 @@ export function transformScriptSetup(sfc: ParsedSFC) {
139139 )
140140 }
141141
142- if ( ! hasBody ) {
142+ if ( ! hasBody && ! options ?. astTransforms ) {
143143 return {
144144 ast : null ,
145145 code : '' ,
@@ -152,6 +152,8 @@ export function transformScriptSetup(sfc: ParsedSFC) {
152152 t . exportDefaultDeclaration ( __sfc ) as any ,
153153 )
154154
155+ ast = options ?. astTransforms ?. post ?.( ast , sfc ) || ast
156+
155157 return {
156158 ast,
157159 code : generate ( ast ) . code ,
0 commit comments