Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wenkm opened this issue Sep 26, 2022 · 4 comments · Fixed by #6778
Closed

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

wenkm opened this issue Sep 26, 2022 · 4 comments · Fixed by #6778

Comments

@wenkm
Copy link

wenkm commented Sep 26, 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

@wenkm
Copy link
Author

wenkm commented Sep 26, 2022

image

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

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

@Amixx
Copy link

Amixx commented Sep 26, 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.

@wenkm
Copy link
Author

wenkm commented Sep 27, 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.

@shengxinjing
Copy link
Contributor

shengxinjing commented Sep 29, 2022

preview url

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants