Commit graph

7114 commits

Author SHA1 Message Date
DonIsaac
de22b81b83 docs(data-structures): enable lint warnings on missing docs, and add missing doc comments (#6612)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-15 22:50:47 +00:00
DonIsaac
335b7f22c5 docs(syntax): enable lint warnings on missing docs, and add a lot of documentation (#6611)
Part of https://github.com/oxc-project/backlog/issues/130

I didn't add doc comments to everything; I'm missing context for module-related data types and I have other things to do :P
2024-10-15 22:50:45 +00:00
DonIsaac
28b1b4efe2 chore(span): enable lint warnings on missing docs (#6610)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-15 22:50:44 +00:00
DonIsaac
3faee66400 refactor(span): remove unused ContentHash::content_hash_slice (#6609)
I've replaced it with impls on `Vec<'a, T>`. I'm hoping this removes some bloat in final binaries.
2024-10-15 22:50:42 +00:00
Don Isaac
a00b43717d
ci: cache compiled dprint plugins (#6605)
Cache downloaded & compiled `dprint` plugins in `autofix.ci` between
runs. It should help shave some time off this pipeline.
2024-10-16 06:48:24 +08:00
DonIsaac
03427af85b chore(parser): enable lint warnings on missing docs (#6608)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-15 21:51:41 +00:00
dalaoshu
d07a9b0fb3
fix(linter): panic in no-zero-fractions (#6607)
closes #6584 

Only fixed character index errors on the linter side.
2024-10-15 16:48:11 -04:00
DonIsaac
5213ba7fb4 feat(website/linter): render mapped types in config docs (#6604)
Render better types for config properties that accept arbitrary keys. For example, `Record<string, boolean>` instead of `object`.
2024-10-15 20:35:45 +00:00
DonIsaac
dcd4607a40 feat(website/linter): render defaults in config docs (#6603)
Render default values for each section in oxlintrc config docs.
2024-10-15 20:35:45 +00:00
DonIsaac
d4cb7e6f58 fix(website/linter): better md rendering for primitive arrays (#6602)
Improves how config docs are rendered for the website. If a config property is an array of primitive values, we now skip subsection rendering and render a better type, e.g. `string[]` instead of `array`.
2024-10-15 20:35:45 +00:00
Boshen
389d2615d0 fix(minifier): ~~ operator should only work on numbers (#6598) 2024-10-15 16:37:00 +00:00
Dunqing
ba385fc9c1 fix(codegen): panic occurred when printing the comment of the right parenthesis (#6593)
fix: https://github.com/oxc-project/monitor-oxc/actions/runs/11349185798/job/31564783192

It's hard to add a test for this because I haven't figured out caused by which plugin
2024-10-15 16:23:43 +00:00
Dunqing
e7c89a596b test(codegen): uncomment passed tests that are related to trailing comments (#6589)
Just uncomment them and replace whitespace with `\t`
2024-10-15 16:23:41 +00:00
Dunqing
721cf0f8b4 fix(parser): should be treated comments where after ( as leading comments of next token (#6588)
same as #6355

The behaviour is also same as esbuild and babel does
2024-10-15 16:23:40 +00:00
Boshen
16bea12f9c fix(minifier): use to_js_string() instead of fs64::to_string (#6597) 2024-10-15 16:16:26 +00:00
camc314
071e5643f3 feat(minifier): finish implementing folding object expressions (#6586) 2024-10-15 15:51:34 +00:00
Boshen
15c04e5cbb
feat(ecmascript): add feature flag for constant evaluation 2024-10-15 23:49:45 +08:00
Boshen
8e4f6368f8
chore(minifier): add --nospace option to minifier example 2024-10-15 23:49:22 +08:00
camc314
590925a40c feat(minifier): finish implementing folding array expressions (#6575) 2024-10-15 15:43:09 +00:00
overlookmotel
7a028b30e0 refactor(transformer): remove unnecessary #![warn] attr (#6585) 2024-10-15 14:57:55 +00:00
overlookmotel
8c6afe05f3 refactor(transformer): reorder imports (#6582)
Re-order `use` statements in order:

1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules

This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.
2024-10-15 14:45:27 +00:00
DonIsaac
c5e66e108f feat(linter/no-unused-vars): report own type references within class, interface, and type alias declarations (#6557)
## What This PR Does

**Tl;Dr**: Using a class/interface/type alias as a type within its own declaration is no longer considered a usage.

### Example
```ts
// LinkedList is only ever referenced within its own definition.
// It could be safely deleted and not affect other code.
class LinkedList<T> {
    #value: T;
    #next: LinkedList<T> | null = null;

    constructor(value: T) {
        this.#value = value;
    }

    [Symbol.iterator]*() {
        let current: LinkedList<T> | null = this;
        while (current !== null) {
            yield current.#value;
            current = current.#next;
        }
    }
}
```
2024-10-15 14:34:05 +00:00
magic-akari
aa6ba24b0c refactor(ecmascript): improve string to number conversion (#6577) 2024-10-15 14:25:30 +00:00
Brian Donovan
b9d7c5fdb5
fix(no-unused-vars): consider functions within conditional expressions usable (#6553) 2024-10-15 09:46:26 -04:00
Dunqing
448388ac9a docs(transformer/module_imports): update outdated comments (#6574)
Follow-up https://github.com/oxc-project/oxc/pull/6560
2024-10-15 13:21:56 +00:00
Boshen
d11770d552 feat(ecmascript): add StringToNumber (#6576) 2024-10-15 08:52:54 +00:00
magic-akari
a71e8a00bf
fix(minifier): Preserve init variable declarations when removing for statements during DCE (#6551)
- Closes: #6547

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-15 16:51:30 +08:00
Boshen
2e4c793a78
chore(Cargo.toml): relax napi version 2024-10-15 13:48:01 +08:00
Boshen
55a0e9e960
chore(Cargo.toml): relax quote 2024-10-15 13:45:24 +08:00
Boshen
85e3119905
chore(Cargo.toml): relax versions of syn and proc-macro2 2024-10-15 13:42:15 +08:00
Boshen
e56188037c feat(ecmascript): add constant_evaluation and side_effects code (#6550)
I intend to move most of the constant evaluation code into the crate.
2024-10-15 05:15:46 +00:00
camchenry
77ddab863f perf(linter/numeric-separators-style): replace regex with number parser (#6546)
Building the Regex here is slow. We can take advantage of the fact that we know what the inputs should look like and parse the number directly.

Cumulatively, this makes linting the RadixUIAdoptionSection.tsx ~7% faster:

```
hyperfine --warmup 100 --shell=none --runs 3000 './oxlint-main -W all --silent ./RadixUIAdoptionSection.jsx' './oxlint-num-separators -W all --silent ./RadixUIAdoptionSection.jsx'
Benchmark 1: ./oxlint-main -W all --silent ./RadixUIAdoptionSection.jsx
Benchmark 1: ./oxlint-main -W all --silent ./RadixUIAdoptionSection.jsx
  Time (mean ± σ):       4.1 ms ±   0.1 ms    [User: 1.8 ms, System: 1.4 ms]
  Range (min … max):     3.8 ms …   4.7 ms    3000 runs

Benchmark 2: ./oxlint-num-separators -W all --silent ./RadixUIAdoptionSection.jsx
  Time (mean ± σ):       3.8 ms ±   0.1 ms    [User: 1.5 ms, System: 1.4 ms]
  Range (min … max):     3.5 ms …   4.5 ms    3000 runs

Summary
  ./oxlint-num-separators -W all --silent ./RadixUIAdoptionSection.jsx ran
    1.08 ± 0.05 times faster than ./oxlint-main -W all --silent ./RadixUIAdoptionSection.jsx
```
2024-10-15 05:02:55 +00:00
camchenry
8f47cd00bd perf(linter/react): remove regex patterns in no-unknown-property (#6536)
Initializing these `Regex`s, even if lazily, is relatively slow on a per-file basis. We can implement these much faster as simple iterators over characters.
2024-10-15 05:02:54 +00:00
camchenry
62afaa99dd perf(linter/jsx-no-comment-textnodes): remove regex for checking comment patterns (#6534)
Improves performance of this rule by replacing `Regex` with simpler string methods. On the `RadixUIAdoptionSection.jsx` file alone, this improves performance by ~5%:

```
hyperfine --warmup 100 --shell=none --runs 3000 './oxlint-main -W jsx-no-comment-textnodes --silent ./RadixUIAdoptionSection.jsx' './oxlint-jsx-no-comment-textnodes-no-regex -W jsx-no-comment-textnodes --silent ./RadixUIAdoptionSection.jsx'
Benchmark 1: ./oxlint-main -W jsx-no-comment-textnodes --silent ./RadixUIAdoptionSection.jsx
  Time (mean ± σ):       4.4 ms ±   0.1 ms    [User: 1.7 ms, System: 1.9 ms]
  Range (min … max):     4.1 ms …   5.3 ms    3000 runs

Benchmark 2: ./oxlint-jsx-no-comment-textnodes-no-regex -W jsx-no-comment-textnodes --silent ./RadixUIAdoptionSection.jsx
  Time (mean ± σ):       4.2 ms ±   0.1 ms    [User: 1.5 ms, System: 1.8 ms]
  Range (min … max):     3.9 ms …   5.0 ms    3000 runs

Summary
  ./oxlint-jsx-no-comment-textnodes-no-regex -W jsx-no-comment-textnodes --silent ./RadixUIAdoptionSection.jsx ran
    1.06 ± 0.05 times faster than ./oxlint-main -W jsx-no-comment-textnodes --silent ./RadixUIAdoptionSection.jsx
```
2024-10-15 05:02:54 +00:00
Boshen
8d9a2da9f3 ci(benchmark): add small test file to linter benchmark (#6572)
closes #6540
2024-10-15 02:37:22 +00:00
Boshen
435a89c6e4 refactor(oxc): remove useless allocator.alloc(program) calls (#6571) 2024-10-15 02:21:20 +00:00
camc314
ef237cf8ff feat(minifier): complete implementation of statement fusion (#6566)
- enables all test in statement fusion
 - implements some more node in `may_have_side_effects`
2024-10-15 02:14:49 +00:00
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