Commit graph

457 commits

Author SHA1 Message Date
github-actions[bot]
1b3cd6c24d
Release crates v0.15.0 (#3743)
## [0.15.0] - 2024-06-18

- 0537d29 cfg: [**BREAKING**] Move control flow to its own crate.
(#3728) (rzvxa)

- 5c38a0f codegen: [**BREAKING**] New code gen API (#3740) (Boshen)

- 4bce59d semantic/cfg: [**BREAKING**] Re-export `petgraph` as
`control_flow::graph`. (#3722) (rzvxa)

- 534242a codegen: [**BREAKING**] Remove
`CodegenOptions::enable_typescript` (#3674) (Boshen)

- 0578ece ast: [**BREAKING**] Remove
`ExportDefaultDeclarationKind::TSEnumDeclaration` (#3666) (Dunqing)

### Features

- 5a99d30 codegen: Improve codegen formatting (#3735) (Boshen)
- bf9b38a codegen: Improve codegen formatting (#3731) (Boshen)
- 4a004e2 codegen: Print TSImport remaining fields (#3695) (Dunqing)
- a56cb1b codegen: Print accessibility for MethodDefinition (#3690)
(Dunqing)
- 38a75e5 coverage: Improve codegen (#3729) (Boshen)
- 750a534 coverage: Transformer idempotency test (#3691) (Boshen)
- ee627c3 isolated-declarations: Create unique name for `_default`
(#3730) (Dunqing)
- 81e9526 isolated-declarations: Inferring set accessor parameter type
from get accessor return type (#3725) (Dunqing)
- 77d5533 isolated-declarations: Report errors that are consistent with
typescript. (#3720) (Dunqing)
- 8f5655d linter: Add eslint/no-useless-constructor (#3594) (Don Isaac)
- 046ff3f linter/eslint: Add `no_unreachable` rule. (#3238) (rzvxa)
- 0b8098a napi: Isolated-declaration (#3718) (Boshen)
- 527bfc8 npm/oxc-transform: Setup npm/oxc-transform and publish
(Boshen)
- d65c652 parser: Display jsx mismatch error, e.g. `<Foo></Bar>` (#3696)
(Boshen)
- 9c31ed9 semantic/cfg: Propagate unreachable edges through subgraphs.
(#3648) (rzvxa)
- d9c5b33 semantic/cfg: Add `Condition` instruction. (#3567) (Ali
Rezvani)
- f2dfd66 semantic/cfg: Add iteration instructions. (#3566) (rzvxa)
- 910193e transformer-dts: Report error for super class (#3711)
(Dunqing)
- 413d7be transformer-dts: Transform enum support (#3710) (Dunqing)
- 35c382e transformer-dts: Remove type annotation from private field
(#3689) (Dunqing)
- 0e6d3ce transformer-dts: Report error for async function and generator
(#3688) (Dunqing)
- b22b59a transformer-dts: Transform namespace support (#3683) (Dunqing)
- 4f2db46 transformer-dts: `--isolatedDeclarations` dts transform
(#3664) (Dunqing)

### Bug Fixes

- 2158268 ast: Incorrect visit order in function (#3681) (Dunqing)
- da1e2d0 codegen: Improve typescript codegen (#3708) (Boshen)
- f1b793f isolated-declarations: Function overloads reaching unreachable
(#3739) (Dunqing)
- 0fbecdc isolated-declarations: Should be added to references, not
bindings (#3726) (Dunqing)
- 8f64d99 minifier: Respect `join_vars: false` option (#3724)
(mysteryven)
- 70fc69b semantic: Add Eq to CtxFlags (#3651) (Yuji Sugiura)
- 7a58fec semantic/cfg: Issue in unlabeled `Ctx`s. (#3678) (rzvxa)
- abd6ac8 semantic/cfg: Discrete finalization path after `NewFunction`s.
(#3671) (rzvxa)
- e148a32 semantic/cfg: Correct unreachability propagation in
try-finally. (#3667) (Ali Rezvani)
- 59666e0 transformer: Do not rename accessible identifier references
(#3623) (Dunqing)
- 90743e2 traverse: Change visit order for `Function` (#3685)
(overlookmotel)

### Performance

- 2717a1a semantic/cfg: Lower the visits in
`neighbors_filtered_by_edge_weight`. (#3676) (rzvxa)

### Refactor

- fa7a6ba codegen: Add `gen` method to ast nodes (#3687) (Boshen)
- 09b92b6 codegen: Move `gen_ts` into `gen` to make searching things
easier (#3680) (Boshen)
- 3c59735 isolated-declarations: Remove `TransformDtsCtx` (#3719)
(Boshen)
- 815260e isolated-declarations: Decouple codegen (#3715) (Boshen)
- 7ec44f8 semantic: Rename `cfg` macro to `control_flow`. (#3742)
(rzvxa)
- d8ad321 semantic: Make control flow generation optional. (#3737)
(rzvxa)
- a94a72d semantic: Expose 1 checker function instead of 2 (#3694)
(Boshen)
- bd8d115 semantic/cfg: Remove unused types. (#3677) (rzvxa)
- f702fb9 semantic/cfg: Cleanup control flow and it's builder. (#3650)
(rzvxa)
- 4f16664 transformer_dts: Create a `Program` for codegen (#3679)
(Boshen)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-19 01:15:55 +08:00
Boshen
051ceb6539
chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
Dunqing
81e952632d feat(isolated-declarations): inferring set accessor parameter type from get accessor return type (#3725) 2024-06-17 15:47:23 +00: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
Dunqing
910193e0aa feat(transformer-dts): report error for super class (#3711) 2024-06-17 08:49:12 +00:00
Dunqing
413d7beb77 feat(transformer-dts): transform enum support (#3710) 2024-06-17 08:49:08 +00:00
overlookmotel
90743e2a07
fix(traverse): change visit order for Function (#3685)
Alter `Traverse`'s visitation order for fields of `Function`, to match
the change made to `Visit` in #3681.
2024-06-17 10:45:36 +08:00
Dunqing
35c382ef24 feat(transformer-dts): remove type annotation from private field (#3689) 2024-06-15 13:34:27 +00:00
Dunqing
0e6d3ceee5 feat(transformer-dts): report error for async function and generator (#3688)
feat(transformer-dts): report error for async function and generator

fix(transformer-dts): correct span for type containing private name error

fix(transformer-dts): should add reference for export specifiers
2024-06-15 13:34:25 +00:00
Boshen
fa7a6babce refactor(codegen): add gen method to ast nodes (#3687) 2024-06-15 13:23:15 +00:00
Dunqing
b22b59ae12 feat(transformer-dts): transform namespace support (#3683)
This PR implements namespace transform:

Look at this example

```ts
let internal = 0;
export namespace ns {
    namespace internal {
        export class Foo {}
    }
    export namespace nested {
        export import inner = internal;
    }
}

// to

export declare namespace ns {
    namespace internal {
        class Foo {
        }
    }
    export namespace nested {
        export import inner = internal;
    }
    export {};
}

```

The `let internal = 0` is unexported, and is unreferenced in other types. So we need to remove it.

I refactored `scope` because the previous implementation could not correctly remove unexported and unreferenced declarations.

For example, in this case
```ts
type T = string;
export function foo<T>(): T {
}
// to
type T = string;
export declare function foo<T>(): T;
```
The `type T = string` should be deleted, Because the `T` is not used in the function return type.
2024-06-15 09:45:58 +00:00
Dunqing
215826874d fix(ast): incorrect visit order in function (#3681)
```ts
function hello<T>(a: T): T {
  return 0 as T
}
```

The `T` is a type parameter. It can be used in `FormalParameters`, `ReturnType`, and `FunctionBody`. Therefore we need to visit `type_parameters` before visiting `FormalParameters`, `ReturnType`, and `FunctionBody`
2024-06-15 09:45:57 +00:00
Dunqing
4f2db46ee5 feat(transformer-dts): --isolatedDeclarations dts transform (#3664)
The goal of this PR is to pass the test cases in https://github.com/microsoft/TypeScript/tree/main/tests/cases/transpile

Once this is polished, we may publish a npm package with napi bindings for people to experiment with.
2024-06-14 12:44:10 +00:00
Dunqing
0578ece6a4
refactor(ast)!: remove ExportDefaultDeclarationKind::TSEnumDeclaration (#3666)
TypeScript doesn't support `export default enum id {}`


https://www.typescriptlang.org/play/?target=2&isolatedDeclarations=true&emitDeclarationOnly=true&isolatedModules=false&ts=5.5.1-rc#code/KYDwDg9gTgLgBAE2AMwIYFcA29gDt0C2cAlgnAN4C+QA

https://github.com/microsoft/TypeScript/issues/3320
2024-06-14 14:40:37 +08:00
rzvxa
046ff3fdfb feat(linter/eslint): add no_unreachable rule. (#3238)
closes #621
[no-unreachable](069aa680c7/lib/rules/no-unreachable.js (L196))

[oxlint-echosystem-ci result](https://github.com/rzvxa/oxlint-ecosystem-ci/actions/runs/9406195143/job/25909079029)

This rule is done but since it is running for every possible statement and does quite a bit of work on them to determine whether it is 100% reachable or not; The performance in my opinion is kind of abysmal.

I'll try to work it out, I know Biome does 2 types of checks to simplify the rule for some nodes, However, they have a lot more false negatives than our implementation.

##### Here is one example of those [false negatives](https://biomejs.dev/playground/?code=ZgB1AG4AYwB0AGkAbwBuACAAeAAoACkAIAB7ACAAZABvACAAewAgAGEAKAApADsAIAB9ACAAdwBoAGkAbABlACgAdAByAHUAZQApADsAIABiACgAKQA7ACAAfQA%3D)

-------------

### Update 1:

I've benchmarked this rule using only the simplified reachability checks and it was around 5% faster, To be honest, it isn't much improvement especially considering that we can only use this check for a small portion of nodes and even that is accompanied by newly introduced checks which would lessen the amount of performance gain further.

Most of the performance regression is because of allocations during our depth first search since we have to store both the visited and finished nodes which results in a bunch of rapid-fire allocations back to back. Currently, At the moment I don't have a great idea of how to improve it, We may have to implement our own graph to use arenas underneath.

Given that this rule is the most extensive use case of control flow (It doesn't come with a limited scope similar to property and constructor rules already implemented) this performance drop might be reasonable to some extent.

------------

### Update 2:

I reworked my approach in 2 senses, First I used @Boshen's suggestion inspired by TypeScript and kept some of the reachability information in the basic block structure instead of calculating it on the fly. It is done by propagating the `Unreachable` edge and `Unreachable` instruction throughout subgraphs.

This for sure helped with the performance but the next part is what never failed to amaze me, Going from something near `O(n!)` in the worst-case scenario to `O(n^2)` (in the worst-case scenario). By changing the approach instead of checking the reachability of each statement we do it in 3 paths; First, we do a path on the entire CFG and query all reachable but suspicious cases, and then we do another path on each of these suspicions subgraphs to determine the reachability with higher confidence. Finally, we iterate all of the appropriate nodes and check their reachability status according to the information collected in 2 previous paths.

With these 2 this rule went from `-24%` to `~-2%`.

This performance gain doesn't come for free though; It increases the likelihood of false positives/negatives, But as long as we are passing our `ecosystem-ci` it should be fine. We can always sacrifice some performance to check for edge cases if there are any.

[new oxlint-echosystem-ci result](https://github.com/rzvxa/oxlint-ecosystem-ci/actions/runs/9490791181)
2024-06-13 09:37:45 +00:00
rzvxa
9b3097147e improvement(semantic/cfg): rework error path. (#3519)
This PR aims to provide a more accurate error/finalization flow, I've nuked the old error path approach and rewrote it with more versatility in mind.

We used to visit the finalizer block twice and create 2 sets of AstNodes/Basic Blocks for them, This was there to differentiate between the error path finalizer and success path one. There is no longer a need for having 2 separate sets of nodes to do this differentiation.

As for the error path now we have 2 kinds of them, Everything is attached to an error block - even if it is not in a try-catch statement - this results in a lot of extra edges to keep track of these "Implicit" error blocks but I believe in future it can help us to track cross block error paths, For example, we can dynamically attach and cache the implicit error block of a function to its call site error path (either implicit or explicit).
2024-06-13 07:36:16 +00:00
Boshen
1edcd87203
chore: change all usages of static_assertions to dev-dependencies (#3654) 2024-06-13 13:18:53 +08:00
Don Isaac
8f5655dfe6
feat(linter): add eslint/no-useless-constructor (#3594)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-13 13:12:18 +08:00
github-actions[bot]
95e0571c2e
Release crates v0.14.0 (#3643)
## [0.14.0] - 2024-06-12

### Breaking

* fix(codegen)!: remove the unecessary 4th argument from `Codegen::new`
(#3640)
* feat(ast)!: make `Trivias` clonable by adding `Arc` (#3638)

### Features

- f6d9ca6 linter: Add `eslint/sort-imports` rule (#3568) (Wang Wenzhe)
- 129f91e span: Port over more methods from TextRange (#3592) (Don
Isaac)

### Bug Fixes

- f8f6d33 ast: Correct `visited_node` attr for strict mode of arrow fns
(#3635) (overlookmotel)
- e6ad3fb diagnostics: Do not print ansi color codes in non-TTYs (#3624)
(Boshen)
- d65202d span: Correct doc comments (#3608) (overlookmotel)
- 35e267b transformer: Arrow function transform use UIDs for `_this`
vars (#3634) (overlookmotel)
- 39bdebc transformer: Arrow func transform maintain scope ID (#3633)
(overlookmotel)
- 5cb7e6a transformer: Arrow func transform use correct spans (#3630)
(overlookmotel)
- 0c4ccb4 transformer: Arrow function transform alter `</this>` (#3627)
(overlookmotel)
- 8d237c4 transformer: JSX source calculate correct column when Unicode
chars (#3615) (overlookmotel)
- 9e8f4d6 transformer: Do not add `__source` for generated nodes (#3614)
(overlookmotel)
- 0fb4c35 transformer: Use UID for JSX source filename var (#3612)
(overlookmotel)

### Performance

- 3a59294 transformer: React display name transform reduce Atom
allocations (#3616) (overlookmotel)
- f4c1389 transformer: Create `Vec` with capacity (#3613)
(overlookmotel)

### Refactor

- 0f92521 ast: Replace recursion with loop (#3626) (overlookmotel)
- 08f1010 ast: Make `AstBuilder` `Copy` (#3602) (overlookmotel)
- 84304b4 linter: Add a `ctx.module_record()` method (#3637) (Boshen)
- f98f777 linter: Add rule fixer (#3589) (Don Isaac)
- e90e6a2 minifier: Make `Prepass` `Copy` (#3603) (overlookmotel)
- 7d61832 semantic: Pass `Rc` by value (#3586) (overlookmotel)
- 89bcbd5 transformer: Move `BoundIdentifier` into helpers (#3610)
(overlookmotel)
- 5793ff1 transformer: Replace `&’a Trivias` with `Rc<Trivias>` (#3580)
(Dunqing)
- 509871f transformer: Comment for unimplemented `spec` option in arrow
fns transform (#3618) (overlookmotel)
- 4b2e3a7 transformer: Fix indentation (#3617) (overlookmotel)
- 3467e3d transformer: Remove outdated comment (#3606) (overlookmotel)
- a799225 transformer: Flatten file structure for React transform
(#3604) (overlookmotel)
- 70f31a8 transformer: Reduce branching in JSX transform (#3596)
(overlookmotel)
- 3ae567d transformer: Remove dead code (#3588) (overlookmotel)
- 60cbdec traverse: `generate_uid_in_root_scope` method (#3611)
(overlookmotel)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-12 17:52:41 +08:00
Boshen
f6752b482f
feat!(ast): make Trivias clonable by adding Arc (#3638)
This makes `Trivias` cloneable and stops us from using `Rc::new` and
`Rc::clone` everywhere.

`Trivias` is rarely cloned so an `Arc` should suffice.
2024-06-12 13:16:10 +08:00
overlookmotel
f8f6d33722 fix(ast): correct visited_node attr for strict mode of arrow fns (#3635)
Correct the `#[visited_node]` attr on `ArrowFunctionExpression` to recognise strict mode functions.

This change has no effect at present as `Traverse` codegen currently ignores `strict_if`. But useful for it to be correct for if we codegen `Visit` / `VisitMut` later on (#3392).
2024-06-11 21:57:56 +00:00
overlookmotel
0f925210af
refactor(ast): replace recursion with loop (#3626)
Replace recursion with loop in
`JSXMemberExpression::get_object_identifier`.

Also add a mutable version
`JSXMemberExpression::get_object_identifier_mut`.
2024-06-11 21:56:08 +08:00
Wang Wenzhe
f6d9ca6e47
feat(linter): add eslint/sort-imports rule (#3568)
Rule detail: https://eslint.org/docs/latest/rules/sort-imports
2024-06-11 16:31:14 +08:00
overlookmotel
3a59294c72 perf(transformer): React display name transform reduce Atom allocations (#3616)
Re-use existing `Atom`s in React Display Name transform rather than writing duplicate strings into the arena.

Also add comments for where our implementation diverges from Babel's (in my opinion, ours is an improvement).
2024-06-11 06:41:19 +00:00
overlookmotel
89bcbd5b8d refactor(transformer): move BoundIdentifier into helpers (#3610)
Pure refactor. Move `BoundIdentifier` into helpers module so it can be reused by other transforms.
2024-06-11 06:41:11 +00:00
overlookmotel
08f1010dca refactor(ast): make AstBuilder Copy (#3602)
`AstBuilder` only contains a shared ref `&Allocator`. So make it `Copy` and pass around `AstBuilder<'a>` instead of `&AstBuilder<'a>` - 1 less level of indirection.

Hopefully this will have little effect on benchmarks as all `AstBuilder`'s methods are marked `#[inline]`, but this change will minimize impact if compiler decides not to inline for some reason.
2024-06-10 11:17:43 +00:00
Don Isaac
f98f7771d8
refactor(linter): add rule fixer (#3589)
Adds a new `RuleFixer` struct that gets passed to
`ctx.diagnostic_with_fix`.
2024-06-10 17:20:14 +08:00
github-actions[bot]
6bdd74c476
Release crates v0.13.5 (#3584)
## [0.13.5] - 2024-06-08

### Bug Fixes

- 48bb97e traverse: Do not publish the build script (Boshen)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-08 16:44:50 +08:00
Boshen
060819894d
chore: crates should only publish src and examples directory 2024-06-08 16:35:16 +08:00
Don Isaac
3e694573df
up(linter): add fixer for no-useless-spread (#3583)
Only fixes array spreads for now.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-08 11:38:38 +08:00
github-actions[bot]
d215e3d906
Release crates v0.13.4 (#3582)
## [0.13.4] - 2024-06-07

### Features

- 5c8e16c coverage: Second transformer build does not print typescript
(#3561) (Dunqing)
- 646b993 coverage/transformer: Handle @jsx option (#3553) (Dunqing)
- a939ddd transformer/typescript: Remove more typescript ast nodes
(#3563) (Dunqing)
- e8a20f8 transformer/typescript: Remove typescript ast nodes (#3559)
(Dunqing)
- ee9a215 transformer/typescript: Handle namespace directive correctly
(#3532) (Dunqing)

### Bug Fixes

- affb2c8 codegen: Print indentation before directive (#3512) (Dunqing)
- f6939cb transformer: Store `react_importer` in `Bindings` in JSX
transform (#3551) (overlookmotel)
- 7982b93 transformer: Correct spans for JSX transform (#3549)
(overlookmotel)
- c00598b transformer: JSX set `reference_id` on refs to imports (#3524)
(overlookmotel)

### Performance

- 37cdc13 transformer: Faster checks if JSX plugin enabled (#3577)
(overlookmotel)
- 9f467b8 transformer: Avoid fragment update where possible (#3535)
(overlookmotel)
- ac394f0 transformer: JSX parse pragma only once (#3534)
(overlookmotel)

### Documentation

- 1d3c0d7 span: Add doc comments to `oxc_span::Span` (#3543) (Don Isaac)

### Refactor

- f2113ae transformer: Reduce cloning and referencing `Rc`s (#3576)
(overlookmotel)
- 0948124 transformer: Pass `Rc`s by value (#3550) (overlookmotel)
- e4d74ac transformer: Remove `update_fragment` from JSX transform
(#3541) (overlookmotel)
- 73b7864 transformer: Combine import and usage in JSX transform (#3540)
(overlookmotel)
- 6978269 transformer/typescript: Replace reference collector with
symbols references (#3533) (Dunqing)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-07 17:41:11 +08:00
Dunqing
a939ddd096 feat(transformer/typescript): remove more typescript ast nodes (#3563)
Remove more TypeScript related AST
2024-06-07 05:04:28 +00:00
Dunqing
e8a20f8d50 feat(transformer/typescript): remove typescript ast nodes (#3559)
According to Babel tests feedback, remove some known ts AST nodes.
There are still many TS AST nodes that need to be deleted
2024-06-07 05:04:22 +00:00
Boshen
1dbc23417d
chore: regenerate changelogs with commit id and author 2024-06-07 01:22:28 +08:00
Boshen
769227b7b4
chore: regenerate changelogs 2024-06-06 15:51:53 +08:00
Boshen
509ed2bcf3
ci: update prepare release crates; regenerate the changelogs 2024-06-06 14:28:51 +08:00
Boshen
0674604d7a
chore: regenerate changelog 2024-06-06 01:29:38 +08:00
github-actions[bot]
d48e62aca4
Publish crates v0.13.3 (#3527)
Automated Release

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-04 18:02:40 +08:00
github-actions[bot]
079d42f68b
Release crates v0.13.2 (#3513)
Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-03 12:40:53 +08:00
overlookmotel
ff7e8c7448 refactor(ast): update scope attrs (#3494)
Update scope attrs used by `oxc_traverse` codegen on `MethodDefinition` and `Function` types. These attrs are currently ignored by the codegen anyway, so causes no change in generated code, but bringing them up to date in preparation for #3392.
2024-05-31 17:58:01 +00:00
overlookmotel
55bbde2888 refactor(ast): move scope from TSModuleBlock to TSModuleDeclaration (#3488)
Closes #3471.

Remove scope from `TSModuleBlock` and add scope to `TSModuleDeclaration` instead.
2024-05-31 17:33:05 +00:00
overlookmotel
9c3d1631a4 refactor(ast): rename function params (#3487)
Rename function params from `_kind` to `kind`. This has no practical effect but makes Rust Analyser give nicer param name hints when using these APIs.
2024-05-31 12:34:48 +00:00
overlookmotel
286b5ed3d7 refactor(ast): remove defunct hashing of Span (#3486)
`Span` has a no-op `Hash` impl.

ea53267956/crates/oxc_span/src/span.rs (L50-L54)

So remove pointless `self.span.hash(state)` operations from `Hash` impls for AST nodes.
2024-05-31 12:25:05 +00:00
Dunqing
ea53267956 fix(ast): UsingDeclaration is not a typescript syntax (#3482) 2024-05-31 11:15:37 +00:00
Dunqing
25e5bdda3c fix(transformer/typescript) if this statement is typescript syntax, replace it with a BlockStatement (#3480) 2024-05-31 07:24:47 +00:00
Wang Wenzhe
0d2c977c11
feat(linter): add oxc/no-const-enum rule (#3435) 2024-05-28 22:50:54 +08:00
Boshen
86beca5379
Release crates v0.13.1 2024-05-22 16:50:30 +08:00
Boshen
1e84644220
chore: update toml format 2024-05-21 22:15:47 +08:00
Boshen
89a1f97320
refactor(parser): improve expression parsing (#3352) 2024-05-19 21:28:16 +08:00
overlookmotel
938ae12203 refactor(ast): fix clippy lint on nightly (#3346)
Clippy on nightly produces a warning for `&t as *const _`.

This warning is spurious in this case - we know `t` is valid, because we just created it. But change it, to keep Clippy happy!
2024-05-18 17:43:51 +00:00