Commit Graph

53 Commits

Author SHA1 Message Date
overlookmotel c966acaac5 fix(parser): do not omit < token opening type argument list (#26328)
Fix tokens produced when `<<` opens a type argument list. e.g.:

```typescript
type Bar = ReturnType<<T>(x: T) => number>;
```

Previously only 1 `<` token was produced between `ReturnType` and `T`. This PR corrects that so 2 `<` tokens are produced.

TS-ESLint get this wrong too - hence why this wasn't noticed before, as our conformance tests compare to TS-ESLint.

PR submitted to fix TS-ESLint: https://github.com/typescript-eslint/typescript-eslint/pull/12821

In meantime, this PR skips the erroneously failing ESTree tokens conformance tests. We can can re-enable those tests once the fix lands in TS-ESLint.
2026-09-04 12:08:49 +00:00
Boshen 1193c9dbaf chore(oxfmt): dogfood operator position at line start (#25937)
dogfood
2026-08-20 14:36:47 +00:00
camc314 46d237c9a7 chore(codegen,parser,tasks): pin benchmark fixtures by sha (#25557)
Pin the Codegen benchmark fixture to an immutable `benchmark-files` commit. This makes benchmark inputs reproducible and prevents `main` updates from silently changing results.
2026-08-12 15:56:52 +00:00
camc314 2ab679af2b chore(napi/parser): enable noImplicitAny (#23830)
follow on from my other changes to this code earlier today
2026-06-26 16:23:41 +00:00
camc314 14509acf61 chore(napi/parser): run matches parseSync test on all bench files (#23823)
**Stack**
 - https://github.com/oxc-project/oxc/pull/23823  👈 this PR
 - https://github.com/oxc-project/oxc/pull/23822
2026-06-26 15:51:58 +00:00
camc314 90e902eea2 chore(napi/parser): re-enable antd.js test cases (#23822)
the timeout should be fixed by https://github.com/oxc-project/oxc/pull/23820 so we can now re-enable the test

**Stack**
 - https://github.com/oxc-project/oxc/pull/23823
 - https://github.com/oxc-project/oxc/pull/23822  👈 this PR
2026-06-26 15:10:44 +00:00
camc314 4b121ab396 test(napi/parser): run async tests sequentially (#23820)
A little breakdown of what was going on:

 - the failing test case was testing that raw transfer vs non raw transfer was the same. This was parsing checker.ts (a 3.2mb file)
 - this test was running concurrently (via vitest's describe.concurrently) with a memory exhaustion test that was running parse with raw transfer 10,000x concurrently
 - as a result of these concurrent tests, it resulted in a large number of JS objects being created (and hence needing to be GC-ed)
 - since CI is not deterministic, it caused a flakiness roughly 2% of the time
 - this can clearly be seen from the attached flamegraph - the  readFile  call (reading checker.ts from the disk) was sometimes taking up to 3 seconds to read the file from the disk

This seems to be fixed by no longer using describe.concurrent, as it reduces the amount of concurrent work and reduces the chance of the timeout.

<img width="4096" height="1724" alt="image" src="https://github.com/user-attachments/assets/0fd5bc59-8d28-4453-adda-bf33834aafa8" />
2026-06-26 13:49:48 +00:00
camc314 c9517f75aa refactor(napi/parser): add some missing TS type annotations (#23817) 2026-06-26 10:08:36 +00:00
Dunqing 188b9e6b43 chore(bench): swap cal.com.tsx for excalidraw App.tsx everywhere (#22895)
## Summary

Follow-up to #22590. That PR replaced the synthetic `cal.com.tsx` fixture — a concatenation of Next.js pages that declares top-level names 70–113× and emits thousands of redeclaration diagnostics, inflating semantic `sys_allocs` — with excalidraw's real, single-file `App.tsx`. But it only touched `TestFiles::complicated()` (used by `track_memory_allocations`).

This applies the same swap to every remaining benchmark that still used `cal.com.tsx`, and unifies **all** excalidraw `App.tsx` references on one pin (`f6d85bc8`):

| File | Change |
| --- | --- |
| `tasks/common/src/test_file.rs` | `minimal()` (feeds every `tasks/benchmark` criterion bench): `cal.com.tsx` → `App.tsx@f6d85bc8`. `formatter()` re-pinned `@v0.18.0` → `@f6d85bc8` |
| `napi/parser/bench.bench.js` | parser benchmark fixture → `App.tsx@f6d85bc8` |
| `napi/parser/test/parse-raw.test.ts` | bench-fixture list + size comment → `App.tsx@f6d85bc8` |
| `tasks/benchmark/benches/semantic.rs` | rewrote the now-false "`cal.com.tsx` has many errors" comment |
| `crates/oxc_ast/src/serialize/mod.rs` | removed the stale `cal.com.tsx` row from the capacity-ratio doc table |

## Why a single pin

`get_source_text` caches downloads by the last URL segment only (`App.tsx`). With two different pins live, a single `cargo bench` run would download both into the same `target/App.tsx` and silently bench whichever landed first. Re-pinning `formatter()` to `f6d85bc8` removes that collision — and the pre-existing latent one between `cargo bench` (`@v0.18.0`) and `cargo allocs` (`@f6d85bc8`).

## Notes

No committed snapshots change: these fixtures feed only timing benches and a `programRaw.toEqual(programStandard)` self-consistency test; the snapshotted `complicated()` / `minifier()` sets are untouched.

---

This PR was prepared with AI assistance; I reviewed, tested, and verified the changes.
2026-06-01 16:21:32 +00:00
overlookmotel 1f9c115632 test(estree/tokens): add tests for tokens via raw transfer (#19885)
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.
2026-03-01 20:02:49 +00:00
camc314 08b0218dd6 chore(submodules): update submodule SHAs to latest commits (#19518) 2026-02-18 14:56:36 +00:00
overlookmotel e7e6d2507c test(napi/parser): patch types for hidden parser options (#16387)
`napi/parser` tests utilize hidden `experimentalRawTransfer` and `experimentalParent` options. Patch the types of `parse` and `parseSync` in the tests so using these options is not a type error. This replaces a bunch of `// @ts-ignore` and `// @ts-expect-error` comments.
2025-12-02 12:37:16 +00:00
overlookmotel 3068658c30 style(napi/parser): prefer const to let (#16386)
Use `const` where variables are not reassigned instead of `let`. Preparation for enabling ESLint's `prefer-const` rule (running as an Oxlint JS plugin) in our linting setup.
2025-12-02 10:27:27 +00:00
Boshen 523a30a016 style(all): apply oxfmt default options (#16091)
Embrace the defaults!

---------

Co-authored-by: Yuji Sugiura <y.sugiura.0316@gmail.com>
2025-11-25 15:56:24 +09:00
overlookmotel b42610cf16 refactor(napi/parser): remove unused oxlint-disable comment (#16058)
This comment was previously needed, due to a bug in Oxlint, but that bug is now fixed.
2025-11-24 13:32:10 +00:00
renovate a4615e596c chore(deps): update dependency oxlint to v1.29.0 (#15780)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [oxlint](https://oxc.rs) ([source](https://redirect.github.com/oxc-project/oxc/tree/HEAD/npm/oxlint)) | [`1.28.0` -> `1.29.0`](https://renovatebot.com/diffs/npm/oxlint/1.28.0/1.29.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/oxlint/1.29.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/oxlint/1.29.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/oxlint/1.28.0/1.29.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/oxlint/1.28.0/1.29.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>oxc-project/oxc (oxlint)</summary>

### [`v1.29.0`](https://redirect.github.com/oxc-project/oxc/blob/HEAD/npm/oxlint/CHANGELOG.md#1290---2025-11-17)

[Compare Source](https://redirect.github.com/oxc-project/oxc/compare/oxlint_v1.28.0...oxlint_v1.29.0)

##### 🚀 Features

- [`84de1ca`](https://redirect.github.com/oxc-project/oxc/commit/84de1ca) oxlint,oxfmt: Allow comments and also commas for vscode-json-ls ([#&#8203;15612](https://redirect.github.com/oxc-project/oxc/issues/15612)) (leaysgur)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNzMuMSIsInVwZGF0ZWRJblZlciI6IjQxLjE3My4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
2025-11-17 14:13:52 +00:00
Boshen ea51b0b5c8 feat(napi)!: standardize function naming with sync suffixes (#15661)
closes #15576

## Summary

Standardizes function naming across all NAPI packages (parser, transform, minify) with a consistent pattern:
- Async functions: `verb` (no suffix)
- Sync functions: `verbSync` (with Sync suffix)

## Changes

### Breaking Changes

**napi/parser:**
- `parseAsync` → `parse` (async)
- `parseSync` remains unchanged (sync)

**napi/transform:**
- `transformAsync` → `transform` (async)
- `transform` → `transformSync` (sync)
- `isolatedDeclaration` → `isolatedDeclarationSync` (sync)
- Added new `isolatedDeclaration` function (async)
- `moduleRunnerTransform` → `moduleRunnerTransformSync` (sync)
- Added new `moduleRunnerTransform` function (async)

**napi/minify:**
- `minify` → `minifySync` (sync)
- Added new `minify` function (async)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-11-13 12:28:23 +00:00
leaysgur a8e5181ab7 chore(infra): dogfooding oxfmt (#14979)
Fixes #14803

- Added `oxfmt` and `oxfmtrc.jsonc`
- Remove `dprint` plugin and useless ignore paths
- Apply `dprint` again
- Apply `oxfmt`
2025-10-28 01:16:46 +00:00
overlookmotel f293e3e320 test(napi/parser): disable raw transfer tests on antd.js fixture (#14446)
The raw transfer test on `antd.js` fixture is timing out sometimes on CI. We already disabled the "range & parent" test on this fixture. Disable the other test on it too. But only skip these tests in CI.

(alternative to #14438)
2025-10-08 17:43:27 +00:00
overlookmotel 994c099182 test(napi/parser): skip slow test (#14424)
The raw transfer range + parent test on `antd.js` fixture is still hitting 5 second timeout on CI. For some reason the `timeout` option isn't increasing the timeout. Just skip this test.
2025-10-07 18:55:02 +00:00
camc314 b3c5132692 feat(parser): use typescript for raw transfer tests (#14390) 2025-10-06 23:27:45 +00:00
overlookmotel 56274a54f1 test(napi/parser): increase timeout on slow test (#14391)
1 raw transfer test sometimes takes longer than 5 secs on CI. Increase the timeout.
2025-10-06 22:32:32 +00:00
overlookmotel 7e4d04fadf feat(napi/parser): add option to add parent prop to AST nodes with raw transfer (#14344)
Add an option to `oxc-parser` to add `parent` to all AST nodes. This option is only available with raw transfer (not really feasible with JSON transfer, as JSON doesn't support circular references).

This is really for the purposes of JS plugins in Oxlint, so have not included the new deserializers which add `parent` in the `oxc-parser` NPM package, to avoid bloating download size. But it's ideal home is in `napi/parser` so can add it to the conformance tests.

`parent` is correct for all nodes in all Test262 and TypeScript test cases.
2025-10-05 00:32:09 +00:00
overlookmotel 6374065095 feat(napi/parser): raw transfer support range field (#14319)
Raw transfer support `range` option, adding `range` field to every AST node.
2025-10-04 15:47:47 +00:00
overlookmotel 8c09592d2c test(napi/parser): align fixture version with other tasks (#14146)
#13465 aligned the version of `antd.js` used in different Rust tasks to v4.16.1. But it missed a couple of places in `napi/parser` tests/benchmarks. Align these to same version too.

Misalignment was problematic as the tasks using these fixtures all download the file to same location (`target` dir) and don't re-download if the file is already present. This lead to unpredictable results depending on which task you ran first, and so which version was downloaded.
2025-09-26 09:41:48 +00:00
overlookmotel bb040bc2d5 refactor(parser, linter): replace .mjs files with .js (#14045)
Now that `apps/oxlint` and `napi/parser` are both ESM packages (#13723 and #14042), we can use `.js` file extensions for all ESM files, rather than the mix of `.js` and `.mjs` file we had previously.

It's less confusing having to remember what's `.js` and what's `.mjs`, and avoids ugly workarounds like #14038 (`.d.mts`??).
2025-09-23 14:47:40 +00:00
Daniel Roe 1f4be382a8 fix(napi/parser): generate .d.mts extension for types (#14038)
the latest version of `oxc-parser` (on npm) does not have resolvable
types because the entry is `.mjs` and the types are `.d.ts` (these need
to match - `.d.mts`). you can see this in the failing CI for [this
renovate
PR](https://github.com/nuxt/nuxt/actions/runs/17940186619/job/51014702361?pr=33290)
but I'm happy to provide a more minimal reproduction if it helps

I also spotted that `napi/parser/test/visit.test.ts` was importing
`visitorKeys` which was not exported from the corresponding declaration,
so took the liberty to add that export as well.

let me know if this needs any changes 🙏 

I hope it helps

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-09-23 11:53:20 +01:00
overlookmotel 01859848b1 fix(napi/parser): raw transfer preserveParens option apply to TSParenthesizedType (#13964)
Partial fix for #13851.

Raw transfer `preserveParens` option remove `TSParenthesizedType`s from AST, same as #13855 removed `ParenthesizedExpression`s.

This is not used in `oxc-parser`, but the raw transfer `preserveParens` option is required in `oxlint` JS plugins, to align with TS-ESLint, which has no `TSParenthesizedType`s in its AST.
2025-09-21 10:13:02 +00:00
overlookmotel ac3e9e966a refactor(napi/parser): move JS code into src-js directory (#13899)
Pure refactor. Root of `napi/parser` was getting really crowded with tons of files, and I'm about to add a load more for the ESTree walker.

Move JS source files into a `src-js` directory, like in `apps/oxlint`, so that the root of the package is just config files and scripts.
2025-09-19 08:46:42 +00:00
overlookmotel 24a21b3185 feat(napi/parser): preserveParens option for raw transfer (#13855)
Partial fix for #13851.

Add a `preserveParens` argument to raw transfer `deserialize` functions. This is not useful in `oxc-parser`, but these generated files will be duplicated in `oxlint`, where this option is required to remove `ParenthesizedExpression`s from AST, to align with ESLint and TS-ESLint.
2025-09-17 11:38:40 +00:00
Boshen 4577b71ec8 feat(napi/parser)!: change oxc-parser to ESM (#13432)
closes #13329
2025-09-08 10:53:05 +00:00
overlookmotel 5baa4f1467 refactor(napi/parser): fix lint errors (#13185)
Same as #13184.

#13173 enabled Oxlint for all the repo, but we currently skip `napi` directory.

Fix all errors that Oxlint flags in `napi/parser`.

We currently can't turn on Oxlint for the directory, because `oxlint-disable` comments don't work for type-aware rules, but we should be able to once that's fixed.
2025-08-18 22:14:15 +00:00
overlookmotel 2f255a06e4 test(napi/parser): ensure target dir exists (#12751)
In tests for `napi/parser`, don't assume `target` dir exists. It generally should, because you'll have built the `.node` binary. But it `cargo clean` will remove it, and it can also not exist on CI if running build and test in separate jobs.
2025-08-02 11:04:47 +00:00
overlookmotel 8cab72fb79 test(napi/parser): env var to run lazy deserialization tests (#11636)
Enable lazy deserialization tests in `napi/parser` with `RUN_LAZY_TESTS=true pnpm test`. This is easier to use than a hard-coded value.
2025-06-12 12:43:03 +00:00
overlookmotel 8ad30611b2 test(napi/parser): run raw transfer tests on multiple threads (#11611)
Fix #10519.

Run raw transfer tests across multiple threads. Vitest can run multiple test *files* in parallel on separate threads, but it doesn't have ability to run test *cases* in the same file in parallel.

So create a worker pool and send details of each test case to the workers, which then run them in parallel.

On my machine, this cuts down the time to run `napi/parser` tests by a factor of 3 - from 19s to 6s.

Also: Fix `parseAsync` tests: `Promise`s weren't being `await`-ed, and cut down number of iterations on `parseAsync` test from 100,000 to 10,000 so it completes in a reasonable amount of time.
2025-06-12 03:44:00 +00:00
overlookmotel 5a55a5856e feat(napi/parser): add lazy deserialization (#11595)
First iteration of lazy deserialization. It works (does not throw an error on any of Test262 or TS test cases), but has some major shortcomings at present:

* Does not match ESTree - shape of AST is more like our Rust types.
* Some missing fields.
* `Vec`s are not lazily deserialized.
* No caching of nodes, so you get a different object each time you get a node e.g. `assert(binaryExpression.left == binaryExpression.left)` fails!

Note: This is a lazy deserializer, which is first step towards a lazy visitor. But there's no visitor implemented yet.

I will build on this starting point in future PRs.
2025-06-11 15:04:19 +00:00
overlookmotel 5c32b7cb1e fix(ast/estree): make error objects via raw transfer match standard transfer (#11481)
Add `codeframe` property to errors returned by `parseSync` / `parseAsync` when using raw transfer. This matches the shape of error objects without raw transfer.
2025-06-04 13:24:02 +00:00
overlookmotel 97aa9ccfc1 test(ast/estree): remove test skip list for TS raw transfer tests (#11478)
There were some test cases we needed to skip because they'd cause parser to panic. That bug is now fixed (#11473), so no need to skip these tests any more.
2025-06-04 12:27:55 +00:00
overlookmotel 75e241c353 test(ast/estree): test raw transfer on TS-ESTree (#11476)
Add NAPI parser tests to check that TS-ESTree AST via raw transfer matches snapshots.

Previous PRs have fixed all remaining issues, so all the tests pass!
2025-06-04 08:52:33 +00:00
overlookmotel b8aa4e34db feat(napi/parser): parseAsync support raw transfer (#11335)
Previously, only `parseSync` supported raw transfer. Extend support to `parseAsync` too.

This requires:

1. A queue to limit the number of files being parsed simultaneously, to avoid the possibility of memory exhaustion.

2. A more complicated mechanism for recycling buffers, since now multiple buffers can be in use at the same time.
2025-05-28 02:01:55 +00:00
overlookmotel c331eceb37 chore(deps): bump acorn-test262 (#11192)
Bump `acorn-test262` dependency to include the following tidy-up PRs:

* https://github.com/oxc-project/acorn-test262/pull/33
* https://github.com/oxc-project/acorn-test262/pull/34
* https://github.com/oxc-project/acorn-test262/pull/35
2025-05-20 18:13:56 +00:00
overlookmotel d47b3057e8 feat(ast/estree): add phase field to ImportExpression in ESTree AST (#11165)
Related to #10978. Add `phase` property to `ImportExpression` in ESTree AST.

This property is *not* added in TS-ESTree, because TS-ESLint supports `import.defer(...)` and `import.source(...)`, but does not align with ESTree - it outputs a `CallExpression` with a `MetaProperty` as its `callee` instead.

We don't have the necessary information in our AST to match TS-ESLint, because we don't have the spans of `import`, `defer`, or `import.defer`, to use for the `MetaProperty`, or the `IdentifierName`s it contains.

Presumably TS-ESLint will change their AST shape to conform to ESTree spec once these reach stage 4, so I don't think we should expend and changing our AST to align with them in the meantime. TypeScript doesn't even have test cases for these (we'd know if they did, as we'd be failing them) - so I doubt these are popular constructs in TS.

`acorn-test262` submodule is bumped to include https://github.com/oxc-project/acorn-test262/pull/31.
2025-05-20 02:55:03 +00:00
overlookmotel 1bc8d29209 feat(ast/estree): add phase field to ImportDeclaration in ESTree AST (#11157)
Fixes #10978. Add `phase` property to `ImportDeclaration` in ESTree and TS-ESTree ASTs.

`ImportExpression` is not covered by this PR. That's more tricky as TS-ESLint already supports `import.defer(...)` and `import.source(...)`, but does not align with ESTree - it outputs a `MetaProperty` instead.

`acorn-test262` submodule is bumped to include https://github.com/oxc-project/acorn-test262/pull/30.
2025-05-19 15:13:31 +00:00
Boshen 3795eb6d98 fix(ci): use jsdelivr for all benchmark files (#11108)
https://github.blog/changelog/2025-05-08-updated-rate-limits-for-unauthenticated-requests/
2025-05-18 04:33:35 +00:00
overlookmotel c8005adae1 fix(ast/estree): add line comment for hashbang in ESTree AST (#10669)
In ESTree (plain ESTree for JS i.e. Acorn), a hashbang is recorded as a line comment. Follow that behavior in our ESTree AST.

In TS-ESTree, hashbangs are ignored. That's not how it looks in AST explorer, because there's some post-processing going on, but `@typescript-eslint/parser` itself ignores hashbangs. So only add the comment in ESTree AST (not TS-ESTree AST).

More info on this rather confusing subtlety: https://github.com/typescript-eslint/typescript-eslint/issues/6500
2025-04-28 14:33:49 +00:00
overlookmotel 14c4bbb4e7 test(ast/estree): fix raw transfer tests (#10666)
The tests for ensuring field order is the same between JSON-based transfer and raw transfer were not working correctly. Fix them. Thankfully they all still pass!
2025-04-28 14:09:03 +00:00
overlookmotel bdded7e80d test(ast/estree): add tests for JSX via raw transfer (#10241)
Add tests for JSX syntax parsing via raw transfer.
2025-04-04 17:13:50 +00:00
overlookmotel 27768a5f19 fix(parser): store lone surrogates in TemplateElementValue as escape sequence (#10182)
Encode lone surrogates in `cooked` property of `TemplateElementValue` using same encoding scheme as for `StringLiteral`s.

In fact, they were already being encoded like this after #10041, but add a `lone_surrogates` flag to `TemplateLiteral` to decode them correctly in ESTree AST.

`oxc_codegen` ignores `cooked` and just prints `raw`, so needs no alteration.
2025-04-02 12:57:52 +00:00
overlookmotel 38d2beaf60 fix(parser): fix parsing lone surrogates in StringLiterals (#10180)
Fix 2 edge cases when parsing lone surrogates in `StringLiteral`s:

* Lone surrogate followed by `\u{...}` escape e.g. `"\uD800\u{41}"`.
* Escaped lossy replacement character after lone surrogate e.g. `"\uD800 \u{FFFD}"`.
2025-04-02 12:57:52 +00:00
overlookmotel ab1a79663a test(napi): disable NAPI parser tests for TS files (#10028)
Disable the NAPI parser tests for TS fixtures while we work on aligning TS AST with TS-ESLint.

As discussed in https://discord.com/channels/1079625926024900739/1352245556235210773/1353945943862546454.
2025-03-25 04:45:48 +00:00