Fix: not import @swc/helpers
in script tag without type="module"
#7599
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
↪️ Pull Request
Fixes: #7597
Hi team! 👋
I investigated about #7597 bug. I found that this issue is caused by the behavior of
swc
replacing new(?) JavaScript syntax with the module imported from@swc/helpers
whileswc
parses the source code. This inserted import declaration causes this error.I fixed this by changing the behavior of importing polyfill into inserting itself.
💻 Examples
This script will be transpiled. see https://play.swc.rs/?version=1.2.133&code=H4sIAAAAAAAAA0srzUsuyczPU8jIT0%2FV0FSo5lIAgqLUktKiPIVoQx0jHeNYrlouruT8vOIShej8vFQdhZLy%2FFgFW6gOawBY3PGGQgAAAA%3D%3D&config=H4sIAAAAAAAAA01POw7CMAy9i2c2JIaegIVDWKlbBeUn20GtqtwdJ1TA9uz3sw94ioPpgIIsxB3JnhQ3mED3QuLYF4ULqNhqwSDUbEBeSU1CcjUu5Cx0shegTYkThjuFQiwwKVdbR5%2F8svcCl2NhEvk6IqY10F88Y5Ilc%2BxqJnQ6QE3qo8kAq%2BaI6p11z%2FSikEukpJ%2Bm1iwh5rn2xGM8MQ69QfsdcRZ7eZzC4XwDSiW6fQ0BAAA%3D
🚨 Test instructions
I've written a test to make sure it doesn't give an error and doesn't import swc helper in a bundled HTML with targeting Chrome 48, which doesn't support Array Destructuring.
✔️ PR Todo