fix(flow): avoid restoring module context when flow syntax is enabled#11819
Conversation
|
Binary Sizes
Commit: 660b2ad |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
Adjusts the TypeScript/Flow strip pass to avoid re-introducing ESM module context for Flow inputs, preventing synthetic export {} from being emitted after Flow type-only imports/exports are stripped (relevant to the reported export type script/IIFE scenario).
Changes:
- Skip
restore_esm_ctxentirely whenConfig::flow_syntaxis enabled. - Simplify last-module-span detection by removing the Flow-only “runtime ESM decl” check and the associated helper methods/import.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c448ec21c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| .as_module() | ||
| // Flow does not need to restore module context | ||
| .filter(|_| !self.config.flow_syntax) | ||
| .and_then(|m| self.get_last_module_span(m)); |
There was a problem hiding this comment.
Keep module restoration for Flow runtime modules
Skipping last_module_span for every Flow input means restore_esm_ctx is never called, even when the original Flow module had runtime ESM that gets stripped later (for example, an unused value import). In transform.rs (strip_module_items_with_semantic), unused non-type imports can be dropped entirely once specifiers are emptied, so this change can turn those files into output with no import/export markers and change module-vs-script behavior (e.g. top-level this / strict-mode assumptions in unambiguous consumers). Previously this path still restored export {}; now it does not.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is exactly what we expected. Flow’s context mode is different from that of TypeScript, and judging from Babel’s behavior, it does not restore the module context at all by adding export {}.
Description:
BREAKING CHANGE:
Related issue (if exists):
export typeissues #11808