vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.75k stars 8.35k forks source link

Cannot use prop as default value for other prop with props destructuring const { foo, bar = foo } #12386

Open minht11 opened 1 week ago

minht11 commented 1 week ago

Vue version

3.5.12

Link to minimal reproduction

https://play.vuejs.org/#__PROD__eNp9UsFOwzAM/RUrF0CaOsHgUrohQEOCA0zAMRIqrVsy2iRK0jKp6r/jZOvY0LRTbL/n5NkvHbvVOmobZDFLHNa6Sh3OuARIHpSCuFBqytlJesIZjKmejHdIlNrMCO3Aoms0VUStlXHgWwujauAsGlPiH+Ds2revG4jKRszZTMlClNHSKkkCOv8uZ5mqtajQvGgnlLScxRAQj6VVpX6eQs2ZBkdDPfvC7PtAfWlXvsbZwqBF05KMLeZSU6Jbw/O3Z1xRvAVrlTcVsY+Ar2hV1XiNa9pdI3OSvcMLah/DToQs3+185VDaYSgv1DP7wOeMlnR/ZPQ/uZPoMvRx2dMWN/v1Bm7cqFJZkmuO+rfO0Katgw7I0BF8pgamPoSezhwLIXFhlLZJIMRgnSHBgXgzZNDPTs/2LKRk/8vkog3BJgxXdR0dfZ+M/4F09QFwiPb+GQ350aLxi6MpJ9FVdH7B+l9N7+ZX

Steps to reproduce

Have code like this: const { foo, bar = foo } = defineProps<{ foo: string, bar?: string }>()

What is expected?

No error.

What is actually happening?

Error foo is not defined

System Info

n/a

Any additional comments?

const { a, b = a } = { a: 1, b: undefined } is valid syntax in regular js and as such should be supported in vue also.