Skip to content

Commit

Permalink
refactor(compiler-sfc): refSugar -> refTransform, export shouldTransf…
Browse files Browse the repository at this point in the history
…ormRef
  • Loading branch information
yyx990803 committed Aug 23, 2021
1 parent 9866815 commit 0805abe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -52,8 +52,8 @@ import { warnExperimental, warnOnce } from './warn'
import { rewriteDefault } from './rewriteDefault'
import { createCache } from './cache'
import {
shouldTransform,
transformAST as transformWithRefSugar
shouldTransform as shouldTransformRef,
transformAST as transformRefAST
} from '@vue/ref-transform'

// Special compiler macros
Expand Down Expand Up @@ -81,10 +81,14 @@ export interface SFCScriptCompileOptions {
*/
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
* @default true
*/
refTransform?: boolean
/**
* @deprecated use `refTransform` instead.
*/
refSugar?: boolean
/**
* Compile the template and inline the resulting render function
Expand Down Expand Up @@ -121,7 +125,7 @@ export function compileScript(
): SFCScriptBlock {
let { script, scriptSetup, source, filename } = sfc
// feature flags
const enableRefSugar = !!options.refSugar
const enableRefTransform = !!options.refSugar || !!options.refTransform
let refBindings: string[] | undefined

// for backwards compat
Expand Down Expand Up @@ -858,12 +862,12 @@ export function compileScript(
}

// 3. Apply ref sugar transform
if (enableRefSugar && shouldTransform(source)) {
if (enableRefTransform && shouldTransformRef(source)) {
warnExperimental(
`ref sugar`,
`https://github.com/vuejs/rfcs/discussions/369`
)
const { rootVars, importedHelpers } = transformWithRefSugar(
const { rootVars, importedHelpers } = transformRefAST(
scriptSetupAst,
s,
startOffset
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-sfc/src/index.ts
Expand Up @@ -4,8 +4,9 @@ export { compileTemplate } from './compileTemplate'
export { compileStyle, compileStyleAsync } from './compileStyle'
export { compileScript } from './compileScript'
export { rewriteDefault } from './rewriteDefault'
export { generateCodeFrame, walkIdentifiers } from '@vue/compiler-core'
export { generateCodeFrame } from '@vue/compiler-core'
export {
shouldTransform as shouldTransformRef,
transform as transformRef,
transformAST as transformRefAST
} from '@vue/ref-transform'
Expand Down

0 comments on commit 0805abe

Please sign in to comment.