Commit Graph

229 Commits

Author SHA1 Message Date
overlookmotel 56a385fe94 feat(napi/parser): add AST walker (#13930)
Add an AST visitor to `oxc-parser`.

```js
import { parseSync, Visitor } from 'oxc-parser';

const { program } = parseSync('test.js', 'let x = { y: z };');

const idents = [];
const visitor = new Visitor({
  Identifier(node) {
    idents.push(node.name);
  }
});

visitor.visit(program);

// Logs [ 'x', 'y', 'z' ]
console.log(idents);
```

Primarily we need a visitor for Oxlint plugins, but it's easier to develop and test in `oxc-parser`, so I thought I'd add it there first. Oxlint build process will copy the generated files for tree-walking from `napi/parser` dir, as it does with other files.

Notes:

* The `walk.mjs` file is large, so it's lazy-loaded only when user first constructs a `Visitor`. Adding `Visitor` to the package will not affect start-up time where user only uses `parseSync` etc.
* TS type definition for `Visitor` and the visitor object it takes are provided.
* Visitor supports enter and exit visitors e.g. `Program` and `Program:exit`.
* `src-js/visit/visitor.mjs` is copied from `apps/oxlint` with only minor modifications, and conversion from TS to JS. It'd be better if we only had this impl in one place, but that would require converting `oxc-parser` to TS and building with TSDown, like `oxlint` is. Leaving that for later - #13935.
2025-09-22 11:08:46 +00:00
overlookmotel 4ee94a3308 feat(napi/parser): export visitor keys (#13927)
Add visitor keys export to `oxc-parser` NPM package. This is useful in itself, but also the first step towards an ESTree walker.

Visitor keys are based on `@typescript-eslint/visitor-keys`.

It'd be ideal to generate visitor keys direct from Oxc's own types, but that's proving difficult due to all the custom serializers we use to translate to ESTree. So using the shortcut of borrowing from TS-ESLint for now.

Oxc's AST is slightly different from TS-ESTree (notably Oxc's AST adds `ParenthesizedExpression`). But apart from those few differences, TS-ESLint's AST and Oxc's are identical, and I made a PR to TS-ESLint earlier this year (https://github.com/typescript-eslint/typescript-eslint/pull/11279) to ensure visitor key order is correct, and matches Oxc.

To avoid adding a runtime dependency on `@typescript-eslint/visitor-keys`, extract the data from TS-ESLint in `oxc_ast_tools`, amend for Oxc/TS-ESTree differences, and re-output it as a simple object literal.

This approach will be faster at runtime, as the object's shape is consistent, and also avoids a dependency.
2025-09-22 11:08:46 +00:00
overlookmotel 48062d06df refactor(napi/parser): itemize files in package.json (#13978)
#13899 made the `files` array in `package.json` for `napi/parser` package a short list of directories. Revert to an itemized list of all files to be included in NPM package.

This is for compatibility with the release workflow which checks the list of files in `package.json` against file system. It fails when `files` list contains directories.
2025-09-21 14:52:09 +00:00
Boshen fb347da614 release(crates): v0.91.0 (#13961) 2025-09-21 13:23:09 +08:00
overlookmotel 329b7e7150 refactor(napi/parser): move scripts to scripts directory (#13900)
Continuation of #13899. Move scripts from root of `napi/parser` package into a `scripts` directory.
2025-09-19 08:46:43 +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
Boshen d116504831 release(crates): v0.90.0 (#13888) 2025-09-18 22:07:37 +08:00
Copilot b52389a569 feat(node): Bump engines field to require Node.js 20.19.0+ for ESM support (#13879)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-09-18 20:10:11 +08:00
Boshen de40f0bee0 release(crates): v0.89.0 (#13774) 2025-09-15 14:33:03 +08:00
Ari Perkkiö 341791e4e3 fix(parser): invalid main entrypoint in package.json (#13767)
In https://github.com/oxc-project/oxc/pull/13432 the filename was
changed but `main` remained as is. I'm now seeing following error in
Vitest:

```
⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
Error: Failed to resolve entry for package "oxc-parser". The package may have incorrect main/module/exports specified in its package.json.
1  |  import { parse as BabelParser } from "@babel/parser";
2  |  import { parse as AcornParser } from "acorn";
3  |  import { parseSync as OxcParser } from "oxc-parser";
   |                                          ^
4  |  import { parseAst as ViteParser } from "vite";
5  |  import { expectTypeOf, test } from "vitest";
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
```


https://github.com/AriPerkkio/ast-v8-to-istanbul/actions/runs/17722503037/job/50357275013?pr=86

See errors from https://publint.dev/oxc-parser@0.88.0.

Signed-off-by: Ari Perkkiö <ari.perkkio@gmail.com>
2025-09-15 13:14:35 +08:00
Boshen 369287abac release(crates): v0.88.0 (#13765)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-09-15 11:01:32 +08:00
Boshen 4577b71ec8 feat(napi/parser)!: change oxc-parser to ESM (#13432)
closes #13329
2025-09-08 10:53:05 +00:00
oxc-bot 7128fb57dd release(crates): v0.87.0 (#13587)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-09-08 11:35:41 +08:00
renovate[bot] 12a5e36bfc chore(deps): update dependency tinypool to v2 (#13482)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [tinypool](https://redirect.github.com/tinylibs/tinypool) | [`^1.1.0`
-> `^2.0.0`](https://renovatebot.com/diffs/npm/tinypool/1.1.1/2.0.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/tinypool/2.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/tinypool/2.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/tinypool/1.1.1/2.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/tinypool/1.1.1/2.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>tinylibs/tinypool (tinypool)</summary>

###
[`v2.0.0`](https://redirect.github.com/tinylibs/tinypool/releases/tag/v2.0.0)

[Compare
Source](https://redirect.github.com/tinylibs/tinypool/compare/v1.1.1...v2.0.0)

#### What's Changed

- fix!: drop Node 18 support by
[@&#8203;AriPerkkio](https://redirect.github.com/AriPerkkio) in
[#&#8203;118](https://redirect.github.com/tinylibs/tinypool/pull/118)
- perf: use `availableParallelism` instead of `exec` by
[@&#8203;sheremet-va](https://redirect.github.com/sheremet-va) in
[#&#8203;123](https://redirect.github.com/tinylibs/tinypool/pull/123)

**Full Changelog**:
<https://github.com/tinylibs/tinypool/compare/v1.1.1...v2.0.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 9am on monday" in timezone
Asia/Shanghai, 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:eyJjcmVhdGVkSW5WZXIiOiI0MS45MS4xIiwidXBkYXRlZEluVmVyIjoiNDEuOTEuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-08-31 19:03:19 +00:00
oxc-bot 7652c8d6ab release(crates): v0.86.0 (#13464)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-08-31 18:46:10 +08:00
oxc-bot 42ebd43ba0 release(crates): v0.85.0 (#13413)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-08-30 15:44:00 +08:00
oxc-bot d6a8aa1ce0 release(crates): v0.84.0 (#13412)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-08-30 13:15:55 +08:00
oxc-bot 732c57e55e release(crates): v0.83.0 (#13387)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-08-29 14:49:51 +08:00
oxc-bot 8b1e022f7f release(crates): v0.82.3 (#13230) 2025-08-20 23:19:06 +08:00
oxc-bot 4d0a05e1e7 release(crates): v0.82.2 (#13158) 2025-08-17 23:31:38 +08:00
Kevin Deng d5431999d0 chore(napi): fix publint issues (#13107)
See https://publint.dev/oxc-parser
2025-08-15 22:25:18 +08:00
oxc-bot 92a3550c40 release(crates): v0.82.1 (#13049) 2025-08-13 12:24:37 +08:00
oxc-bot c58a699e19 release(crates): v0.82.0 (#13014) 2025-08-12 13:53:10 +08:00
renovate[bot] 9e69e1abef chore(deps): lock file maintenance npm packages (#12973) 2025-08-11 14:17:42 +08:00
oxc-bot c245d9bf78 release(crates): v0.81.0 (#12850) 2025-08-06 23:05:58 +08:00
oxc-bot 9671def11f release(crates): v0.80.0 (#12777) 2025-08-03 16:38:23 +08:00
overlookmotel 0ec214b4aa test(napi): compile tests in debug mode (#12750)
Compile NAPI tests in debug mode (not release mode), to speed up build in CI.

Only exception is `napi/parser` which is compiled with `--profile coverage`. The tests for this package are quite slow, so they'd take too long if package was compiled with no optimizations. `coverage` profile is closer to `--release`, but enables debug assertions, and has somewhat faster compilation (`-O 2` not `-O 3` etc).

In CI:

* Build time reduced by 1m30s.
* Test run time increased by 30s.
* Total reduction in CI time: 1 minute.

NAPI tests are still the slowest task in CI by a long margin. Trimming a minute off the time is something, but this task is still too slow.
2025-08-02 12:18:41 +00:00
oxc-bot 5ff286a57a release(crates): v0.79.1 (#12655) 2025-07-31 16:13:45 +08:00
oxc-bot 0fa9b8a8ab release(crates): v0.79.0 (#12600) 2025-07-30 10:31:53 +08:00
oxc-bot ccf1fb4241 release(crates): v0.78.0 (#12486) 2025-07-24 12:02:16 +08:00
renovate[bot] bb8c635b5c chore(deps): update dependency @napi-rs/wasm-runtime to v1 (#12412) 2025-07-21 08:54:02 +08:00
oxc-bot 11cad7d0f6 release(crates): v0.77.3 (#12407) 2025-07-20 22:34:27 +08:00
oxc-bot f4e06c89ab release(crates): v0.77.2 (#12372) 2025-07-17 23:40:00 +08:00
oxc-bot ab68d5c7b4 release(crates): v0.77.1 (#12319) 2025-07-16 19:28:15 +08:00
overlookmotel d009bdb886 refactor(napi/parser): raw transfer: store offsets as consts (#12268)
Pure refactor. Instead of hard-coding constants for fixed offsets of data in the buffer, generate these constants in one place and import them from `constants.js` everywhere else.
2025-07-14 18:56:27 +00:00
oxc-bot 95b13e8c00 release(crates): v0.77.0 (#12234) 2025-07-12 10:15:34 +08:00
camc314 baa372641e refactor(tests/napi): add build-test script for tests (#12132) 2025-07-08 17:08:14 +00:00
oxc-bot 671b596ab1 release(crates): v0.76.0 (#12125) 2025-07-08 17:33:59 +08:00
overlookmotel 9ae081590d refactor(napi/parser): move files (#12088)
Pure refactor. Move generated files for lazy deserialization into a separate directory from generated files for raw transfer.
2025-07-06 11:29:05 +00:00
oxc-bot a257d9732c release(crates): v0.75.1 (#12057) 2025-07-03 21:51:31 +08:00
oxc-bot d25dc35b19 release(crates): v0.75.0 (#11897) 2025-06-25 19:49:12 +08:00
oxc-bot 94a418d201 release(crates): v0.74.0 (#11853) 2025-06-23 13:27:08 +08:00
renovate[bot] 15d84be165 chore(deps): lock file maintenance npm packages (#11850) 2025-06-23 13:02:38 +08:00
overlookmotel 93069a5b6c feat(napi/parser): add experimental lazy visitor (#11837)
Add lazy visitor to `oxc-parser`.

This API is experimental and not ready for use yet. AST is not ESTree-compatible at present (same as lazy deserializer).

Usage:

```js
import { parseSync, experimentalGetLazyVisitor } from 'oxc-parser';

// Get `Visitor` class.
// `Visitor` is not exported directly from `oxc-parser` as all code
// related to lazy deserialization is lazy-loaded.
const Visitor = experimentalGetLazyVisitor();

// Define visitor.
// This visitor counts how many identifiers in AST.
let identCount = 0;
const visitor = new Visitor({
  BindingIdentifier(ident) {
    identCount++;
  },
  IdentifierReference(ident) {
    identCount++;
  },
  IdentifierName(ident) {
    identCount++;
  },
});

const code = 'let x, y; x = { z: 2 };';
const { visit, dispose } = parseSync('test.js', code, { experimentalLazy: true });

visit(visitor);

assert(identCount === 4);

// Dispose of AST now we're done with it.
// This returns buffer storing AST data to the pool for reuse.
dispose();
```
2025-06-20 18:23:56 +00:00
overlookmotel bfed7f21ab refactor(napi/parser): rename file (#11808)
Pure refactor. Rename `raw-transfer/index.js` to `raw-transfer/common.js`. After #11807, it's no longer the entry point, so `index.js` is misleading.
2025-06-19 12:33:11 +00:00
overlookmotel 3a0a673b31 perf(napi/parser): lazy-load raw transfer and lazy deser code (#11807)
Raw transfer and raw lazy deserialization are experimental and not publicly advertised. Lazy-load all code for these features only when they're first used.

Lazy deserialization in particular requires a non-trivial amount of code.

`rawTransferSupported` still needs to be eagerly loaded, as user would call it before calling `parseSync` or `parseAsync`. So move it into a separate module.
2025-06-19 12:33:11 +00:00
oxc-bot 3de6b99990 release(crates): v0.73.2 (#11785) 2025-06-18 13:23:17 +08:00
oxc-bot 14f7033f66 release(crates): v0.73.1 (#11774) 2025-06-17 21:17:38 +08:00
LongYinan 81ef44329f feat(napi): add aarch64-linux-android target (#11769)
- Close https://github.com/oxc-project/oxc/issues/11566
2025-06-17 15:46:41 +08:00
renovate[bot] 9525250ccb chore(deps): lock file maintenance npm packages (#11731) 2025-06-16 10:14:59 +08:00