Commit Graph

811 Commits

Author SHA1 Message Date
overlookmotel c2fb4e08b0 refactor(ast_tools): print number of padding bytes in layout assertions files (#11059)
Add comments to `assert_layouts.rs` files stating the number of padding bytes each time contains. This is useful when trying to reduce size of AST types.
2025-05-15 13:42:22 +00:00
Boshen 635aa96219 fix(napi): computed final source type from lang then sourceType (#11060)
closes #10980

Previously final source type was only computed when `lang` is not set.

It is changed to:

* compute source type from `lang`, use filename extension if `lang` is
not set
* reset the computed source type with 'script` or `module` if provided
2025-05-15 21:41:42 +08:00
Boshen 584d8b93b7 fix(napi): enable mimalloc no_opt_arch feature on linux aarch64 (#11053)
fixes #11045

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-05-15 17:09:43 +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
overlookmotel a4b5716a23 perf(ast/estree): streamline raw deserializer for WithClause (#10974)
All the fields of `WithClause` except `with_entries` are ignored, so there's no point deserializing them.
2025-05-12 17:38:20 +00:00
overlookmotel 6f3f9d7a2a fix(ast/estree): fix raw_deser for TSMappedTypeOptional serializer (#10971) 2025-05-12 14:46:52 +00:00
Yuji Sugiura d036cf5140 fix(estree): Ensure the same key order for AssignmentPattern (#10953)
Part of #9705 

With this PR, all AST nodes now have a consistent key order for each
node type.
(Checked by
https://github.com/leaysgur/oxc_estree_ts-ast-diff-viewer/blob/main/scripts/verify-key-order-oxc.js)

Except for:

- `Literal`: `regex` and `bigint` keys
- `TSModuleDeclaration`: `body` key is missing when `declare module
"jq";`
2025-05-12 14:04:30 +01: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
overlookmotel 53329f8bf2 fix(ast/estree): fix field order for FormalParameter (#10962)
Order last 3 fields: `decorators`, `optional`, `typeAnnotation` - to match these types in other positions.
2025-05-12 11:35:24 +00:00
overlookmotel 8b8f78f1d2 fix(ast/estree): fix field order and type def for RestElement in FormalParameters (#10961)
Change field order for a `RestElement` in `FormalParameters` to contain `decorators`, `optional`, `typeAnnotation` in that order - to match `RestElement` in other positions.

Fix TS type def for `FormalParameterRest` to include all fields.
2025-05-12 11:10:30 +00:00
renovate[bot] ed983f895d chore(deps): lock file maintenance npm packages (#10945) 2025-05-12 17:57:45 +08:00
overlookmotel 2b76ab51d8 fix(ast/estree): fix TSModuleDeclaration raw deserializer (#10924)
Fix #10901.
2025-05-11 13:25:22 +00:00
oxc-bot 2b890aba8f release(crates): v0.69.0 (#10925) 2025-05-10 00:06:12 +08:00
overlookmotel 2b5d82687a fix(ast)!: fix field order for TSTypeAssertion (#10906)
Fix field order for `TSTypeAssertion`. Move `type_annotation` to before `expression`, because it comes first in source:

```ts
//                ___ expression
let foo = <number>bar;
//        ^^^^^^^^ type_annotation
```
2025-05-09 01:35:42 +00:00
overlookmotel 1f3591076f fix(ast)!: fix field order for TSNamedTupleMember (#10905)
Fix field order for `TSNamedTupleMember`. Move `label` to before `element_type`, because it comes first in source:

```ts
type Foo = [first: string, second: number];
//    label ^^^^^  ^^^^^^ element_type
```
2025-05-09 01:35:42 +00:00
overlookmotel 8a3bba8356 fix(ast)!: fix field order for PropertyDefinition (#10902)
Fix field order for `PropertyDefinition`. Move `type_annotation` to before `value`, because it comes first in source:

```ts
class C {
    x: number = 123;
}
```
2025-05-08 15:34:06 +00:00
overlookmotel 5746d36f04 fix(ast)!: fix field order for NewExpression (#10893)
Fix field order for `NewExpression`. Move `type_arguments` to before `arguments`, because they come first in source:

```tsx
const foo = new Foo<T>(1, 2, 3);
```
2025-05-08 15:34:05 +00:00
Boshen 3cf867cc93 feat(napi/parser): expose module record data for export default interface (#10894)
fixes #10644
2025-05-08 13:04:59 +00:00
Boshen 22ba60b6c4 feat(napi): add s390x-unknown-linux-gnu build (#10892) 2025-05-08 20:13:41 +08:00
overlookmotel 013979359e fix(ast)!: re-order fields of TaggedTemplateExpression (#10889)
Fix field order for `TaggedTemplateExpression`. Move `type_arguments` to before `quasi`, because they come first in source:

```ts
const foo = tag<T>`quasi`;
```
2025-05-08 11:59:35 +00: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 6646b6b481 fix(ast)!: fix field order for JSXOpeningElement (#10882)
Fix field order for `JSXOpeningElement`. Move `type_arguments` to before `attributes`, because they come first in source:

```tsx
<Component<T> foo={123} />
```
2025-05-08 07:58:23 +00:00
overlookmotel cc2ed216f5 fix(ast)!: fix field order for JSXElement and JSXFragment (#10881)
Fix field order for `JSXElement` and `JSXFragment`. Move `children` field to before closing field, because `children` comes first in source.
2025-05-08 07:58:23 +00:00
overlookmotel 2c09243a27 fix(ast): fix field order for AccessorProperty (#10878)
In `AccessorProperty`, move `type_annotation` field to before `value`, because it appears first in AST.

```ts
class C {
  accessor x: number = 123;
}
```

This also aligns with TS-ESLint's visitation order.
2025-05-08 01:39:52 +00:00
overlookmotel e7228faf2b fix(ast/estree): fix optional field of TSMappedType in TS-ESTree AST (#10874)
Part of #9705.

Recent changes in TS-ESLint made `TSMappedType`'s `optional` field default to `false` instead of `null`. Update our TS-ESTree AST to match it.
2025-05-07 16:46:32 +00:00
overlookmotel 6f0638ae17 fix(ast/estree): remove TSImportTypeOptions custom serializer (#10873)
`TSImportTypeOptions` custom serializer was to work around a bug in TS-ESLint parser. That bug has now been fixed, so we don't need this workaround any more.

https://github.com/typescript-eslint/typescript-eslint/issues/11114
2025-05-07 17:37:24 +01:00
overlookmotel e6657ae13a fix(ast/estree): reorder fields for TS Identifier types in TS-ESTree AST (#10864)
Change field order of TS types which are converted to `Identifier`s in TS-ESTree AST, to be consistent with other `Identifier`s.
2025-05-07 14:14:33 +00:00
overlookmotel d066516b6a feat(ast_tools): support #[estree(prepend_to)] (#10849)
Add an `#[estree(prepend_to = ...)]` attribute to accompany `#[estree(append_to = ...)]`.

* `#[estree(prepend_to = target)]` prepends the field to *start* of the target field.
* `#[estree(append_to = target)]` appends the field to *end* of the target field.

This also allow both prepending *and* appending to the same field. e.g. combining `TSThisParameter`, `FormalParameter`s, and `BindingRestElement` into a single array.
2025-05-07 13:25:17 +00:00
overlookmotel b16331ecfa refactor(ast/estree): generalize concatenating fields with Concat2 (#10848)
Pure refactor. Replace `AppendTo` and `AppendToConcat` which are used in ESTree serializer to concatenate 2 fields with a more generalized `Concat2`, which performs both functions.
2025-05-07 13:25:17 +00:00
overlookmotel daba0a7c2a refactor(estree): remove regular expression types from ESTree AST (#10855)
`Pattern` and other types in `oxc_regular_expression` are not part of ESTree AST. Don't implement `ESTree`, and don't generate raw transfer deserializers for these types. None of that code is actually used.

This reduces the scope of ESTree serialization.
2025-05-07 13:46:32 +01:00
overlookmotel ad4fbf44db refactor(ast)!: simplify RegExpPattern (#10834)
`RegExpPattern` was an enum with `Raw`, `Invalid`, and `Pattern` variants. i.e. only the raw string *or* the `Pattern` could be stored, but not both.

This required complications in various places, because if the regexp has been parsed, in order to examine or print it, you have to either convert the `Pattern` back to a `String`, or rely on the `Span` and slice the source text.

The `Invalid` variant is not very useful. It's only created if `parse_regular_expression` option is enabled, in which case an error is reported from the parser anyway.

Instead, always store the pattern string as an `Atom`, and store the parsed pattern as `Option<Box<Pattern>>`.

This simplifies code in various places, and makes printing `RegExpLiteral`s faster in `oxc_codegen` when `parse_regular_expression` is enabled, because it can just print the pattern string, rather than converting a `Pattern` back to a `String`.
2025-05-07 10:05:37 +00: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
overlookmotel 09057676fd perf(napi/parser): simplify recursion and avoid function calls in fixup visitor (#10813)
Follow-on after #10791, part of #10783.

In the fixup visitor, replace `visitNode` with a more specialized
`transformNode` function. The difference is that `transformNode` doesn't
need to be passed `fn` as 2nd param.

Also, move the check for whether a node is a `Literal` into
`transformNode` to avoid the cost of a function call for every node
(most of which are not `Literal`s).

Running benchmarks locally (`pnpm run bench` in `napi/parser`), I'm
seeing a 2%-3% speed-up.
2025-05-05 22:38:47 +08: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
overlookmotel 62c3a4a576 style(ast_tools): add full stop to end of generated comments (#10809) 2025-05-05 12:52:20 +01:00
oxc-bot e6074275ae release(crates): v0.68.1 (#10796) 2025-05-05 00:53:44 +08:00
overlookmotel c33eb9c937 fix(ast/estree): fix raw deser for TSTypeReference (#10787)
Fix #10782.
2025-05-04 07:38:17 +00:00
oxc-bot 61dfcfdfd8 release(crates): v0.68.0 (#10777) 2025-05-04 09:06:24 +08:00
overlookmotel 28ceb90228 refactor(ast)!: remove TSMappedTypeModifierOperator::None variant (#10749)
It seems odd for `TSMappedTypeModifierOperator` to have a `None` variant. It's more conventional to represent "doesn't exist" as `Option::None`.

Remove the `TSMappedTypeModifierOperator::None` variant, and use `Option<TSMappedTypeModifierOperator>` instead of `TSMappedTypeModifierOperator`.

Both are the same to the compiler due to the niche optimization on `Option` (`Option<TSMappedTypeModifierOperator>` is 1 byte), but it just seems more logical to me this way.

Also an unrelated change: Shorten code in codegen and formatter.
2025-05-01 14:50:17 +00:00
overlookmotel 050ecd90fc refactor(ast/estree): remove custom serializer for TSMappedTypeModifierOperator (#10747)
Use the support for `#[estree(via = ...)]` on fieldless enum variants added in #10746 to remove custom serializer for `TSMappedTypeModifierOperator`. This serializer can now be auto-generated.

Does not effect output, only simplifies how it's generated.
2025-05-01 11:14:23 +00:00
overlookmotel a2ba7c35f9 refactor(napi/parser): add comments about hashbang comments (#10692)
Add comments about hashbang comments which I should have included in #10669.
2025-04-29 11:13:47 +00:00
overlookmotel d882eaa876 perf(napi/parser): lazy load raw transfer deserializers (#10482)
Don't eagerly load raw transfer deserializer code. These files are large and will take JS engine some time to parse. Instead, `require` the appropriate deserializer lazily, when it's first needed.

For the majority of users who aren't using raw transfer (almost everyone, as it's currently behind an experimental option), avoid loading this code entirely.
2025-04-29 10:41:41 +01: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
overlookmotel 61d825b8bf fix(ast/estree): rename assert to with in TSImportType options in TS-ESTree AST (#10681)
TS-ESLint parser replaces a property of `options` called `assert` with one called `with`.

https://github.com/typescript-eslint/typescript-eslint/issues/11114

This looks like it's an error on their side, but in the meantime replicate this behavior.
2025-04-28 18:48:52 +00:00
overlookmotel c8005adae1 fix(ast/estree): add line comment for hashbang in ESTree AST (#10669)
In ESTree (plain ESTree for JS i.e. Acorn), a hashbang is recorded as a line comment. Follow that behavior in our ESTree AST.

In TS-ESTree, hashbangs are ignored. That's not how it looks in AST explorer, because there's some post-processing going on, but `@typescript-eslint/parser` itself ignores hashbangs. So only add the comment in ESTree AST (not TS-ESTree AST).

More info on this rather confusing subtlety: https://github.com/typescript-eslint/typescript-eslint/issues/6500
2025-04-28 14:33:49 +00:00
overlookmotel 14c4bbb4e7 test(ast/estree): fix raw transfer tests (#10666)
The tests for ensuring field order is the same between JSON-based transfer and raw transfer were not working correctly. Fix them. Thankfully they all still pass!
2025-04-28 14:09:03 +00:00
oxc-bot 7cf80ef7fd release(crates): v0.67.0 (#10637) 2025-04-27 22:30:07 +08:00
Ulrich Stark a9785e347e fix(parser,linter): consider typescript declarations for named exports (#10532)
Only VariableDeclaration, FunctionDeclaration and ClassDeclaration were
considered when collecting named export declarations for the module
record. Now the parser also considers TSTypeAliasDeclaration,
TSInterfaceDeclaration, TSEnumDeclaration, TSImportEqualsDeclaration and
TSModuleDeclaration named export declarations of the module.

Maybe the other `decl.declaration.is_typescript_syntax()` check in
`module_record.rs` also needs to be removed?

Closes #10318
Closes #10556
2025-04-25 14:44:12 +08:00
overlookmotel 24ab2f36d2 fix(ast/estree): convert TSClassImplements::expression to MemberExpression in TS-ESTree AST (#10607)
Part of #9705.

TS-ESLint parser represents `X.Y` in `class C implements X.Y {}` as a `MemberExpression`, whereas in our AST it's a `TSQualifiedName`. Convert to `MemberExpression` in TS-ESTree AST.
2025-04-24 19:31:17 +00:00