Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Dec 2, 2025

NAPI-RS 3.6.0 makes a change to the ordering of objects. It now puts optional fields last.

This made tests in napi/parser for module record fail when we tried to update (#16383) because the module_request field of ExportEntry moves to last which breaks the snapshots.

The change in NAPI-RS is unlikely to be reverted, because it's a sizeable perf optimization: napi-rs/napi-rs#2990

To work around this problem:

  1. Move the field in the ExportEntry intermediate struct in napi/parser to last, so NAPI's output matches what you'd expect from the struct definition.
  2. Alter the #[estree] attr on ExportEntry struct in oxc_syntax crate to match.

Note: The ExportEntry struct in napi/parser is just an intermediate structure used for serialization. So I think it's fine to fiddle with its field order. The actual ExportEntry struct used in the module record is in oxc_syntax crate, and it remains unaltered.

@github-actions github-actions bot added the A-parser Area - Parser label Dec 2, 2025
Copy link
Member Author


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.

@github-actions github-actions bot added the C-bug Category - Bug label Dec 2, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 2, 2025

CodSpeed Performance Report

Merging #16403 will not alter performance

Comparing 12-02-fix_napi_parser_move_exportentry_module_request_field_to_last (18d85c2) with main (f29e7a5)1

Summary

✅ 42 untouched
⏩ 3 skipped2

Footnotes

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

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

@overlookmotel overlookmotel marked this pull request as ready for review December 2, 2025 17:42
Copilot AI review requested due to automatic review settings December 2, 2025 17:42
@overlookmotel overlookmotel self-assigned this Dec 2, 2025
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Dec 2, 2025
Copy link
Member Author

overlookmotel commented Dec 2, 2025

Merge activity

…16403)

NAPI-RS 3.6.0 makes a change to the ordering of objects. It now puts optional fields last.

