Compilation failed. 使用逗号定义时编译错误
Vue version
3.2.39
Link to minimal reproduction
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
const { ctx } = getCurrentInstance();
const .....
这样分开定义没问题 It's okay with separate definitions.
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.
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 reproductionHope 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.