Subscribe on changes!

Compilation failed. 使用逗号定义时编译错误

avatar
Sep 26th 2022

Vue version

3.2.39

Link to minimal reproduction

https://sfc.vuejs.org/#eNptUMtOw0AM/BVrL0mlNrmHthJCHDjBneWQLk7ZkH1o7fBQlH/H20LooT55PPbYnkndxlh9jKgatSWTbGQg5DHutbcuhsQwwRH5bkwJPT944tYbhBm6FBwUMllor70Jwkir4S/hdldGytVaezhFTCGSNL1iZz0+ZVROfySAZXQNXBQA+DtiA4+HHg0vMjlEoh0HbqBcwW4P5TT/rwGYl/yijM7ysvxeAJXPhRmseS9eVjfab+uzD+KAALklDi2jIIBMLgW1VmeHNq6NVU/Bi4enq/UvQVotf2glVmWs1RtzpKauqTPZ+Z6qkI61ZFUaPVuHFZLbHFL4JEwirFWWmLWf1fwDqRCLOg==

Steps to reproduce

getCurrentInstance 和其他一起使用逗号定义,会出现编译错误,详见SFC。 Use comma definitions with getCurrentInstance and others, compilation errors will occur, see SFC for details.

What is expected?

Compilation passed.

What is actually happening?

Compilation failed.

System Info

No response

Any additional comments?

No response

avatar
Sep 26th 2022
image 上图为编译错误截图 The picture above is a screenshot of the compilation error.
const { ctx } = getCurrentInstance();
const .....

这样分开定义没问题 It's okay with separate definitions.

avatar
Sep 26th 2022

I have played around with the provided example and here are some observations:

  • the issue disappears with any of these changes:
    • removing props definition;
    • removing emit definition;
    • swapping { ctx } definition with props or emit definitions;
    • adding another definition.
  • the source of the error is obviously the comma after getCurrentInstance() in the compiled output. it is not there if any of the changes described above have been applied.
  • it seems like { ctx } = getCurrentInstance() definition is not the cause - any other definition causes the same error. Here is a link to a more minimal reproduction

Hope this helps.

avatar
Sep 27th 2022

I have played around with the provided example and here are some observations:

  • the issue disappears with any of these changes:

    • removing props definition;
    • removing emit definition;
    • swapping { ctx } definition with props or emit definitions;
    • adding another definition.
  • the source of the error is obviously the comma after getCurrentInstance() in the compiled output. it is not there if any of the changes described above have been applied.

  • it seems like { ctx } = getCurrentInstance() definition is not the cause - any other definition causes the same error. Here is a link to a more minimal reproduction

Hope this helps.

如果有定义并且在getCurrentInstance()后,就会报错,不论是否解构都一样。 把 getCurrentInstance() 放在最后定义则不会出错。

Any definition after getCurrentInstance(), an error will be occur, whether deconstructed or not. And it's okay with getCurrentInstance() at the end of the definition.

avatar
Sep 29th 2022