This made tests in `napi/parser` for module record fail when we tried to update (#16383) because the `module_request` field of `ExportEntry` moves to last which breaks the snapshots.

The change in NAPI-RS is unlikely to be reverted, because it's a sizeable perf optimization: napi-rs/napi-rs#2990

To work around this problem:

1. Move the field in the `ExportEntry` intermediate struct in `napi/parser` to last, so NAPI's output matches what you'd expect from the struct definition.
2. Alter the `#[estree]` attr on `ExportEntry` struct in `oxc_syntax` crate to match.

Note: The `ExportEntry` struct in `napi/parser` is just an intermediate structure used for serialization. So I think it's fine to fiddle with its field order. The actual `ExportEntry` struct used in the module record is in `oxc_syntax` crate, and it remains unaltered.
@graphite-app graphite-app bot force-pushed the 12-02-fix_napi_parser_move_exportentry_module_request_field_to_last branch from 18d85c2 to 12bd794 Compare December 2, 2025 17:42
@overlookmotel overlookmotel changed the title fix(napi/parser): move ExportEntry::module_request field to last fix(napi/parser): reorder fields of ExportEntry on JS side Dec 2, 2025
Copy link
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

This PR adapts the ExportEntry serialization to accommodate NAPI-RS 3.6.0's performance optimization which places optional fields last in serialized objects. The change ensures test snapshots pass by aligning the field order across Rust, TypeScript, and generated code.

  • Moved module_request optional field to last position in StaticExportEntry struct definition
  • Updated #[estree] attribute with explicit field_order to control serialization
  • Regenerated all affected code including TypeScript definitions, ESTree serializers, and JavaScript deserializers

Reviewed changes

Copilot reviewed 3 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
napi/parser/src/types.rs Moved module_request field from line 185 to line 203 in StaticExportEntry struct
napi/parser/src-js/index.d.ts Updated TypeScript definition to match Rust struct field ordering
crates/oxc_syntax/src/module_record.rs Added field_order attribute to #[estree] macro to explicitly control serialization order
crates/oxc_syntax/src/generated/derive_estree.rs Regenerated ESTree serializer with moduleRequest field serialized last
napi/parser/generated/deserialize/*.js Updated all 8 deserializer variants to construct objects with moduleRequest property last
napi/parser/test/snapshots/esm.test.ts.snap Updated snapshot expectations to reflect new field ordering in JSON output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@graphite-app graphite-app bot merged commit 12bd794 into main Dec 2, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 12-02-fix_napi_parser_move_exportentry_module_request_field_to_last branch December 2, 2025 17:48
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 2, 2025
graphite-app bot pushed a commit that referenced this pull request Dec 2, 2025
…ll` (#16411)

Follow-on after #16383 and #16403.

While working on those I discovered an option NAPI-RS has to represent `Option::None` as `null`, instead of omitting the field entirely.

Use that option on the structs used for transferring errors and module record over to JS.

I think this is likely more performant because:

1. NAPI-RS can create all properties of the objects using only the faster `node_api_create_object_with_properties` API.
2. It produces consistent object shapes, so JS engine can better optimize code using these objects.

It also brings the shape of the data perfectly into line between standard transfer and raw transfer, and is consistent with how empty fields in the AST are represented as `null`.

I would have used this option before if I'd known it existed.

### Breaking change

I've marked this as a breaking change because code consuming these objects would now need to check for empty fields with `value === null` instead of `value === undefined`.

However in practice, most people probably use `!value` or `value ?? ...`, so it's unlikely to affect many users. This only affects module record and errors anyway, not the AST itself, as we transfer that as JSON, not via NAPI.
graphite-app bot pushed a commit that referenced this pull request Dec 2, 2025
…16412)

Revert the change made in #16403. It's no longer necessary after #16411, because NAPI-RS no longer re-orders the fields.
Afsoon pushed a commit to Afsoon/oxc that referenced this pull request Dec 3, 2025
…ll` (oxc-project#16411)

Follow-on after oxc-project#16383 and oxc-project#16403.

While working on those I discovered an option NAPI-RS has to represent `Option::None` as `null`, instead of omitting the field entirely.

Use that option on the structs used for transferring errors and module record over to JS.

I think this is likely more performant because:

1. NAPI-RS can create all properties of the objects using only the faster `node_api_create_object_with_properties` API.
2. It produces consistent object shapes, so JS engine can better optimize code using these objects.

It also brings the shape of the data perfectly into line between standard transfer and raw transfer, and is consistent with how empty fields in the AST are represented as `null`.

I would have used this option before if I'd known it existed.

### Breaking change

I've marked this as a breaking change because code consuming these objects would now need to check for empty fields with `value === null` instead of `value === undefined`.

However in practice, most people probably use `!value` or `value ?? ...`, so it's unlikely to affect many users. This only affects module record and errors anyway, not the AST itself, as we transfer that as JSON, not via NAPI.
Afsoon pushed a commit to Afsoon/oxc that referenced this pull request Dec 3, 2025
…xc-project#16412)

Revert the change made in oxc-project#16403. It's no longer necessary after oxc-project#16411, because NAPI-RS no longer re-orders the fields.
overlookmotel pushed a commit that referenced this pull request Dec 8, 2025
### 💥 BREAKING CHANGES

- 083fea9 napi/parser: [**BREAKING**] Represent empty optional fields on
JS side as `null` (#16411) (overlookmotel)

### 🚀 Features

- 7a2afee parser: Add TS1174 error for classes extending multiple base
classes (#15993) (sapphi-red)
- da87812 semantic: Add TS2309 error for export assignment with other
exports (#15992) (sapphi-red)
- d6d2bcd minifier: Remove unused function calls that are marked by
`manual_pure_functions` (#16534) (sapphi-red)
- c90f053 minifier: Support `.` separated values for
`compress.treeshake.manualPureFunctions` (#16529) (sapphi-red)
- a607cc4 codegen: Preserve comments between CatchClause's param and
body (#16167) (copilot-swe-agent)
- 8c10694 semantic: Expose get_comment_at method (#16439) (camc314)
- 3981e7a ast: Add get_comment_at to lookup a comment by span (#16438)
(camc314)

### 🐛 Bug Fixes

- 699406a napi/parser: Move `ExportEntry::module_request` field to first
(#16412) (overlookmotel)
- 12bd794 napi/parser: Move `ExportEntry::module_request` field to last
(#16403) (overlookmotel)

### ⚡ Performance

- 790beeb napi/parser: Do not remove extraneous options on JS side
(#16447) (overlookmotel)

Co-authored-by: Boshen <[email protected]>
Copilot AI pushed a commit that referenced this pull request Dec 10, 2025
### 💥 BREAKING CHANGES

- 083fea9 napi/parser: [**BREAKING**] Represent empty optional fields on
JS side as `null` (#16411) (overlookmotel)

### 🚀 Features

- 7a2afee parser: Add TS1174 error for classes extending multiple base
classes (#15993) (sapphi-red)
- da87812 semantic: Add TS2309 error for export assignment with other
exports (#15992) (sapphi-red)
- d6d2bcd minifier: Remove unused function calls that are marked by
`manual_pure_functions` (#16534) (sapphi-red)
- c90f053 minifier: Support `.` separated values for
`compress.treeshake.manualPureFunctions` (#16529) (sapphi-red)
- a607cc4 codegen: Preserve comments between CatchClause's param and
body (#16167) (copilot-swe-agent)
- 8c10694 semantic: Expose get_comment_at method (#16439) (camc314)
- 3981e7a ast: Add get_comment_at to lookup a comment by span (#16438)
(camc314)

### 🐛 Bug Fixes

- 699406a napi/parser: Move `ExportEntry::module_request` field to first
(#16412) (overlookmotel)
- 12bd794 napi/parser: Move `ExportEntry::module_request` field to last
(#16403) (overlookmotel)

### ⚡ Performance

- 790beeb napi/parser: Do not remove extraneous options on JS side
(#16447) (overlookmotel)

Co-authored-by: Boshen <[email protected]>
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…xc-project#16403)

NAPI-RS 3.6.0 makes a change to the ordering of objects. It now puts optional fields last.

This made tests in `napi/parser` for module record fail when we tried to update (oxc-project#16383) because the `module_request` field of `ExportEntry` moves to last which breaks the snapshots.

The change in NAPI-RS is unlikely to be reverted, because it's a sizeable perf optimization: napi-rs/napi-rs#2990

To work around this problem:

1. Move the field in the `ExportEntry` intermediate struct in `napi/parser` to last, so NAPI's output matches what you'd expect from the struct definition.
2. Alter the `#[estree]` attr on `ExportEntry` struct in `oxc_syntax` crate to match.

Note: The `ExportEntry` struct in `napi/parser` is just an intermediate structure used for serialization. So I think it's fine to fiddle with its field order. The actual `ExportEntry` struct used in the module record is in `oxc_syntax` crate, and it remains unaltered.
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…ll` (oxc-project#16411)

Follow-on after oxc-project#16383 and oxc-project#16403.

While working on those I discovered an option NAPI-RS has to represent `Option::None` as `null`, instead of omitting the field entirely.

Use that option on the structs used for transferring errors and module record over to JS.

I think this is likely more performant because:

1. NAPI-RS can create all properties of the objects using only the faster `node_api_create_object_with_properties` API.
2. It produces consistent object shapes, so JS engine can better optimize code using these objects.

It also brings the shape of the data perfectly into line between standard transfer and raw transfer, and is consistent with how empty fields in the AST are represented as `null`.

I would have used this option before if I'd known it existed.

### Breaking change

I've marked this as a breaking change because code consuming these objects would now need to check for empty fields with `value === null` instead of `value === undefined`.

However in practice, most people probably use `!value` or `value ?? ...`, so it's unlikely to affect many users. This only affects module record and errors anyway, not the AST itself, as we transfer that as JSON, not via NAPI.
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…xc-project#16412)

Revert the change made in oxc-project#16403. It's no longer necessary after oxc-project#16411, because NAPI-RS no longer re-orders the fields.
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
### 💥 BREAKING CHANGES

- 083fea9 napi/parser: [**BREAKING**] Represent empty optional fields on
JS side as `null` (oxc-project#16411) (overlookmotel)

### 🚀 Features

- 7a2afee parser: Add TS1174 error for classes extending multiple base
classes (oxc-project#15993) (sapphi-red)
- da87812 semantic: Add TS2309 error for export assignment with other
exports (oxc-project#15992) (sapphi-red)
- d6d2bcd minifier: Remove unused function calls that are marked by
`manual_pure_functions` (oxc-project#16534) (sapphi-red)
- c90f053 minifier: Support `.` separated values for
`compress.treeshake.manualPureFunctions` (oxc-project#16529) (sapphi-red)
- a607cc4 codegen: Preserve comments between CatchClause's param and
body (oxc-project#16167) (copilot-swe-agent)
- 8c10694 semantic: Expose get_comment_at method (oxc-project#16439) (camc314)
- 3981e7a ast: Add get_comment_at to lookup a comment by span (oxc-project#16438)
(camc314)

### 🐛 Bug Fixes

- 699406a napi/parser: Move `ExportEntry::module_request` field to first
(oxc-project#16412) (overlookmotel)
- 12bd794 napi/parser: Move `ExportEntry::module_request` field to last
(oxc-project#16403) (overlookmotel)

### ⚡ Performance

- 790beeb napi/parser: Do not remove extraneous options on JS side
(oxc-project#16447) (overlookmotel)

Co-authored-by: Boshen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants