close#13768
Setup [publint](https://publint.dev/) and fix warnings.
target directory: `napi/` and `editor/vscode`. (I couldn’t determine
whether I should include the `npm/` directory or not.)
Co-authored-by: Boshen <boshenc@gmail.com>
#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.
Move all build scripts in `napi` packages into a `scripts` dir. These packages don't have root directories with tons of files like `napi/parser` and `apps/oxlint` do, but IMO it's preferable to have a consistent directory structure in all NAPI packages.
Also, rename these scripts from `.mjs` to `.js`, since these packages are ESM.
`webcontainer-fallback.js` in `napi/minify` and `napi/transform` are CommonJS files, but these packages are ESM. Rename them to `webcontainer-fallback.cjs` to avoid module resolution errors/fallbacks.
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`??).
Completion of the work begun in #13432. Make `oxc-parser` package fully ESM.
Aside from adding `"type": "module"` to `package.json`, only other change required is renaming `webcontainer-fallback.js` -> `webcontainer-fallback.cjs`. All other files already have the extension matching their ESM/CommonJS content.
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>
Pure refactor. Add a function `deserializeProgramOnly` to generated deserializer code. This function is not used in `oxc-parser`, but is needed to be able to reuse the same code in Oxlint.
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.
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.
#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.
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.
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.
#13888 broke CI because it didn't run `pnpm build` to update version number in NAPI bindings files.
I don't think the published packages are broken, because it only matters if `NAPI_RS_ENFORCE_VERSION_CHECK` env is set.
## Summary
This PR adds an async transform function to the NAPI transform package, following the same pattern used in the parser package for consistency.
Closes#10900
## Changes
- Added `transformAsync` function that returns a Promise
- Implemented `TransformTask` struct with `napi::Task` trait
- Reuses existing transform logic from the synchronous version
- Added comprehensive tests to verify async behavior
## Test Plan
Added tests in `test/transform.test.ts` that verify:
- Async function works correctly
- Produces identical results to sync version
- Properly handles errors
All existing tests continue to pass.
🤖 Generated with [Claude Code](https://claude.ai/code)
## Summary
- Add `cfg` field to `OxcRunOptions` to control Control Flow Graph generation in semantic analysis
- Replace hardcoded `with_cfg(true)` calls with configurable `run_options.cfg` option
- Update TypeScript definitions to include the new `cfg` boolean field
## Motivation
Previously, CFG generation was always enabled (`with_cfg(true)`) in both the main semantic analysis and linter semantic analysis. This change allows users to control CFG generation for better performance when CFG data is not needed.
## Changes
- **napi/playground/src/options.rs**: Add `cfg: bool` field to `OxcRunOptions` struct
- **napi/playground/src/lib.rs**:
- Update `build_semantic` method to use `run_options.cfg` instead of hardcoded `true`
- Update `run_linter` method to use `run_options.cfg` instead of hardcoded `true`
- **napi/playground/index.d.ts**: Add `cfg: boolean` to TypeScript definitions
## Test plan
- [ ] Verify compilation succeeds
- [ ] Test NAPI playground with `cfg: true` (should work as before)
- [ ] Test NAPI playground with `cfg: false` (should skip CFG generation for better performance)
🤖 Generated with [Claude Code](https://claude.ai/code)
## Summary
- Added a new `semanticErrors` field to `OxcParserOptions` to allow users to control whether semantic syntax errors should be checked and reported
- Updated the `build_semantic` method to use this configuration option
- Semantic errors are now only collected when explicitly enabled through the configuration
## Changes
- Add `semantic_errors: bool` field to `OxcParserOptions` struct in `napi/playground/src/options.rs`
- Update `build_semantic` method in `napi/playground/src/lib.rs` to:
- Accept `parser_options` parameter
- Use `parser_options.semantic_errors` for `with_check_syntax_error()`
- Conditionally collect errors based on the configuration
- Auto-generated TypeScript definitions updated to include the new field
## Test plan
Tested manually by creating a simple Node.js script that:
1. Parses code with duplicate variable declarations (semantic error)
2. Tests with `semanticErrors: true` - confirms error is reported
3. Tests with `semanticErrors: false` - confirms no error is reported
The feature works as expected, providing users with control over semantic error checking.
🤖 Generated with [Claude Code](https://claude.ai/code)
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.
Pure refactor. Export functions directly with `export function` instead of an additional `export { ... }` statement. This makes it easier to see which functions are exported and which are not.
Convert `oxlint` to a NAPI package.
This PR:
1. Moves files from `napi/oxlint` into `apps/oxlint`.
2. Converts `oxlint` into a NAPI package.
3. Alters the [release workflow](https://github.com/oxc-project/oxc/pull/13723/files#diff-80cb497c859bbaf7756da6ced2bca3d31933affc96102983eee1ad7d4bcc60fd) and [script](https://github.com/oxc-project/oxc/pull/13723/files#diff-4c4b7045c68805aeeae7c0af94cf7cf7487cb0403496da974a6a23accdc457d0) for building `oxlint` packages.
Most of necessary code modifications and refactoring was done in previous PRs (#13701, #13712, #13722, #13745), so this PR only includes changes necessary for packaging as NAPI.
I've done my best to update release workflow, but am mostly "flying blind" without ability to test it, so very likely there are mistakes.
A few notes and oddities:
* I've kept the `oxlint` NPM package as CommonJS. We could probably switch to ESM, but I thought it better to minimize the changes in this PR.
* NAPI-RS creates `.node` files named with a `-msvc` postfix for Windows. The scripts here remove that postfix so that filename of `.node` files and NPM package names match for all platforms, for simplicity.
* `tasks/website` has a dependency on `oxlint` as a normal library. This resulted in linker errors, so have had to put all the NAPI stuff behind `napi` cargo feature. Tests for `tasks/website` are run separately in CI, to avoid feature unification turning on the `napi` feature for `website`.
I've made a few comments below for the parts which aren't fairly self-explanatory.
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>
Fixes#13694.
Some 32-bit platforms give `u64` and `f64` alignment of 8, and others alignment of 4. WASM32 uses alignment 8, and layout calculator assumes that.
Skip layout assertions for platforms where alignment is 4, because we know some layouts are wrong for those platforms, and it causes compilation failure in debug builds. But retain the assertions for other 32-bit platforms (notably WASM), to make sure they remain correct. This will make it easier to extend raw transfer support to WASM later on.