Skip to content

Commit ef688ba

Browse files
authored
feat(compiler-sfc): promote defineModel stable (#9598)
1 parent 7438792 commit ef688ba

File tree

6 files changed

+8
-36
lines changed

6 files changed

+8
-36
lines changed

packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ describe('defineModel()', () => {
1010
const c = defineModel('count')
1111
const toString = defineModel('toString', { type: Function })
1212
</script>
13-
`,
14-
{ defineModel: true }
13+
`
1514
)
1615
assertCode(content)
1716
expect(content).toMatch('props: {')
@@ -44,8 +43,7 @@ describe('defineModel()', () => {
4443
defineEmits(['change'])
4544
const count = defineModel({ default: 0 })
4645
</script>
47-
`,
48-
{ defineModel: true }
46+
`
4947
)
5048
assertCode(content)
5149
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels({ foo: String }`)
@@ -66,8 +64,7 @@ describe('defineModel()', () => {
6664
defineProps(['foo', 'bar'])
6765
const count = defineModel('count')
6866
</script>
69-
`,
70-
{ defineModel: true }
67+
`
7168
)
7269
assertCode(content)
7370
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels(['foo', 'bar'], {
@@ -94,8 +91,7 @@ describe('defineModel()', () => {
9491
9592
const local = true
9693
const hoist = defineModel('hoist', { local })
97-
</script>`,
98-
{ defineModel: true }
94+
</script>`
9995
)
10096
assertCode(content)
10197
expect(content).toMatch(`_useModel(__props, "modelValue", { local: true })`)
@@ -115,8 +111,7 @@ describe('defineModel()', () => {
115111
const disabled = defineModel<number>('disabled', { required: false })
116112
const any = defineModel<any | boolean>('any')
117113
</script>
118-
`,
119-
{ defineModel: true }
114+
`
120115
)
121116
assertCode(content)
122117
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
@@ -155,7 +150,7 @@ describe('defineModel()', () => {
155150
const optional = defineModel<string>('optional', { required: false })
156151
</script>
157152
`,
158-
{ defineModel: true, isProd: true }
153+
{ isProd: true }
159154
)
160155
assertCode(content)
161156
expect(content).toMatch('"modelValue": { type: Boolean }')

packages/compiler-sfc/src/compileScript.ts

-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ export interface SFCScriptCompileOptions {
9898
* @default true
9999
*/
100100
hoistStatic?: boolean
101-
/**
102-
* (**Experimental**) Enable macro `defineModel`
103-
* @default false
104-
*/
105-
defineModel?: boolean
106101
/**
107102
* (**Experimental**) Enable reactive destructure for `defineProps`
108103
* @default false

packages/compiler-sfc/src/script/defineModel.ts

-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
toRuntimeTypeString
99
} from './utils'
1010
import { BindingTypes, unwrapTSNode } from '@vue/compiler-dom'
11-
import { warnOnce } from '../warn'
1211

1312
export const DEFINE_MODEL = 'defineModel'
1413

@@ -27,21 +26,6 @@ export function processDefineModel(
2726
return false
2827
}
2928

30-
if (!ctx.options.defineModel) {
31-
warnOnce(
32-
`defineModel() is an experimental feature and disabled by default.\n` +
33-
`To enable it, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
34-
)
35-
return false
36-
}
37-
38-
warnOnce(
39-
`This project is using defineModel(), which is an experimental ` +
40-
`feature. It may receive breaking changes or be removed in the future, so ` +
41-
`use at your own risk.\n` +
42-
`To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
43-
)
44-
4529
ctx.hasDefineModelCall = true
4630

4731
const type =

packages/runtime-core/src/apiSetupHelpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export function defineSlots<
219219
}
220220

221221
/**
222-
* (**Experimental**) Vue `<script setup>` compiler macro for declaring a
222+
* Vue `<script setup>` compiler macro for declaring a
223223
* two-way binding prop that can be consumed via `v-model` from the parent
224224
* component. This will declare a prop with the same name and a corresponding
225225
* `update:propName` event.

packages/sfc-playground/src/App.vue

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ const sfcOptions: SFCOptions = {
5656
script: {
5757
inlineTemplate: !useDevMode.value,
5858
isProd: !useDevMode.value,
59-
propsDestructure: true,
60-
defineModel: true
59+
propsDestructure: true
6160
},
6261
style: {
6362
isProd: !useDevMode.value

packages/sfc-playground/vite.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default defineConfig({
1010
plugins: [
1111
vue({
1212
script: {
13-
defineModel: true,
1413
fs: {
1514
fileExists: fs.existsSync,
1615
readFile: file => fs.readFileSync(file, 'utf-8')

0 commit comments

Comments
 (0)