Skip to content

Commit 8e34357

Browse files
authored
fix(compiler-sfc): fix scope handling for props destructure in function parameters and catch clauses
close #12790
1 parent 343c891 commit 8e34357

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,25 @@ return () => {}
192192
}"
193193
`;
194194

195+
exports[`sfc reactive props destructure > handle function parameters with same name as destructured props 1`] = `
196+
"
197+
export default {
198+
setup(__props) {
199+
200+
201+
function test(value) {
202+
try {
203+
} catch {
204+
}
205+
}
206+
console.log(__props.value)
207+
208+
return () => {}
209+
}
210+
211+
}"
212+
`;
213+
195214
exports[`sfc reactive props destructure > multi-variable declaration 1`] = `
196215
"
197216
export default {

packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,22 @@ describe('sfc reactive props destructure', () => {
358358
expect(content).toMatch(`props: ['item'],`)
359359
})
360360

361+
test('handle function parameters with same name as destructured props', () => {
362+
const { content } = compile(`
363+
<script setup>
364+
const { value } = defineProps()
365+
function test(value) {
366+
try {
367+
} catch {
368+
}
369+
}
370+
console.log(value)
371+
</script>
372+
`)
373+
assertCode(content)
374+
expect(content).toMatch(`console.log(__props.value)`)
375+
})
376+
361377
test('defineProps/defineEmits in multi-variable declaration (full removal)', () => {
362378
const { content } = compile(`
363379
<script setup>

packages/compiler-sfc/src/script/definePropsDestructure.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ export function transformDestructuredProps(
291291
parent && parentStack.pop()
292292
if (
293293
(node.type === 'BlockStatement' && !isFunctionType(parent!)) ||
294-
isFunctionType(node)
294+
isFunctionType(node) ||
295+
node.type === 'CatchClause'
295296
) {
296297
popScope()
297298
}

0 commit comments

Comments
 (0)