import { warnOnce } from './warn'
import { rewriteDefault } from './rewriteDefault'
import { createCache } from './cache'
-import {
- shouldTransform as shouldTransformRef,
- transformAST as transformRefAST
-} from '@vue/reactivity-transform'
+import { shouldTransform, transformAST } from '@vue/reactivity-transform'
// Special compiler macros
const DEFINE_PROPS = 'defineProps'
let { script, scriptSetup, source, filename } = sfc
// feature flags
// TODO remove support for deprecated options when out of experimental
- const enableRefTransform =
+ const enableReactivityTransform =
!!options.reactivityTransform ||
!!options.refSugar ||
!!options.refTransform
scriptLang === 'tsx' ||
scriptSetupLang === 'ts' ||
scriptSetupLang === 'tsx'
+
+ // resolve parser plugins
const plugins: ParserPlugin[] = []
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
plugins.push('jsx')
sourceType: 'module'
}).program
const bindings = analyzeScriptBindings(scriptAst.body)
- if (enableRefTransform && shouldTransformRef(content)) {
+ if (enableReactivityTransform && shouldTransform(content)) {
const s = new MagicString(source)
const startOffset = script.loc.start.offset
const endOffset = script.loc.end.offset
- const { importedHelpers } = transformRefAST(scriptAst, s, startOffset)
+ const { importedHelpers } = transformAST(scriptAst, s, startOffset)
if (importedHelpers.length) {
s.prepend(
`import { ${importedHelpers
}
}
- // apply ref transform
- if (enableRefTransform && shouldTransformRef(script.content)) {
- const { rootRefs: rootVars, importedHelpers } = transformRefAST(
+ // apply reactivity transform
+ if (enableReactivityTransform && shouldTransform(script.content)) {
+ const { rootRefs, importedHelpers } = transformAST(
scriptAst,
s,
scriptStartOffset!
)
- refBindings = rootVars
+ refBindings = rootRefs
for (const h of importedHelpers) {
helperImports.add(h)
}
}
}
- // 3. Apply ref sugar transform
+ // 3. Apply reactivity transform
if (
- (enableRefTransform && shouldTransformRef(scriptSetup.content)) ||
+ (enableReactivityTransform &&
+ // normal <script> had ref bindings that maybe used in <script setup>
+ (refBindings || shouldTransform(scriptSetup.content))) ||
propsDestructureDecl
) {
- const { rootRefs, importedHelpers } = transformRefAST(
+ const { rootRefs, importedHelpers } = transformAST(
scriptSetupAst,
s,
startOffset,