diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
index ee00977c131..a1d37621345 100644
--- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
+++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
@@ -653,6 +653,48 @@ return { }
}"
`;
+exports[`SFC compile
+ `,
+ { defineModel: true }
+ )
+ assertCode(content)
+ expect(content).toMatch('props: {\n "modelValue": { required: true }')
+ expect(content).toMatch('"count": {},')
+ expect(content).toMatch('emits: ["update:modelValue", "update:count"],')
+ expect(content).toMatch(
+ `const modelValue = _useModel("modelValue", { required: true })`
+ )
+ expect(content).toMatch(`const c = _useModel("count")`)
+ expect(content).toMatch(`return { modelValue, c }`)
+ expect(content).not.toMatch('defineModel')
+
+ expect(bindings).toStrictEqual({
+ modelValue: BindingTypes.SETUP_REF,
+ count: BindingTypes.PROPS,
+ c: BindingTypes.SETUP_REF
+ })
+ })
+
+ test('w/ defineProps and defineEmits', () => {
+ const { content, bindings } = compile(
+ `
+
+ `,
+ { defineModel: true }
+ )
+ assertCode(content)
+ expect(content).toMatch(`props: _mergeModels({ foo: String }`)
+ expect(content).toMatch(`"modelValue": { default: 0 }`)
+ expect(content).toMatch(
+ `const count = _useModel("modelValue", { default: 0 })`
+ )
+ expect(content).not.toMatch('defineModel')
+ expect(bindings).toStrictEqual({
+ count: BindingTypes.SETUP_REF,
+ foo: BindingTypes.PROPS,
+ modelValue: BindingTypes.PROPS
+ })
+ })
+ })
+
test('
+ `,
+ { defineModel: true }
+ )
+ assertCode(content)
+ expect(content).toMatch('"modelValue": [Boolean, String]')
+ expect(content).toMatch('"count": Number')
+ expect(content).toMatch('emits: ["update:modelValue", "update:count"]')
+ expect(content).toMatch(`const modelValue = _useModel("modelValue")`)
+ expect(content).toMatch(`const count = _useModel("count")`)
+ expect(bindings).toStrictEqual({
+ modelValue: BindingTypes.SETUP_REF,
+ count: BindingTypes.SETUP_REF
+ })
+ })
+
+ test('w/ production mode', () => {
+ const { content, bindings } = compile(
+ `
+
+ `,
+ { defineModel: true, isProd: true }
+ )
+ assertCode(content)
+ expect(content).toMatch('"modelValue": Boolean')
+ expect(content).toMatch('"fn": Function')
+ expect(content).toMatch('"str": {}')
+ expect(content).toMatch(
+ 'emits: ["update:modelValue", "update:fn", "update:str"]'
+ )
+ expect(content).toMatch(`const modelValue = _useModel("modelValue")`)
+ expect(content).toMatch(`const fn = _useModel("fn")`)
+ expect(content).toMatch(`const str = _useModel("str")`)
+ expect(bindings).toStrictEqual({
+ modelValue: BindingTypes.SETUP_REF,
+ fn: BindingTypes.SETUP_REF,
+ str: BindingTypes.SETUP_REF
+ })
+ })
+ })
+
test('runtime Enum', () => {
const { content, bindings } = compile(
`