mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): allow declaring variables after defineProps (#7461)
* fix(compiler-sfc): allow declaring variables after defineProps * test(compiler-sfc): test defineProps in multiple variable declaration
This commit is contained in:
parent
1fa3d95730
commit
686c829fec
|
@ -136,6 +136,24 @@ return () => {}
|
|||
})"
|
||||
`;
|
||||
|
||||
exports[`sfc props transform multiple variable declarations 1`] = `
|
||||
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
|
||||
|
||||
|
||||
export default {
|
||||
props: ['foo'],
|
||||
setup(__props) {
|
||||
|
||||
const bar = 'fish', hello = 'world'
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock("div", null, _toDisplayString(__props.foo) + " " + _toDisplayString(hello) + " " + _toDisplayString(bar), 1 /* TEXT */))
|
||||
}
|
||||
}
|
||||
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`sfc props transform nested scope 1`] = `
|
||||
"export default {
|
||||
props: ['foo', 'bar'],
|
||||
|
|
|
@ -28,6 +28,26 @@ describe('sfc props transform', () => {
|
|||
})
|
||||
})
|
||||
|
||||
test('multiple variable declarations', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup>
|
||||
const bar = 'fish', { foo } = defineProps(['foo']), hello = 'world'
|
||||
</script>
|
||||
<template><div>{{ foo }} {{ hello }} {{ bar }}</div></template>
|
||||
`)
|
||||
expect(content).not.toMatch(`const { foo } =`)
|
||||
expect(content).toMatch(`const bar = 'fish', hello = 'world'`)
|
||||
expect(content).toMatch(`_toDisplayString(hello)`)
|
||||
expect(content).toMatch(`_toDisplayString(bar)`)
|
||||
expect(content).toMatch(`_toDisplayString(__props.foo)`)
|
||||
assertCode(content)
|
||||
expect(bindings).toStrictEqual({
|
||||
foo: BindingTypes.PROPS,
|
||||
bar: BindingTypes.SETUP_CONST,
|
||||
hello: BindingTypes.SETUP_CONST
|
||||
})
|
||||
})
|
||||
|
||||
test('nested scope', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup>
|
||||
|
|
|
@ -1758,8 +1758,7 @@ function walkDeclaration(
|
|||
registerBinding(bindings, id, bindingType)
|
||||
} else {
|
||||
if (isCallOf(init, DEFINE_PROPS)) {
|
||||
// skip walking props destructure
|
||||
return
|
||||
continue
|
||||
}
|
||||
if (id.type === 'ObjectPattern') {
|
||||
walkObjectPattern(id, bindings, isConst, isDefineCall)
|
||||
|
|
Loading…
Reference in New Issue