Skip to content
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: not import @swc/helpers in script tag without type="module" #7599

Conversation

Shinyaigeek
Copy link
Contributor

@Shinyaigeek Shinyaigeek commented Jan 23, 2022

↪️ 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 while swc 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

<html>
<script>
  function hoge() {
    return [1,2,3]
}

const [one, two] = hoge();
</script>
</html>

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

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@height
Copy link

height bot commented Jan 23, 2022

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@Shinyaigeek Shinyaigeek changed the title Fix/import swc helper errors on script Fix: not import @swc/helpers in script tag without type="module" Jan 23, 2022
@Shinyaigeek Shinyaigeek force-pushed the fix/import-swc-helper-errors-on-script branch from f040669 to ae49891 Compare January 23, 2022 10:56
@Shinyaigeek Shinyaigeek marked this pull request as draft January 23, 2022 10:59
@Shinyaigeek Shinyaigeek force-pushed the fix/import-swc-helper-errors-on-script branch from ae49891 to e9bd92a Compare January 23, 2022 10:59
Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reasonable fix. Thanks!

@devongovett devongovett merged commit a930ba5 into parcel-bundler:v2 Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parcel Incorrectly Detects Destructuring Assignment As Module Usage
2 participants