Commit Graph

12 Commits

Author SHA1 Message Date
overlookmotel 699406af5e fix(napi/parser): move ExportEntry::module_request field to first (#16412)
Revert the change made in #16403. It's no longer necessary after #16411, because NAPI-RS no longer re-orders the fields.
2025-12-02 23:30:56 +00:00
overlookmotel 083fea9fa6 feat(napi/parser)!: represent empty optional fields on JS side as null (#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.
2025-12-02 23:30:56 +00:00
overlookmotel 12bd7940bf fix(napi/parser): move ExportEntry::module_request field to last (#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: https://github.com/napi-rs/napi-rs/pull/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.
2025-12-02 17:42:53 +00:00
Ulrich Stark 4f1343b235 fix(parser): fix missing type export in module information (#10516)
Closes #10505

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2025-04-21 17:18:50 +08:00
Boshen 4a5a7cf921 feat(napi/parser)!: remove magic string; enable utf16 span converter by default (#9291)
Benchmark reveals utf16 span converter is not that slow:

```
 ✓ bench.bench.mjs 1491ms
     name                                                  hz      min      max     mean      p75      p99     p995     p999     rme  samples
   · parser_napi[checker.ts] convertSpanUtf16: true   31.3194  30.8477  34.4288  31.9291  32.3740  34.4288  34.4288  34.4288  ±1.61%       16
   · parser_napi[checker.ts] convertSpanUtf16: false  34.1307  28.6449  29.9385  29.2991  29.6852  29.9385  29.9385  29.9385  ±0.70%       18   fastest

 BENCH  Summary

  parser_napi[checker.ts] convertSpanUtf16: false - bench.bench.mjs
    1.09x faster than parser_napi[checker.ts] convertSpanUtf16: true
```

```
 ✓ bench.bench.mjs 2127ms
     name                                               hz      min      max     mean      p75      p99     p995     p999     rme  samples
   · parser_napi[antd.js] convertSpanUtf16: true   15.1191  65.1335  67.4651  66.1414  66.6032  67.4651  67.4651  67.4651  ±0.70%       10
   · parser_napi[antd.js] convertSpanUtf16: false  17.3037  57.0110  58.6842  57.7911  58.1348  58.6842  58.6842  58.6842  ±0.69%       10   fastest

 BENCH  Summary

  parser_napi[antd.js] convertSpanUtf16: false - bench.bench.mjs
    1.14x faster than parser_napi[antd.js] convertSpanUtf16: true
```

Remove the option and enable the conversion by default.

Magic string API becomes useless at this point. 

This is a trade off between dx, maintenance and performance. dx and
maintainance wins this time.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-02-22 14:27:35 +08:00
hi-ogawa 4803059925 test(ast): remove old ast snapshot tests (#8976) 2025-02-09 04:14:36 +00:00
Hiroshi Ogawa e30cf6aeb1 fix(ast): estree compat MemberExpression (#8921)
Part of https://github.com/oxc-project/oxc/issues/2854

I added a bit weird macro `add_entry(computed = true)` to add constant.
Likely this is not the best way. I would appreciate any suggestion for a
better approach 🙏

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-02-06 11:50:31 +00:00
Hiroshi Ogawa 0c55dd684e fix(ast): serialize Function.params like estree (#8772)
- part of https://github.com/oxc-project/oxc/issues/2854

This PR attempts to handle estree ast incompatibility of
`Function.params: FormalParameters` as mentioned in the above issue:

> `FormalParameters` is closer to ESTree now, but should be inlined
directly into `<node>.params` in multiple nodes.

Estree spec has `Function.params: Pattern[]`
https://github.com/estree/estree/blob/master/es5.md#functions, but oxc
already has `interface Pattern`, so I named it to `Function.params:
ParamPattern[]` for now.

Also I'm not sure about the testing (I suppose that's a part of
https://github.com/oxc-project/oxc/issues/8630), so I snapshoted one
example code. For comparison, here is acorn's output
https://astexplorer.net/#/gist/25138c0605f82dcfc1a8fd363dc2a681/5ad30d36c9f276519063e6fd2e340c113d8c85b0

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-02-05 02:40:02 +00:00
Boshen c479a58718 feat(napi/parser): expose dynamic import expressions (#8540)
closes #8369
2025-01-16 22:25:22 +08:00
Boshen 00fea9285b feat(napi/parser): expose span positions of import.meta (#7677) 2024-12-05 11:03:52 +00:00
Boshen 1de2842f8e feat(napi/parser): return EcmaScriptModule::hasModuleSyntax (#7647) 2024-12-04 13:00:47 +00:00
Boshen 7c62a33a06 feat(napi/parser): return esm info (#7602)
The parser now returns import / export statement information, which can be used for parser plugins.
2024-12-03 11:21:54 +00:00