Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(compiler-sfc): promote defineModel stable #9598

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe('defineModel()', () => {
const c = defineModel('count')
const toString = defineModel('toString', { type: Function })
</script>
`,
{ defineModel: true }
`
)
assertCode(content)
expect(content).toMatch('props: {')
Expand Down Expand Up @@ -44,8 +43,7 @@ describe('defineModel()', () => {
defineEmits(['change'])
const count = defineModel({ default: 0 })
</script>
`,
{ defineModel: true }
`
)
assertCode(content)
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels({ foo: String }`)
Expand All @@ -66,8 +64,7 @@ describe('defineModel()', () => {
defineProps(['foo', 'bar'])
const count = defineModel('count')
</script>
`,
{ defineModel: true }
`
)
assertCode(content)
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels(['foo', 'bar'], {
Expand All @@ -94,8 +91,7 @@ describe('defineModel()', () => {

const local = true
const hoist = defineModel('hoist', { local })
</script>`,
{ defineModel: true }
</script>`
)
assertCode(content)
expect(content).toMatch(`_useModel(__props, "modelValue", { local: true })`)
Expand All @@ -115,8 +111,7 @@ describe('defineModel()', () => {
const disabled = defineModel<number>('disabled', { required: false })
const any = defineModel<any | boolean>('any')
</script>
`,
{ defineModel: true }
`
)
assertCode(content)
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
Expand Down Expand Up @@ -155,7 +150,7 @@ describe('defineModel()', () => {
const optional = defineModel<string>('optional', { required: false })
</script>
`,
{ defineModel: true, isProd: true }
{ isProd: true }
)
assertCode(content)
expect(content).toMatch('"modelValue": { type: Boolean }')
Expand Down
5 changes: 0 additions & 5 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ export interface SFCScriptCompileOptions {
* @default true
*/
hoistStatic?: boolean
/**
* (**Experimental**) Enable macro `defineModel`
* @default false
*/
defineModel?: boolean
/**
* (**Experimental**) Enable reactive destructure for `defineProps`
* @default false
Expand Down
16 changes: 0 additions & 16 deletions packages/compiler-sfc/src/script/defineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
toRuntimeTypeString
} from './utils'
import { BindingTypes, unwrapTSNode } from '@vue/compiler-dom'
import { warnOnce } from '../warn'

export const DEFINE_MODEL = 'defineModel'

Expand All @@ -27,21 +26,6 @@ export function processDefineModel(
return false
}

if (!ctx.options.defineModel) {
warnOnce(
`defineModel() is an experimental feature and disabled by default.\n` +
`To enable it, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
)
return false
}

warnOnce(
`This project is using defineModel(), which is an experimental ` +
`feature. It may receive breaking changes or be removed in the future, so ` +
`use at your own risk.\n` +
`To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
)

ctx.hasDefineModelCall = true

const type =
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiSetupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function defineSlots<
}

/**
* (**Experimental**) Vue `<script setup>` compiler macro for declaring a
* Vue `<script setup>` compiler macro for declaring a
* two-way binding prop that can be consumed via `v-model` from the parent
* component. This will declare a prop with the same name and a corresponding
* `update:propName` event.
Expand Down
3 changes: 1 addition & 2 deletions packages/sfc-playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ const sfcOptions: SFCOptions = {
script: {
inlineTemplate: !useDevMode.value,
isProd: !useDevMode.value,
propsDestructure: true,
defineModel: true
propsDestructure: true
},
style: {
isProd: !useDevMode.value
Expand Down
1 change: 0 additions & 1 deletion packages/sfc-playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default defineConfig({
plugins: [
vue({
script: {
defineModel: true,
fs: {
fileExists: fs.existsSync,
readFile: file => fs.readFileSync(file, 'utf-8')
Expand Down