Fix transformation of import/requires wrapped into Promise.resolve(). #8167
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
Previously we noticed that parcel incorrectly transforms
Promise.resolve(import('foo')).then(...)
as described in #8116.The transformer that rewrites the nodes of the code
Promise.resolve().then(() => return require('foo'))
erroneously restructures the above code too.However, there is no need to transform this require/import statement, when wrapped into
Promise.resolve()
because it is used to promisify the import in the first place.This PR adds a unit test to illustrate the issue, and a condition that prevents the incorrect processing of the statement.
💻 Examples
Expected behaviour
Current behaviour
The current code causes the runtime to crash because it injects a variable called
res
incorrectly, and thus destroys the code.🚨 Test instructions
Or use the minimal reproduction code here
✔️ PR Todo