Commit graph

5831 commits

Author SHA1 Message Date
renovate[bot]
6a97e29c19
chore(deps): update crate-ci/typos action to v1.29.4 (#8265)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [crate-ci/typos](https://redirect.github.com/crate-ci/typos) | action
| minor | `v1.28.3` -> `v1.29.4` |

---

### Release Notes

<details>
<summary>crate-ci/typos (crate-ci/typos)</summary>

###
[`v1.29.4`](https://redirect.github.com/crate-ci/typos/releases/tag/v1.29.4)

[Compare
Source](https://redirect.github.com/crate-ci/typos/compare/v1.29.3...v1.29.4)

#### \[1.29.4] - 2025-01-03

###
[`v1.29.3`](https://redirect.github.com/crate-ci/typos/releases/tag/v1.29.3)

[Compare
Source](https://redirect.github.com/crate-ci/typos/compare/v1.29.2...v1.29.3)

#### \[1.29.3] - 2025-01-02

###
[`v1.29.2`](https://redirect.github.com/crate-ci/typos/compare/v1.29.1...v1.29.2)

[Compare
Source](https://redirect.github.com/crate-ci/typos/compare/v1.29.1...v1.29.2)

###
[`v1.29.1`](https://redirect.github.com/crate-ci/typos/releases/tag/v1.29.1)

[Compare
Source](https://redirect.github.com/crate-ci/typos/compare/v1.29.0...v1.29.1)

#### \[1.29.1] - 2025-01-02

##### Fixes

-   Don't correct `deriver`

###
[`v1.29.0`](https://redirect.github.com/crate-ci/typos/releases/tag/v1.29.0)

[Compare
Source](https://redirect.github.com/crate-ci/typos/compare/v1.28.4...v1.29.0)

#### \[1.29.0] - 2024-12-31

##### Features

- Updated the dictionary with the [December
2024](https://redirect.github.com/crate-ci/typos/issues/1156) changes

##### Performance

-   Sped up dictionary lookups

###
[`v1.28.4`](https://redirect.github.com/crate-ci/typos/releases/tag/v1.28.4)

[Compare
Source](https://redirect.github.com/crate-ci/typos/compare/v1.28.3...v1.28.4)

#### \[1.28.4] - 2024-12-16

##### Features

-   `--format sarif` support

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - "before 11am on monday" in timezone Asia/Shanghai.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/oxc-project/oxc).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS44NS4wIiwidXBkYXRlZEluVmVyIjoiMzkuODUuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2025-01-05 22:13:32 +00:00
Boshen
cec63e2119
feat(minifier): {} evals to f64::NaN 2025-01-05 23:09:57 +08:00
Boshen
4d8a08d2ac feat(minifier): improve constant evaluation (#8252) 2025-01-05 12:41:57 +00:00
Boshen
e84f267a39 feat(minifier): compress more property keys (#8253) 2025-01-05 07:20:56 +00:00
camc314
d1224f95ce feat(minifier): improve minimizing conditional expressions (#8251) 2025-01-05 04:14:02 +00:00
camc314
91b42defb5 test(minifier): enable some passing tests (#8250) 2025-01-05 04:14:01 +00:00
camc314
3c534aeb5a refactor(linter): refactor LintBuilder to prep for nested configs (#8034)
More simplification/preparations for nested configurations:

1. renames `LinterBuilder` to `ConfigStoreBuilder`
2. moves the `options` logic out of `LintBuilder`
3. make `ConfigStoreBuilder::build()` return a result (currently always returns OK, but it will return errors when nested config is implemented

The next steps to implement nested config which i hope to do in the next week are:
1. refactor the `from_oxlintrc` to accept a file path
2. introduce a new method on `ConfigStoreBuilder` (name TBC) that walks all child directories, collecting `.oxlintrc` files. these will be put into `ConfigStore` as a hash map of path > config.
2025-01-05 04:08:26 +00:00
Boshen
65f46f5409
feat(minifier): constant fold String.fromCharCode (#8248) 2025-01-04 23:22:32 +08:00
Boshen
0845162372
refactor(minifier): clean up ReplaceKnownMethods 2025-01-04 21:57:20 +08:00
Boshen
bd8d677352 feat(minifier): minimize ~undefined, ~null, ~true, ~false (#8247) 2025-01-04 13:34:53 +00:00
Boshen
f73dc9ea9b
feat(minifier): constant fold 'x'.toString() and true.toString() (#8246) 2025-01-04 21:28:26 +08:00
Boshen
fd5af73a22 feat(minifier): minimize Number constructor (#8245) 2025-01-04 09:56:03 +00:00
Boshen
2f52f333fa feat(minifier): minsize !!!foo ? bar : baz -> foo ? baz : bar (#8244) 2025-01-04 09:10:22 +00:00
Boshen
7c7f5d7af9
refactor(minifier): clean up peephole_fold_constants 2025-01-04 16:57:08 +08:00
Boshen
ce2b5a994b chore(minifier): disable RemoveUnusedCode (#8243)
A lot of edge cases fail in test262 and monitor-oxc.
2025-01-04 08:49:20 +00:00
Boshen
d2f8eaa842 fix(minifier): fix panic in peephole_minimize_conditions (#8242)
https://github.com/oxc-project/monitor-oxc caught some crashes.

Make things safer by returning falling back to true.
2025-01-04 07:56:21 +00:00
Boshen
ad9a0a9c4a feat(mininifier): minimize variants of a instanceof b == true (#8241) 2025-01-04 06:04:52 +00:00
Boshen
ccdc039f54 feat(minifier): always put literals on the rhs of equal op 1==x => x==1 (#8240) 2025-01-04 04:07:54 +00:00
Boshen
bf0fbcea6e refactor(minifier): improve constant fold numbers (#8239)
Ported esbuild's implementation
2025-01-04 03:30:20 +00:00
Cameron
39353b22e9
feat(minifier): improve minimizing conditionals (#8238) 2025-01-04 08:36:54 +08:00
camc314
c90fc16bba feat(minifier): restore conditional minification and fix edge case (#8235)
This restore's the changes made in #8233, but fixing the edge cases.

If the conditional expression is not a child of an `IfStatementTest`, `WhileStatementTest`, `DoWhileStatementText` or `ExpressionStatementExpression`, we must coerce the test to a boolean.
2025-01-03 14:20:42 +00:00
Boshen
6c8ee9fdef feat(minifier): remove last redundant return statement (#8234) 2025-01-03 12:24:57 +00:00
Boshen
a698deff51 fix(minifier): fix incorrect return value for (x ? true : y) (#8233)
Need to check if the return value is used or not:

```
function foo() {
    return foo ? true : bar; // no transformed
}

foo ? true : bar; // transformed to `foo || bar;`
```
2025-01-03 11:58:28 +00:00
camc314
62f8fba98c refactor(minifier): move all conditional minification logic to minimze_conditions (#8231)
@Boshen feel free to close this one if you want. 🙂

https://github.com/oxc-project/oxc/pull/8229 compresses some conditionals

this PR moves compression of all conditionals into the same place
2025-01-03 11:20:56 +00:00
Boshen
51f47926ef feat(minifier): minimize foo ? foo : bar and foo ? bar : foo (#8229) 2025-01-03 10:55:59 +00:00
Boshen
6e2ec17d51 feat(minifier): statement fusion switch cases; improved minimize exit poitns (#8228) 2025-01-03 10:07:04 +00:00
Boshen
574a2428fd feat(minifier): minimize all variants of typeof x == 'undefined' (#8227) 2025-01-03 07:05:55 +00:00
Boshen
2041477f51 feat(minifier): fold if(x)return;y -> if(!x)y (#8226) 2025-01-03 05:24:53 +00:00
Alexander S.
2f9fab9172
refactor(linter): remove remapping for plugin name in diagnostics (#8223)
came across this code.

I do not think this is practicable in the real world. Many projects areo
migrating from jest to vitest and are currently installing both,
So we can't really tell what plugin name should be outputted.

The same is for typescript <-> eslint and our newest candidate:


2da4365fbe/crates/oxc_linter/src/config/rules.rs (L163-L165)
2025-01-03 11:40:26 +08:00
Boshen
2da4365fbe feat(parser): missing initializer in destructuring declaration inside for loop head (#8222)
closes #8220
2025-01-02 14:02:49 +00:00
Boshen
9c1afa4729 feat(minifier): optional catch binding when catch param is unused (#8221) 2025-01-02 13:20:49 +00:00
Boshen
4a29845d82 feat(minifier): add ConvertToDottedProperties (#8212) 2025-01-02 13:02:22 +00:00
Boshen
2786dea164 feat(minifier): add RemoveUnusedCode (#8210) 2025-01-02 12:50:21 +00:00
oxc-bot
d2d90b077b
release(oxlint): v0.15.5 (#8218)
## [0.15.5] - 2025-01-02

### Features

- 0e168b8 linter: Catch more cases in const-comparisons (#8215)
(Cameron)
- bde44a3 linter: Add `statement_span` to `ModuleRecord/ImportEntry`
(#8195) (Alexander S.)
- ccaa9f7 linter: Implement `eslint/new-cap`  (#8146) (Alexander S.)

### Bug Fixes

- 2b14a6f linter: Fix `ignorePattern` config for windows (#8214)
(Alexander S.)

### Testing

- cb709c9 linter: Fix some oxlint tests on windows (#8204) (Cameron)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-01-02 18:55:31 +08:00
Alexander S.
2b14a6fb54
fix(linter): fix ignorePattern config for windows (#8214)
Changes:

- Config `ignorePatterns` not as `Path`, because the create `ignore`
does only handle `/` and not Win-style `\`
- Passed full path to the config and do not use `canonicalize` because
it prefix the paths with `\\?\`,
  read more here: https://stackoverflow.com/a/41233992/7387397
- Updated and enabled tests for windows, some are still failing 

closes #8188

---------

Co-authored-by: Alexander Schlegel <alexander.schlegel@clicksports.de>
2025-01-02 18:34:02 +08:00
Cameron
0e168b8c19
feat(linter): catch more cases in const-comparisons (#8215) 2025-01-02 18:32:47 +08:00
Cameron
cd274eeb02
feat(minifier): minimize logical exprs (#8209) 2025-01-02 18:32:20 +08:00
Boshen
05be1fc639 fix(minifier): remove incorrect fold Expression::AssignmentExpression (#8211) 2025-01-01 05:44:01 +00:00
camc314
4ae15df042 feat(minifier): imprve more conditional expr minification with boolean lit (#8208) 2025-01-01 02:31:18 +00:00
camc314
3202b4fed0 feat(minifier): imprve conditional expr minification with boolean lit (#8207) 2025-01-01 02:31:18 +00:00
camc314
3b4501183c feat(minifier): handle conditional expr with boolean lit (#8206) 2025-01-01 02:31:17 +00:00
camc314
4c2059af29 feat(minifier): reverse negated conditional exprs (#8205) 2025-01-01 02:31:17 +00:00
Dunqing
e5ee38fdf1 chore(transformer): enable class-properties plugin (#7750)
Done!
2024-12-31 12:30:58 +00:00
Dunqing
0592a8b43f feat(transformer/class-properties): transform private in expression (#8202)
This PR support transforms `#prop in object` in class-properties to cover https://www.npmjs.com/package/@babel/plugin-transform-private-property-in-object  plugin does
2024-12-31 12:30:58 +00:00
Dunqing
ad77ad5c12 feat(transformer/class-properties): transform static/instance accessor methods (#8132)
This PR supports transforming private `getter` or `setter` methods, and the output is a little different from Babel's output, For example:

Input:
```js
class Cls {
  #prop = 0;

  get #accessor() {
    return this.#prop;
  }
  set #accessor(v) {
    console.log(arguments);
    this.#prop = v;
  }

  constructor() {
    console.log(this.#accessor)
    [this.#accessor] = [1];
  }
}
```

[Babel's output](https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYGwhgzhAEDCIwN4ChrQMQAcBOB7T0AvNAAwDcyq0A5gKYAuGYwwtUu2AFAJTQpppsDAK7YAdtHoALAJYQAdFjyYKaAL5UIDJizYQOnAG69-A4LjH6QteSFzVOYbNWEBbWmPoRuqgdLmKOPhE0Ia-GlTmlvTYwsD0BiZUaFFWNnYO_grozKzs2NzJ0ADaWYq5ehwAuiHFAIxV4cgaQA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&evaluate=false&fileSize=false&timeTravel=false&sourceType=script&lineWrap=true&presets=&prettier=false&targets=&version=7.26.4&externalPlugins=%40babel%2Fplugin-transform-class-properties%407.25.9%2C%40babel%2Fplugin-transform-private-methods%407.25.9%2C%40babel%2Fplugin-external-helpers%407.25.9&assumptions=%7B%7D):
```js
var _prop = new WeakMap();
var _Cls_brand = new WeakSet();
class Cls {
  constructor() {
    babelHelpers.classPrivateMethodInitSpec(this, _Cls_brand);
    babelHelpers.classPrivateFieldInitSpec(this, _prop, 0);
    console.log(babelHelpers.classPrivateGetter(_Cls_brand, this, _get_accessor));
    [babelHelpers.classPrivateGetter(_Cls_brand, this, _get_accessor)] = [1];
  }
}
function _get_accessor(_this) {
  return babelHelpers.classPrivateFieldGet(_prop, _this);
}
function _set_accessor(_this2, v) {
  var _arguments = [].slice.call(arguments, 1);
  console.log(_arguments);
  babelHelpers.classPrivateFieldSet(_prop, _this2, v);
}
```

Oxc's output:
```js
var _prop = new WeakMap();
var _Cls_brand = new WeakSet();
class Cls {
        constructor() {
                babelHelpers.classPrivateMethodInitSpec(this, _Cls_brand);
                babelHelpers.classPrivateFieldInitSpec(this, _prop, 0);
                console.log(_get_accessor.call(babelHelpers.assertClassBrand(_Cls_brand, this)));
                [babelHelpers.toSetter(_set_accessor.bind(babelHelpers.assertClassBrand(_Cls_brand, this)), [])._] = [1];
        }
}
function _get_accessor() {
        return babelHelpers.classPrivateFieldGet2(_prop, this);
}
function _set_accessor(v) {
        console.log(arguments);
        babelHelpers.classPrivateFieldSet2(_prop, this, v);
}
```

### Main difference
```diff
// Babel
+ console.log(babelHelpers.classPrivateGetter(_Cls_brand, this, _get_accessor));
+ [babelHelpers.classPrivateGetter(_Cls_brand, this, _get_accessor)] = [1];

+ function _get_accessor(_this) {
+   return babelHelpers.classPrivateFieldGet(_prop, _this);
+ }

+ function _set_accessor(_this2, v) {
+   var _arguments = [].slice.call(arguments, 1);
+   console.log(_arguments);
+   babelHelpers.classPrivateFieldSet(_prop, _this2, v);
+ }

// Oxc
-  console.log(_get_accessor.call(babelHelpers.assertClassBrand(_Cls_brand, this)));- -
-  [babelHelpers.toSetter(_set_accessor.bind(babelHelpers.assertClassBrand(_Cls_brand, this)), [])._] = [1];

- function _get_accessor() {
-   return babelHelpers.classPrivateFieldGet2(_prop, this);
- }

- function _set_accessor(v) {
-   console.log(arguments);
-   babelHelpers.classPrivateFieldSet2(_prop, this, v);
- }
```

From the main differences, we can see that Babel handles `getter` and `setter` methods using `classPrivateGetter` and `classPrivateSetter` helper functions, which causes all use `this` and `arguments` needs to rewrite to use a temp var instead in `getter` and `setter` methods. This is unnecessary and is not an efficient transformation for us.

Instead, I adapt binding a `this` instead of passing in `this`, this way we don't need to rewrite anything. We can't control the `helper` library for now, so I just transformed the AST to bind `this`, in the future, we can create a helper function to do the same thing.
2024-12-31 12:30:56 +00:00
Dunqing
e405f79577 feat(transformer/class-properties): transform static private method invoking (#8117) 2024-12-31 12:30:56 +00:00
Dunqing
3303e9986b feat(transformer/class-properties): insert statements after statement of class expression (#8116) 2024-12-31 12:30:55 +00:00
Dunqing
0cc71cf5e3 feat(transformer/class-properties): transform super expressions and identifiers that refers to class binding in private method (#8106)
All private methods will be moved out of class, so we need to transform all `super` expressions in private methods and transform identifiers that refer to class binding.
2024-12-31 12:30:55 +00:00
Dunqing
c786a13c4f refactor(transformer/class-properties): share replace_class_name_with_temp_var in class_properties (#8105) 2024-12-31 12:30:54 +00:00
Dunqing
f54f48e94f refactor(transformer/class-properties): remove all *_if_super methods in static_block_and_prop_init (#8104)
Calling an intermediate function is not intutide, and these functions only have one line, so we can directly call it
2024-12-31 12:30:54 +00:00