Commit graph

5555 commits

Author SHA1 Message Date
oxc-bot
bd48dfbf8b
release(crates): v0.29.0 (#5763)
## [0.29.0] - 2024-09-13

- 71116a1 index: [**BREAKING**] Remove ability to index `IndexVec` with
`usize` (#5733) (overlookmotel)

- c3dd2a0 ast: [**BREAKING**] Revert: reduce byte size of
`TaggedTemplateExpression::quasi` by `Boxing` it (#5679) (#5715)
(overlookmotel)

### Features

- 953fe17 ast: Provide `NONE` type for AST builder calls (#5737)
(overlookmotel)
- a362f51 index: Add `IndexVec::shrink_to` (#5713) (overlookmotel)
- e968e9f minifier: Constant fold nullish coalescing operator (#5761)
(Boshen)
- 6bc13f6 minifier: Add `MinimizeConditions` pass (#5747) (Boshen)
- 805fbac oxc_cfg: Better control flow graph dot dot repr (#5731)
(IWANABETHATGUY)
- f3baa49 semantic: Add `SemanticBuilder::with_stats` (#5757)
(overlookmotel)
- 7fa0cb3 semantic: Expose `Stats` (#5755) (overlookmotel)

### Bug Fixes

- 8ff013a minifier: Handle dce CallExpression::callee (#5752) (Boshen)
- 608b7d3 napi/transformer: Refresh plugin doesn't work even after
passing the refresh option (#5702) (Dunqing)
- 042afa9 syntax: Correctly check for valid `RedeclarationId`s (#5759)
(overlookmotel)
- 77d9170 transformer/react: IsStaticChildren should be false when there
is only one child (#5745) (Dunqing)

### Performance

- 333e2e0 index: Remove `Idx` bounds-checks from `first` + `last`
methods (#5726) (overlookmotel)
- d18c896 rust: Use `cow_utils` instead (#5664) (dalaoshu)

### Refactor

- 2890c98 minifier: Add tests for `remove_syntax` (#5749) (Boshen)
- 9a9d8f6 minifier: Replace `self.ast` with `ctx.ast` (#5748) (Boshen)
- 746f7b3 minifier: Align code with closure compiler (#5717) (Boshen)
- 21e2df5 minifier: Replace `VisitMut` with `Traverse` for inject and
define plugins (#5705) (Boshen)
- 4bdc202 rust: Remove some #[allow(unused)] (#5716) (Boshen)
- a35fb14 semantic: `Stats::assert_accurate` take `self` (#5758)
(overlookmotel)
- 4b896f1 semantic: Make `Stats` `Copy` (#5756) (overlookmotel)
- b4b460f semantic: `Stats` store counts as `u32` (#5754)
(overlookmotel)
- 667170c semantic: Rename `Counts` to `Stats` (#5753) (overlookmotel)
- cc0408b semantic: S/AstNodeId/NodeId (#5740) (Boshen)
- 7dfcdfc semantic: Remove `more-asserts` dependency (#5739)
(overlookmotel)
- 6436524 semantic: Fix dead code warning in release mode (#5728)
(overlookmotel)
- e02621d semantic: Re-order use statements (#5712) (overlookmotel)
- ac6203c semantic: Move `Counts` code into counter module (#5710)
(overlookmotel)
- 339fcfc semantic: Rename `Counts` in transform checker (#5709)
(overlookmotel)
- d8ec781 semantic: Remove `record_ast_node` call for `Program` (#5701)
(overlookmotel)

### Styling

- 1857ff0 semantic: Rename vars for node IDs (#5699) (overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-09-13 21:43:23 +08:00
Boshen
e968e9ffd0 feat(minifier): constant fold nullish coalescing operator (#5761) 2024-09-13 13:25:58 +00:00
Dunqing
77d9170f84 fix(transformer/react): isStaticChildren should be false when there is only one child (#5745)
We found a warning report [here](206df66e70/packages/react/src/jsx/ReactJSXElement.js (L614-L632)). It caused by we transform incorrectly
2024-09-13 13:20:59 +00:00
overlookmotel
a35fb14454 refactor(semantic): Stats::assert_accurate take self (#5758)
Improve API of `Stats::assert_accurate`.
2024-09-13 12:19:55 +00:00
overlookmotel
f3baa49662 feat(semantic): add SemanticBuilder::with_stats (#5757)
Add `SemanticBuilder::with_stats` method to optionally pass in a `Stats` object. If `Stats` are provided, `SemanticBuilder` skips the AST traversal.
2024-09-13 12:19:55 +00:00
overlookmotel
4b896f1494 refactor(semantic): make Stats Copy (#5756)
`Stats` type is small. Make it `Copy`.
2024-09-13 12:19:54 +00:00
overlookmotel
7fa0cb3861 feat(semantic): expose Stats (#5755)
Expose `Stats` type, and provide a method `Semantic::Stats` to obtain them.

Note: If we move counting into parser later, parser can use this same `Stats` type (we'd need to move it into `oxc_parser` or `oxc_ast` crate, but `oxc_semantic` can still re-export it.
2024-09-13 12:19:54 +00:00
overlookmotel
b4b460f425 refactor(semantic): Stats store counts as u32 (#5754)
These counts can never exceed `u32`, so reduce size of these fields.
2024-09-13 12:19:54 +00:00
overlookmotel
667170cbfc refactor(semantic): rename Counts to Stats (#5753)
Pure refactor. Just rename the type.
2024-09-13 12:19:54 +00:00
overlookmotel
042afa9fd6 fix(syntax): correctly check for valid RedeclarationIds (#5759)
Previously we truncated `usize` to `u32` and *then* checked validity of the `u32`. Fix that by checking validity *before* truncating.
2024-09-13 12:15:20 +00:00
Boshen
8ff013ada1 fix(minifier): handle dce CallExpression::callee (#5752) 2024-09-13 10:46:14 +00:00
Dunqing
c9fea5dd16 chore(tasks/transformer_conformance): remove an ignored test that has passed (#5750) 2024-09-13 09:03:48 +00:00
Boshen
2890c98d62 refactor(minifier): add tests for remove_syntax (#5749) 2024-09-13 08:59:45 +00:00
Boshen
9a9d8f61d4 refactor(minifier): replace self.ast with ctx.ast (#5748) 2024-09-13 08:49:45 +00:00
Boshen
6bc13f6cd4 feat(minifier): add MinimizeConditions pass (#5747)
I expect small performance regression.

But managed to improve the following case from react.developmement.js

```
oxc  main ❯ diff before.js after.js
670c670
< 		if (!(dispatcher !== null)) throw Error("Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.");
---
> 		if (dispatcher === null) throw Error("Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.");
```
2024-09-13 08:31:45 +00:00
Dunqing
b4ed564a35 fix(linter/no-unused-vars): writes to members triggering false positive (#5744)
close: #5246

similar to #5722
2024-09-13 06:00:48 +00:00
heygsc
19790dbc9c
chore(docs): add mako on readme (#5742)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-09-13 13:06:29 +08:00
Boshen
cc0408b5d4 refactor(semantic): s/AstNodeId/NodeId (#5740)
part of #5689
2024-09-13 03:00:00 +00:00
overlookmotel
7dfcdfced6 refactor(semantic): remove more-asserts dependency (#5739)
Remove `more-asserts` dependency which was added in #5710.

As suggested by @Boshen in https://github.com/oxc-project/oxc/pull/5710#pullrequestreview-2299016692.
2024-09-13 02:53:00 +00:00
overlookmotel
333e2e04c4 perf(index): remove Idx bounds-checks from first + last methods (#5726)
The following methods of `IndexVec` call `Idx::from_usize` which performs a bounds check, with a panicking branch:

* `first`
* `first_mut`
* `last`
* `last_mut`

These bounds checks are unnecessary. Remove them by delegating to the underlying `Vec`'s methods.
2024-09-13 02:46:57 +00:00
overlookmotel
953fe17f0e feat(ast): provide NONE type for AST builder calls (#5737)
Closes #5736.

Introduce a `NONE` type which can be used for any `AstBuilder` method call param which expects an `IntoIn<'a, Something<'a>>`, where otherwise you have to provide a verbose type annotation.

Before:

```rs
ast.arrow_function_expression(
    SPAN,
    is_expression,
    is_async,
    None::<TSTypeParameterDeclaration>,
    params,
    None::<TSTypeAnnotation>,
    body,
)
```

After:

```rs
ast.arrow_function_expression(SPAN, is_expression, is_async, NONE, params, NONE, body)
```
2024-09-13 02:42:01 +00:00
overlookmotel
71116a1cbd feat(index)!: remove ability to index IndexVec with usize (#5733)
`IndexVec` should only be indexed into with its associated `Idx` type. The implementation taken from `index_vec` crate however also includes the ability to index into the `Vec` with a `usize` "as an ergonomic concession, it's too painful without":

https://docs.rs/index_vec/0.1.4/src/index_vec/indexing.rs.html#112-134

I think we want to be stricter than this, so remove this ability.
2024-09-13 02:37:34 +00:00
overlookmotel
20a7861838 refactor(linter): shorten Option syntax (#5735)
Use `Some` instead of `Option::Some`.
2024-09-12 18:42:51 +00:00
IWANABETHATGUY
805fbac44c feat(oxc_cfg): better control flow graph dot dot repr (#5731)
1. add basic block index for each basicblock, so there should no basic block display empty string
2. use `shape` box, since it is basic **block**
## Before
![image](https://github.com/user-attachments/assets/9b556cca-8401-40bd-b3b6-d31c5e7cf8ba)

## After
![image](https://github.com/user-attachments/assets/b8e4c52d-ecdf-4e92-85be-ea37f0cb2330)
2024-09-12 18:39:01 +00:00
IWANABETHATGUY
d8b612c038
refactor(oxc_linter): prefer pass Enum instead of str no_plus_plus (#5730)
1. remove redundant branch.
2024-09-12 11:43:24 -04:00
overlookmotel
6436524ff1 refactor(semantic): fix dead code warning in release mode (#5728)
`Counts::assert_accurate` is only used in debug mode. Silence the dead code warning in release mode.
2024-09-12 13:33:57 +00:00
overlookmotel
3ce8546393 ci(benchmarks): NeverGrowInPlaceAllocator not pub (#5727)
Global allocator used in benchmarks `NeverGrowInPlaceAllocator` doesn't need to be `pub`.
2024-09-12 12:58:13 +00:00
Dunqing
e9c084a705 fix(linter/no-unused-vars): false positive when a variable used as a computed member property (#5722)
close: #5671
2024-09-12 11:23:01 +00:00
Boshen
748e6f80fe
chore(minsize): update minsize.snap 2024-09-12 19:02:46 +08:00
oxc-bot
1dad9fa301
release(oxlint): v0.9.5 (#5724)
## [0.9.5] - 2024-09-12

### Features

- 4b04f65 linter: Implement `no-plusplus` rule (#5570) (Cam McHenry)

---------

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-09-12 16:59:25 +08:00
Cam McHenry
4b04f65275
feat(linter): implement no-plusplus rule (#5570)
- part of https://github.com/oxc-project/oxc/issues/479

This PR implements the `no-plusplus` rule and is more-or-less a direct
port of the ESLint version of the rule.

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-09-12 16:50:19 +08:00
Boshen
2b8369fb8c
ci(oxlint): pnpm publish need to declare binary as executable 2024-09-12 16:38:56 +08:00
Boshen
f14a534777
ci: fix oxlint publish 2024-09-12 14:53:45 +08:00
oxc-bot
d06bab6260
release(oxlint): v0.9.4 (#5718)
## [0.9.4] - 2024-09-12

### Features

- 9ca2593 linter: Eslint/sort-keys  (#4845) (Na'aman Hirschfeld)
- 023c160 linter: Impl `Serialize` for `OxlintConfig` (#5594) (DonIsaac)
- 24d6a47 linter: Implement `eslint/no-invalid-regexp` (#5443) (Boshen)

### Bug Fixes

- af6d240 linter: Panic in consistent-function-scoping (#5613)
(DonIsaac)
- 54e2e76 linter: `react/no_set_state` + `react/no_string_refs` rules
find correct parent (#5615) (overlookmotel)
- 3b87ac4 linter: Fix no_unused_vars panic when encountering unicode
(#5582) (Boshen)

### Performance

- bfe9186 linter: Use `cow_replace` instead of `replace` (#5643)
(dalaoshu)
- e3ae5db linter: Use cow_to_ascii_lowercase/uppercase (#5637) (heygsc)
- a0370bf linter: Use cow_utils in no_script_url (#5633) (heygsc)
- 37e922c linter: `eslint/no_shadow_restricted_names` use
`run_on_symbol` (#5618) (overlookmotel)
- 0b7fccf linter: `react/no_set_state` + `react/no_string_refs` rules
reduce iteration over ancestors (#5616) (overlookmotel)
- 2c3f3fe linter: Make `jsx_key` slightly faster (#5585) (Boshen)
- cd81d12 linter: Add `should_run` to check path only once to
nextjs/no_typos (#5584) (Boshen)
- d18c896 rust: Use `cow_utils` instead (#5664) (dalaoshu)

### Documentation

- 64f9575 linter: Add plugin usage to example with configuration
(Boshen)
- 8c9179d linter: Fix typos (#5591) (Brian Donovan)

### Refactor

- 9e9435f linter: Add `LintFilter` (#5685) (DonIsaac)
- 4f70fe5 linter: Start internal/external split of LintPluginOptions
(#5660) (DonIsaac)
- 5ae9b48 linter: Start internal/external split of `OxlintOptions`
(#5659) (DonIsaac)
- c8bc6f0 linter: Use `std::ptr::eq` (#5649) (overlookmotel)
- a37c064 linter: Use `ContentHash` for `no_duplicate_case`; remove
`calculate_hash` (#5648) (Boshen)
- 0b3c1d7 linter: Start internal/external split of `OxlintConfig`
(#5595) (DonIsaac)
- 89bdf55 linter: Inline `Rule` trait default methods (#5619)
(overlookmotel)
- afea8d5 linter: Rename `Rule` trait method params (#5617)
(overlookmotel)
- 4e748b5 linter: Replace ast "compare by hash" to "compare by content"
(#5602) (dalaoshu)
- bac03e3 linter: Make fields of `LintServiceOptions` private (#5593)
(DonIsaac)
- 2661d8b linter: Jest prefer_strict_equal (#5588) (IWANABETHATGUY)
- 20d0068 oxlint: Move cli-related exports to `cli` module (#5139)
(DonIsaac)
- 067f9b5 semantic: Introduce `IsGlobalReference` trait (#5672)
(Boshen)- 26d9235 Enable clippy::ref_as_ptr (#5577) (夕舞八弦)

### Testing

- 8e79f8d linter: Add class method test cases for `oxc/no-async-await`
(#5550) (DonIsaac)
- 3835189 linter: Add test case for no_unused_vars in 3b87ac4 (Boshen)
- 5f27551 linter: Add a passing case to no_undef (#5580) (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-09-12 13:56:38 +08:00
Boshen
746f7b3a02 refactor(minifier): align code with closure compiler (#5717)
also fixes #4341
2024-09-12 04:18:41 +00:00
Boshen
4bdc202325 refactor(rust): remove some #[allow(unused)] (#5716) 2024-09-12 02:19:01 +00:00
overlookmotel
c3dd2a048d perf(ast)!: revert: reduce byte size of TaggedTemplateExpression::quasi by Boxing it (#5679) (#5715)
As discussed in #5601, there is little benefit to reducing type sizes for the sake of it. In this case, the `quasi` field in not in an `Option`, so putting it in a `Box` does not save data, only moves where that data is stored, and introduces pointer-indirection.
2024-09-12 00:53:20 +00:00
overlookmotel
a362f51523 feat(index): add IndexVec::shrink_to (#5713)
Add `IndexVec::shrink_to` to match `std::vec::Vec::shrink_to`.
2024-09-11 22:57:58 +00:00
overlookmotel
e02621d2d1 refactor(semantic): re-order use statements (#5712)
Pure refactor. Re-order `use` statements in `oxc_semantic` to follow this order:

1. `std`
2. External crates.
3. `oxc_*` crates.
4. Local crate.
5. `super`
6. `mod`

This is intended to be in order from "furthest above" to "furthest below".
2024-09-11 20:41:49 +00:00
overlookmotel
ac6203c891 refactor(semantic): move Counts code into counter module (#5710)
Pure refactor. Move code for counting nodes etc, and verifying counts, into `counter` module.
2024-09-11 20:41:48 +00:00
overlookmotel
339fcfc8be refactor(semantic): rename Counts in transform checker (#5709)
Pure refactor. Just renaming.
2024-09-11 20:41:48 +00:00
Na'aman Hirschfeld
9ca2593aaa
feat(linter): eslint/sort-keys (#4845)
This PR adds the `eslint/sort-keys` implementation as part of #479 

Note: two tests are commented out. I was not able to model this behavior
properly. I would be happy to have some assistance there.
2024-09-11 13:10:55 -04:00
Boshen
21e2df57a0 refactor(minifier): replace VisitMut with Traverse for inject and define plugins (#5705)
closes #5704
2024-09-11 16:13:10 +00:00
Boshen
945d2744ae
chore(linter: fix snapshot 2024-09-11 21:07:23 +08:00
Boshen
64f9575ed5
docs(linter): add plugin usage to example with configuration
closes #5400
2024-09-11 20:58:29 +08:00
Dunqing
608b7d37d6 fix(napi/transformer): refresh plugin doesn't work even after passing the refresh option (#5702) 2024-09-11 12:39:51 +00:00
renovate[bot]
c2997f1775
chore(deps): update vscode npm packages (#5697) 2024-09-11 19:45:31 +08:00
heygsc
a79c5535e3
chore(clippy): fix typo (#5700) 2024-09-11 19:42:41 +08:00
overlookmotel
d8ec78192e refactor(semantic): remove record_ast_node call for Program (#5701)
Remove a tiny bit of dead code from `SemanticBuilder`.

`record_ast_node` does nothing if `ast_node_records` is empty. It is always empty when visiting `Program`, so is a no-op.
2024-09-11 11:31:20 +00:00
overlookmotel
1857ff09eb style(semantic): rename vars for node IDs (#5699)
`test_node_id` not `test_node` to better describe what these vars contain.
2024-09-11 10:55:42 +00:00