Commit graph

4192 commits

Author SHA1 Message Date
Boshen
0ba375899c
chore(tasks/benchmark): add isolated_declarations bench 2024-07-07 19:22:49 +08:00
Boshen
0ec12cf38d
chore(linter): change no-negation-in-equality-check to pedantic 2024-07-07 19:19:09 +08:00
Boshen
94bac93550
ci: pin cargo-shear to v1 2024-07-07 19:09:00 +08:00
Boshen
7b2dc3b92b fix(linter): fix panic in import/namespace (#4080) 2024-07-07 11:04:20 +00:00
Dunqing
54b3b6c0da
chore(benchmark): add isolated declarations (#4078) 2024-07-07 17:14:48 +08:00
mysteryven
4414774d7d chore(tasks/rulegen): generate options for fix cases (#4076)
Our fixer support rule option, and we need to generate `options` for them.

328445b4ca/crates/oxc_linter/src/tester.rs (L238)

cc @eryue0220
2024-07-07 03:01:55 +00:00
github-actions[bot]
51d56d37ff
Release crates v0.17.1 (#4075)
## [0.17.1] - 2024-07-06

### Bug Fixes

- aa585d3 ast_codegen, ast: Visit `ExpressionArrayElement` as
`Expression`. (#4061) (rzvxa)
- 564a75a codegen: Missing TypeParameters in TSConstructSignature
(#4063) (michaelm)
- adee728 isolated_declarations: Don't report an error for parameters if
they are ObjectPattern or ArrayPattern with an explicit type (#4065)
(michaelm)
- 1b8f208 isolated_declarations: Correct emit for private static methods
(#4064) (michaelm)
- 719fb96 minifier: Omit dce `undefined` which can be a shadowed
variable (#4073) (Boshen)
- 150f4d9 napi/transform: Display error with spanned messages (Boshen)

### Performance

- 7fe2a2f parser: Do not copy comments (#4067) (overlookmotel)

### Refactor

- 8fa98e0 ast: Inline trivial functions and shorten code (#4066)
(overlookmotel)
- 65aee19 isolated-declarations: Reorganize scope tree (#4070) (Luca
Bruno)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-07 01:29:52 +08:00
Boshen
719fb9672b
fix(minifier): omit dce undefined which can be a shadowed variable (#4073)
```
 // Shadowed `undefined` as a variable should not be erased.
    test(
        "function foo(undefined) { if (!undefined) { } }",
        "function foo(undefined){if(!undefined){}}",
    );
```

I'm not using the cheap `ident.reference_id.get().is_some()` here yet
because I don't know what I'm doing - how should minifier consume
`Semantic`?
2024-07-07 01:25:54 +08:00
michaelm
adee7280d7
fix(isolated_declarations): Don't report an error for parameters if they are ObjectPattern or ArrayPattern with an explicit type (#4065)
The logic in https://github.com/oxc-project/oxc/pull/3810 was slightly
off as demonstrated by the snapshot test.

Co-authored-by: MichaelMitchell-at <=>
2024-07-06 22:58:07 +08:00
Luca Bruno
65aee19098
refactor(isolated-declarations): reorganize scope tree (#4070)
This reorganizes scope fields into levels which atomically follow the
enter/leave pattern. It avoids tracking the same lenght and capacity
separately for each property, and does not need to grow multiple vectors
while traversing.
2024-07-06 22:53:00 +08:00
Jelle van der Waa
aa45604bd3
feat(linter/eslint): Implement no-multi-str (#4038)
Rule Detail:
[link](https://eslint.org/docs/latest/rules/no-multi-str)

---------

Co-authored-by: wenzhe <mysteryven@gmail.com>
2024-07-06 22:12:10 +08:00
overlookmotel
7fe2a2f681 perf(parser): do not copy comments (#4067)
Follow-on from #4045. `.from_iter()` copies the `Vec` of comments into another `Vec` before converting to a boxed slice. This copy is unnecessary - just convert direct.
2024-07-06 09:56:41 +00:00
overlookmotel
8fa98e03ae refactor(ast): inline trivial functions and shorten code (#4066)
Follow on from #4045. Mark trivial functions related to `Trivias` as `#[inline]` and remove a couple of unnecessary `matches!` macro calls.
2024-07-06 09:56:36 +00:00
michaelm
564a75ab37
fix(codegen): missing TypeParameters in TSConstructSignature (#4063) 2024-07-06 13:59:49 +08:00
michaelm
1b8f208572
fix(isolated_declarations): correct emit for private static methods (#4064) 2024-07-06 12:30:13 +08:00
cinchen
1681b11adb
feat(linter): eslint-plugin-jest/consistent-test-it (#4053)
part of https://github.com/oxc-project/oxc/issues/492

Rule Detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/consistent-test-it.ts)
2024-07-06 11:03:14 +08:00
rzvxa
aa585d31e1
fix(ast_codegen, ast): visit ExpressionArrayElement as Expression. (#4061)
hotfix for #4060

I just added an edge case, We can come back to it later on and make it a
standard in our codegen.

The diff is big because it causes the code to reorder, The edge case
generated code doesn't follow the order in which they are defined in the
source of truth(eg `js.rs`)
2024-07-06 00:29:36 +08:00
Boshen
cdd4ee5dff
ci: cargo-shear v1 2024-07-05 23:46:15 +08:00
Boshen
150f4d90fc
fix(napi/transform): display error with spanned messages 2024-07-05 23:41:39 +08:00
Boshen
74aae108da
chore(minifier): add dce example 2024-07-05 16:23:51 +08:00
github-actions[bot]
224f5ef2cc
Release crates v0.17.0 (#4059)
## [0.17.0] - 2024-07-05

- e32b4bc ast: [**BREAKING**] Store trivia comments in a sorted slice
(#4045) (Luca Bruno)

- 1df6ac0 ast: [**BREAKING**] Rename `visit_enum_memeber` to
`visit_ts_enum_member`. (#4000) (rzvxa)

- 4a0eaa0 ast: [**BREAKING**] Rename `visit_enum` to
`visit_ts_enum_declaration`. (#3998) (rzvxa)

- c98d8aa ast: [**BREAKING**] Rename `visit_arrow_expression` to
`visit_arrow_function_expression`. (#3995) (rzvxa)

### Features

- 1854a52 ast_codegen: Introduce the `#[span]` hint. (#4012) (rzvxa)
- 7538af1 ast_codegen: Add visit generator (#3954) (rzvxa)
- 7768d23 isolated-declarations: Support optional class methods (#4035)
(Egor Blinov)
- 0da9dfb minifier: Add constant folding to remove dead code (#4058)
(Boshen)

### Bug Fixes

- aaac2d8 codegen: Preserve parentheses from AST instead calculating
from operator precedence (#4055) (Boshen)
- 5e5b1b1 codegen: Correct accessibility emit for class
formal-parameters/methods/properties (#4042) (Egor Blinov)
- 7844734 codegen: Missing const keyword in TSTypeParamter (#4022)
(Dunqing)
- 6254a41 codegen: Missing TypeParamters in TSCallSignature (#4021)
(Dunqing)
- 3d29e9c isolated-declarations: Eliminate imports incorrectly when they
are used in `TSInferType` (#4043) (Dunqing)
- 02ea19a isolated-declarations: Should emit `export {}` when only
having `ImportDeclaration` (#4026) (Dunqing)
- 7c915f4 isolated-declarations: Binding elements with export should
report an error (#4025) (Dunqing)
- 05a047c isolated-declarations: Method following an abstract method
gets dropped (#4024) (Dunqing)
- c043bec isolated_declarations: Add mapped-type constraint to the scope
(#4037) (Egor Blinov)
- b007553 isolated_declarations: Fix readonly specifier on class
constructor params (#4030) (Egor Blinov)
- da62839 isolated_declarations: Inferring literal types for readonly
class fileds (#4027) (Egor Blinov)

### Refactor

- b51f75b ast_codegen: No longer outputs discard variable for empty
visitors. (#4008) (rzvxa)
- edb557c minifier: Add a folder struct for constant folding (#4057)
(Boshen)
- 243c9f3 parser: Use function instead of trait to parse list with rest
element (#4028) (Boshen)
- 1dacb1f parser: Use function instead of trait to parse delimited lists
(#4014) (Boshen)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-05 15:46:50 +08:00
Boshen
0da9dfbf09
feat(minifier): add constant folding to remove dead code (#4058) 2024-07-05 15:44:01 +08:00
Boshen
edb557c02b
refactor(minifier): add a folder struct for constant folding (#4057) 2024-07-05 15:11:08 +08:00
Boshen
aaac2d8775
fix(codegen): preserve parentheses from AST instead calculating from operator precedence (#4055)
…operator precedence

Calculating from operator precedence is currently unsafe and will result
incorrect semantics.
2024-07-05 14:01:17 +08:00
jordan boyer
6876490baa
feat(linter): add rule no-undefined (#4041)
Implementing rule https://eslint.org/docs/latest/rules/no-undefined

This is my first time contributing here, I wanted to started with a
simple rule before contributing more.

related to #479
2024-07-04 23:50:46 -04:00
Nissim Chekroun
bf04dee861
feat(linter): implement unicorn/no-negation-in-equality-check (#4034)
Fixes https://github.com/oxc-project/oxc/issues/3869

Hey there, thought I'd give this a try as it's tagged "good first issue"
:) Let me know if there's anything that needs to change, I wasn't sure
about the rule category so left as TODO.
2024-07-04 23:05:47 +08:00
burlinchen
38e7351a91
chore(napi): Refactor async parsing functions to remove tokio dependency (#4049)
Resolves #4044
- Added `use napi::{bindgen_prelude::AsyncTask, Task}` to handle async
tasks without tokio.
- Introduced `ResolveTask` struct implementing `Task` for asynchronous
parsing.
- Replaced `parse_sync` function implementation with `parse_with_return`
to reuse code.
- Refactored `parse_async` to use `AsyncTask` and `ResolveTask` for
async parsing.
- Removed tokio dependency by avoiding `tokio::spawn` and using
`AsyncTask` for async operations.

This refactor enhances code readability and removes the dependency on
tokio, streamlining the async task handling within the napi framework.
2024-07-04 20:31:19 +08:00
Luca Bruno
e32b4bc57c
refactor(ast)!: store trivia comments in a sorted slice (#4045)
This gets rid of `TriviasMap`, introducing `SortedComments` in order to
store trivia comments in a sorted slice.

Closes: https://github.com/oxc-project/backlog/issues/38
2024-07-04 01:57:36 +08:00
Boshen
09cc760475
chore(tasks/benchmark): turn on jsdoc parsing in semantic benchmark 2024-07-04 00:00:52 +08:00
Dunqing
3d29e9cb75 fix(isolated-declarations): eliminate imports incorrectly when they are used in TSInferType (#4043)
close: #4018
2024-07-03 15:32:27 +00:00
Egor Blinov
5e5b1b14a1
fix(codegen): correct accessibility emit for class formal-parameters/methods/properties (#4042) 2024-07-03 17:27:41 +08:00
Egor Blinov
7768d233c6
feat(isolated-declarations): support optional class methods (#4035)
Example class
```
export class A {
  m1?(): void;
  m2(): void {}
}
```

Before the fix:
```
export declare class A {
  m1(): void;
}
```

with the fix:
```
export declare class A {
  m1?(): void;
  m2(): void;
}
```
2024-07-03 09:46:59 +08:00
Egor Blinov
c043bec674
fix(isolated_declarations): add mapped-type constraint to the scope (#4037)
Fixes https://github.com/oxc-project/oxc/issues/4020

Example:
```ts
import {K} from 'foo'
import {T} from 'bar'

export interface I {
    prop: {[key in K]: T}
}
```

Before:
```ts
import {T} from 'bar'
export interface I {
    prop: {[key in K]: T}
}
```

After:
```ts
import {K} from 'foo'
import {T} from 'bar'
export interface I {
    prop: {[key in K]: T}
}
```

TSC:
```ts
import { K } from 'foo';
import { T } from 'bar';
export interface I {
    prop: {
        [key in K]: T;
    };
}

```
2024-07-03 09:45:03 +08:00
Egor Blinov
b007553ebe
fix(isolated_declarations): Fix readonly specifier on class constructor params (#4030) 2024-07-02 23:26:19 +08:00
Egor Blinov
da628399fa
fix(isolated_declarations): inferring literal types for readonly class fileds (#4027) 2024-07-02 23:00:37 +08:00
github-actions[bot]
b66ad0b675
Release oxlint v0.6.0 (#4029)
## [0.6.0] - 2024-07-02

- c98d8aa ast: [**BREAKING**] Rename `visit_arrow_expression` to
`visit_arrow_function_expression`. (#3995) (rzvxa)

### Features

- dc6d45e ast,codegen: Add `TSParenthesizedType` and print type
parentheses correctly (#3979) (Boshen)
- b257d53 linter: Support report
`@typescript-eslint/consistent-type-imports` (#3895) (mysteryven)
- 2114475 linter: Implement @typescript-eslint/no-dynamic-delete (#3971)
(kaykdm)
- 10a3c9a linter/eslint-plugin-react: Implement no-set-state (#3975)
(Jelle van der Waa)

### Bug Fixes

- 432d6d9 linter: Find disabled directives using the message's `Span`.
(#4010) (rzvxa)
- dbbb6fc linter: Global variable check should always check builtin
variables (#3973) (Boshen)

### Performance

- 1eac3d2 semantic: Use `Atom<'a>` for `Reference`s (#3972) (Don Isaac)

### Refactor

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-02 22:07:52 +08:00
Dunqing
02ea19a3b7 fix(isolated-declarations): should emit export {} when only having ImportDeclaration (#4026)
close: #4023
2024-07-02 13:47:30 +00:00
Dunqing
7c915f4665 fix(isolated-declarations): binding elements with export should report an error (#4025)
close: #3976
2024-07-02 13:47:28 +00:00
Dunqing
05a047c17d fix(isolated-declarations): method following an abstract method gets dropped (#4024)
close: #4019
2024-07-02 13:47:26 +00:00
Dunqing
7844734856 fix(codegen): missing const keyword in TSTypeParamter (#4022)
close: #4017
2024-07-02 13:47:24 +00:00
Boshen
243c9f35b0 refactor(parser): use function instead of trait to parse list with rest element (#4028)
closes #3887
2024-07-02 13:43:14 +00:00
Dunqing
6254a4106f fix(codegen): missing TypeParamters in TSCallSignature (#4021)
close: #4015
2024-07-02 11:10:15 +00:00
rzvxa
432d6d93c9 fix(linter): find disabled directives using the message's Span. (#4010)
fixes #4005
2024-07-02 10:49:05 +00:00
rzvxa
1854a52bd7 feat(ast_codegen): introduce the #[span] hint. (#4012)
closes #3904
2024-07-02 10:18:58 +00:00
rzvxa
71e9286fa6 improvement(ast_codegen): use visit_as attribute to create aliased AstKinds. (#4011) 2024-07-02 10:18:56 +00:00
rzvxa
352c0b4103 pref(ast): inline visit walks with small bodies. (#4009)
~~Attempt to improve the performance of visitors, It is mostly for experiments. I'm not sure how much performance is there to gain back.~~

- [x] inline plural visits (eg: visit_statements)
- [x] inline enums when there are 5 or fewer match cases
- [x] inline structs when there are 5 or less fields
- [x] inline `Visit::alloc`
2024-07-02 10:18:55 +00:00
rzvxa
b51f75baf8 refactor(ast_codegen): no longer outputs discard variable for empty visitors. (#4008) 2024-07-02 10:18:53 +00:00
rzvxa
cd1e9bde7f improvement(ast): generate visit_mut.rs. (#4007) 2024-07-02 10:18:51 +00:00
rzvxa
272df6ee90 feat(ast_codegen): support for generating VisitMut. (#4006) 2024-07-02 10:18:49 +00:00
rzvxa
7a3cb830b4 improvement(ast): generate the visit.rs file. (#4001)
Performance degression is expected since now we are doing more work by visiting things that we wouldn't enter before.
2024-07-02 10:18:47 +00:00