-
Notifications
You must be signed in to change notification settings - Fork 575
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
fix: fix web-component tag name transform issue #1318
fix: fix web-component tag name transform issue #1318
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
be6fb21
to
3d812d5
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 3d812d5. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
// For exmaple: we pass a tag called "swiper-container", and it will be renamed as "swiper - container" after babel transforming, | ||
// because babel will automatically identify the "-" as an operator, and add a space before and after it. | ||
// So we need to replace ' - ' with '-' to fix this issue. | ||
return babelTransform({ code, visitor, stripTypes })?.code?.replace(' - ', '-') || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution is too extreme/broad: it will replace every single occurrence of -
with -
across every code block evaluated by the Mitosis compiler. That includes all props, state, event handlers, etc. This means that even comments inside functions will be transformed by this change.
I don't mind having a .replace()
approach, but it would need to be localized to only the JSX tag name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If you run
yarns snapupdate
inmitosis/core
, you will see how much this code change impacts generated code. - you also need to
yarn run fmt:prettier
to lint this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks @samijaber. I will soon submit a new patch for this PR.
I just commented a better solution to this problem here: #1303 (comment) Thanks a lot for taking this on! |
3d812d5
to
4193f2c
Compare
4193f2c
to
252fc2e
Compare
252fc2e
to
200df04
Compare
200df04
to
a2038bb
Compare
Hi @samijaber, I have commited new changes based on your advices, and have added snapshot and unit test. Please hava a look when you have time. |
b9dabcf
to
ad49e3a
Compare
Hi @samijaber! Please check the pr if you have the free time, thanks. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit f4b2c92. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
401c54a
to
3cf894d
Compare
3cf894d
to
44ad269
Compare
413393e
to
abce2ee
Compare
abce2ee
to
f4b2c92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful fix. Well done. Thanks for the contribution! 🎉
Description
Fix the web-component tag issue mentioned in #1303
Issue Reason
The babel transform will automatically identify the "-" as an operator, and add a space before and after it.
So when it met a tag name such as
swiper-container
provided byweb-components
, it will transform the tag name asswiper - container
.How to Fix
We need to replace ' - ' with '-' in the babel transformed code to fix this issue.