Subscribe on changes!

Ref sugar compile result incorrect with destructuring + arrow function expression

avatar
Apr 10th 2021

Version

3.0.11

Reproduction link

https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbnJlZjogKHt9ID0gKCkgPT4gMSk7XG5yZWY6ICh7fSA9IHVzZVNvbXRoaW5nKCgpID0+IDEpKTtcbnJlZjogKHt9ID0gdXNlU29tdGhpbmcoY29tcHV0ZWQoKCkgPT4gMSkpKTtcbjwvc2NyaXB0PiJ9

Steps to reproduce

Check the JS compile result.

What is expected?

Result is:

const {} = (() => 1);
const {} = useSomthing((() => 1));
const {} = useSomthing(computed((() => 1)));

What is actually happening?

Result is:

const {} = ( => 1);
const {} = useSomthing(( => 1));
const {} = useSomthing(computed(( => 1)));
avatar
Apr 10th 2021

@johnsoncodehk Assigning a value to {} is not a wise choice, because {}==={} returns false and you will never be able to use the {} you defined. But I think in this case, it would be better to report an exception when compiling.

avatar
Apr 10th 2021

@ygj6 this is just to show the problem, I use something like ref: ({ foo } = useSomthing(...)) in real code, thanks.

avatar
Apr 10th 2021

Oh~~ I did see @HcySunYang 's PR.