Skip to content

test(estree/tokens): add tests for tokens via raw transfer#19885

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer
Mar 1, 2026
Merged

test(estree/tokens): add tests for tokens via raw transfer#19885
graphite-app[bot] merged 1 commit intomainfrom
om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 1, 2026

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.

Copy link
Member Author

overlookmotel commented Mar 1, 2026


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.

@overlookmotel overlookmotel marked this pull request as ready for review March 1, 2026 16:10
Copilot AI review requested due to automatic review settings March 1, 2026 16:10
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 1, 2026

Merging this PR will not alter performance

✅ 53 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer (be741da) with main (449080c)2

Open in CodSpeed

Footnotes

  1. 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.

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

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

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 experimentalTokens option 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 experimentalTokens is “only available with experimental raw transfer”, but the option is now plumbed into parse_impl for all parsing paths (parseSync/parse too). That means callers can enable experimentalTokens without raw transfer and still pay the tokenization cost, while never receiving tokens in the returned JS object. Consider enforcing this constraint (ignore/throw unless experimentalRawTransfer/experimentalLazy is 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::new now accepts tokens_offset/tokens_len, which means these fields are no longer always 0 in 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 }
    }

@overlookmotel overlookmotel self-assigned this Mar 1, 2026
@overlookmotel overlookmotel added the A-linter-plugins Area - Linter JS plugins label Mar 1, 2026
@overlookmotel overlookmotel changed the base branch from om/03-01-test_napi_parser_fix_tests_for_range_parent_and_lazy_on_ts_fixtures to graphite-base/19885 March 1, 2026 17:27
@overlookmotel overlookmotel force-pushed the om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer branch from c9df0d3 to e594f3d Compare March 1, 2026 19:25
@overlookmotel overlookmotel changed the base branch from graphite-base/19885 to main March 1, 2026 19:25
@overlookmotel overlookmotel force-pushed the om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer branch from e594f3d to be741da Compare March 1, 2026 19:39
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 1, 2026
@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 1, 2026

Merge activity

graphite-app bot pushed a commit that referenced this pull request Mar 1, 2026
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.
@graphite-app graphite-app bot force-pushed the om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer branch from be741da to 0a87dbd Compare March 1, 2026 20:00
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.
@graphite-app graphite-app bot force-pushed the om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer branch from 0a87dbd to 1f9c115 Compare March 1, 2026 20:02
@graphite-app graphite-app bot merged commit 1f9c115 into main Mar 1, 2026
24 checks passed
@graphite-app graphite-app bot deleted the om/03-01-test_estree_tokens_add_tests_for_tokens_via_raw_transfer branch March 1, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue A-linter-plugins Area - Linter JS plugins A-parser Area - Parser C-test Category - Testing. Code is missing test cases, or a PR is adding them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants