]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): fix scope handling for props destructure in function parameters...
authoredison <daiwei521@126.com>
Tue, 13 May 2025 14:17:24 +0000 (22:17 +0800)
committerGitHub <noreply@github.com>
Tue, 13 May 2025 14:17:24 +0000 (22:17 +0800)
close #12790

packages/compiler-sfc/__tests__/compileScript/__snapshots__/definePropsDestructure.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts
packages/compiler-sfc/src/script/definePropsDestructure.ts

index 1044b0e167cbdd12e57de493d59cde1c2f71539d..9306d31da97401cd3c05d696349edef858fbd559 100644 (file)
@@ -192,6 +192,25 @@ return () => {}
 }"
 `;
 
+exports[`sfc reactive props destructure > handle function parameters with same name as destructured props 1`] = `
+"
+export default {
+  setup(__props) {
+
+    
+    function test(value) {
+      try {
+      } catch {
+      }
+    }
+    console.log(__props.value)
+    
+return () => {}
+}
+
+}"
+`;
+
 exports[`sfc reactive props destructure > multi-variable declaration 1`] = `
 "
 export default {
index 50602eb59bc0fa607d36e3507ff3eca7551f0322..25dd817bbe5d4996808523051c1f3dd231bb7b40 100644 (file)
@@ -358,6 +358,22 @@ describe('sfc reactive props destructure', () => {
     expect(content).toMatch(`props: ['item'],`)
   })
 
+  test('handle function parameters with same name as destructured props', () => {
+    const { content } = compile(`
+    <script setup>
+    const { value } = defineProps()
+    function test(value) {
+      try {
+      } catch {
+      }
+    }
+    console.log(value)
+    </script>
+  `)
+    assertCode(content)
+    expect(content).toMatch(`console.log(__props.value)`)
+  })
+
   test('defineProps/defineEmits in multi-variable declaration (full removal)', () => {
     const { content } = compile(`
     <script setup>
index 27b4d445bbeb83be254ced0ce651379c4b813100..81763cda53469666925a78bba5682aaa1d97fe85 100644 (file)
@@ -291,7 +291,8 @@ export function transformDestructuredProps(
       parent && parentStack.pop()
       if (
         (node.type === 'BlockStatement' && !isFunctionType(parent!)) ||
-        isFunctionType(node)
+        isFunctionType(node) ||
+        node.type === 'CatchClause'
       ) {
         popScope()
       }