Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit bf95ec1

Browse files
committed
BREAKING CHANGE: refTransform to reactivityTransform
See vuejs/rfcs#413, vuejs/rfcs#369
1 parent ec1d7ae commit bf95ec1

13 files changed

+39
-64
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ If you are using ESLint, you might get `@typescript-eslint/no-unused-vars` warni
310310
Ref Sugar (take 2)
311311
</summary>
312312

313-
In v0.5.x, we shipped the **experimental** [Ref Sugar (take 2)](https://github.com/vuejs/rfcs/discussions/369) implementation based on Vue 3's [`@vue/ref-transform`](https://github.com/vuejs/vue-next/tree/master/packages/ref-transform) package. Notice the syntax is not settled yet and might be changed in the future updates. **Use at your own risk!**
313+
In v0.5.x, we shipped the **experimental** [Ref Sugar (take 2)](https://github.com/vuejs/rfcs/discussions/369) implementation based on Vue 3's [`@vue/reactivity-transform`](https://github.com/vuejs/vue-next/tree/master/packages/reactivity-transform) package. Notice the syntax is not settled yet and might be changed in the future updates. **Use at your own risk!**
314314

315315
To enabled it, pass the option:
316316

317317
```ts
318318
ScriptSetup({
319-
refTransform: true
319+
reactivityTransform: true
320320
})
321321
```
322322

examples/nuxt-bridge/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"devDependencies": {
99
"@nuxt/bridge": "latest",
1010
"nuxt-edge": "latest",
11-
"vue": "^2",
12-
"vue2": "npm:vue@^2"
11+
"vue": "^2.6.14",
12+
"vue2": "npm:vue@^2.6.14"
1313
}
1414
}

examples/vue-cli/vue.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
configureWebpack: {
1010
plugins: [
1111
ScriptSetup({
12-
refTransform: true,
12+
reactivityTransform: true,
1313
}),
1414
],
1515
},

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@rollup/pluginutils": "^4.1.2",
8181
"@vue/compiler-core": "^3.2.26",
8282
"@vue/compiler-dom": "^3.2.26",
83-
"@vue/ref-transform": "^3.2.24",
83+
"@vue/reactivity-transform": "^3.2.26",
8484
"@vue/shared": "^3.2.26",
8585
"defu": "^5.0.0",
8686
"htmlparser2": "5.0.1",
@@ -110,7 +110,7 @@
110110
"rollup-plugin-typescript2": "^0.31.1",
111111
"typescript": "^4.5.4",
112112
"vite": "^2.7.10",
113-
"vitest": "^0.0.141"
113+
"vitest": "0.0.120"
114114
},
115115
"peerDependencies": {
116116
"pug": "^3.0.2"

playground/vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
Vue2(),
1111
Inspect(),
1212
ScriptSetup({
13-
refTransform: true,
13+
reactivityTransform: true,
1414
}),
1515
],
1616
})

pnpm-lock.yaml

+21-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function resolveOptions(options: ScriptSetupTransformOptions = {}): Resol
55
{},
66
{
77
sourceMap: true,
8-
refTransform: false,
8+
reactivityTransform: false,
99
importHelpersFrom: '@vue/composition-api',
1010
astTransforms: {},
1111
},

src/core/transform.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MagicString from 'magic-string'
2-
import { shouldTransform as shouldTransformRefSugar, transform as transformRef } from '@vue/ref-transform'
2+
import { shouldTransform as shouldTransformRefSugar, transform as transformRef } from '@vue/reactivity-transform'
33
import type { ResolvedOptions, ScriptSetupTransformOptions, TransformResult } from '../types'
44
import { parseSFC } from './parseSFC'
55
import { transformScriptSetup } from './transformScriptSetup'
@@ -12,7 +12,7 @@ export function shouldTransform(code: string, id: string, options?: ScriptSetupT
1212
// avoid transforming twice
1313
if (code.includes('export default __sfc_main'))
1414
return false
15-
return (options?.refTransform && shouldTransformRefSugar(code)) || scriptSetupRE.test(code)
15+
return (options?.reactivityTransform && shouldTransformRefSugar(code)) || scriptSetupRE.test(code)
1616
}
1717

1818
export function transform(input: string, id: string, options?: ScriptSetupTransformOptions): TransformResult {
@@ -26,7 +26,7 @@ export function transform(input: string, id: string, options?: ScriptSetupTransf
2626
}
2727

2828
function transformNonVue(input: string, id: string, options: ResolvedOptions): TransformResult {
29-
if (options.refTransform && shouldTransformRefSugar(input)) {
29+
if (options.reactivityTransform && shouldTransformRefSugar(input)) {
3030
return transformRef(input, {
3131
filename: id,
3232
sourceMap: options.sourceMap,
@@ -41,7 +41,7 @@ function transformVue(input: string, id: string, options: ResolvedOptions): Tran
4141

4242
const sfc = parseSFC(input, id)
4343

44-
if (options.refTransform)
44+
if (options.reactivityTransform)
4545
transformSfcRefSugar(sfc, options)
4646

4747
const { code } = transformScriptSetup(sfc, options)

src/core/transformSfcRefSugar.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { shouldTransform, transformAST } from '@vue/ref-transform'
1+
import { shouldTransform, transformAST } from '@vue/reactivity-transform'
22
import MagicString from 'magic-string'
33
import type { ParsedSFC, ResolvedOptions } from '../types'
44
import { parse, t } from './babel'

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export * from './core'
77

88
export const unplugin = createUnplugin<PluginOptions>((options = {}) => {
99
const filter = createFilter(
10-
options.include || (options.refTransform ? [/\.vue$/, /\.vue\?vue/, /\.[jt]sx?$/] : [/\.vue$/, /\.vue\?vue/]),
10+
options.include || (options.reactivityTransform ? [/\.vue$/, /\.vue\?vue/, /\.[jt]sx?$/] : [/\.vue$/, /\.vue\?vue/]),
1111
options.exclude || [/node_modules/, /\.git/, /\.nuxt/],
1212
)
1313

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface ScriptSetupTransformOptions {
3434
scriptSetup?: (ast: Program) => Program
3535
post?: (ast: Program, sfc: ParsedSFC) => Program
3636
}
37-
refTransform?: boolean
37+
reactivityTransform?: boolean
3838
importHelpersFrom?: string
3939
sourceMap?: boolean
4040
}

test/errors.test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ const {data} = await something()
5050
it('ref sugar', () => {
5151
const consoleWarnMock = vi.spyOn(console, 'warn')
5252

53-
expect(() =>
54-
t(`
55-
const a = $ref(1)
56-
`, 'Ref.ts', { refTransform: true }))
57-
.toThrowError('$ref() bindings can only be declared with let')
58-
5953
expect(() =>
6054
t(`
6155
<script setup>

test/transform.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ describe('transform', () => {
1818
for (const file of files) {
1919
it(file.replace(/\\/g, '/'), async() => {
2020
const fixture = await fs.readFile(resolve(root, file), 'utf-8')
21-
const result = transform(fixture, file, { refTransform: true })?.code || fixture
21+
const result = transform(fixture, file, { reactivityTransform: true })?.code || fixture
2222
expect(result).toMatchSnapshot()
2323

24-
const result2 = transform(result, file, { refTransform: true })?.code || result
24+
const result2 = transform(result, file, { reactivityTransform: true })?.code || result
2525
expect(result).toEqual(result2)
2626
})
2727
}

0 commit comments

Comments
 (0)