Skip to content

Commit 6b13e04

Browse files
committed
feat(compiler-sfc): mark props destructure as experimental and require explicit opt-in
1 parent 760755f commit 6b13e04

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

Diff for: packages/compiler-sfc/__tests__/compileScript/__snapshots__/definePropsDestructure.spec.ts.snap

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`sfc props transform > aliasing 1`] = `
3+
exports[`sfc reactive props destructure > aliasing 1`] = `
44
"import { toDisplayString as _toDisplayString } from \\"vue\\"
55
66
@@ -20,7 +20,7 @@ return (_ctx, _cache) => {
2020
}"
2121
`;
2222

23-
exports[`sfc props transform > basic usage 1`] = `
23+
exports[`sfc reactive props destructure > basic usage 1`] = `
2424
"import { toDisplayString as _toDisplayString } from \\"vue\\"
2525
2626
@@ -39,7 +39,7 @@ return (_ctx, _cache) => {
3939
}"
4040
`;
4141

42-
exports[`sfc props transform > computed static key 1`] = `
42+
exports[`sfc reactive props destructure > computed static key 1`] = `
4343
"import { toDisplayString as _toDisplayString } from \\"vue\\"
4444
4545
@@ -58,7 +58,7 @@ return (_ctx, _cache) => {
5858
}"
5959
`;
6060

61-
exports[`sfc props transform > default values w/ array runtime declaration 1`] = `
61+
exports[`sfc reactive props destructure > default values w/ array runtime declaration 1`] = `
6262
"import { mergeDefaults as _mergeDefaults } from 'vue'
6363
6464
export default {
@@ -77,7 +77,7 @@ return () => {}
7777
}"
7878
`;
7979

80-
exports[`sfc props transform > default values w/ object runtime declaration 1`] = `
80+
exports[`sfc reactive props destructure > default values w/ object runtime declaration 1`] = `
8181
"import { mergeDefaults as _mergeDefaults } from 'vue'
8282
8383
export default {
@@ -97,7 +97,7 @@ return () => {}
9797
}"
9898
`;
9999

100-
exports[`sfc props transform > default values w/ type declaration 1`] = `
100+
exports[`sfc reactive props destructure > default values w/ type declaration 1`] = `
101101
"import { defineComponent as _defineComponent } from 'vue'
102102
103103
export default /*#__PURE__*/_defineComponent({
@@ -116,7 +116,7 @@ return () => {}
116116
})"
117117
`;
118118

119-
exports[`sfc props transform > default values w/ type declaration, prod mode 1`] = `
119+
exports[`sfc reactive props destructure > default values w/ type declaration, prod mode 1`] = `
120120
"import { defineComponent as _defineComponent } from 'vue'
121121
122122
export default /*#__PURE__*/_defineComponent({
@@ -138,7 +138,7 @@ return () => {}
138138
})"
139139
`;
140140

141-
exports[`sfc props transform > multiple variable declarations 1`] = `
141+
exports[`sfc reactive props destructure > multiple variable declarations 1`] = `
142142
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
143143
144144
@@ -156,7 +156,7 @@ return (_ctx, _cache) => {
156156
}"
157157
`;
158158

159-
exports[`sfc props transform > nested scope 1`] = `
159+
exports[`sfc reactive props destructure > nested scope 1`] = `
160160
"export default {
161161
props: ['foo', 'bar'],
162162
setup(__props) {
@@ -173,7 +173,7 @@ return () => {}
173173
}"
174174
`;
175175

176-
exports[`sfc props transform > non-identifier prop names 1`] = `
176+
exports[`sfc reactive props destructure > non-identifier prop names 1`] = `
177177
"import { toDisplayString as _toDisplayString } from \\"vue\\"
178178
179179
@@ -192,7 +192,7 @@ return (_ctx, _cache) => {
192192
}"
193193
`;
194194

195-
exports[`sfc props transform > rest spread 1`] = `
195+
exports[`sfc reactive props destructure > rest spread 1`] = `
196196
"import { createPropsRestProxy as _createPropsRestProxy } from 'vue'
197197
198198
export default {

Diff for: packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { BindingTypes } from '@vue/compiler-core'
22
import { SFCScriptCompileOptions } from '../../src'
33
import { compileSFCScript, assertCode } from '../utils'
44

5-
describe('sfc props transform', () => {
5+
describe('sfc reactive props destructure', () => {
66
function compile(src: string, options?: Partial<SFCScriptCompileOptions>) {
77
return compileSFCScript(src, {
88
inlineTemplate: true,
9+
propsDestructure: true,
910
...options
1011
})
1112
}

Diff for: packages/compiler-sfc/src/compileScript.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ export interface SFCScriptCompileOptions {
7272
* https://babeljs.io/docs/en/babel-parser#plugins
7373
*/
7474
babelParserPlugins?: ParserPlugin[]
75-
/**
76-
* (Experimental) Enable syntax transform for using refs without `.value` and
77-
* using destructured props with reactivity
78-
* @deprecated the Reactivity Transform proposal has been dropped. This
79-
* feature will be removed from Vue core in 3.4. If you intend to continue
80-
* using it, disable this and switch to the [Vue Macros implementation](https://vue-macros.sxzz.moe/features/reactivity-transform.html).
81-
*/
82-
reactivityTransform?: boolean
8375
/**
8476
* Compile the template and inline the resulting render function
8577
* directly inside setup().
@@ -108,8 +100,14 @@ export interface SFCScriptCompileOptions {
108100
hoistStatic?: boolean
109101
/**
110102
* (**Experimental**) Enable macro `defineModel`
103+
* @default false
111104
*/
112105
defineModel?: boolean
106+
/**
107+
* (**Experimental**) Enable reactive destructure for `defineProps`
108+
* @default false
109+
*/
110+
propsDestructure?: boolean
113111
/**
114112
* File system access methods to be used when resolving types
115113
* imported in SFC macros. Defaults to ts.sys in Node.js, can be overwritten
@@ -119,6 +117,14 @@ export interface SFCScriptCompileOptions {
119117
fileExists(file: string): boolean
120118
readFile(file: string): string | undefined
121119
}
120+
/**
121+
* (Experimental) Enable syntax transform for using refs without `.value` and
122+
* using destructured props with reactivity
123+
* @deprecated the Reactivity Transform proposal has been dropped. This
124+
* feature will be removed from Vue core in 3.4. If you intend to continue
125+
* using it, disable this and switch to the [Vue Macros implementation](https://vue-macros.sxzz.moe/features/reactivity-transform.html).
126+
*/
127+
reactivityTransform?: boolean
122128
}
123129

124130
export interface ImportBinding {

Diff for: packages/compiler-sfc/src/script/definePropsDestructure.ts

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export function processPropsDestructure(
2626
ctx: ScriptCompileContext,
2727
declId: ObjectPattern
2828
) {
29+
if (!ctx.options.propsDestructure) {
30+
return
31+
}
32+
2933
ctx.propsDestructureDecl = declId
3034

3135
const registerBinding = (
@@ -91,6 +95,10 @@ export function transformDestructuredProps(
9195
ctx: ScriptCompileContext,
9296
vueImportAliases: Record<string, string>
9397
) {
98+
if (!ctx.options.propsDestructure) {
99+
return
100+
}
101+
94102
const rootScope: Scope = {}
95103
const scopeStack: Scope[] = [rootScope]
96104
let currentScope: Scope = rootScope

0 commit comments

Comments
 (0)