Commit graph

6358 commits

Author SHA1 Message Date
overlookmotel
c91ffbcb01 refactor(ast, transformer)!: remove IdentifierName::new method (#6784) 2024-10-23 03:36:30 +00:00
overlookmotel
2bee4e2735 refactor(ast, transformer)!: remove BlockStatement::new methods (#6783)
First of a series of PRs removing `new` and `new_with_scope_id` etc methods from AST types. Following #6760, all AST node creation can now go via the AST builder.

This lays groundwork for Node IDs (#5689), as we'll need `NodeId`s to be generated in `AstBuilder`, so that all nodes receive an ID.
2024-10-23 03:36:30 +00:00
Boshen
8f179534c2 fix(coverage): remove some broken cases (#6797) 2024-10-23 03:10:49 +00:00
Boshen
9c7ae78c75 fix(coverage): better handling of test262 failling cases (#6794) 2024-10-23 02:02:18 +00:00
mysteryven
0acca58581 feat(linter): support --print-config all to print config file for project (#6579)
Continue work on #4742.

Only `oxlint --print-config all` is supported. It's useful to migrate from command-line interface to config file.

The `--print-config PATH` looks not really useful for us now, I will add it after config file overrides supported.
2024-10-22 17:56:23 +00:00
Boshen
ffa3945465 chore(coverage): ignore v8 failed cases from runtime.snap (#6780) 2024-10-22 16:21:42 +00:00
Dunqing
b711ee1881 fix(transformer): after using StatementInjector, some statements disappeared (#6778) 2024-10-22 14:10:19 +00:00
overlookmotel
d2b8f505f1 refactor(ast_tools): TypeDef::name return a &str (#6776)
It's generally an anti-pattern for functions to return `&String`. `&str` is preferable.
2024-10-22 12:14:41 +00:00
overlookmotel
09d2df1085 refactor(ast_tools): shorter code in AstKindGenerator (#6775)
Tiny refactor. Shorten code a little and avoid converting `Ident`s unnecessarily.
2024-10-22 12:14:40 +00:00
overlookmotel
46898654a2 refactor(ast_tools): simplify code in AstKindGenerator (#6774)
Combine multiple filters into one.

The first 2 filters were doing the same thing, and combining the remaining 2 makes the code easier to read.
2024-10-22 12:14:40 +00:00
overlookmotel
0b6db0e17c refactor(ast_tools): remove support for #[visit(as)] (#6773)
#6740 and #6744 removed visitor type aliases (`#[visit(as(ClassHeritage))]`). Remove support for `#[visit(as(...))]` from `oxc_ast_tools`, since it's now dead code.
2024-10-22 12:14:39 +00:00
Cam McHenry
e221ea3fb5
chore(tasks/lint_rules): sync rules with ESLint v9 (#6777)
The previous version of the `react-perf` ESLint plugin was holding us
back from updating this to ESLint V9. I've manually specified the ESLint
version here, because we want to make sure we are running the latest
major version of ESLint which changes a lot of things.

Also changed it so that rules which are not supported and also
implemented do not get counted twice in the total count. For example,
`eslint/no-with` is marked as not supported but it is still implemented.
This was previously counted for both, which made it look like we had an
additional rule implemented.
2024-10-22 20:14:10 +08:00
overlookmotel
91651e0a3b docs(ast): fix comment for ClassElement::r#static (#6771)
Follow-up after #6731. Make a long comment to remove ambiguity about what this method does for once and for all!
2024-10-22 10:38:15 +00:00
Boshen
e15b7ce09c fix(coverage): tests for --> in the first line should not have raw flag. (#6772) 2024-10-22 10:24:27 +00:00
dalaoshu
3116fd3dc1
fix(oxc_language_server): correct diagnostic link (#6765) 2024-10-22 06:23:54 -04:00
_Kerman
c916505c42
docs(ast): fix comment of ClassElement::r#static (#6731)
The comment says: `Returns true if this ClassElement is a static block
or has a static modifier.`
2024-10-22 18:05:45 +08:00
Boshen
eac34b676f
build(linter): oxc_resolver 2.0.0 (#6766) 2024-10-22 14:51:25 +08:00
leaysgur
8032813bf8 fix(regular_expression)!: Migrate to new regexp parser API (#6741)
Follow up #6635

- [x] Remove old APIs
- [x] Update linter usage
- [x] Update parser usage
- [x] Update transformer usage
2024-10-22 05:34:18 +00:00
dalaoshu
54a50322db
fix(linter): correct false positive in no-duplicates (#6748)
closes #6736 

There may be a better solution. If there is a good way to fix it, please
feel free to close it. I will fix the clippy problem later because I
went back to the dormitory to sleep and my computer was in the studio.

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-10-22 13:34:03 +08:00
oxc-bot
9648e98998
release(oxlint): v0.10.2 (#6764)
## [0.10.2] - 2024-10-22

### Features

- dbe1972 linter: Import/no-cycle should turn on ignore_types by default
(#6761) (Boshen)
- 619d06f linter: Fix suggestion for `eslint:no_empty_static_block` rule
(#6732) (Tapan Prakash)

### Bug Fixes


### Performance

- 8387bac linter: Apply small file optimization, up to 30% faster
(#6600) (camchenry)

### Refactor

- b884577 linter: All ast_util functions take Semantic (#6753)
(DonIsaac)
- 744aa74 linter: Impl `Deref<Target = Semantic>` for `LintContext`
(#6752) (DonIsaac)
- 6ffdcc0 oxlint: Lint/mod.rs -> lint.rs (#6746) (Boshen)

### Testing

- b03cec6 oxlint: Add `--fix` test case (#6747) (Boshen)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-22 12:31:17 +08:00
overlookmotel
10484cdeeb feat(transformer): class static block transform (#6733)
Add ES2022 class static block transform.
2024-10-22 03:40:02 +00:00
overlookmotel
78fee6ee24 feat(ast): add AstBuilder::*_with_scope_id etc methods (#6760)
Add methods to `AstBuilder` to create AST nodes with `ScopeId`, `SymbolId`, `ReferenceId`, for use in transformer.

e.g. `identifier_reference_with_reference_id`, `binding_identifier_with_symbol_id`, `block_statement_with_scope_id `.
2024-10-22 03:40:02 +00:00
Boshen
dbe1972283 feat(linter): import/no-cycle should turn on ignore_types by default (#6761)
closes #6759
2024-10-22 02:35:28 +00:00
camchenry
8387bac51f perf(linter): apply small file optimization, up to 30% faster (#6600)
Theory: iterating over the rules three times has slightly worse cache locality, because the prior iterations have pushed `rule` out of the cache by the time we iterate over it again. By iterating over each rule only once, we improve cache performance (hopefully). We also don't need to collect rules to a Vec, so it saves some CPU/memory there too.

In practice: the behavior here actually depends on the number of AST nodes that are in the program. If the number of nodes is large, then it's better to iterate over the nodes only once and iterate the rules multiple times. But if the number of nodes is small, then it's better to iterate over nodes multiple times and only iterate over the rules once. See this comment for more context: https://github.com/oxc-project/oxc/pull/6600#issuecomment-2427837715, as well as the comment inside the PR: https://github.com/oxc-project/oxc/pull/6600/files#diff-207225884c5e031ffd802bb99e4fbacbd8364b1343a1cec5485bf50f29186300R131-R143.

In practice, this can make linting a file 1-45% faster, depending on the size of the file, number of AST nodes, number of files, CPU cache size, etc. To accommodate large and small files better, we have an explicit threshold of 200,000 AST nodes, which is an arbitrary number picked based on some benchmarks on my laptop. For large files, the linter behavior doesn't change. For small files, we switch to iterating over nodes in the inner loop and iterating over rules once in the outer loop.
2024-10-22 02:24:41 +00:00
Tapan Prakash
619d06f004
feat(linter): Fix suggestion for eslint:no_empty_static_block rule (#6732)
Relates to https://github.com/oxc-project/oxc/issues/4179

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-22 09:01:44 +08:00
overlookmotel
ab0353553a docs(transformer): correct typos and reformat doc comments (#6758) 2024-10-22 00:20:55 +00:00
overlookmotel
e8d3d8b07b refactor(ast_tools): remove dead code in AstBuilder generator (#6757)
`ReferenceFlags` no longer appears in the AST.
2024-10-22 00:12:01 +00:00
overlookmotel
46720be7af docs(ast): improve formatting of AstBuilder doc comments (#6756) 2024-10-22 00:12:01 +00:00
DonIsaac
b8845773f7 refactor(linter): all ast_util functions take Semantic (#6753)
Needed in `oxc/no-map-spread` rule.
2024-10-21 22:39:39 +00:00
DonIsaac
744aa74e81 refactor(linter): impl Deref<Target = Semantic> for LintContext (#6752)
`LintContext` contains many wrapper methods that invoke a method with the same
name on `Semantic`. Implementing `Deref` lets us remove those redundant methods.
2024-10-21 22:39:37 +00:00
Boshen
70efa47d75 fix(coverage): turn off refresh plugin in runtime test (#6749) 2024-10-21 15:53:29 +00:00
Boshen
b03cec6ae9 test(oxlint): add --fix test case (#6747)
closes #6061
2024-10-21 15:38:19 +00:00
Boshen
6ffdcc0e3e refactor(oxlint): lint/mod.rs -> lint.rs (#6746) 2024-10-21 15:10:52 +00:00
overlookmotel
8c489a4e7e refactor(ast_tools): remove dead code (#6745)
This code has been unused for a couple of months, so it seems unlikely we'll need it again.
2024-10-21 14:53:23 +00:00
overlookmotel
b66ae2e45e refactor(ast): move impl GetAddress for Statement (#6742)
Follow-on after #6738. Since `GetAddress` is now defined in `oxc_allocator` crate, `impl GetAddress for Statement` doesn't need its own file.
2024-10-21 14:45:51 +00:00
Boshen
1248557f0e refactor(ast)!: remove AstKind::FinallyClause (#6744) 2024-10-21 14:37:51 +00:00
DonIsaac
85d52201b4 docs(span): enhance Span documentation (#6707)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-21 14:32:55 +00:00
overlookmotel
5b41eeaa9d fix(ast_tools): fix miscalculation of enum niches (#6743)
Follow-on after #5774. Correct the logic for calculating niches in enums.

It's still not quite correct - number of niches depends on how many spare discriminant "slots" there are at *start or end* of the range, not in total. But this is closer to correct than it was - we now don't take into account whether enum variant payloads have niches or not, which is not relevant.
2024-10-21 14:27:45 +00:00
Boshen
202c7f66c7 fix(ast)!: remove AstKind::ExpressionArrayElement and AstKind::ClassHeritage (#6740)
closes #6392
2024-10-21 13:30:48 +00:00
rzvxa
e8f8409d01 fix(ast_tools): fix miscalculation of enum layouts. (#5774)
Fixes a bug with how we were calculating the size of enums when there are different padding on variants and there aren't enough niches. Now it aligns the largest variant size to the largest alignment before consuming niches.
2024-10-21 12:19:37 +00:00
overlookmotel
ab8aa2f7b0 refactor(allocator): move GetAddress trait into oxc_allocator (#6738)
Pure refactor. It makes more sense to me for `Address` and `GetAddress` to be defined in the same place. Also then we can use the trait for `impl GetAddress for Box`.
2024-10-21 11:46:29 +00:00
overlookmotel
06e06e3689 refactor(transformer): rename OxcVec to AVec (#6737)
`use oxc_allocator::Vec as AVec` as per naming convention suggested in https://github.com/oxc-project/backlog/issues/120
2024-10-21 11:46:29 +00:00
Boshen
b09e28b720
fix(coverage): fix compile error 2024-10-21 19:44:02 +08:00
Dunqing
7fbca9dd75 feat(transformer): introduce StatementInjector helper (#6653)
close: #6641
2024-10-21 11:00:18 +00:00
Dunqing
b2f3040e4f feat(ast): add GetAddress trait (#6652)
part of #6641
2024-10-21 10:45:48 +00:00
Boshen
112580a408 feat(coverage): add transformer and minifier to runtime test (#6734)
closes #6578
2024-10-21 08:55:29 +00:00
leaysgur
f8e1907c4f feat(regular_expression): Intro ConstructorParser(and LiteralParser) to handle escape sequence in RegExp('pat') (#6635)
Preparation for #6141

`oxc_regular_expression` can already parse and validate both `/regexp-literal/` and `new RegExp("string-literal")`.

But one thing that is not well-supported was reporting `Span` for the `RegExp("string-literal-with-\\escape")` case.

For example, these two cases produce the same `RegExp` instances in JavaScript:

- `/\d+/`
- `new RegExp("\\d+")`

For now, mainly in `oxc_linter`, the latter case is parsed with `oxc_parser` -> `ast::literal::StringLiteral` AST node -> `value` property.

At this point, escape sequences are resolved(!), `oxc_regular_expression` can handle aligned `&str` as an argument without any problem in both cases.

However, in terms of `Span` representation, these cases should be handled differently because of the `\\` in string literals...

As a result, the parsed AST's `Span` for `new RegExp("string-literal")` is not accurate if it contains escape sequences.

e.g. a01a5dfdaf/crates/oxc_linter/src/snapshots/no_invalid_regexp.snap (L118-L122)

Each time the `\` appears, the subsequent position is shifted. `_` should be placed under `*` in this case.

So... to resolve this issue, we need to implement `string_literal_parser` first, and use them as reading units of `oxc_regular_expression`.
2024-10-21 07:07:27 +00:00
Boshen
82bc745da1
chore: use bacon instead of cargo watch 2024-10-21 15:04:40 +08:00
Boshen
2e8579ce81 chore(coverage): update codegen runtime snapshot (#6730) 2024-10-21 06:14:53 +00:00
DonIsaac
a7dd5aa3ee docs(ast): enforce doc comments on AST node methods (#6714)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-21 05:28:55 +00:00