@@ -48,10 +48,7 @@ import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate'
48
48
import { warnOnce } from './warn'
49
49
import { rewriteDefault } from './rewriteDefault'
50
50
import { createCache } from './cache'
51
- import {
52
- shouldTransform as shouldTransformRef ,
53
- transformAST as transformRefAST
54
- } from '@vue/reactivity-transform'
51
+ import { shouldTransform , transformAST } from '@vue/reactivity-transform'
55
52
56
53
// Special compiler macros
57
54
const DEFINE_PROPS = 'defineProps'
@@ -143,7 +140,7 @@ export function compileScript(
143
140
let { script, scriptSetup, source, filename } = sfc
144
141
// feature flags
145
142
// TODO remove support for deprecated options when out of experimental
146
- const enableRefTransform =
143
+ const enableReactivityTransform =
147
144
! ! options . reactivityTransform ||
148
145
! ! options . refSugar ||
149
146
! ! options . refTransform
@@ -170,6 +167,8 @@ export function compileScript(
170
167
scriptLang === 'tsx' ||
171
168
scriptSetupLang === 'ts' ||
172
169
scriptSetupLang === 'tsx'
170
+
171
+ // resolve parser plugins
173
172
const plugins : ParserPlugin [ ] = [ ]
174
173
if ( ! isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx' ) {
175
174
plugins . push ( 'jsx' )
@@ -193,11 +192,11 @@ export function compileScript(
193
192
sourceType : 'module'
194
193
} ) . program
195
194
const bindings = analyzeScriptBindings ( scriptAst . body )
196
- if ( enableRefTransform && shouldTransformRef ( content ) ) {
195
+ if ( enableReactivityTransform && shouldTransform ( content ) ) {
197
196
const s = new MagicString ( source )
198
197
const startOffset = script . loc . start . offset
199
198
const endOffset = script . loc . end . offset
200
- const { importedHelpers } = transformRefAST ( scriptAst , s , startOffset )
199
+ const { importedHelpers } = transformAST ( scriptAst , s , startOffset )
201
200
if ( importedHelpers . length ) {
202
201
s . prepend (
203
202
`import { ${ importedHelpers
@@ -862,14 +861,14 @@ export function compileScript(
862
861
}
863
862
}
864
863
865
- // apply ref transform
866
- if ( enableRefTransform && shouldTransformRef ( script . content ) ) {
867
- const { rootRefs : rootVars , importedHelpers } = transformRefAST (
864
+ // apply reactivity transform
865
+ if ( enableReactivityTransform && shouldTransform ( script . content ) ) {
866
+ const { rootRefs, importedHelpers } = transformAST (
868
867
scriptAst ,
869
868
s ,
870
869
scriptStartOffset !
871
870
)
872
- refBindings = rootVars
871
+ refBindings = rootRefs
873
872
for ( const h of importedHelpers ) {
874
873
helperImports . add ( h )
875
874
}
@@ -1109,12 +1108,14 @@ export function compileScript(
1109
1108
}
1110
1109
}
1111
1110
1112
- // 3. Apply ref sugar transform
1111
+ // 3. Apply reactivity transform
1113
1112
if (
1114
- ( enableRefTransform && shouldTransformRef ( scriptSetup . content ) ) ||
1113
+ ( enableReactivityTransform &&
1114
+ // normal <script> had ref bindings that maybe used in <script setup>
1115
+ ( refBindings || shouldTransform ( scriptSetup . content ) ) ) ||
1115
1116
propsDestructureDecl
1116
1117
) {
1117
- const { rootRefs, importedHelpers } = transformRefAST (
1118
+ const { rootRefs, importedHelpers } = transformAST (
1118
1119
scriptSetupAst ,
1119
1120
s ,
1120
1121
startOffset ,
0 commit comments