Commit Graph

811 Commits

Author SHA1 Message Date
therewillbecode bf90072ee0 fix(ast/estree): Fix ObjectProperty node (#10018)
Align our AST's ESTree output with that of TS-ESLint's for
the`ObjectProperty` node. Relates to #9705

Add `optional` field and set to `false` fo the `ObjectProperty` when
serializing to TS estree.
2025-04-02 12:27:43 +01:00
oxc-bot 3b72e5b151 release(crates): v0.62.0 (#10158) 2025-04-02 09:48:40 +08:00
overlookmotel f0e1510b44 fix(parser): store lone surrogates as escape sequence (#10041)
Closes #3526.

Fully parse strings containing lone surrogates and encode the string in `value`.

Encoding schema is to encode a lone surrogate as the lossy replacement character, followed by the code point in hex. i.e. `"\uD800"` in source code would be encoded as `\u{FFFD}d800` in `value`. The lossy replacement character itself is encoded as `\u{FFFD}fffd`.

There's nothing special about the lossy replacement character. Just had to choose *some* valid Unicode character to be the escape marker, and that seemed like a reasonable choice of a character which is likely to be rare in real-world code.

All the ESTree-Test262 test cases related to lone surrogates now pass.

WIP. A bit of tidying up to do yet.
2025-03-29 12:48:01 +00: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
overlookmotel 95e69f68ef fix(ast/estree): fix StringLiterals containing lone surrogates (#10036)
Improve output for `StringLiteral`s containing lone surrogates.

Most of the remaining failing tests are just due to difference in case e.g.:

```diff
- "value": "\ud83d",
+ "value": "\uD83D",
```

But there are still a few genuine test fails. We don't have it exactly right yet. But this is a step in the right direction.
2025-03-28 04:30:19 +00:00
therewillbecode 8408606af8 fix(ast/estree): Fix TSMethodSignature (#10032)
Adds and skips fields to the Estree serialiser for the
`TSMethodSignature` node.

Part of our broader work to align our AST's ESTree output with that of
TS-ESLint's. Relates to https://github.com/oxc-project/oxc/issues/9705
2025-03-25 17:39:47 +05:30
therewillbecode 1a0bd7c42c fix(ast/estree): Fix TSPropertySignature (#10031)
Adds the `static` and `accessibility` fields to the Estree serialiser
for the `TSPropertySignature` node.

Part of our broader work to align our AST's ESTree output with that of
TS-ESLint's. Relates to https://github.com/oxc-project/oxc/issues/9705

This PR is a follow up from #10020.
2025-03-25 17:26:35 +05:30
overlookmotel ab1a79663a test(napi): disable NAPI parser tests for TS files (#10028)
Disable the NAPI parser tests for TS fixtures while we work on aligning TS AST with TS-ESLint.

As discussed in https://discord.com/channels/1079625926024900739/1352245556235210773/1353945943862546454.
2025-03-25 04:45:48 +00:00
overlookmotel 707a77664a fix(ast/estree): fix TS type defs for TSIndexSignature and TSIndexSignatureName (#10003)
Follow-on after #9968. These 2 types are TS-only, so none of the fields are optional. Correct TS type defs by replacing `TSNull` with `Null` etc in the extra field types.
2025-03-24 07:41:09 +00:00
therewillbecode c98d3f4829 fix(ast/estree): Add custom serializer for extends field of TSInterfaceDeclaration (#9996)
Make the`extends` field in `TSInterfaceDeclaration` serialize to `[]`
instead of `null` for interface declarations when the field is empty.

`"extends": null` -> `"extends": []`

PR is part of ongoing work to align our AST's ESTree output with that of
TS-ESLint's. Relates to #9705
2025-03-24 13:34:28 +09: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
therewillbecode 89cb3687ad fix(ast/estree): Add decorators field to AssignmentPattern (#9967)
Adds a `decorators` field with an empty array to align our AST's ESTree
output with that of TS-ESLint's for the `AssignmentPattern` node.
Relates to #9705

---------

Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
2025-03-23 15:27:41 +09:00
therewillbecode 4980b735af fix(ast/estree): Add missing estree fields to TSIndexSignature and TSIndexSignatureName (#9968)
Add missing estree fields to TSIndexSignature and TSIndexSignatureName

PR is part of ongoing work to align our AST's ESTree output with that of
TS-ESLint's. Relates to #9705.

---------

Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
2025-03-23 15:16:11 +09:00
therewillbecode b9f80b9877 fix(ast/estree): Fix TSFunctionType and TSCallSignatureDeclaration (#9959)
Skips estree serialisation for the field named `this_param` for both
`TSFunctionType` and `TSCallSignatureDeclaration` nodes.

PR is part of ongoing work to align our AST's ESTree output with that of
TS-ESLint's. Relates to #9705.

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-03-22 10:24:24 +05:30
therewillbecode 0cdeedd19d fix(ast/estree): Fix ArrayPattern (#9956)
Align our AST's ESTree output with that of TS-ESLint's for
the`ArrayPattern` node. Relates to #9705

Adds the following fields for estree serialization `decorators`
`optional` `typeAnnotation`.
2025-03-22 09:51:39 +05:30
therewillbecode 6fcd34290a fix(ast/estree): Fix FormalParameter (#9954)
Align our AST's ESTree output with that of TS-ESLint's for the
`FormalParameter` node. Relates to #9705

Skips the estree serialization of `accessibility` `readonly` and
`overrides` fields.
2025-03-21 18:42:16 +05:30
overlookmotel db642eb022 refactor(ast/estree): shorten raw deser code (#9944)
Shorten and simplify some `raw_deser` code, by using `THIS.prop` instead of `DESER[TypeOfProp](POS_OFFSET.prop)`.

As well as being shorter, this also results in more efficient deserializer code, as it avoids deserializing the same value twice.
2025-03-21 07:56:25 +00:00
overlookmotel 9d1035ebce fix(ast/estree): fix TS type def for TSThisParameter (#9942)
Follow-on after #9913.

`TSThisParameter` is a TS-only type, so its fields aren't optional the way the TS fields of JS types are.

Fix the type def by using JS versions of added fields (`False` instead of `TsFalse` etc).

Also re-order the fields, so that `name` is first. We want the object shape to be the same (same field order) for all types which are `Identifier`s in the ESTree AST.
2025-03-21 07:46:00 +00:00
hi-ogawa 8228b74af2 fix(ast/estree): fix Function.this_param (#9913)
`Function.this_param` is included in `Function.params` as an `Identifier` with `name: "this"`

https://ast-explorer.dev/#eNolykEKwzAMRNGrmFm10F7AB+lKG2MU6uAoJlICwfjuUchiNu9PR0XEnI6keSvN8EFzsLPxA1/WWuT27D7tkq2sEqaX/YvG0Mfb53X12klCIHBe0o839R8hOtRkrEYgGRgXircmAw==
2025-03-21 07:25:42 +00:00
overlookmotel 5631ebd2ec fix(ast/extree): fix TSModuleDeclaration.global (#9941)
This is a copy of #9907. For some reason Graphite bungled things up, and that PR got merged into the wrong branch.

spec: https://github.com/typescript-eslint/typescript-eslint/blob/6428670b94de0027189803e5a291858d2e45362d/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts#L26-L36

It looks like this is a deprecated property as its redundant. I thought of removing it in https://github.com/oxc-project/acorn-test262, but that means I need to modify 10K files there, so I went with fixing this side.
2025-03-21 07:12:50 +00:00
hi-ogawa d69cc34e39 fix(ast/estree): fix BindingIdentifier (#9822)
spec: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/ast-spec/src/expression/Identifier/spec.ts

I'm not sure whether this can be fixed on struct side `BindingIdentifier` instead of field side `Class.id`. `BindingIdentifier` is used inside flatten `BindingPatternKind` enum, so changing it might be complicated.

There are probably many instances like this, so I'm just trying to see the pattern first.
2025-03-21 05:47:40 +00: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
Boshen 59c8f71c4a feat(parser,codegen): handle lone surrogate in string literal (#9918)
closes #3526
2025-03-20 09:04:09 +00:00
overlookmotel 040e993150 test(napi): refactor NAPI parser benchmarks (#9911)
Pure refactor. Just make the NAPI parser benchmark a bit more readable.
2025-03-20 06:34:09 +00:00
Boshen c6312915df feat(parser)!: parse TSImportAttributes as ObjectExpression (#9902)
closes #9662
closes #9663
closes #9670
2025-03-20 03:42:20 +00:00
overlookmotel 5f97f28ddb perf(ast/estree): speed up raw deser for JSXElement (#9895)
Follow-on after #9863. Speed up the raw deserializer code for `JSXElement` that PR introduced. Using `delete` in JS is usually a deoptimization. Better to create a new object.
2025-03-19 17:05:25 +00:00
Toshit a9a47a6e1a feat(parser): Add regex cargo feature to oxc_parser (#9879)
Fixes #9839.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2025-03-19 20:57:20 +08:00
hi-ogawa 28a2ed33ec fix(estree/ast): fix IdentifierName and IdentifierReference (#9863)
Binding side is tricky https://github.com/oxc-project/oxc/pull/9822, so I went with chipping away these two first.
2025-03-19 11:39:20 +00:00
Boshen 2cedfe4148 feat(napi): add codeframe to napi error (#9893)
closes #8684
2025-03-19 08:41:31 +00:00
Hiroshi Ogawa 2283ff8a19 chore(napi/parser): add example script (#9889)
There wasn't a quick way to test out raw transfer, so I added a oneshot
script to do something similar to `just example parser`.
2025-03-19 15:56:35 +08:00
Hiroshi Ogawa 233c1fc863 refactor(napi/playground): add JSON.parse wrapper (#9880)
- playground PR https://github.com/oxc-project/playground/pull/78
2025-03-19 13:51:49 +08: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
Boshen 961b95d834 refactor(napi): move common code to oxc_napi (#9875) 2025-03-18 16:06:53 +00:00
Boshen c8979d9bff chore(wasm/parser): remove parser wasm32-unknown-unknown build (#9865)
In favor of napi wasm32-wasip1-threads build
2025-03-18 10:33:50 +00:00
Boshen 590a258776 docs(napi/parser): add stackblitz link for wasm build 2025-03-18 18:07:07 +08:00
oxc-bot 9baa7568f8 release(crates): v0.60.0 (#9861) 2025-03-18 17:01:17 +08:00
Boshen aa3dff887a feat(napi): add mimalloc to parser and transformr (#9859) 2025-03-18 16:51:37 +08:00
overlookmotel 2d63704d75 perf(ast): re-order VariableDeclarationKind variants (#9853)
Micro-optimization.

Re-order variants of `VariableDeclarationKind`. With this order:

* Checking if it's a lexical declaration is `discriminant != 0`
* Checking if it's const is `discriminant > 1`.

The latter is a couple of instructions shorter than it was before (`discriminant == 1 || discriminant > 2`).
2025-03-18 07:37:55 +00: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
overlookmotel 3f858c4c28 fix(ast/estree): add directive field to ExpressionStatement in TS AST (#9844)
See #9835. Add `directive` field to `ExpressionStatement` only in TS AST.
2025-03-18 05:15:26 +00:00
overlookmotel 3d17860ddf refactor(ast)!: reorder fields of TemplateElement (#9821)
Re-order the fields of `TemplateElement`, moving `tail` to last. This
means fields are in same order as ESTree, withou having to manually
re-order them.

The field order makes no real difference here, since `tail` field is not
visited, so I figure might as well align with ESTree.
2025-03-18 13:10:16 +08:00
Boshen 07e24a8123 ci(wasm): clean up test-wasm32-wasip1-threads (#9840) 2025-03-18 04:18:21 +00: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
hi-ogawa cd18358420 fix(ast/extree): fix Class.implements (#9817)
No effect on conformance yet since basic `Identifier` mismatches.
2025-03-18 01:47:10 +00:00