Commit Graph

229 Commits

Author SHA1 Message Date
overlookmotel 2749931a40 fix(napi/parser): lazy deserializer block class constructors correctly (#11679)
Ensure get the appropriate error when user calls a forbidden class constructor for a lazy-deserializing type. Move code for this to a shared module.
2025-06-13 17:39:18 +00:00
overlookmotel 60f754e37c perf(napi/parser): lazily deserialize Vecs (#11678)
Lazy deserialization return `NodeArray`s which deserialize their contents lazily, instead of plain JS arrays.

`program.body.find(stmt => stmt.type === 'ImportDeclaration')` now only deserializes the nodes up until first `ImportDeclaration`, rather than deserializing every statement in the program into an array, and then searching it. Similarly getting `program.body.length` does not deserialize any nodes, and all other array methods are similarly optimized.

Also provide an optimized iterator for the common case of:

```js
for (const stmt of program.body) {
  doStuff(stmt);
}
```
2025-06-13 16:45:15 +00:00
oxc-bot e7af8c470c release(crates): v0.73.0 (#11669) 2025-06-13 18:33:56 +08:00
overlookmotel 0bdf718230 chore(napi)!: drop support for NodeJS before v20 in oxc-parser (#11586)
Drop support for NodeJS before v20 in `oxc-parser` NPM package.

All versions of NodeJS earlier than v20 are now EOL. I don't think we need to support them.

https://nodejs.org/en/about/previous-releases

I would like to use `FinalizationRegistry`, which is not available in Node v14 (our current lowest supported version).
2025-06-12 09:53:06 +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 95ee174347 refactor(napi/parser): move raw transfer code into separate directory (#11583)
Pure refactor. Move code for raw transfer into separate directory. This will enable exposing some internals to benchmarks without exposing them publicly from the package. Also lazy deserialization is going to add a lot more code - don't want `index.js` to get too bloated.

Also make main entry point `index.js` run in strict mode (doesn't much matter, but it's good practice).
2025-06-11 15:04:18 +00:00
renovate[bot] 888b9c8d43 chore(deps): lock file maintenance npm packages (#11557) 2025-06-09 14:34:46 +08:00
oxc-bot 958849ca05 release(crates): v0.72.3 (#11504) 2025-06-06 15:40:07 +08:00
oxc-bot 972c76572b release(crates): v0.72.2 (#11411) 2025-05-31 13:45:07 +08:00
oxc-bot 01a4647a18 release(crates): v0.72.1 (#11345) 2025-05-28 16:54:01 +08:00
renovate[bot] 9e2686a62b chore(deps): lock file maintenance npm packages (#11289) 2025-05-26 11:55:59 +08:00
oxc-bot 3efc25fdeb release(crates): v0.72.0 (#11267) 2025-05-24 14:53:50 +08:00
Boshen 9a2a6c6c37 chore(napi): remove --no-dts-cache 2025-05-20 15:20:12 +08:00
oxc-bot 4086e24083 release(crates): v0.71.0 (#11182) 2025-05-20 13:11:01 +08:00
oxc-bot 58d2e6effe release(crates): v0.70.0 (#11061) 2025-05-15 21:55:38 +08:00
Boshen 2787193e7f chore(napi): adjust test commands (#11021)
so we can run `pnpm run test -u`
2025-05-14 04:04:52 +00:00
Bernd Storath 647b6f3177 feat(napi): add arm musl (#10958)
closes #10954

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2025-05-12 20:13:58 +08:00
renovate[bot] ed983f895d chore(deps): lock file maintenance npm packages (#10945) 2025-05-12 17:57:45 +08:00
oxc-bot 2b890aba8f release(crates): v0.69.0 (#10925) 2025-05-10 00:06:12 +08:00
Boshen 22ba60b6c4 feat(napi): add s390x-unknown-linux-gnu build (#10892) 2025-05-08 20:13:41 +08:00
Boshen 308fe732d9 feat(napi): add x86_64-unknown-freebsd and riscv64gc-unknown-linux-gnu builds (#10886)
closes #10822
2025-05-08 18:26:22 +08:00
overlookmotel 49a6f97388 perf(napi/parser): faster fixup of BigInts and RegExps (#10820)
#10791 fixed the performance of `oxc-parser` NPM package by removing the reviver from `JSON.parse` call. However, it replaced it with a complete traversal of the AST on JS side to locate `Literal` nodes and update them.

Instead, generate a list of paths to `Literal` nodes needing fixing on Rust side in `ESTree` serializer.

e.g. for this program:

```js
123n;
foo(/xyz/);
```

the fix paths are:

```json
[
    ["body", 0, "expression"],
    ["body", 1, "expression", "arguments", 2]
]
```

Having the location of nodes which need updating reduces work on JS side, as no need to search the entire AST.

Running `pnpm run bench` (in `napi/parser`) locally shows between 8% and 15% speed-up from this change.
2025-05-06 02:34:24 +00:00
overlookmotel 87fc90365a fix(napi/parser): expose visitor keys files in NPM package (#10817)
#10791 added 2 files `generated/visitor-keys.cjs` and `visitor-keys.mjs` to the NAPI package. When I amended the original PR, I forgot to update `package.json` to include them both in NPM package.
2025-05-06 02:34:24 +00:00
Arnaud Barré f85bda4fda perf(parser): use visitor instead of JSON.parse reviver (#10791)
Fixes #10783

This requires having a list of ~135 nodes with their non primitive keys.
Technically this list could be generated alongside the raw deserializer
but I don't know this code enough to do it.
I've chosen to inline visitor keys to avoid adding [3
dependencies](https://pkg-size.dev/@typescript-eslint%2Fvisitor-keys)
for that.
I didn't find how the main LICENCE was injected during the publish so I
couldn't append the bundled LICENSES and choose to use `@licence`
comments with links

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-05-05 13:11:43 +01:00
oxc-bot e6074275ae release(crates): v0.68.1 (#10796) 2025-05-05 00:53:44 +08:00
oxc-bot 61dfcfdfd8 release(crates): v0.68.0 (#10777) 2025-05-04 09:06:24 +08:00
overlookmotel 3b6d52d009 refactor(napi/parser): move generated deserializer files (#10481)
Pure refactor. Move generated deserializer files for `napi/parser` into a `generated/deserialize` directory. This is to make room for more generated files (e.g. visitor, more specialized deserializers), without the number of file in root of the package exploding.
2025-04-29 10:30:27 +01:00
oxc-bot 7cf80ef7fd release(crates): v0.67.0 (#10637) 2025-04-27 22:30:07 +08:00
oxc-bot ff67f13f99 release(crates): v0.66.0 (#10565)
## [0.66.0] - 2025-04-23

### Features

- 7d5ad7d parser: Report error when `import type { type }` is used
(#10528) (camc314)
- 6e40fac parser: Report error when `export type { type }` is used
(#10524) (camc314)

### Bug Fixes

- 43ad4e9 ast: Box `this_param` in `TSCallSignatureDeclaration` (#10558)
(Yuji Sugiura)
- 8eb3c0a ast/estree: Fix raw deser for `FormalParameter` (#10548)
(overlookmotel)
- 3ebf220 codegen: Generate missing `type` in `export type {} from
'mod'` (#10539) (Boshen)
- f19b287 estree: Add `TSParameterProperty` (#10534) (Yuji Sugiura)
- 7284f16 isolated-declarations: Leading comments of
`ExportDefaultDeclaration` and `TSExportAssignment` appear in incorrect
places (#10559) (Dunqing)
- 4c316a5 isolated_declarations: Fix broken snapshot files (#10561)
(Boshen)
- 84742d8 transformer/module_runner: Fix export default live binding
(#10560) (hi-ogawa)
- 6c115c7 transformer/module_runner: Fix execution order of re-export
(#10362) (hi-ogawa)
- b9d84b0 transformer/typescript: Remove `StringLiteral::raw` when
rewriting extensions (#10554) (overlookmotel)

### Performance

- 6a045c8 codegen: Speed up printing `Directive`s (#10551)
(overlookmotel)
- 3418ae5 transformer/class-properties: Re-use
`InstanceInitializerVisitor` (#10543) (overlookmotel)
- 7fcf0ac transformer/typescript: Reduce allocations renaming extensions
(#10555) (overlookmotel)

### Documentation

- 1a9530c transformer/class-properties: Fix typo (#10542)
(overlookmotel)

### Refactor

- 7e71282 transformer/class-properties: Correct outdated comment
(#10546) (overlookmotel)
- 596978b transformer/class-properties: Simplify to get `constructor`
method only once (#10493) (Dunqing)
- f13fe0a transformer/class-properties: Defer re-parenting initializers
scopes until all instance properties are transformed (#10495) (Dunqing)
- c83dad6 transformer/class-properties: Streamline handling scope of
instance property initializer (#10492) (Dunqing)

### Styling

- e10dfc8 traverse: Remove excess whitespace (#10544) (overlookmotel)

### Testing

- 227febf allocator: Ignore a slow doc test (#10521) (Dunqing)
- 14bb2be codegen: Add more tests for strings (#10552) (overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-04-23 22:42:12 +08:00
renovate[bot] 1d2154e0c9 chore(deps): lock file maintenance npm packages (#10530) 2025-04-22 12:08:36 +08:00
oxc-bot 0ab2cb4a22 release(crates): v0.65.0 (#10522) 2025-04-21 18:03:15 +08:00
oxc-bot 619488a05a release(crates): v0.64.0 (#10459) 2025-04-17 10:09:07 +08:00
oxc-bot eba5fcf33b release(crates): v0.63.0 (#10309) 2025-04-08 13:52:15 +08:00
renovate[bot] e34967eb20 chore(deps): lock file maintenance npm packages (#10273) 2025-04-07 16:43:16 +08:00
oxc-bot 3b72e5b151 release(crates): v0.62.0 (#10158) 2025-04-02 09:48:40 +08:00
Hiroshi Ogawa 1ab88718a8 feat(napi/parser): auto download wasm binding on webcontainer (#10049)
Oxc-parser equivalent of https://github.com/rolldown/rolldown/pull/3922

As discussed within Stackblitz and Rolldown team, stackblitz's package
swap isn't as simple nor as perfect as I thought, so Rolldown went with
auto downloading wasm binding during runtime. I suggest doing the same
for `oxc-parser`.

~TODO: I need to figure out how to patch `binding.js` during build
pipeline.~
TODO: Let nuxt folks know if this is released.

This is yet again only testable with the actual release, so
trial-and-error expected 😄
(At least, I tested running webcontainer-fallback.js directly on
stackblitz
https://stackblitz.com/edit/stackblitz-starters-yvuqgxo6?file=webcontainer-fallback.js)
2025-03-29 20:23:24 +08:00
renovate[bot] 41fffed5bd chore(deps): lock file maintenance npm packages (#9989) 2025-03-24 10:18:50 +08:00
oxc-bot 76b245dafc release(crates): v0.61.2 (#9983) 2025-03-23 19:42:43 +08:00
oxc-bot 9a36e677b2 release(crates): v0.61.1 (#9936)
## [0.61.1] - 2025-03-21

### Features

- 8e3b20d napi/parser: Add portable wasm browser build (#9901) (Hiroshi
Ogawa)
- bc0670c tasks,oxc_allocator: Add new method clone_in_with_semantic_ids
for `CloneIn` trait (#9894) (IWANABETHATGUY)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-03-21 12:46:52 +08:00
Hiroshi Ogawa 8e3b20d8e2 feat(napi/parser): add portable wasm browser build (#9901)
- Required by https://github.com/sxzz/ast-explorer/pull/148

<details><summary>(old comment about my failed attempt with
esm.sh)</summary>


https://esm.sh/gh/oxc-project/oxc@03-20-fix_napi_parser_make_wasi_browser_usable_on_cdn/napi/parser/parser.wasi-browser.js

I think this is supposed to work, but redirected wasm ended up 404. It's
possible that this is only for `/gh/` mode and a published package might
work fine.

https://esm.sh/oxc-project/oxc@7d785c3/napi/parser/parser.wasm32-wasi.wasm

I asked it on https://github.com/esm-dev/esm.sh/issues/1109.

---

Testing https://esm.sh/@oxc-parser/wasm, it doesn't look like esm.sh
supports `new URL(.., import.meta.url)` for published packages anyways.

</details>

This PR added a extra script to bundle `wasm.js` into
`browser-bundle.mjs`, which is included in
`@oxc-parser/binding-wasm32-wasi` package. For example, this will allow
`oxc-parser` equivalent (though only sync API) to be consumed on browser
via CDN such as
https://cdn.jsdelivr.net/npm/@oxc-parser/binding-wasm32-wasi/browser-bundle.mjs.

I didn't test an actual package release, but I've tested jsdeliver's gh
prefix works by directlly commiting `browser-bundle.mjs` and wasm on
this branch (now it's removed from commits).

https://cdn.jsdelivr.net/gh/oxc-project/oxc@03-20-fix_napi_parser_make_wasi_browser_usable_on_cdn/napi/parser/browser-bundle.mjs
2025-03-21 11:48:06 +08:00
oxc-bot 33c1c76955 release(crates): v0.61.0 (#9923)
## [0.61.0] - 2025-03-20

- c631291 parser: [**BREAKING**] Parse `TSImportAttributes` as
`ObjectExpression` (#9902) (Boshen)

- eef7eb6 minifier: [**BREAKING**] Rename
`CompressOptions::all_true`/`all_false` to `smallest`/`safest` (#9866)
(sapphi-red)

### Features

- 38ad787 data_structures: Add `assert_unchecked!` macro (#9885)
(overlookmotel)
- dcd356e minifier: Support `keep_names` option (#9867) (sapphi-red)
- 6565fc4 napi: Feature gate allocator (#9921) (Boshen)
- 2cedfe4 napi: Add codeframe to napi error (#9893) (Boshen)
- a9a47a6 parser: Add regex cargo feature to oxc_parser (#9879) (Toshit)
- d4a83ba parser: Report duplicate modifier `Accessibility modifier
already seen.` (#9890) (Boshen)
- 59c8f71 parser,codegen: Handle lone surrogate in string literal
(#9918) (Boshen)

### Bug Fixes

- 28a2ed3 estree/ast: Fix `IdentifierName` and `IdentifierReference`
(#9863) (hi-ogawa)
- 3d4c5f3 semantic: Correctly visit `IfStmt` `test` when building cfg
(#9864) (camc314)
- 1774225 transformer/using: Incorrect scope ids for bindings (#9871)
(camc314)- 68018e1 Ast changes (Boshen)

### Performance

- 5f97f28 ast/estree: Speed up raw deser for `JSXElement` (#9895)
(overlookmotel)
- b272893 mangler, minifier: Initialize a Vec with a specific value
using `Vec::from_iter_in` combined with `repeat_with` (#9908) (Dunqing)
- f7d078c semantic: Use `reserve_exact` instead of `reserve` to save
memory in pre-reserve (#9910) (Dunqing)

### Documentation

- 590a258 napi/parser: Add stackblitz link for wasm build (Boshen)

### Refactor

- 62e2859 ast/ast_builder: Use `self.vec_from_iter` instead of
`Vec::from_iter_in` for consistency (#9909) (Dunqing)
- b2f3d23 isolated_declarations: Remove unused `self` params (#9868)
(overlookmotel)
- 961b95d napi: Move common code to `oxc_napi` (#9875) (Boshen)
- 233c1fc napi/playground: Add JSON.parse wrapper (#9880) (Hiroshi
Ogawa)
- dbe61c5 transformer/module-runner-transform: Remove redundant
converison (#9912) (Dunqing)
- ecdfe2e transformer/using: Move work to `exit_static_block` (#9713)
(camc314)

### Testing

- 9314147 data_structures: Enable doc tests for `oxc_data_structures`
crate (#9884) (overlookmotel)
- 040e993 napi: Refactor NAPI parser benchmarks (#9911) (overlookmotel)
- e637e2e napi/parser: Tweak vitest config (#9878) (Hiroshi Ogawa)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-03-20 20:06:21 +08:00
Boshen 6565fc4261 feat(napi): feature gate allocator (#9921)
Rolldown already has allocator enabled, double allocator is a compile error.
2025-03-20 11:40:08 +00:00
Hiroshi Ogawa e637e2edcf test(napi/parser): tweak vitest config (#9878)
- fixed `@vitest/browser` version mismatch
- removed `--typecheck` since `tsc` catches same errors (and honestly
vitest typecheck mode is not so intuitive 🙃)
- added `diff.expand: false` since raw transfer mismatch is huge (we
might change the default on Vitest side
https://github.com/vitest-dev/vitest/pull/7697)
2025-03-19 09:28:45 +08:00
oxc-bot 9baa7568f8 release(crates): v0.60.0 (#9861) 2025-03-18 17:01:17 +08:00
hi-ogawa 7106e5dc0f refactor(napi): disable unused browser fs (#9848)
I don't think file access is needed for napi packages. I've already disabled this on napi/playground.
2025-03-18 05:53:21 +00:00
oxc-bot 7cfe1a5e01 release(crates): v0.59.0 (#9850) 2025-03-18 13:50:33 +08:00
Hiroshi Ogawa 48bac9278a test(napi/parser): test wasi browser (#9793) 2025-03-18 12:04:09 +08:00
Boshen 06518ae761 feat(napi/parser): JSON.parse the returned AST in wasm (#9630)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-03-18 11:31:52 +08:00
oxc-bot 7856a0b091 release(crates): v0.58.1 (#9754)
## [0.58.1] - 2025-03-13

### Features

- a8331f7 transformer: Turn off explicit resource management by default
(#9749) (Boshen)

### Bug Fixes

- cd3f2fb ast/estree: Fix `JSXOpeningFragment` (#9747) (Hiroshi Ogawa)
- fecec56 ast/estree: Fix `JSXOpeningElement` field order (#9746)
(hi-ogawa)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-03-13 20:34:27 +08:00