Scope hoisting renaming after babel transforms #2292
Merged
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
With this change the renaming part of scope-hoisting seems to work with other babel-transforms as well. E.g.:
<span>Test</span>
gets transpiled toReact.createElement("span", null, "Test")
, but React isn't getting renamed (same forh
of preact, hyperapp). (closes Tree shaking and React #1699, closes Scope hoisting/tree shaking bug (--experimental-scope-hoisting) #2084)babel-plugin-lodash
transforms the ast just like jsx (closes babel lodash plugin and parcel tree shaking #1821)constantViolations undefined
: withstyled-jsx
- closes Experimental scope hoisting: Cannot read property 'constantViolations' of undefined #1538, withplugin-transform-runtime
- closes scope hoisting: Cannot read property 'constantViolations' of undefined #2255I've added test for jsx and superclasses to the scope-hoisting/es6 folder.
Is a reason for the custom renaming logic? All scope-hoisting tests still pass with simply
scope.rename(oldName, newName)
.💻 Examples
Previously, scope-hoisting didn't correctly rename the superclass identifier (same problem with jsx)
src:
Before hoisting:
After hoisting: