refactor(compiler-sfc): refSugar -> refTransform, export shouldTransformRef
This commit is contained in:
parent
986681568f
commit
0805abe573
@ -52,8 +52,8 @@ import { warnExperimental, warnOnce } from './warn'
|
|||||||
import { rewriteDefault } from './rewriteDefault'
|
import { rewriteDefault } from './rewriteDefault'
|
||||||
import { createCache } from './cache'
|
import { createCache } from './cache'
|
||||||
import {
|
import {
|
||||||
shouldTransform,
|
shouldTransform as shouldTransformRef,
|
||||||
transformAST as transformWithRefSugar
|
transformAST as transformRefAST
|
||||||
} from '@vue/ref-transform'
|
} from '@vue/ref-transform'
|
||||||
|
|
||||||
// Special compiler macros
|
// Special compiler macros
|
||||||
@ -81,10 +81,14 @@ export interface SFCScriptCompileOptions {
|
|||||||
*/
|
*/
|
||||||
babelParserPlugins?: ParserPlugin[]
|
babelParserPlugins?: ParserPlugin[]
|
||||||
/**
|
/**
|
||||||
* Introduce a compiler-based syntax sugar for using refs without `.value`
|
* (Experimental) Enable syntax transform for using refs without `.value`
|
||||||
* https://github.com/vuejs/rfcs/discussions/369
|
* https://github.com/vuejs/rfcs/discussions/369
|
||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
|
refTransform?: boolean
|
||||||
|
/**
|
||||||
|
* @deprecated use `refTransform` instead.
|
||||||
|
*/
|
||||||
refSugar?: boolean
|
refSugar?: boolean
|
||||||
/**
|
/**
|
||||||
* Compile the template and inline the resulting render function
|
* Compile the template and inline the resulting render function
|
||||||
@ -121,7 +125,7 @@ export function compileScript(
|
|||||||
): SFCScriptBlock {
|
): SFCScriptBlock {
|
||||||
let { script, scriptSetup, source, filename } = sfc
|
let { script, scriptSetup, source, filename } = sfc
|
||||||
// feature flags
|
// feature flags
|
||||||
const enableRefSugar = !!options.refSugar
|
const enableRefTransform = !!options.refSugar || !!options.refTransform
|
||||||
let refBindings: string[] | undefined
|
let refBindings: string[] | undefined
|
||||||
|
|
||||||
// for backwards compat
|
// for backwards compat
|
||||||
@ -858,12 +862,12 @@ export function compileScript(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. Apply ref sugar transform
|
// 3. Apply ref sugar transform
|
||||||
if (enableRefSugar && shouldTransform(source)) {
|
if (enableRefTransform && shouldTransformRef(source)) {
|
||||||
warnExperimental(
|
warnExperimental(
|
||||||
`ref sugar`,
|
`ref sugar`,
|
||||||
`https://github.com/vuejs/rfcs/discussions/369`
|
`https://github.com/vuejs/rfcs/discussions/369`
|
||||||
)
|
)
|
||||||
const { rootVars, importedHelpers } = transformWithRefSugar(
|
const { rootVars, importedHelpers } = transformRefAST(
|
||||||
scriptSetupAst,
|
scriptSetupAst,
|
||||||
s,
|
s,
|
||||||
startOffset
|
startOffset
|
||||||
|
@ -4,8 +4,9 @@ export { compileTemplate } from './compileTemplate'
|
|||||||
export { compileStyle, compileStyleAsync } from './compileStyle'
|
export { compileStyle, compileStyleAsync } from './compileStyle'
|
||||||
export { compileScript } from './compileScript'
|
export { compileScript } from './compileScript'
|
||||||
export { rewriteDefault } from './rewriteDefault'
|
export { rewriteDefault } from './rewriteDefault'
|
||||||
export { generateCodeFrame, walkIdentifiers } from '@vue/compiler-core'
|
export { generateCodeFrame } from '@vue/compiler-core'
|
||||||
export {
|
export {
|
||||||
|
shouldTransform as shouldTransformRef,
|
||||||
transform as transformRef,
|
transform as transformRef,
|
||||||
transformAST as transformRefAST
|
transformAST as transformRefAST
|
||||||
} from '@vue/ref-transform'
|
} from '@vue/ref-transform'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user