Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 1, 2025

Implementation Complete: ES2020 Export Namespace From Transformation

Successfully implemented the transformation for export * as ns from "mod" to convert it to:

import * as _ns from "mod";
export { _ns as ns };

Changes Made:

  • Core transformation in es2020/export_namespace_from.rs
  • ES2020 module integration and options
  • Browser compatibility mapping in oxc_compat (auto-generated from custom compat data)
  • Babel plugin support (transform-export-namespace-from)
  • Target-based transformation (works with old browsers, skips modern ones)
  • Code optimizations (removed clones, reserved capacity, used vec1)
  • Custom compat data infrastructure for features not in compat-table
  • Early return optimization to avoid unnecessary allocations
  • Implemented GatherNodeParts for ModuleExportName to avoid string allocations
  • All tests passing ✅

Code Review Addressed:

  • Reserved capacity for statements vector
  • Removed unnecessary clones via destructuring
  • Used ctx.ast.vec1() for single-element vectors
  • Created custom compat data system to avoid manual edits
  • Imported TransformCtx directly
  • Added early return when no export namespace declarations exist
  • Implemented GatherNodeParts for ModuleExportName and use generate_uid_based_on_node

Example:

Input:

export * as ns from "mod";

Output:

import * as _ns from 'mod';
export { _ns as ns };
Original prompt

This section details on the original issue you should resolve

<issue_title>transformer: transform export * as ns from "mod"; to import * as ns from "mod"; export { ns }</issue_title>
<issue_description>This transformation is supported by babel: https://babeljs.io/docs/babel-plugin-transform-export-namespace-from

export * as ns from "mod";

// to

import * as _ns from "mod";
export { _ns as ns };
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
Fixes #14257

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 1, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copilot AI changed the title [WIP] transformer: transform export * as ns from "mod"; to import * as ns from "mod"; export { ns } transformer: Add ES2020 export namespace from transformation Oct 1, 2025
Copilot AI requested a review from sapphi-red October 1, 2025 12:33
Copilot finished work on behalf of sapphi-red October 1, 2025 12:33
Copilot AI requested a review from sapphi-red October 2, 2025 03:53
Copilot finished work on behalf of sapphi-red October 2, 2025 03:53
Copilot AI requested a review from sapphi-red October 2, 2025 04:26
Copilot finished work on behalf of sapphi-red October 2, 2025 04:26
@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Oct 2, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 2, 2025

CodSpeed Performance Report

Merging #14277 will not alter performance

Comparing copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 (7b7c67b) with main (d0a8e3e)1

Summary

✅ 33 untouched
⏩ 4 skipped2

Footnotes

  1. No successful run was found on main (a631dd7) during the generation of this report, so d0a8e3e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 4 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.

@sapphi-red sapphi-red changed the base branch from main to graphite-base/14277 October 3, 2025 13:54
@sapphi-red sapphi-red force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch from 206a446 to da2a113 Compare October 3, 2025 13:54
@sapphi-red sapphi-red changed the base branch from graphite-base/14277 to 10-03-feat-compat-add-custom-compat-data-for-export-namespace-from October 3, 2025 13:54
Copy link
Member

sapphi-red commented Oct 3, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sapphi-red sapphi-red force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch from da2a113 to e1775f4 Compare October 3, 2025 13:58
@sapphi-red sapphi-red changed the title transformer: Add ES2020 export namespace from transformation feat(transformer): add ES2020 export namespace from transformation Oct 3, 2025
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Oct 3, 2025
@sapphi-red sapphi-red force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch 2 times, most recently from bbbd512 to ce11e1e Compare October 3, 2025 14:57
@sapphi-red sapphi-red force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch from ce11e1e to 695cf4d Compare October 3, 2025 15:01
@sapphi-red sapphi-red requested a review from Dunqing as a code owner October 3, 2025 16:32
@sapphi-red sapphi-red force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch from 1686f42 to da4b742 Compare October 4, 2025 14:24
@sapphi-red sapphi-red force-pushed the 10-03-feat-compat-add-custom-compat-data-for-export-namespace-from branch from 13f3e7b to be53dad Compare October 4, 2025 14:24
@sapphi-red sapphi-red changed the base branch from 10-03-feat-compat-add-custom-compat-data-for-export-namespace-from to graphite-base/14277 October 7, 2025 04:36
@sapphi-red sapphi-red force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch from da4b742 to 524a43b Compare October 7, 2025 04:37
@sapphi-red sapphi-red force-pushed the graphite-base/14277 branch from be53dad to f81e2bd Compare October 7, 2025 04:37
@sapphi-red sapphi-red changed the base branch from graphite-base/14277 to 10-03-feat-compat-add-custom-compat-data-for-export-namespace-from October 7, 2025 04:37
@graphite-app graphite-app bot changed the base branch from 10-03-feat-compat-add-custom-compat-data-for-export-namespace-from to graphite-base/14277 October 7, 2025 07:46
@graphite-app graphite-app bot force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch from 524a43b to 1c34540 Compare October 7, 2025 07:54
@graphite-app graphite-app bot force-pushed the graphite-base/14277 branch from f81e2bd to d1ff718 Compare October 7, 2025 07:54
@graphite-app graphite-app bot changed the base branch from graphite-base/14277 to main October 7, 2025 07:54
@graphite-app graphite-app bot force-pushed the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch from 1c34540 to 6f30b10 Compare October 7, 2025 07:54
Copy link
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

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

I just noticed that we should improve the case where there is no export * as ns from "mod".


Additionally, we could try an alternative approach to implement this, which may have better performance than this in some scenarios.

How to implement it?

Do transform in exit_module_declaration. In this method, you can get a ModuleDeclaration, then check whether this is an ExportAllDeclaration whose exported is some, if so, you mutate it with the export part (export { _ns as ns }), and insert the import part (import * as _ns from "mod") by self.ctx.statement_injector.insert_before.

@Dunqing
Copy link
Member

Dunqing commented Oct 9, 2025

@copilot please check the requested changes

- Import TransformCtx directly instead of using full path
- Add early return to avoid unnecessary allocation when no export namespace declarations exist
- Use exported_name.name() to get the identifier name directly
- Simplify UID generation

Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
Copilot AI requested a review from Dunqing October 9, 2025 02:44
Copilot finished work on behalf of Dunqing October 9, 2025 02:44
Implement GatherNodeParts trait for ModuleExportName to avoid string allocation
when generating UIDs. This allows using generate_uid_based_on_node instead of
generate_uid with name().as_str(), eliminating unnecessary to_string() allocation.

Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
Copilot finished work on behalf of Dunqing October 11, 2025 02:45
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Signed-off-by: Dunqing <dengqing0821@gmail.com>
@Dunqing Dunqing merged commit bc4f0a1 into main Oct 11, 2025
28 checks passed
@Dunqing Dunqing deleted the copilot/fix-ced06a9a-b046-4d87-90de-6fe4af5bb650 branch October 11, 2025 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transformer: transform export * as ns from "mod"; to import * as ns from "mod"; export { ns }

3 participants