test(estree/tokens): add tests for tokens via raw transfer#19885
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
Adds initial (experimental) token support to napi/parser via raw transfer, and introduces snapshot-based tests to validate that raw-transferred tokens match expected outputs across existing fixture suites.
Changes:
- Introduces an undocumented
experimentalTokensoption and wires it through the Rust parser configuration and raw-transfer pipeline. - Adds raw-transfer token deserialization on the JS side and stores token offsets/lengths in raw-transfer metadata.
- Adds/extends Vitest + CI configuration and raw-transfer test runners to execute token snapshot tests for Test262, Acorn JSX, and TypeScript fixtures.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| napi/parser/vitest.config.ts | Enables raw-test execution when RUN_RAW_TOKENS_TESTS is set. |
| napi/parser/test/parser.ts | Extends test-only option typings with experimentalTokens. |
| napi/parser/test/parse-raw.test.ts | Adds token test suites gated by RUN_RAW_TOKENS_TESTS. |
| napi/parser/test/parse-raw-worker.ts | Adds worker-side token snapshot verification and token-fixture loading logic. |
| napi/parser/test/parse-raw-common.ts | Adds a new test-type bitflag and a tokens fixture directory path constant. |
| napi/parser/src/types.rs | Exposes experimentalTokens (Rust ParserOptions.tokens) to JS bindings. |
| napi/parser/src/raw_transfer_types.rs | Extends RawTransferMetadata::new to include token offset/length. |
| napi/parser/src/raw_transfer.rs | Populates token offset/length in metadata and converts tokens for raw transfer. |
| napi/parser/src/lib.rs | Enables runtime token collection through RuntimeParserConfig. |
| napi/parser/src-js/raw-transfer/eager.js | Adds raw-transfer token deserialization and tokens getter when enabled. |
| napi/parser/Cargo.toml | Adds dependency on oxc_estree_tokens. |
| Cargo.lock | Locks the new oxc_estree_tokens dependency. |
| .github/workflows/ci.yml | Enables RUN_RAW_TOKENS_TESTS in the NAPI CI job. |
Comments suppressed due to low confidence (2)
napi/parser/src/types.rs:40
- The docs say
experimentalTokensis “only available with experimental raw transfer”, but the option is now plumbed intoparse_implfor all parsing paths (parseSync/parsetoo). That means callers can enableexperimentalTokenswithout raw transfer and still pay the tokenization cost, while never receiving tokens in the returned JS object. Consider enforcing this constraint (ignore/throw unlessexperimentalRawTransfer/experimentalLazyis set) or ensuring tokens are only enabled in the raw-transfer code path.
/// Controls whether parser should return tokens.
///
/// This option is not stable yet, and only available with experimental raw transfer.
///
/// @default false
#[napi(skip_typescript, js_name = "experimentalTokens")]
pub tokens: Option<bool>,
napi/parser/src/raw_transfer_types.rs:54
RawTransferMetadata::newnow acceptstokens_offset/tokens_len, which means these fields are no longer always0in the parser. The doc comments on the struct fields above still state they’re parser-invariant and only used in the linter; please update that documentation to match the new behavior (and clarify what these offsets/lengths point to in the parser case).
impl RawTransferMetadata {
pub fn new(data_offset: u32, is_ts: bool, tokens_offset: u32, tokens_len: u32) -> Self {
Self { data_offset, is_ts, is_jsx: false, has_bom: false, tokens_offset, tokens_len }
}
c9df0d3 to
e594f3d
Compare
3d9f043 to
8b89309
Compare
e594f3d to
be741da
Compare
Merge activity
|
Implement the beginnings of support for tokens in `napi/parser`. This PR only adds support for tokens via raw transfer, and behind an undocumented `experimentalTokens` option. Add tests checking that tokens received on JS side via raw transfer match snapshots for all Test262, AcornJSX, and TypeScript test cases. They do! The tests are the main purpose of this PR, making sure it works before we switch over to tokens via raw transfer in Oxlint. We can add full tokens support to `napi/parser` (including via JSON transfer) later on.
be741da to
0a87dbd
Compare
Implement the beginnings of support for tokens in `napi/parser`. This PR only adds support for tokens via raw transfer, and behind an undocumented `experimentalTokens` option. Add tests checking that tokens received on JS side via raw transfer match snapshots for all Test262, AcornJSX, and TypeScript test cases. They do! The tests are the main purpose of this PR, making sure it works before we switch over to tokens via raw transfer in Oxlint. We can add full tokens support to `napi/parser` (including via JSON transfer) later on.
0a87dbd to
1f9c115
Compare

Implement the beginnings of support for tokens in
napi/parser.This PR only adds support for tokens via raw transfer, and behind an undocumented
experimentalTokensoption.Add tests checking that tokens received on JS side via raw transfer match snapshots for all Test262, AcornJSX, and TypeScript test cases. They do!
The tests are the main purpose of this PR, making sure it works before we switch over to tokens via raw transfer in Oxlint.
We can add full tokens support to
napi/parser(including via JSON transfer) later on.