feat(compiler-sfc): promote defineModel stable (#9598)
This commit is contained in:
parent
74387929cd
commit
ef688ba92b
|
@ -10,8 +10,7 @@ describe('defineModel()', () => {
|
||||||
const c = defineModel('count')
|
const c = defineModel('count')
|
||||||
const toString = defineModel('toString', { type: Function })
|
const toString = defineModel('toString', { type: Function })
|
||||||
</script>
|
</script>
|
||||||
`,
|
`
|
||||||
{ defineModel: true }
|
|
||||||
)
|
)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch('props: {')
|
expect(content).toMatch('props: {')
|
||||||
|
@ -44,8 +43,7 @@ describe('defineModel()', () => {
|
||||||
defineEmits(['change'])
|
defineEmits(['change'])
|
||||||
const count = defineModel({ default: 0 })
|
const count = defineModel({ default: 0 })
|
||||||
</script>
|
</script>
|
||||||
`,
|
`
|
||||||
{ defineModel: true }
|
|
||||||
)
|
)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels({ foo: String }`)
|
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels({ foo: String }`)
|
||||||
|
@ -66,8 +64,7 @@ describe('defineModel()', () => {
|
||||||
defineProps(['foo', 'bar'])
|
defineProps(['foo', 'bar'])
|
||||||
const count = defineModel('count')
|
const count = defineModel('count')
|
||||||
</script>
|
</script>
|
||||||
`,
|
`
|
||||||
{ defineModel: true }
|
|
||||||
)
|
)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels(['foo', 'bar'], {
|
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels(['foo', 'bar'], {
|
||||||
|
@ -94,8 +91,7 @@ describe('defineModel()', () => {
|
||||||
|
|
||||||
const local = true
|
const local = true
|
||||||
const hoist = defineModel('hoist', { local })
|
const hoist = defineModel('hoist', { local })
|
||||||
</script>`,
|
</script>`
|
||||||
{ defineModel: true }
|
|
||||||
)
|
)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`_useModel(__props, "modelValue", { local: true })`)
|
expect(content).toMatch(`_useModel(__props, "modelValue", { local: true })`)
|
||||||
|
@ -115,8 +111,7 @@ describe('defineModel()', () => {
|
||||||
const disabled = defineModel<number>('disabled', { required: false })
|
const disabled = defineModel<number>('disabled', { required: false })
|
||||||
const any = defineModel<any | boolean>('any')
|
const any = defineModel<any | boolean>('any')
|
||||||
</script>
|
</script>
|
||||||
`,
|
`
|
||||||
{ defineModel: true }
|
|
||||||
)
|
)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
|
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
|
||||||
|
@ -155,7 +150,7 @@ describe('defineModel()', () => {
|
||||||
const optional = defineModel<string>('optional', { required: false })
|
const optional = defineModel<string>('optional', { required: false })
|
||||||
</script>
|
</script>
|
||||||
`,
|
`,
|
||||||
{ defineModel: true, isProd: true }
|
{ isProd: true }
|
||||||
)
|
)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch('"modelValue": { type: Boolean }')
|
expect(content).toMatch('"modelValue": { type: Boolean }')
|
||||||
|
|
|
@ -98,11 +98,6 @@ export interface SFCScriptCompileOptions {
|
||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
hoistStatic?: boolean
|
hoistStatic?: boolean
|
||||||
/**
|
|
||||||
* (**Experimental**) Enable macro `defineModel`
|
|
||||||
* @default false
|
|
||||||
*/
|
|
||||||
defineModel?: boolean
|
|
||||||
/**
|
/**
|
||||||
* (**Experimental**) Enable reactive destructure for `defineProps`
|
* (**Experimental**) Enable reactive destructure for `defineProps`
|
||||||
* @default false
|
* @default false
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
toRuntimeTypeString
|
toRuntimeTypeString
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import { BindingTypes, unwrapTSNode } from '@vue/compiler-dom'
|
import { BindingTypes, unwrapTSNode } from '@vue/compiler-dom'
|
||||||
import { warnOnce } from '../warn'
|
|
||||||
|
|
||||||
export const DEFINE_MODEL = 'defineModel'
|
export const DEFINE_MODEL = 'defineModel'
|
||||||
|
|
||||||
|
@ -27,21 +26,6 @@ export function processDefineModel(
|
||||||
return false
|
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
|
ctx.hasDefineModelCall = true
|
||||||
|
|
||||||
const type =
|
const type =
|
||||||
|
|
|
@ -219,7 +219,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
|
* 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
|
* component. This will declare a prop with the same name and a corresponding
|
||||||
* `update:propName` event.
|
* `update:propName` event.
|
||||||
|
|
|
@ -56,8 +56,7 @@ const sfcOptions: SFCOptions = {
|
||||||
script: {
|
script: {
|
||||||
inlineTemplate: !useDevMode.value,
|
inlineTemplate: !useDevMode.value,
|
||||||
isProd: !useDevMode.value,
|
isProd: !useDevMode.value,
|
||||||
propsDestructure: true,
|
propsDestructure: true
|
||||||
defineModel: true
|
|
||||||
},
|
},
|
||||||
style: {
|
style: {
|
||||||
isProd: !useDevMode.value
|
isProd: !useDevMode.value
|
||||||
|
|
|
@ -10,7 +10,6 @@ export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
vue({
|
vue({
|
||||||
script: {
|
script: {
|
||||||
defineModel: true,
|
|
||||||
fs: {
|
fs: {
|
||||||
fileExists: fs.existsSync,
|
fileExists: fs.existsSync,
|
||||||
readFile: file => fs.readFileSync(file, 'utf-8')
|
readFile: file => fs.readFileSync(file, 'utf-8')
|
||||||
|
|
Loading…
Reference in New Issue