-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
use IIFE in script setup throws error #4917
Comments
If you only can reproduce it in a git repo, please share a git repo. We can't debug what we can't reproduce reliably. Issues without reproductions are closed. We can reopen the issue when you provide a runnable reproduction. |
OK,thanks, this is my demo repo, it will throws error when i use IIFE in script setup https://github.com/heart-er/vue3-error-repo |
Okay, can reproduce it and also found a workaround/solution: a leading semicolon: <script setup>
;(() => {
console.log('----')
})()
</script> It seems there's an issue with generated code that's being inserted before that IIFE which breaks ASI. However, it's also a good practice to have a leading semicolon here in general. prettier even adds it for me, usually. |
OK, Thanks for the solution! |
I look into the code and find another problem. see sfc <script setup>
defineExpose({ foo: 123 })
(() => {
console.log('----');
})();
</script> in this case, the |
@edison1105 Well, you need to add a semicolon after In your example you caused it yourself and can fix it yourself. In OP's example there's no previous code that would require a semicolon before compilation, so it must likely be caused and solved by the compiler. |
make sence. |
Version
3.2.21
Reproduction link
sorry, online sfc not throws error
This is my local error and my source code
Steps to reproduce
What is expected?
not throw error
What is actually happening?
use IIFE function in script setup throws error
The text was updated successfully, but these errors were encountered: