Skip to content

Hoist re-export dependencies before module body#1774

Closed
robhogan wants to merge 1 commit into
mainfrom
export-D111013896
Closed

Hoist re-export dependencies before module body#1774
robhogan wants to merge 1 commit into
mainfrom
export-D111013896

Conversation

@robhogan

Copy link
Copy Markdown
Contributor

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

Expo

Along with the previous diff, this is another change introduced in Expo last year in #38111, on by default for Expo apps.

Changelog

  - **[Experimental]**: `experimentalImportSupport`: Move `export from` imports to be evaluated at module prelude, rather than within/after module body

Reviewed By: huntie

Differential Revision: D111013896

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
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 10, 2026
@meta-codesync

meta-codesync Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111013896.

@meta-codesync

meta-codesync Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 27a5adc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant