Commit graph

6177 commits

Author SHA1 Message Date
Dunqing
c67acfaae7 chore(transformer): turns off async_to_generator plugin in enable_all (#6554)
The plugin is not ready to test
2024-10-15 02:08:28 +00:00
Don Isaac
04d09b3d1b
ci: auto-label PRs with category tags based on their title (#6533)
Automatically add category labels (e.g. `C-enhancement`) to PRs based on
the conventional commit type (e.g. `feat`) used in their title.
2024-10-15 10:07:21 +08:00
overlookmotel
f70a413536 perf(transformer): object spread transform: do not lookup Object binding if not needed (#6570)
If `set_spread_properties` option is not set, skip looking up binding for `Object`, as it's not used.
2024-10-15 01:20:38 +00:00
overlookmotel
c6f2b5f0a1 fix(transformer): HelperLoader common transform: do not assume babelHelpers is global (#6569)
Unfortunately, we cannot assume `babelHelpers` is a global var. Obviously, the transform won't work correctly if it's not, but at least `SymbolTable` will be consistent with the AST.
2024-10-15 01:20:36 +00:00
overlookmotel
779ff46166 refactor(transformer): HelperLoader common transform: Helper struct (#6568)
Pure refactor. Use a struct with named fields to store loaded helper details, for clarity.
2024-10-15 01:20:35 +00:00
overlookmotel
bc24a24541 refactor(transformer): HelperLoader common transform: use hashmap Entry API (#6567)
Perform lookup in `loaded_helpers` via more efficient hashmap `Entry` API, avoiding a double-lookup.
2024-10-15 01:20:34 +00:00
overlookmotel
9f02fc7701 refactor(transformer): HelperLoader common transform: re-order fields (#6565)
Style nit. Keep fields in same order throughout.
2024-10-15 01:20:33 +00:00
overlookmotel
50ecade892 refactor(transformer): HelperLoader common transform: remove Rcs (#6564)
State is uniquely owned by `HelperLoaderStore`, so no need for `Rc`.
2024-10-15 01:20:31 +00:00
overlookmotel
1c1e9fc2c4 refactor(transformer): HelperLoader common transform: reorder methods (#6563)
Refactor `HelperLoader` common transform to split up public and internal methods. Move `add_imports` function to be a method of `HelperLoaderStore`, so `impl Traverse for HelperLoader` is as minimal as possible.

This is for consistency with the other common transforms.
2024-10-15 01:20:30 +00:00
overlookmotel
c9054c8421 refactor(transformer): rename ImportKind to Import (#6561)
Pure refactor. Just change name of the type from `ImportKind` to `Import`. I don't think "Kind" adds anything.
2024-10-15 01:20:29 +00:00
overlookmotel
9542c4e300 refactor(transformer): add more specific methods to ModuleImportsStore (#6560)
Make `ImportKind` private implementation detail of `ModuleImports` common transform. Provide `add_default_import` and `add_named_import` methods instead.
2024-10-15 01:20:28 +00:00
overlookmotel
7e57a1d2fc refactor(transformer): ImportKind use BoundIdentifier (#6559)
Follow-on after #6434.

Store `BoundIdentifier` in `ImportKind`, rather than storing `name` and `symbol_id` separately. Pure refactor - just allows shortening some code.
2024-10-15 01:20:26 +00:00
overlookmotel
602df9df63 refactor(transformer): re-order fields of Common and TransformCtx (#6562)
Follow-on after #6162.

Tiny refactor. Put `HelperLoader` first, so order of fields is same order the common transforms run in.
2024-10-14 20:22:16 +00:00
DonIsaac
06b09b2022 test(linter/no-unused-vars): enable now-passing tests (#6556)
Un-comment tests that are now passing. This PR does not change rule behavior; these have been passing for a while now, but were not getting run.
2024-10-14 19:19:58 +00:00
DonIsaac
badd11ce0d test(linter/no-unused-vars): ignored catch parameters (#6555)
Add test cases covering unused/ignored catch parameters after [this discussion](https://discord.com/channels/1079625926024900739/1080712072012238858/1295014826388623414) on discord.
2024-10-14 19:19:56 +00:00
Ethan Goh
a9260cf6d1
feat(transformer): async-to-generator plugin. (#5590)
Tests are still not passed. A lot need to do yet.

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-10-14 17:16:58 +08:00
Boshen
3556062213 feat(ecmascript): add ConstantEvaluation (#6549) 2024-10-14 07:53:44 +00:00
Boshen
67ad08a056 refactor(minifier): unify ValueType (#6545) 2024-10-14 04:21:42 +00:00
Boshen
521d295830 chore(deps): update vscode npm packages (#6544) 2024-10-14 03:30:41 +00:00
Tapan Prakash
9f9057b99f
fix(regular_expression): Fixed control Y regular expression (#6524)
Fixes https://github.com/oxc-project/oxc/issues/6413

Fixed regular expression for control Y
2024-10-14 11:19:37 +08:00
Boshen
591f5dd960 chore(deps): update rust crates (#6542) 2024-10-14 03:14:15 +00:00
Boshen
3c7540e4ca
chore(deps): update dependency express to v4.21.1 (#6543)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-14 10:30:15 +08:00
Dunqing
41c8675f0d feat(transformer/object-rest-spread): using helper loader (#6449) 2024-10-14 01:34:53 +00:00
overlookmotel
c0e9d7eb77 refactor(codegen)!: Codegen::into_source_text consume Codegen (#6539)
Breaking change. `Codegen::into_source_text` consume `Codegen`, instead of taking the `CodeBuffer` and substituting an empty one.

Keeping the `Codegen` alive seems unintuitive, as its state is then out of sync. Consuming the `CodeBuffer` is also marginally cheaper.
2024-10-14 01:09:03 +00:00
overlookmotel
7e909a7e6c docs(codegen): fix example for CodeBuffer::print_ascii_bytes (#6535)
Fix example and add a test.
2024-10-14 01:09:02 +00:00
overlookmotel
77f3a1a9dd perf(codegen): check last char with byte methods (#6509)
When checking what last char in buffer is, avoid calculating a `char` when only comparing to an ASCII char (byte) anyway.
2024-10-14 01:09:02 +00:00
overlookmotel
18b68ff90e perf(codegen): optimize CodeBuffer::print_ascii_byte (#6516)
Optimize `CodeBuffer`'s `print_byte_unchecked` and `print_ascii_byte` methods by making a fast path for when the buffer has sufficient capacity to be pushed to without growing.

As discussed in https://github.com/oxc-project/oxc/pull/6148#issuecomment-2381635390
2024-10-14 01:09:01 +00:00
DonIsaac
2b86de9e74 fix(linter/no-control-regex): false negative for flags in template literals (#6531)
Updates regex flag extraction logic to handle no-substitution template literals, allowing cases like this to be correctly reported:
```js
let r = new RegExp('\\u{0}', `u`);
```
2024-10-14 00:59:28 +00:00
no-yan
ecce5c53f8
refactor(linter): improve recursive argument handling and diagnostics creation (#6513)
### Overview
This PR refactors `only-used-in-recursion` codebase to make the
implementation of #5530 easier.

The diff isn't displaying cleanly, so it might be better to review it
commit by commit when looking at the changes.

### Key changes
1. Extracted diagnostic logic into `craete_diagnostic` function:
3bf00152e9359d26dccc75bc7ae9fb03970fc409
2. Removed redundant check in `is_function_maybe_reassigned`:
a133ec63d12562bbcd4030fd5e4e7245380e5ced
3. Simplified `is_argument_only_used_in_recursion` by removing nesting:
6e6bd0495374528ec20458cb95247a8f88b1b260
2024-10-14 08:58:25 +08:00
Don Isaac
111e2d798a
ci: auto-label editor-related PRs (#6532) 2024-10-14 08:57:42 +08:00
Don Isaac
f12571f9a7
chore(repo): add note to bug report template (#6522)
I'm seeing lots of bug reports for oxlint & the VSCode extension that
are not using the "linter bug report" template. This PR adds a notice to
our default bug report template that redirects people to the correct
place.
2024-10-14 08:54:48 +08:00
DonIsaac
685a590030 fix(linter/no-control-regex): better diagnostic messages (#6530)
1. Handle plural/singular cases in message and help text
2. Shrink spans in `RegExp` constructors to only cover the regular expression itself.
2024-10-13 19:34:20 +00:00
DonIsaac
6d5a9f2ee0 fix(linter/no-control-regex): allow capture group references (#6529)
Closes #6525.

Allows `\1`, `\2`, etc. when referencing a capturing group.

Examples of now-allowed patterns:
```js
// both of these have a capture group with an index of 1
const r = /([a-z]+)\1/;
const r = /\1([a-z]+)/;
```

Examples of still-banned patterns:
```js
/([a-z])\0/; //out of range: capture groups are 1-indexed
/([a-z])\2/; // there's only one capture group here
```
2024-10-13 19:34:19 +00:00
DonIsaac
7c200560c7 perf(regex): reduce string allocations in Display impls (#6528)
There's still room for improvement here.
2024-10-13 19:34:18 +00:00
DonIsaac
2c32dac691 refactor(linter/no-control-regex): remove duplicate code (#6527) 2024-10-13 19:29:39 +00:00
overlookmotel
7cc05f1626 fix(data_structures): fix compilation failure on older Rust versions (#6526)
I thought I was being clever, but too clever = stupid.

The dummy code designed to flag when our MSRV is bumped and supports `NonNull::add` would fail to compile on Rust versions below 1.80.0. Precisely because of the condition this code is testing - it's not supported!

Fix this by skipping compilation unless running clippy.
2024-10-13 17:32:10 +00:00
dalaoshu
97c8a3608f
feat(minifier): implement collapse-variable-declarations (#6464) 2024-10-13 23:01:50 +08:00
camchenry
f960e9ea83 refactor(linter): Add suggested file names for unicorn/filename-case (#6465) 2024-10-13 14:22:15 +00:00
camchenry
d6a0d2e164 fix(linter): fix file name checking behavior of unicorn/filename-case (#6463)
- closes #6459

Currently, the `unicorn/filename-case` doesn't match the behavior of the original rule. There are several issues which this PR fixes:

- The defaults cases were incorrect: only kebab case should be enabled by default, according to the original rule docs.
- Setting a single case or multiple cases did not remove the default cases as it should.
- Leading/trailing underscores were not ignored by default.
- We did not provide a clear diagnostic message indicating which cases are allowed.
- We did not try to parse out multiple file parts (separated by `.`).
  - TODO: We should also support multiple file part checking (which the original rule supports via a config option), for file names such as `someTest.fileName.js`

I have also added many of the original test cases to ensure we are more closely compatible.

This also improves the performance of just running the `unicorn/filename-case` alone by 4% (20ms total) on the `vscode` codebase:

```
Benchmark 1: ./oxlint-main -A all -W unicorn/filename-case --silent vscode
  Time (mean ± σ):     489.4 ms ±  24.0 ms    [User: 2623.8 ms, System: 447.2 ms]
  Range (min … max):   474.7 ms … 622.9 ms    100 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark 2: ./oxlint-new-filename-case -A all -W unicorn/filename-case --silent vscode
  Time (mean ± σ):     470.8 ms ±  22.9 ms    [User: 2478.8 ms, System: 463.5 ms]
  Range (min … max):   455.6 ms … 599.3 ms    100 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Summary
  ./oxlint-new-filename-case -A all -W unicorn/filename-case --silent vscode ran
    1.04 ± 0.07 times faster than ./oxlint-main -A all -W unicorn/filename-case --silent vscode
```

Perplexingly, it seems like it might actually be even faster on the `vscode` repository, saving ~5% (70ms) with the default ruleset enabled as well. Maybe my laptop was just running a bit faster.

```
Benchmark 1: ./oxlint-main -W unicorn/filename-case --silent vscode
  Time (mean ± σ):      1.402 s ±  0.096 s    [User: 8.863 s, System: 0.505 s]
  Range (min … max):    1.318 s …  1.920 s    100 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark 2: ./oxlint-new-filename-case -W unicorn/filename-case --silent vscode
  Time (mean ± σ):      1.339 s ±  0.042 s    [User: 8.582 s, System: 0.511 s]
  Range (min … max):    1.266 s …  1.506 s    100 runs

Summary
  ./oxlint-new-filename-case -W unicorn/filename-case --silent vscode ran
    1.05 ± 0.08 times faster than ./oxlint-main -W unicorn/filename-case --silent vscode
```
2024-10-13 14:22:14 +00:00
camchenry
725f9f6eb0 perf(linter): get fewer parent nodes in unicorn/prefer-dom-node-text-content (#6467)
Profiling showed that this rule was one of the slower ones, partially due to the fact that it was constantly calling `ctx.nodes()` and `ctx.nodes().parent_node()`. I've tried to fix this by reordering the logic so that we only fetch the parent nodes right before we need it. If we can early return, such as the identifier name not being `innerText`, or the node kind not being right, then we can skip fetching the parent.

Before:

<img width="1147" alt="Screenshot 2024-10-12 at 3 05 05 AM" src="https://github.com/user-attachments/assets/4a551b04-370f-4ed9-b0d5-99d58b03235b">

After (-0.4% reduction in number of samples spent in this rule):

<img width="1146" alt="image" src="https://github.com/user-attachments/assets/340edc36-55cc-4bf4-aa8e-9a600848b798">
2024-10-13 14:17:08 +00:00
Boshen
6d041fb469 refactor(ecmascript): remove NumberValue (#6519) 2024-10-13 14:11:37 +00:00
overlookmotel
51fc63da45 refactor(codegen): rename CodeBuffer::print_bytes_unchecked method (#6517) 2024-10-13 13:14:49 +00:00
overlookmotel
782f0a7a69 refactor(codegen)!: rename print_char method to print_ascii_byte (#6512)
`print_ascii_byte` is more descriptive of what this method does, and makes clear the invariant that `byte` must be ASCII.
2024-10-13 12:51:37 +00:00
overlookmotel
05a2ebd03c refactor(codegen): reorder dependencies in Cargo.toml (#6514) 2024-10-13 12:37:20 +00:00
overlookmotel
235d357600 docs(codegen): improve doc comments for CodeBuffer (#6511) 2024-10-13 12:21:39 +00:00
overlookmotel
e7f3e28076 refactor(codegen): rename var in CodeBuffer (#6510) 2024-10-13 11:58:39 +00:00
Boshen
39c2e66b0b feat(ecmascript): add ToBigInt and StringToBigInt (#6508) 2024-10-13 11:26:07 +00:00
overlookmotel
1bbd383d0f refactor(codegen): rename CodeBuffer::print_ascii_bytes method (#6507)
Pure refactor.
2024-10-13 11:19:09 +00:00
overlookmotel
cd9fe9ec03 refactor(codegen): rename vars in CodeBuffer methods (#6506)
Pure refactor. Consistently use `byte` for bytes, and `ch` for `char`s.
2024-10-13 11:10:10 +00:00
overlookmotel
c8fa2eb17a docs(codegen): correct and reformat doc comments for CodeBuffer (#6504)
Comment about `take_source_text` was erroneous. Clean up and reformat other doc comments.
2024-10-13 11:10:09 +00:00