Commit Graph

52 Commits

Author SHA1 Message Date
Cameron 77e318af2e chore(all): add .pnpm-store to .gitignore (#25563)
https://github.com/orgs/pnpm/discussions/6936

maybe this should be in my local gitignore?
2026-08-16 19:11:58 +08:00
overlookmotel a4478e960a feat(codegen): add oxc-codegen package (#25488)
Add `oxc-codegen` package - a printer written in TS.

### Features

- Prints JS, JSX, TS, TSX.
- Matches `oxc_codegen` exactly on all Test262, TypeScript, Acorn-JSX fixtures.
- Very fast.

### Deficiencies

- Pretty-printing only (no compact/minified output).
- No support for printing comments.
- Source map support is semi-there, but largely untested, and poor API (design doc has some ideas on how to improve it).

### This PR adds

- The printer code.
- Conformance testing infra.
- Further tests for edge cases.
- README.
- Design doc - how it differs from `oxc_codegen` and why, what produces the perf.

### This PR doesn't add

- Not integrated into CI or release pipeline.

### Notes

This started as a slop port of `oxc_codegen`. I've iterated on that base, cleaned it up a lot, and at least skimmed through all of it. I think it's in fairly decent shape.

The design doc is I think worth a read. It explains the rationale for the choices, in particular the "1 codebase, 4 builds" approach.

I've put it in a new top-level directory called `packages`. It's not an app, so didn't seem to me to fit alongside `apps/oxlint` and `apps/oxfmt`. It's pure JS, so not like e.g. `napi/parser`. And it felt too heavyweight to put into `npm` dir. But maybe there's a better place for it.

Co-authored-by: Cameron <cameron.clark@hey.com>
2026-08-12 13:41:31 +00:00
leaysgur 0fa91283fd refactor(formatter,formatter_tests): move out prettier JS,TS,JSDoc conformance from tasks/ (#25477)
Migration from tasks/prettier_conformance to each crate test using oxc_formatter_tests, for JS/TS and JSDoc.
2026-08-12 00:48:32 +00:00
leaysgur 6ef3984410 refactor(ci): self-provision prettier suite in oxc_formatter_tests (#25467)
Remove the Prettier related stuff from the conformance, which is purely aimed at JS/TS.

Instead, `oxc_formatter_tests` manage Prettier's test fixtures along with Oxfmt.
2026-08-12 00:40:59 +00:00
Copilot a26c437268 fix(linter/rulegen): handle Flow type parse errors gracefully in rule generator (#21794)
`just new-jsx-a11y-rule <name>` panics because `eslint-plugin-jsx-a11y`
uses Flow type annotations, which the Oxc parser can't handle, causing
parse errors that hit `assert!(ret.errors.is_empty())` (introduced in
#15865).

## Changes

- **`tasks/rulegen/src/main.rs`**: Replace two
`assert!(ret.errors.is_empty())` calls — one for test file parsing, one
for rule source file parsing — with `eprintln!` warnings that allow
execution to continue with the partial AST.

The tool can still extract test cases and rule config from a
partially-parsed AST, so this restores pre-#15865 behavior while
surfacing parse issues to the user:

```
Warning: 3 parse error(s) in rule source file (possibly due to Flow types). Attempting to extract rule config anyway.
```

---------

Signed-off-by: Connor Shea <2977353+connorshea@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: connorshea <2977353+connorshea@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Cameron <cameron.clark@hey.com>
2026-04-27 08:41:36 +01:00
anthropic-code-agent 245273ef0a feat(napi/playground): add optimizeEnums and optimizeConstEnums options (#21815)
## Summary
This PR adds `optimizeEnums` and `optimizeConstEnums` options to the playground's transformer configuration, enabling TypeScript enum optimization features that are already available in the transformer.

## Changes
- Added `optimize_enums: bool` and `optimize_const_enums: bool` fields to the `OxcTransformerOptions` struct in `napi/playground/src/options.rs`
- Updated `apply_transformations` method in `napi/playground/src/lib.rs` to apply these options to `options.typescript.optimize_enums` and `options.typescript.optimize_const_enums`

## Reference
Resolves https://github.com/oxc-project/oxc/blob/d1cf22efc2bc9cf9fa82e887c34965d2ce3004c3/napi/playground/src/options.rs#L59

These options enable:
- `optimize_enums`: Optimize regular (non-const) enums by inlining their member accesses at usage sites when the member value is statically known
- `optimize_const_enums`: Optimize const enums by inlining their values at usage sites and removing the enum declaration
2026-04-27 04:10:29 +00:00
Dunqing 4fec907ad5 feat(formatter): add JSDoc comment formatting support (#19828)
## Summary

Implements native JSDoc comment formatting in oxfmt, porting behavior from [prettier-plugin-jsdoc](https://github.com/hosseinmd/prettier-plugin-jsdoc) (v1.8.0). Tracked in #19702.

### Conformance

**145/145 (100%)** compatibility with prettier-plugin-jsdoc test suite.

- 1 fixture intentionally skipped (`descriptions/032-jsx-tsx-css`) — requires embedded CSS/HTML formatter callbacks not available in the standalone conformance runner
- Run with: `cargo run -p oxc_prettier_conformance -- --jsdoc`

Prettier conformance (non-JSDoc):
- **JS**: 746/753 (99.07%)
- **TS**: 591/601 (98.34%)

### Real-World Repository Testing

Validated against 5 real-world repositories (7,542 JSDoc tags total) using Prettier 3.8.1 + prettier-plugin-jsdoc 1.8.0 as baseline:

| Repository | JSDoc Tags | Files with Diffs |
|------------|-----------|-----------------|
| evolu      | 134       | 13              |
| wxt        | 1,183     | 1               |
| typedoc    | 792       | 11              |
| Chart.js   | 1,276     | 4               |
| svelte     | 4,157     | 5               |
| **Total**  | **7,542** | **34**          |

All 34 remaining diffs are **intentional design differences**, not bugs:
- `{@link}` kept atomic (upstream breaks across lines) — ~11 files
- `{@includeCode}` placed on own line (upstream splits tag syntax) — 3 files
- Sub-list continuation indent normalized to 4-space — 5 files
- `?Type` expanded to `Type | null` — 1 file
- Minor line-break position differences — 5 files
- Double-space normalized to single space — 1 file

10 upstream bugs documented in `tasks/prettier_conformance/jsdoc/upstream-jsdoc-bugs.md` — oxfmt intentionally produces correct output where the upstream plugin has known issues.

### Performance

Measured with `hyperfine` using `oxfmt --check` on real-world repos (16 threads):

| Repository | Without JSDoc | With JSDoc | Overhead    |
|------------|--------------|------------|-------------|
| evolu      | 434ms        | 427ms      | ~0% (noise) |
| wxt        | 410ms        | 410ms      | ~0% (noise) |
| typedoc    | 532ms        | 567ms      | ~7%         |
| Chart.js   | 497ms        | 479ms      | ~0% (noise) |
| svelte     | 510ms        | 549ms      | ~8%         |

typedoc and svelte (highest JSDoc density) show measurable ~7-8% wall-clock overhead. The rest are within noise. CPU time overhead is ~1-2% as JSDoc work parallelizes across threads.

### Architecture

The formatting pipeline processes each JSDoc comment through these stages:

1. **Parse** — Extract JSDoc structure via `oxc_jsdoc` (description, tags with type/name/comment)
2. **Normalize** — Canonicalize tag aliases (`@return` → `@returns`), normalize types (`Array.<T>` → `T[]`, `?Type` → `Type | null`), normalize markdown emphasis (`__bold__` → `**bold**`, `*italic*` → `_italic_`)
3. **Sort & Group** — Sort tags by upstream priority weights within `@typedef`/`@callback` groups; reorder `@param` tags to match function signature
4. **Format** — Route each tag to its specific formatter (type+name+comment, type+comment, generic, example); format descriptions via markdown AST with word wrapping; format embedded code blocks
5. **Serialize** — Assemble final comment with `/** ... */` wrapper, `* ` prefixes, and single-line optimization

**Key modules:**
- `serialize.rs` — Main pipeline orchestrator (`JsdocFormatter` struct)
- `tag_formatters.rs` — Tag-specific formatters (type+name+comment, type+comment, generic, example)
- `normalize.rs` — Type/emphasis/capitalization normalization
- `mdast_serialize.rs` — Markdown AST → formatted text serialization with `tag_string_length` offset
- `wrap.rs` — Word wrapping with `first_line_offset`, atomic JSDoc link tokens, table formatting
- `embedded.rs` — Embedded JS/TS/JSX/TSX code formatting in @example blocks
- `imports.rs` — `@import` tag parsing, merging, and sorting
- `param_order.rs` — `@param` tag reordering to match function signature
- `line_buffer.rs` — Single-allocation line accumulator

### Options Support

All 11 options from prettier-plugin-jsdoc are implemented:

| Option | Default | Status |
|--------|---------|--------|
| `capitalizeDescriptions` | `true` | ✅ |
| `commentLineStrategy` | `"singleLine"` | ✅ |
| `separateTagGroups` | `false` | ✅ |
| `separateReturnsFromParam` | `false` | ✅ |
| `bracketSpacing` | `false` | ✅ |
| `descriptionWithDot` | `false` | ✅ |
| `addDefaultToDescription` | `true` | ✅ |
| `preferCodeFences` | `false` | ✅ |
| `lineWrappingStyle` | `"greedy"` | ✅ (greedy + balance) |
| `descriptionTag` | `false` | ✅ |
| `keepUnparsableExampleIndent` | `false` | ✅ |

**Not yet ported** (no conformance fixtures): `jsdocVerticalAlignment`, `tsdoc` mode — can be added when needed.

### Features

- **Description formatting**: Capitalize first letter, normalize markdown emphasis, wrap text to print width
- **Markdown AST processing**: Parse descriptions via mdast for heading normalization, list formatting, reference links, code blocks, blockquotes, tables
- **Tag description wrapping**: Matches upstream's `tagStringLength` architecture — full description passes through markdown AST with first-line offset
- **Tag normalization**: 17 tag synonyms, sort by upstream priority weights within groups
- **Type formatting**: Normalize JSDoc types, format via the formatter's TS parser (simulating upstream's `formatType()`), handle rest params, bracket spacing
- **@example formatting**: Format embedded JS/TS/JSX/TSX code; fenced code blocks with language detection
- **@import handling**: Parse, merge by module path, sort (third-party before relative), format consolidated imports
- **@param reordering**: Reorder tags to match function signature parameter order
- **Default value handling**: Extract `[name=value]` defaults with "Default is \`value\`" suffix

### Upstream Fidelity

Verified against [prettier-plugin-jsdoc](https://github.com/hosseinmd/prettier-plugin-jsdoc) v1.8.0 source:

- **Identical**: Tag synonyms (17), sort priorities (46 tags), grouping logic (`TAGS_GROUP_HEAD`, `TAGS_GROUP_CONDITION`), type normalization pipeline, rest param handling, JSDoc link protection, emphasis normalization, capitalization rules
- **Architecture aligned**: Tag description wrapping uses `tag_string_length` / `first_line_offset` (equivalent to upstream's `!...?` prefix trick), balance mode effective width calculation, greedy fallback
- **10 upstream bugs documented** — oxfmt intentionally produces correct output where the plugin has known issues (HTML comment wrapping, `{@link}` off-by-one, `{@includeCode}` splitting, `@type` capitalization inconsistency, etc.)

### Optimization Techniques

- Single `LineBuffer` allocation per comment (one contiguous `String`, not `Vec<String>`)
- `Cow<'_, str>` throughout normalization — borrows when unchanged, allocates only when modified
- Fast-path skip of mdast parsing for plain-text descriptions (`needs_mdast_parsing()` heuristic)
- Fast-path skip of TS formatter for simple types (`needs_formatter_pass()` check)
- `SmallVec<[usize; 4]>` for import tag indices (stack allocation for common case)

## Test plan

- [x] `cargo test -p oxc_formatter` — 335 tests pass (76 unit + 259 fixture)
- [x] `cargo run -p oxc_prettier_conformance -- --jsdoc` — 145/145 (100%)
- [x] Prettier conformance: JS 746/753 (99.07%), TS 591/601 (98.34%)
- [x] Real-world repos: 34 diffs across 5 repos (7,542 JSDoc tags) — all design differences
- [x] Performance: 0-8% overhead across 5 real-world repos (typedoc ~7%, svelte ~8%, rest within noise)
- [x] `cargo clippy -p oxc_formatter --all-targets` — clean
- [x] `cargo fmt -- --check` — clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-03-23 07:44:47 +00:00
camc314 ee0491e937 fix(apps,napi): explicitly specify libs in tsconfigs (#20071)
Replaces #20064

The `dom` lib was implicitly being injected, this means stuff like `Token` and `Comment` were in the global scope, which was incorrect.

cc @overlookmotel
2026-03-06 14:46:23 +00:00
Boshen 4179e4f85a chore(editors): remove VS Code extension (moved to oxc-vscode repo) (#18982)
## Summary

- Removes `editors/vscode` directory - code has been moved to
https://github.com/nicholasrice/oxc-vscode
- Removes `tasks/vscode_docs` crate (no longer needed)
- Removes CI and release workflows for VS Code extension
- Updates `editors/README.md` to point to the new repository
- Cleans up references in `.gitignore`, `justfile`, `oxc_release.toml`,
`oxfmtrc.jsonc`, `oxlintrc.json`, and `pnpm-workspace.yaml`

closes #17484

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 21:14:03 +08:00
Boshen eef12302ff fix(ci): update Claude prompt to explicitly reference issue
- Add issue number and repository to prompt
- Instruct Claude to use `gh issue view` to read issue details first

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 16:15:54 +08:00
Sysix 9c107fac65 test(vscode): move unit tests into own test suite (#17533)
> This PR reorganizes the VSCode extension tests by separating unit tests into their own test suite, distinct from integration tests. This allows unit tests to run independently and faster without requiring LSP server initialization.
2025-12-31 17:41:17 +00:00
Boshen c8281dd0bb chore(pnpm): move workspace devDependencies to used packages (#16982)
To ensure monorepo dependencies are only visible to where they are used.
2025-12-17 15:09:08 +08:00
Boshen 6fca2f7f60 chore(infra): use oxfmt for all files, remove dprint (#16599)
Toml formatting is missing but there's only a few toml files, can wait
for oxfmt plugins.

- [x] Something is slow, can't figure out why, need #16607
2025-12-15 12:06:24 +00:00
Boshen 3f6387dd3b ci(workflows): add workflow_call support to update_submodules.yml (#16431)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-12-03 19:47:57 +08:00
overlookmotel 33bb9a62da fix(tasks): git ignore node-compat-table submodule (#14132)
#13925 added a submodule `node-compat-table`. Add it to `.gitignore`
with the other submodules.
2025-09-26 10:38:50 +08:00
Boshen e29e6c04e3 chore: remove .claude 2025-09-11 13:49:03 +08:00
Copilot e84ae8b883 feat(tasks/mcp): Add parser tool (#13207)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Boshen <boshenc@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-20 12:40:06 +08:00
Sysix 76b6b3395f test(editor): add tests for multi workspace folder setup (#10904)
We have now 3 different test setups:

###  `test()`
Will be executed in both modes.  Should be used to make sure this works for both ways.

###  `testSingleFolderMode()`
Will only be executed for single folders. Testing with multi folder is redundant.

###  `testMultiFolderMode()`
Will only be executed in multi folder mode. These are special tests which are only designed for multi folders and makes no sense that it will work in single folder.

---

`loadFixture()` and `getDiagnostics()` will use the second folder when the multi folder mode is activated
2025-05-11 17:47:54 +00:00
Dunqing 91130dea9a test(transformer): add nestjs e2e test (#10634)
Add a NestJS e2e test to avoid breaking legacy decorator + `emitDecoratorMetadata` transformations. Code copied from the NestJS template.
2025-04-27 11:58:40 +00:00
Sysix 8e55395efb chore(editor): git ignore test_workspace (#10082) 2025-03-27 21:20:42 +00:00
Hiroshi Ogawa 48bac9278a test(napi/parser): test wasi browser (#9793) 2025-03-18 12:04:09 +08:00
Hiroshi Ogawa 0e2dd1974e feat(tasks/coverage): estree test262 conformance runner (#8946)
Related https://github.com/oxc-project/oxc/issues/8630

I updated Boshen's branch
https://github.com/oxc-project/oxc/compare/estree. Instead of creating a
2nd serializer to strip ts ast suggested by overlookmotel, for now I'm
stripping extra properties on oxc side before comparing acorn output,
which allows easier diff and usable coverage report at this current
state.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2025-02-07 13:08:31 +00:00
Boshen 5cb9e979fe feat(tasks/e2e): transformer + minifier runtime tests for popular npm packages (#8552)
Code extracted from
https://github.com/privatenumber/minification-benchmarks
2025-01-17 19:13:59 +08:00
Boshen 85d4c93778 chore(.gitignore): ignore all wasm files 2024-11-28 10:34:14 +08:00
Boshen 3169bc61d1 ci: clean up wasm type check (#7466)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-25 17:56:17 +08:00
Alexander S. 5190b7fb28 test(editor): add test setup (#7361)
Tried it with `vitest`, but there was too many problems with `vscode`
integration.
That why I followed the official guide:
-
https://code.visualstudio.com/api/working-with-extensions/testing-extension#migrating-from-vscode
-
https://code.visualstudio.com/api/working-with-extensions/continuous-integration
2024-11-20 12:46:01 +08:00
Boshen 14ce0eef44 feat(tasks/compat_data): init compat data task (#7156) 2024-11-07 07:39:32 +00:00
Boshen c2802e63fc feat(transform_conformance): add babel runtime to exec tests (#7114) 2024-11-04 14:38:15 +00:00
Boshen abfca2ab90 chore: clean up .gitignore 2024-09-23 12:03:55 +08:00
Boshen be63a2cafc chore: add dprint 2024-09-08 13:24:58 +08:00
overlookmotel f3aedf6501 chore: remove .idea from .gitignore (#4496)
`.idea` snuck its way into `.gitignore` in #4484. Remove it again.

See #4355 for reason why it shouldn't be there.
2024-07-26 23:59:24 +00:00
Ethan Goh 1667491868 fix(syntax): correct is_reserved_keyword_or_global_object's incorrect function calling. (#4484)
It may be a problem, but doesn't matter previously.

Formerly, the `is_reserved_keyword_or_global_object` is
`is_reserved_keyword(s) || is_reserved_keyword(s)`. I think it should be
`is_reserved_keyword(s) || is_global_object(s)` according to its name.

Also, the `.idea` may be because I am using RustRover, which may
automatically create `.idea` folder. So I ignore it in `.gitignore`.

I think I can contribute to `oxc` more when I am free.
2024-07-26 17:20:10 -04:00
Boshen da1e2d0e9b fix(codegen): improve typescript codegen (#3708)
Remaining issues are tracked in https://github.com/oxc-project/oxc/issues/3692
2024-06-17 09:34:54 +00:00
overlookmotel 93e1ea4419 feat(tasks): shard benchmarks in CI (#2751)
This PR shards benchmarks when running on CI. Each benchmark (parser, minifier etc) runs as a separate job, and then a final job combines the results and uploads to Codspeed.

A bit of a hacky implementation. Uses a small NodeJS HTTP server to intercept the results from `codspeed-runner`, and then another NodeJS script to combine them all together, and upload to CodSpeed.

I will submit PRs on Codspeed's runner + action to do it properly, but as I imagine it'll be a slow process getting that merged upstream, I wanted to see if it worked first. We can replace this once it's supported upstream.

Sharding only reduces total time to run the benchmarks by about 70 secs at present, because linter benchmark takes 6 mins alone and holds up the whole process (all the rest are done in ~2 mins). If we can split up the linter benchmark, we can likely get total run time down to around 3 mins. I'll try that in a follow-on PR.

I guess the other upside is we can now add as many benchmarks as we like with impunity - they'll run in parallel, and so won't slow things down overall.
2024-03-18 10:45:44 +08:00
Andrew McClenaghan 6b3b260dcc feat(Codegen): Improve codegen (#2460)
This gets all the new TS types working to the same level TS output was
before and fixes a bunch of other codegen

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-02-21 14:41:57 +08:00
Boshen a574f2852e chore: ignore git submodules 2024-02-04 16:15:01 +08:00
Tzvi Melamed 27681951e1 feat(oxc_semantic): Improve sample visualization (#2251)
1. add a `test.js` file to the project root:

```js
class A extends B {
  constructor() {
    try {
      super();
    } finally {
      this.a;
    }
  }
}
```

2. run:

```bash
$ cargo run -p oxc_semantic --example simple
   Compiling oxc_semantic v0.5.0 (/home/tzvipm/src/github.com/tzvipm/oxc/crates/oxc_semantic)
    Finished dev [unoptimized + debuginfo] target(s) in 32.07s
     Running `target/debug/examples/simple`
Wrote AST to: test.ast.txt
Wrote CFG blocks to: test.cfg.txt
Wrote CFG dot diagram to: test.dot
```

3. resulting graph from .dot file:


![image](https://github.com/TzviPM/oxc/assets/1950680/7163deaa-ab75-4bed-a093-946e2d6d2206)
2024-02-01 12:55:56 +00:00
u9g ec2af2b24a chore: add lint plugins to gitignore (#1524) 2023-11-24 10:43:34 +08:00
Boshen 90ff0ddbe0 refactor: change @oxidation-compiler/napi to oxc-parser (#1209) 2023-11-10 06:17:05 +00:00
Boshen e4c097bb91 chore: mv dir editor/vscode to editors/vscode (#1203) 2023-11-09 21:13:11 +08:00
ubugeeei f75485b41f add icon file for vscode extension (#1134) (#1135)
Closes #1134 

I'm not sure if it's the correct solution, but I solved it this way, so
I'll submit a PR. As for the icon, I took it from the marketplace.

https://marketplace.visualstudio.com/items?itemName=oxc.oxc-vscode
2023-11-04 08:42:18 +08:00
Boshen 223877b6fd feat(vscode): prepare for publish (#1123) 2023-11-01 09:49:29 +08:00
Wenzhe Wang 7192520d2b feat(transformer_conformance): use bun to run babel exec.js test cases (#1012)
closes #999 

Co-authored-by: Boshen <boshenc@gmail.com>
2023-10-25 03:06:07 +00:00
阿良仔 8a915cec5c feat: vscode extension (#690)
related: #688 .
There are some unfinished things that need to be finalised by Boshen.

1. Official icon and description for the package.
2. Publishing strategy ( It's probably not a good idea to use
`package.json` as a probe to publish extension, as there's too much
vscode configuration coupled to it, a git tag like `vscode_v0.0.x` might
be worth considering ).
3. License for the extension.
2023-08-06 21:28:49 +08:00
Boshen fda6d83712 feat(resolver): resolve extensions (#549) 2023-07-14 23:25:47 +08:00
Boshen 231b987c0c chore: add just watch command for overcoming cargo-watch being slow 2023-05-16 13:22:42 +08:00
Boshen d49195f7f2 feat: napi (#302)
* chore: only ignore js files from the root

* feat: napi
2023-04-22 14:41:45 +08:00
Boshen 4c4cb4d526 ci: setup npm publish 2023-03-02 06:55:56 -08:00
Boshen 8dc4d82cc5 chore: igore .js(x), .ts(x) in root directory 2023-02-26 02:02:05 +08:00
Boshen 636a974686 feat(benchmark): setup hyperfine benchmark
closes #25
2023-02-25 18:58:31 +08:00