Skip to content

fix(flow): avoid restoring module context when flow syntax is enabled#11819

Merged
kdy1 merged 2 commits intoswc-project:mainfrom
magic-akari:refactor/flow-avoid-restoring-module-context
Apr 25, 2026
Merged

fix(flow): avoid restoring module context when flow syntax is enabled#11819
kdy1 merged 2 commits intoswc-project:mainfrom
magic-akari:refactor/flow-avoid-restoring-module-context

Conversation

@magic-akari
Copy link
Copy Markdown
Member

@magic-akari magic-akari commented Apr 24, 2026

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: 2c448ec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

Binary Sizes

File Size
swc.linux-x64-gnu.node 27M (27782984 bytes)

Commit: 660b2ad

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 24, 2026

Merging this PR will not alter performance

✅ 219 untouched benchmarks
⏩ 31 skipped benchmarks1


Comparing magic-akari:refactor/flow-avoid-restoring-module-context (2c448ec) with main (be38316)

Open in CodSpeed

Footnotes

  1. 31 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@magic-akari magic-akari marked this pull request as ready for review April 24, 2026 16:51
@magic-akari magic-akari requested a review from a team as a code owner April 24, 2026 16:51
Copilot AI review requested due to automatic review settings April 24, 2026 16:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ctx entirely when Config::flow_syntax is 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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +45 to +48
.as_module()
// Flow does not need to restore module context
.filter(|_| !self.config.flow_syntax)
.and_then(|m| self.get_last_module_span(m));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {}.

Copy link
Copy Markdown
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kdy1 kdy1 merged commit 3ed7243 into swc-project:main Apr 25, 2026
85 of 87 checks passed
@github-actions github-actions Bot modified the milestones: Planned, 1.15.32 Apr 25, 2026
@magic-akari magic-akari deleted the refactor/flow-avoid-restoring-module-context branch April 27, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants