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);
}
```
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).
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.
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.
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).
#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.
#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.
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>
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.
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)
- 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)