]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
Revert "fix(compiler-sfc): add error handling for defineModel() without varia…" ...
authoredison <daiwei521@126.com>
Tue, 27 May 2025 10:49:34 +0000 (18:49 +0800)
committerGitHub <noreply@github.com>
Tue, 27 May 2025 10:49:34 +0000 (18:49 +0800)
This reverts commit 00734afef5f7bddbdaee52aa5359a6ef989f32d3.

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

index b2a8036a0ee53d9c00a2cfe00da455f98181f2c1..73c6d316a40a77e2cbc95008834fdc96a2fb69a4 100644 (file)
@@ -1007,7 +1007,7 @@ describe('SFC compile <script setup>', () => {
       expect(() =>
         compile(`<script setup>
         let bar = 1
-        const model = defineModel({
+        defineModel({
           default: () => bar
         })
         </script>`),
@@ -1017,7 +1017,7 @@ describe('SFC compile <script setup>', () => {
       expect(() =>
         compile(`<script setup>
         const bar = 1
-        const model = defineModel({
+        defineModel({
           default: () => bar
         })
         </script>`),
@@ -1027,7 +1027,7 @@ describe('SFC compile <script setup>', () => {
       expect(() =>
         compile(`<script setup>
         let bar = 1
-        const model = defineModel({
+        defineModel({
           get: () => bar,
           set: () => bar
         })
index 104d3dc7ab7210d213418fdc3c6559f52ca0023f..5d696a95d8836058c64a8ee4367aaa1127fcfba1 100644 (file)
@@ -269,16 +269,4 @@ describe('defineModel()', () => {
       modelValue: BindingTypes.SETUP_REF,
     })
   })
-
-  test('error when defineModel is not assigned to a variable', () => {
-    expect(() =>
-      compile(`
-        <script setup>
-        defineModel()
-        </script>
-      `),
-    ).toThrow(
-      'defineModel() must be assigned to a variable. For example: const model = defineModel()',
-    )
-  })
 })
index 746bbabe55210a2a0a9f3a1dabd1fb23b06b677b..05082800284667a63c61466fd83950eb898e8de2 100644 (file)
@@ -22,13 +22,6 @@ export function processDefineModel(
     return false
   }
 
-  if (!declId) {
-    ctx.error(
-      'defineModel() must be assigned to a variable. For example: const model = defineModel()',
-      node,
-    )
-  }
-
   ctx.hasDefineModelCall = true
 
   const type =