Hoist re-export dependencies before module body#1774
Closed
robhogan wants to merge 1 commit into
Closed
Conversation
Summary: In ESM, static imports (including `export * from`) must be evaluated before the current module's body. Metro's `import-export-plugin` currently evaluates named re-exports at their declared position within the body (by turning them into a CJS `require` at that posiiton), and `export *` after the body - both are incorrect. Move static re-export helper requires and export-star copies into the import prelude instead of leaving them at the original export declaration location or after the module body. ## `inlineRequires` Under `inlineRequires`, which runs after this plugin, evaluation of imported modules may be deferred back to where they were before this diff - contrary to the spec but by design for startup performance. ## Spec - Source Text Module Records collect imported and re-exported module specifiers as requested modules: https://tc39.es/ecma262/#sec-source-text-module-records - ECMA-262 `InnerModuleEvaluation` evaluates requested modules before executing the current module body: https://tc39.es/ecma262/#sec-innermoduleevaluation ## Expo Along with the previous diff, this is another change introduced in Expo last year in [#38111](expo/expo#38111), on by default for Expo apps. ## Changelog ```javascript - **[Experimental]**: `experimentalImportSupport`: Move `export from` imports to be evaluated at module prelude, rather than within/after module body ``` Reviewed By: huntie Differential Revision: D111013896
Contributor
|
@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111013896. |
Contributor
|
This pull request has been merged in 27a5adc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
In ESM, static imports (including
export * from) must be evaluated before the current module's body.Metro's
import-export-plugincurrently evaluates named re-exports at their declared position within the body (by turning them into a CJSrequireat that posiiton), andexport *after the body - both are incorrect.Move static re-export helper requires and export-star copies into the import prelude instead of leaving them at the original export declaration location or after the module body.
inlineRequiresUnder
inlineRequires, which runs after this plugin, evaluation of imported modules may be deferred back to where they were before this diff - contrary to the spec but by design for startup performance.Spec
InnerModuleEvaluationevaluates requested modules before executing the current module body: https://tc39.es/ecma262/#sec-innermoduleevaluationExpo
Along with the previous diff, this is another change introduced in Expo last year in #38111, on by default for Expo apps.
Changelog
Reviewed By: huntie
Differential Revision: D111013896