facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.25k stars 626 forks source link

Fix `inlinePlugin` replacing `__DEV__` in invalid Babel AST locations #1195

Closed kitten closed 10 months ago

kitten commented 10 months ago

Summary

We've encountered this as part of a report on the expo repo: https://github.com/expo/expo/issues/25965

There, an issue is caused by a dependency using an export alias named __DEV__, which the inlinePlugin is trying to replace:

export { DEV as __DEV__ };

This only occurs in certain cases, since usually, as part of the iOS/Android builds, we would be applying the inlinePlugin only after export statements, where this issue may occur, have been transpiled away.

However, looking at this issue, I found more cases that would fail with the current implementation of the inlinePlugin. This is part of what I added in tests but not an exhaustive list:

All of these issues can be addressed by letting this replacement use ReferencedIdentifier as a visitor, rather than just Identifier.

Test plan

facebook-github-bot commented 10 months ago

Hi @kitten!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

codecov-commenter commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (702e1b8) 83.31% compared to head (7857c4d) 83.31%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1195 +/- ## ========================================== - Coverage 83.31% 83.31% -0.01% ========================================== Files 207 207 Lines 10633 10631 -2 Branches 2642 2640 -2 ========================================== - Hits 8859 8857 -2 Misses 1774 1774 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

facebook-github-bot commented 10 months ago

@motiz88 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot commented 10 months ago

@motiz88 merged this pull request in facebook/metro@8eeb5dbc5afbd7b4d6de867214c0f7485d6f578e.