mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): fix scope handling for props destructure in function parameters and catch clauses
close #12790
This commit is contained in:
parent
343c891224
commit
8e3435779a
|
@ -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`] = `
|
exports[`sfc reactive props destructure > multi-variable declaration 1`] = `
|
||||||
"
|
"
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -358,6 +358,22 @@ describe('sfc reactive props destructure', () => {
|
||||||
expect(content).toMatch(`props: ['item'],`)
|
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)', () => {
|
test('defineProps/defineEmits in multi-variable declaration (full removal)', () => {
|
||||||
const { content } = compile(`
|
const { content } = compile(`
|
||||||
<script setup>
|
<script setup>
|
||||||
|
|
|
@ -291,7 +291,8 @@ export function transformDestructuredProps(
|
||||||
parent && parentStack.pop()
|
parent && parentStack.pop()
|
||||||
if (
|
if (
|
||||||
(node.type === 'BlockStatement' && !isFunctionType(parent!)) ||
|
(node.type === 'BlockStatement' && !isFunctionType(parent!)) ||
|
||||||
isFunctionType(node)
|
isFunctionType(node) ||
|
||||||
|
node.type === 'CatchClause'
|
||||||
) {
|
) {
|
||||||
popScope()
|
popScope()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue