]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): model name conflict (#8798)
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Fri, 20 Oct 2023 09:36:36 +0000 (17:36 +0800)
committerGitHub <noreply@github.com>
Fri, 20 Oct 2023 09:36:36 +0000 (17:36 +0800)
packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineModel.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts
packages/compiler-sfc/src/script/context.ts

index fdfd3710efcabd33d4201dd6f6d83e5b2c42238a..297ee62724c0ba5a3b10349b31fdad3b91a1ad4c 100644 (file)
@@ -7,15 +7,17 @@ export default {
   props: {
     \\"modelValue\\": { required: true },
     \\"count\\": {},
+    \\"toString\\": { type: Function },
   },
-  emits: [\\"update:modelValue\\", \\"update:count\\"],
+  emits: [\\"update:modelValue\\", \\"update:count\\", \\"update:toString\\"],
   setup(__props, { expose: __expose }) {
   __expose();
 
       const modelValue = _useModel(__props, \\"modelValue\\")
       const c = _useModel(__props, \\"count\\")
+      const toString = _useModel(__props, \\"toString\\")
       
-return { modelValue, c }
+return { modelValue, c, toString }
 }
 
 }"
index 61a9adcbe0de28b27b588bda36a6f1e39dd52eb9..10fab947c13a6c3acceb6983e548fce387a935f3 100644 (file)
@@ -8,6 +8,7 @@ describe('defineModel()', () => {
       <script setup>
       const modelValue = defineModel({ required: true })
       const c = defineModel('count')
+      const toString = defineModel('toString', { type: Function })
       </script>
       `,
       { defineModel: true }
@@ -16,18 +17,22 @@ describe('defineModel()', () => {
     expect(content).toMatch('props: {')
     expect(content).toMatch('"modelValue": { required: true },')
     expect(content).toMatch('"count": {},')
-    expect(content).toMatch('emits: ["update:modelValue", "update:count"],')
+    expect(content).toMatch('"toString": { type: Function },')
+    expect(content).toMatch(
+      'emits: ["update:modelValue", "update:count", "update:toString"],'
+    )
     expect(content).toMatch(
       `const modelValue = _useModel(__props, "modelValue")`
     )
     expect(content).toMatch(`const c = _useModel(__props, "count")`)
-    expect(content).toMatch(`return { modelValue, c }`)
+    expect(content).toMatch(`return { modelValue, c, toString }`)
     expect(content).not.toMatch('defineModel')
 
     expect(bindings).toStrictEqual({
       modelValue: BindingTypes.SETUP_REF,
       count: BindingTypes.PROPS,
-      c: BindingTypes.SETUP_REF
+      c: BindingTypes.SETUP_REF,
+      toString: BindingTypes.SETUP_REF
     })
   })
 
index 5fe09d28a4289e146d83c2aedaa50147690984e3..692eab3ab9e09f9238a05e4140d7f84bee94f9ee 100644 (file)
@@ -53,7 +53,7 @@ export class ScriptCompileContext {
   emitDecl: Node | undefined
 
   // defineModel
-  modelDecls: Record<string, ModelDecl> = {}
+  modelDecls: Record<string, ModelDecl> = Object.create(null)
 
   // defineOptions
   optionsRuntimeDecl: Node | undefined