Skip to content

Commit b2b5f57

Browse files
authoredMay 8, 2024··
fix(compile-sfc): register props destructure rest id as setup bindings (#10888)
close #10885
1 parent 4619461 commit b2b5f57

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
 

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

+16
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,19 @@ return () => {}
304304
305305
}"
306306
`;
307+
308+
exports[`sfc reactive props destructure > rest spread non-inline 1`] = `
309+
"import { createPropsRestProxy as _createPropsRestProxy } from 'vue'
310+
311+
export default {
312+
props: ['foo', 'bar'],
313+
setup(__props, { expose: __expose }) {
314+
__expose();
315+
316+
const rest = _createPropsRestProxy(__props, ["foo"])
317+
318+
return { rest }
319+
}
320+
321+
}"
322+
`;

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

+21
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,27 @@ describe('sfc reactive props destructure', () => {
265265
})
266266
})
267267

268+
test('rest spread non-inline', () => {
269+
const { content, bindings } = compile(
270+
`
271+
<script setup>
272+
const { foo, ...rest } = defineProps(['foo', 'bar'])
273+
</script>
274+
<template>{{ rest.bar }}</template>
275+
`,
276+
{ inlineTemplate: false },
277+
)
278+
expect(content).toMatch(
279+
`const rest = _createPropsRestProxy(__props, ["foo"])`,
280+
)
281+
assertCode(content)
282+
expect(bindings).toStrictEqual({
283+
foo: BindingTypes.PROPS,
284+
bar: BindingTypes.PROPS,
285+
rest: BindingTypes.SETUP_REACTIVE_CONST,
286+
})
287+
})
288+
268289
// #6960
269290
test('computed static key', () => {
270291
const { content, bindings } = compile(`

‎packages/compiler-sfc/src/compileScript.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,14 @@ export function compileScript(
523523
)
524524
}
525525

526-
// defineProps / defineEmits
526+
// defineProps
527527
const isDefineProps = processDefineProps(ctx, init, decl.id)
528+
if (ctx.propsDestructureRestId) {
529+
setupBindings[ctx.propsDestructureRestId] =
530+
BindingTypes.SETUP_REACTIVE_CONST
531+
}
532+
533+
// defineEmits
528534
const isDefineEmits =
529535
!isDefineProps && processDefineEmits(ctx, init, decl.id)
530536
!isDefineEmits &&

0 commit comments

Comments
 (0)
Please sign in to comment.