-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Using export & then using decorator before the word "default" breaks SFC compilation. #13060
Comments
Perhaps this could be a cleaner "fix" - making the regex's a bit more explicit? |
I'm seeing the same problem in vite. This was a very nasty bug to debug and discover.
Not sure how to accomplish the same result this with I forced the babel parser to 7.19.6 with |
@gbalduzzi Not sure it's particularly to do with Vite. We use Vite also & still managed to work around it.
To our Bare in mind, our intention is that this is temporary. Upgrading to vue3 should resolve the issue properly |
@andrewbrennanfr thank you, I can confirm this works. Yes, this is a temporary solution for us too while we migrate to vue3 |
Version
2.7.14
Reproduction link
https://stackblitz.com/edit/vitejs-vite-bctp3t?file=src%2FApp.vue
Steps to reproduce
Export a const from a SFC.
Use a
vue-property-decorator
with@Component
& export your class component as default.Include the word "default" in a comment (for example).
Your component is not built correctly - in my reproduction example, the props are not initialized as an object. (you can see there is also no console warning related to
someString
).Remove the word "default" from the comment & refresh the page - props will initialize correctly & you also have the expected console warning.
Looks very similar to several issues (such as this one & this one)
Apparently this has been fixed here.
However it fails to work for me when
@babel/parser
is upgraded beyond7.19.6
🟢 Working use case with 7.19.6
🛑 Non-working use case with 7.20.0
After some debugging it seems that the method
hasDefaultExport
invuejs/vue
is the one that's broken for this case & the one invuejs/core
is working.https://github.com/vuejs/vue/blob/main/packages/compiler-sfc/src/rewriteDefault.ts#L91-L93
This regex change here would cause some unit tests (for my use case) start to fail. And for me this regex is maybe too loose.
Here 👉 there's no default export, yet this regex is a match https://regex101.com/r/LmYL8l/1
What is expected?
I expect my component to be built correctly & to not have a comment impacting the behavior of my component.
What is actually happening?
When inspecting the compiled code - it looks to me that the
@Component
decorator here is just completely stripped in the outputted code.🙈 I've probably mistakenly opened an issue on
vue/core
hereWorkaround for me, is to override
@babel/parser
for@vue/sfc-compiler
to be7.19.6
and the problem disappears.Removing the exported const/type/interface/etc from the SFC works around the issue.
Moving the exported const/interface/type/etc below the class component also works around the issue.
This issue is not isolated to only comments, but rather the presence of
default
.Meaning, code such as
@Prop({ type: String, required: false, default: '' })
is also breaking - as the worddefault
here has the same impact.💡 I've attempted a sort of "backport" of the changes from
vue/core
& added a test for my use case. It looks to work.https://github.com/andrewbrennanfr/vue/commits/fix/rewriteDefault-decorator-parsing
The text was updated successfully, but these errors were encountered: