Commit graph

7714 commits

Author SHA1 Message Date
Boshen
0726581f4f
chore(deps): update github-actions (#8409)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-01-10 14:06:49 +08:00
Boshen
7ce6a7c741 fix(minifier): a in b has error throwing side effect (#8406) 2025-01-10 05:23:07 +00:00
Boshen
2f3a9dc74c fix(minifier): cannot transform property key #constructor (#8405) 2025-01-10 04:04:05 +00:00
Boshen
438a6e7abc feat(minifier): minimize conditions in boolean context (#8381) 2025-01-10 03:47:10 +00:00
overlookmotel
e7c89bad98 refactor(transformer/class-properties): TODO comments (#8392) 2025-01-10 03:38:27 +00:00
翠 / green
aaa009dd4d
docs(minifier): clarify assumptions for compressor (#8404)
Listed the assumptions that the compressor probably makes.
2025-01-10 11:37:41 +08:00
overlookmotel
8d2176e2e1 test(transformer/arrow-functions): add decorators to test (#8393)
Follow-on after #8382. Add decorators to the test fixture.
2025-01-10 03:27:46 +00:00
overlookmotel
3dad85e514 refactor(transformer/private-methods): remove unnecessary clone (#8400) 2025-01-10 03:22:40 +00:00
Boshen
33d776db51
chore(tasks/coverage): ignore fn-name-cover.js in test262 minifier runtime 2025-01-10 10:47:09 +08:00
overlookmotel
45e2402ebe style(transformer/private-methods): move comments (#8399) 2025-01-10 02:36:10 +00:00
overlookmotel
05cba5bf09 docs(transformer/private-methods): amend comments (#8398) 2025-01-10 02:05:28 +00:00
Alexander S.
4e05e66d7c
refactor(linter): remove glob for windows (#8390)
The current implementations does not work. Under linux it tells me 0
files, under windows:

```
> oxc-vscode@0.15.5 lint C:\dev\oxc\editors\vscode
> npx oxlint --config=oxlint.json --tsconfig=tsconfig.json client/*.js

Finished in 5ms on 5 files with 101 rules using 24 threads.
Found 0 warnings and 0 errors.
```

I do not think this glob is needed. we are using `ignore` in our
`Walker`, which should already covering the use case.

---------

Co-authored-by: Sysix <alexander.schlegel@clicksports.de>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-10 10:03:43 +08:00
overlookmotel
0a1ffc045d style(transformer/private-methods): rename var (#8397)
Some types' properties have names that require `r#` escape, and we can't really avoid it. But in my view, it's preferable not to name vars `r#...` when we don't have to.
2025-01-10 01:58:42 +00:00
Dunqing
07edf74c58 perf(transformer/arrow-function): stop traversal at function as super() can't appear in a nested function (#8383) 2025-01-10 00:30:11 +00:00
overlookmotel
fd35866141 chore(deps): bump MSRV to 1.79 (#8394)
Bump MSRV to 1.79 in line with our policy to support last 6 minor versions.

We can now use `const {}` expressions which became stable in 1.79. https://releases.rs/docs/1.79.0/
2025-01-09 19:11:59 +00:00
renovate
772b71c838 chore(deps): update dependency rust to v1.84.0 (#8391)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [rust](https://redirect.github.com/rust-lang/rust) | minor | `1.83.0` -> `1.84.0` |

---

### Release Notes

<details>
<summary>rust-lang/rust (rust)</summary>

### [`v1.84.0`](https://redirect.github.com/rust-lang/rust/blob/HEAD/RELEASES.md#Version-1840-2025-01-09)

[Compare Source](https://redirect.github.com/rust-lang/rust/compare/1.83.0...1.84.0)

\==========================

<a id="
Language"></a>

## Language

-   [Allow `#[deny]` inside `#[forbid]` as a no-op](https://redirect.github.com/rust-lang/rust/pull/121560/)
-   [Show a warning when `-Ctarget-feature` is used to toggle features that can lead to unsoundness due to ABI mismatches](https://redirect.github.com/rust-lang/rust/pull/129884)
-   [Use the next-generation trait solver in coherence](https://redirect.github.com/rust-lang/rust/pull/130654)
-   [Allow coercions to drop the principal of trait objects](https://redirect.github.com/rust-lang/rust/pull/131857)
-   [Support `/` as the path separator for `include!()` in all cases on Windows](https://redirect.github.com/rust-lang/rust/pull/125205)
-   [Taking a raw ref (`raw (const|mut)`) of a deref of a pointer (`*ptr`) is now safe](https://redirect.github.com/rust-lang/rust/pull/129248)
-   [Stabilize s390x inline assembly](https://redirect.github.com/rust-lang/rust/pull/131258)
-   [Stabilize Arm64EC inline assembly](https://redirect.github.com/rust-lang/rust/pull/131781)
-   [Lint against creating pointers to immediately dropped temporaries](https://redirect.github.com/rust-lang/rust/pull/128985)
-   [Execute drop glue when unwinding in an `extern "C"` function](https://redirect.github.com/rust-lang/rust/pull/129582)

<a id="1.84.0-Compiler"></a>

## Compiler

-   [Add `--print host-tuple` flag to print the host target tuple and affirm the "target tuple" terminology over "target triple"](https://redirect.github.com/rust-lang/rust/pull/125579)
-   [Declaring functions with a calling convention not supported on the current target now triggers a hard error](https://redirect.github.com/rust-lang/rust/pull/129935)
-   [Set up indirect access to external data for `loongarch64-unknown-linux-{musl,ohos}`](https://redirect.github.com/rust-lang/rust/pull/131583)
-   [Enable XRay instrumentation for LoongArch Linux targets](https://redirect.github.com/rust-lang/rust/pull/131818)
-   [Extend the `unexpected_cfgs` lint to also warn in external macros](https://redirect.github.com/rust-lang/rust/pull/132577)
-   [Stabilize WebAssembly `multivalue`, `reference-types`, and `tail-call` target features](https://redirect.github.com/rust-lang/rust/pull/131080)
-   [Added Tier 2 support for the `wasm32v1-none` target](https://redirect.github.com/rust-lang/rust/pull/131487)

<a id="1.84.0-Libraries"></a>

## Libraries

-   [Implement `From<&mut {slice}>` for `Box/Rc/Arc<{slice}>`](https://redirect.github.com/rust-lang/rust/pull/129329)
-   [Move `<float>::copysign`, `<float>::abs`, `<float>::signum` to `core`](https://redirect.github.com/rust-lang/rust/pull/131304)
-   [Add `LowerExp` and `UpperExp` implementations to `NonZero`](https://redirect.github.com/rust-lang/rust/pull/131377)
-   [Implement `FromStr` for `CString` and `TryFrom<CString>` for `String`](https://redirect.github.com/rust-lang/rust/pull/130608)
-   [`std::os::darwin` has been made public](https://redirect.github.com/rust-lang/rust/pull/123723)

<a id="1.84.0-Stabilized-APIs"></a>

## Stabilized APIs

-   [`Ipv6Addr::is_unique_local`](https://doc.rust-lang.org/stable/core/net/struct.Ipv6Addr.html#method.is_unique_local)
-   [`Ipv6Addr::is_unicast_link_local`](https://doc.rust-lang.org/stable/core/net/struct.Ipv6Addr.html#method.is_unicast_link_local)
-   [`core::ptr::with_exposed_provenance`](https://doc.rust-lang.org/stable/core/ptr/fn.with_exposed_provenance.html)
-   [`core::ptr::with_exposed_provenance_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.with_exposed_provenance_mut.html)
-   [`<ptr>::addr`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.addr)
-   [`<ptr>::expose_provenance`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.expose_provenance)
-   [`<ptr>::with_addr`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.with_addr)
-   [`<ptr>::map_addr`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.map_addr)
-   [`<int>::isqrt`](https://doc.rust-lang.org/stable/core/primitive.i32.html#method.isqrt)
-   [`<int>::checked_isqrt`](https://doc.rust-lang.org/stable/core/primitive.i32.html#method.checked_isqrt)
-   [`<uint>::isqrt`](https://doc.rust-lang.org/stable/core/primitive.u32.html#method.isqrt)
-   [`NonZero::isqrt`](https://doc.rust-lang.org/stable/core/num/struct.NonZero.html#impl-NonZero%3Cu128%3E/method.isqrt)
-   [`core::ptr::without_provenance`](https://doc.rust-lang.org/stable/core/ptr/fn.without_provenance.html)
-   [`core::ptr::without_provenance_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.without_provenance_mut.html)
-   [`core::ptr::dangling`](https://doc.rust-lang.org/stable/core/ptr/fn.dangling.html)
-   [`core::ptr::dangling_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.dangling_mut.html)

These APIs are now stable in const contexts

-   [`AtomicBool::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicBool.html#method.from_ptr)
-   [`AtomicPtr::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicPtr.html#method.from_ptr)
-   [`AtomicU8::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU8.html#method.from_ptr)
-   [`AtomicU16::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU16.html#method.from_ptr)
-   [`AtomicU32::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU32.html#method.from_ptr)
-   [`AtomicU64::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU64.html#method.from_ptr)
-   [`AtomicUsize::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicUsize.html#method.from_ptr)
-   [`AtomicI8::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI8.html#method.from_ptr)
-   [`AtomicI16::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI16.html#method.from_ptr)
-   [`AtomicI32::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI32.html#method.from_ptr)
-   [`AtomicI64::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI64.html#method.from_ptr)
-   [`AtomicIsize::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicIsize.html#method.from_ptr)
-   [`<ptr>::is_null`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.is_null-1)
-   [`<ptr>::as_ref`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.as_ref-1)
-   [`<ptr>::as_mut`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.as_mut)
-   [`Pin::new`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.new)
-   [`Pin::new_unchecked`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.new_unchecked)
-   [`Pin::get_ref`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.get_ref)
-   [`Pin::into_ref`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.into_ref)
-   [`Pin::get_mut`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.get_mut)
-   [`Pin::get_unchecked_mut`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.get_unchecked_mut)
-   [`Pin::static_ref`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.static_ref)
-   [`Pin::static_mut`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.static_mut)

<a id="1.84.0-Cargo"></a>

## Cargo

-   [Stabilize MSRV-aware resolver config](https://redirect.github.com/rust-lang/cargo/pull/14639/)
-   [Stabilize resolver v3](https://redirect.github.com/rust-lang/cargo/pull/14754/)

<a id="1.84-Rustdoc"></a>

## Rustdoc

-   [rustdoc-search: improve type-driven search](https://redirect.github.com/rust-lang/rust/pull/127589)

<a id="1.84.0-Compatibility-Notes"></a>

## Compatibility Notes

-   [Enable by default the `LSX` target feature for LoongArch Linux targets](https://redirect.github.com/rust-lang/rust/pull/132140)
-   [The unstable `-Zprofile` flag (“gcov-style” coverage instrumentation) has been removed.](https://redirect.github.com/rust-lang/rust/pull/131829) This does not affect the stable flags for coverage instrumentation (`-Cinstrument-coverage`) and profile-guided optimization (`-Cprofile-generate`, `-Cprofile-use`), which are unrelated and remain available.
-   Support for the target named `wasm32-wasi` has been removed as the target is now named `wasm32-wasip1`. This completes the [transition](https://redirect.github.com/rust-lang/compiler-team/issues/607) [plan](https://redirect.github.com/rust-lang/compiler-team/issues/695) for this target following [the introduction of `wasm32-wasip1`](https://redirect.github.com/rust-lang/rust/pull/120468) in Rust 1.78. Compiler warnings on [use of `wasm32-wasi`](https://redirect.github.com/rust-lang/rust/pull/126662) introduced in Rust 1.81 are now gone as well as the target is removed.
-   [The syntax `&pin (mut|const) T` is now parsed as a type which in theory could affect macro expansion results in some edge cases](https://redirect.github.com/rust-lang/rust/pull/130635#issuecomment-2375462821)
-   [Legacy syntax for calling `std::arch` functions is no longer permitted to declare items or bodies (such as closures, inline consts, or async blocks).](https://redirect.github.com/rust-lang/rust/pull/130443#issuecomment-2445678945)
-   The `wasm32-unknown-emscripten` target's binary release of the standard library is now [built with the latest emsdk 3.1.68](https://redirect.github.com/rust-lang/rust/pull/131533), which fixes an ABI-incompatibility with Emscripten >= 3.1.42. If you are locally using a version of emsdk with an incompatible ABI (e.g. before 3.1.42 or a future one), you should build your code with `-Zbuild-std` to ensure that `std` uses the correct ABI.
-   [Declaring functions with a calling convention not supported on the current target now triggers a hard error](https://redirect.github.com/rust-lang/rust/pull/129935)
-   [The next-generation trait solver is now enabled for coherence, fixing multiple soundness issues](https://redirect.github.com/rust-lang/rust/pull/130654)

</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:eyJjcmVhdGVkSW5WZXIiOiIzOS45Mi4wIiwidXBkYXRlZEluVmVyIjoiMzkuOTIuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
2025-01-09 18:11:17 +00:00
Dunqing
3feac2711b fix(transformer/arrow-functions): outer super() in nested class (#8382) 2025-01-09 17:54:06 +00:00
overlookmotel
0df18667ea fix(transformer/typescript): create Reference for require (#8355)
Create a `Reference` when generating new `IdentifierReference` for `require`.
2025-01-09 16:50:46 +00:00
overlookmotel
6c7acac72e feat(allocator): implement IntoIterator for &mut Vec (#8389)
Implement `IntoIterator` for `&mut Vec` like `std::vec::Vec` does. This allows shorter and more idiomatic syntax.

Before:

```rs
for item in object.collection.iter_mut() {
  // ...
}
```

After:

```rs
for item in &mut object.collection {
  // ...
}
```
2025-01-09 15:32:16 +00:00
overlookmotel
eb25bc0ec6 fix(allocator): fix lifetimes on IntoIterator for Vec (#8388)
Lifetime on our impl of `IntoIterator` for `&Vec` was wrong.

Previously:

```rs
impl<'alloc, T> IntoIterator for &'alloc Vec<'alloc, T> {
    type IntoIter = std::slice::Iter<'alloc, T>;
    type Item = &'alloc T;
    fn into_iter(self) -> Self::IntoIter { self.0.iter() }
}
```

This means that the iterator borrows the `Vec` for the lifetime of the allocator, which is way too long. It should only borrow it for the lifetime of the reference `&Vec`. Insisting we borrow the `Vec` for so long to iterate over it was unnecessarily restrictive.

Instead:

```rs
impl<'i, T> IntoIterator for &'i Vec<'_, T> {
    type IntoIter = std::slice::Iter<'i, T>;
    type Item = &'i T;
    fn into_iter(self) -> Self::IntoIter { self.0.iter() }
}
```

This matches the lifetimes on [`allocator_api2::vec::Vec`'s implementation](63cd7fcc2f/src/stable/vec/mod.rs (L2682-L2690)).
2025-01-09 15:32:15 +00:00
Alexander S.
b19d809be3
refactor(linter): split unicorn/prefer-spread and eslint/prefer-spread into own rules (#8329)
closes #7948
2025-01-09 14:28:36 +00:00
overlookmotel
dddbd299d0 refactor(transformer/arrow-functions): reorder assertions (#8386)
Nit. Group assertions about the same thing together.
2025-01-09 12:23:54 +00:00
Dunqing
335065d8c8 fix(transformer/arrow-functions): do not transform super that inside nested non-async method (#8335)
This `super.value` belongs to the nested class, we shouldn't transform it.
```js
class Outer {
    async method() {
      class Inner extends Outer {
        normal() {
          // `super.value` should not be transformed, because it is not in an async method
          super.value
        }
      }
    }
 }
```
2025-01-09 11:41:20 +00:00
camc314
793cb43138 feat(minifier): a != null ? a : b -> a ?? b (#8352) 2025-01-09 10:12:52 +00:00
Boshen
1c4658d617 refactor(minifier): change ast passes order, !in_fixed_loop happen last (#8380) 2025-01-09 07:45:20 +00:00
Boshen
c0a3ddac28 fix(minifier): instanceof has error throwing side effect (#8378) 2025-01-09 06:49:27 +00:00
Yuji Sugiura
c1c0d71162
refactor(prettier): Make hardline! to return Doc (#8379)
For cleaner Doc construction.
2025-01-09 14:48:52 +08:00
Dunqing
0903501a98 refactor(semantic): check super usage based on scope (#8377)
No stronger opinion on both implementations, I just think the scope-based is clearer, and iterating over scope is always faster than node. The only bad point in this implementation we don't have specific ScopeFlags for class methods, thus we need to check if the parent of the function is a `MethodDefinition`
2025-01-09 06:38:09 +00:00
Dunqing
79a8fc6f7d fix(semantic): report error for super property appearing in function body (#8376)
Missing error that super property inside plain function.

```js
class C {
  constructor() {
    function g() {
      // * It is a Syntax Error if PropName of MethodDefinition is not "constructor" and HasDirectSuper of MethodDefinition is true.
      super();
    }
  }
  method() {
    function func() {
      // It is a Syntax Error if FunctionBody Contains SuperProperty is true.
      super.good();
    }
  }
}
```

I am not sure why test262 doesn't cover tests like that
2025-01-09 06:38:09 +00:00
Boshen
5516f7fcb9 fix(minifier): do not fold object comparisons (#8375) 2025-01-09 05:47:35 +00:00
Boshen
a1752a062c fix(codegen): fix incorrect minified return 1n output (#8374) 2025-01-09 05:01:41 +00:00
Boshen
cb098c7d3c fix(minifier): computed property key prototype cannot be changed (#8373) 2025-01-09 04:24:03 +00:00
Boshen
82ee77ef19 fix(minifier): do not remove shadowned undefined in return statement (#8371)
closes #8370
2025-01-09 04:03:18 +00:00
sapphi-red
814da55f81
feat(minifier): compress x = x || 1 to x ||= 1 (#8368)
The simplified version of the evaluation of `a = a || b` is:

> AssignmentExpression : LeftHandSideExpression = LogicalORExpression || LogicalANDExpression
> 1. Let lRef be ? Evaluation of LeftHandSideExpression.
> 2. Let llRef be ? Evaluation of LogicalORExpression.
> 3. Let llVal be ? GetValue(llRef).
> 4. If ToBoolean(llVal) is true
>   a. Perform ? PutValue(lRef, llVal).
>   b. return llVal.
> 5. Let lrRef be ? Evaluation of LogicalANDExpression.
> 6. Let rRef be ? GetValue(lrRef).
> 7. Let rVal be ? GetValue(rRef). [Note GetValue(rRef) returns rRef itself]
> 8. Perform ? PutValue(lRef, rVal).
> 9. Return rVal.

The simplified version of the evaluation of `a ||= b` is:

> AssignmentExpression : LeftHandSideExpression ||= AssignmentExpression
> 1. Let lRef be ? Evaluation of LeftHandSideExpression.
> 2. Let lVal be ? GetValue(lRef).
> 3. If ToBoolean(lVal) is true, return lVal.
> 4. Let rRef be ? Evaluation of AssignmentExpression.
> 5. Let rVal be ? GetValue(rRef).
> 6. Perform ? PutValue(lRef, rVal).
> 7. Return rVal.

The difference of these is that

- the evaluation of `a` is done twice for `a = a || b`, one with `1. Let lRef be ? Evaluation of LeftHandSideExpression` and one with `2. Let llRef be ? Evaluation of LogicalORExpression.`. This is same with #8366, #8367.
- `PutValue(lRef, llVal)` is performed when `ToBoolean(lVal)` is `true`.

So `x = x || 1` can be compressed to `x ||= 1` when the conditions written in #8366 are met and `PutValue(lRef, llVal)` does not have a side effect. When `a` is a non-global identifier (and not a reference created by a `with` statement), these conditions are met.

**References**
- [Spec of `||`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-binary-logical-operators-runtime-semantics-evaluation)
- [Spec of `=` / `||=`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-binary-logical-operators-runtime-semantics-evaluation)
2025-01-09 03:47:12 +00:00
sapphi-red
a596821d85
feat(minifier): compress a.b = a.b + c to a.b += c (#8367)
The simplified version of the evaluation of `a += b` is:

> AssignmentExpression : LeftHandSideExpression AssignmentOperator AssignmentExpression
> 1. Let lRef be ? Evaluation of LeftHandSideExpression.
> 2. Let lVal be ? GetValue(lRef).
> 3. Let rRef be ? Evaluation of AssignmentExpression.
> 4. Let rVal be ? GetValue(rRef).
> 5. Let r be ? ApplyStringOrNumericBinaryOperator(lVal, opText, rVal).
> 6. Perform ? PutValue(lRef, r).
> 7. Return r.

The simplified version of the evaluation of `a = a + b` is:

> AssignmentExpression : LeftHandSideExpression = AssignmentExpressionLeft + AssignmentExpressionRight
> 1. Let lRef be ? Evaluation of LeftHandSideExpression.
> 2. Let alRef be ? Evaluation of AssignmentExpressionLeft.
> 3. Let alVal be ? GetValue(alRef).
> 4. Let arRef be ? Evaluation of AssignmentExpressionRight.
> 5. Let arVal be ? GetValue(arRef).
> 6. Let rRef be ? ApplyStringOrNumericBinaryOperator(alVal, opText, arVal).
> 7. Let rVal be ? GetValue(rRef). [Note GetValue(rRef) returns rRef itself]
> 8. Perform ? PutValue(lRef, rVal).
> 9. Return rVal.

The difference of these is that the evaluation of `a` is done twice for `a = a + b`, one with `1. Let lRef be ? Evaluation of LeftHandSideExpression` and one with `2. Let alRef be ? Evaluation of AssignmentExpressionLeft.`

So this is same with #8366 and can be compressed similarly when the conditions are met (`a.b = a.b + c` -> `a.b += c`).

**References**
- [Spec of `=`, `+=`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-assignment-operators-runtime-semantics-evaluation)
- [Spec of `+`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-addition-operator-plus-runtime-semantics-evaluation)
2025-01-09 03:47:11 +00:00
sapphi-red
579eb603d5
feat(minifier): compress a.b || (a.b = c) to a.b ||= c (#8366)
As noted in https://github.com/oxc-project/oxc/pull/8315, the only difference of `x ||= y` and `x || (x = y)` is that `Let lRef be ? Evaluation of LeftHandSideExpression` is done twice.

If the LeftHandSideExpression is a MemberExpression, `GetValue(baseReference)` is the only place that might have a side effect. Further more, if the `baseReference` is an IdentifierReference that is not a global reference (and not a reference created by a `with` statement), `GetValue(baseReference)` does not have a side effect.

When those conditions are met, `a.b || (a.b = c)` can be compress to `a.b ||= c`.

**References**
- [Spec of `a.b`](<https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-property-accessors-runtime-semantics-evaluation:~:text=%2C%20strict).-,MemberExpression,4.%20Return%20MakePrivateReference(baseValue%2C%20fieldNameString).,-CallExpression>)
- [Spec of `GetValue`](https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-getvalue)
- [Spec of `IdentifierReference`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-identifiers-runtime-semantics-evaluation)
-  [Spec of `DeclarativeEnvironmentRecord.GetBindingValue`](https://tc39.es/ecma262/multipage/executable-code-and-execution-contexts.html#sec-declarative-environment-records-getbindingvalue-n-s)
2025-01-09 03:47:10 +00:00
overlookmotel
aa5e65ff3c refactor(transformer/private-methods): simplify finding parent statement of class expression (#8364)
Pure refactor. Simplify code a little.
2025-01-09 03:17:41 +00:00
overlookmotel
c786fd1add refactor(transformer/private-methods): TODO comments (#8363) 2025-01-09 03:17:40 +00:00
overlookmotel
ac72adbade fix(transformer/private-methods): fix panic if instance private accessor in class (#8362)
Fix panic if a private accessor is present in class which also has property. e.g.:

```js
let C = class C {
  prop = 1;
  accessor #private = 2;
};
```

Panic occurred due to trying to unwrap `brand` property, but it's `None` because no private instance methods in the class.
2025-01-09 03:17:39 +00:00
overlookmotel
f1f129b09d fix(transformer/private-methods): create brand binding var in hoist scope (#8361)
Brand binding is a `var`, so is bound in hoist scope.
2025-01-09 03:17:38 +00:00
overlookmotel
ab6142503f fix(transformer/private-methods): no temp var for class when unused private methods (#8360)
No temp var is required for class if it contains static private method which is not referenced within class. e.g.:

```js
let C = class {
  static #method() {}
};
```

->

```js
let C = class {};
function _method() {}
```
2025-01-09 03:17:37 +00:00
camc314
f367a16364 feat(minifier): port esbuild conditional expr minification (#8351)
still some TODOs, but the main framework is there
2025-01-09 02:49:33 +00:00
Boshen
09f0f483f6 refactor(minifier): remove the buggy minimize_exit_points implementation (#8349) 2025-01-09 02:49:32 +00:00
翠 / green
3ba0b5316d
chore(tasks/coverage): fix test262 cases to run on windows (#8358)
`skip_test_path` was not working on windows because the path included
`\\`.
2025-01-09 10:48:37 +08:00
Alexander S.
b6c1546d07
test(linter): use plugin name instead of category for finding rule (#8353)
needed for #8329

I wanted to use `proc_macro::Span::SourceFile` to auto detect the plugin
name. But this feature is unstable :/
2025-01-09 10:48:11 +08:00
overlookmotel
78d7c97357 fix(transformer/typescript): create Reference for Infinity (#8354)
Create a `Reference` when generating new `IdentifierReference` for `Infinity`.
2025-01-09 02:26:33 +00:00
overlookmotel
6790d1d219 refactor(transformer/class-properties): simplify determining if class is declaration (#8357)
Small improvement. Use `Class::type` field to determine if class is declaration/expression. Not sure why it did it in such a complicated way previously!
2025-01-09 02:20:50 +00:00
Dunqing
e4d66e4636 fix(transformer/arrow-functions): store super_methods on a Stack to fix nested async methods (#8331)
In the following case, async methods can be nested in another async method. The implementation is changing to store `super_methods` on a stack, and then we can store super method information in the correct `super_methods` map.

```js
const outer = {
  value: 0,
  async method() {
    () => super.value;

    const inner = {
      value: 0,
      async method() {
        () => super.value;
      }
    };

    () => super.value;
  }
};
```
2025-01-08 21:00:45 +00:00
overlookmotel
e0a09ab023 docs(data_structures): improve docs for stack types (#8356)
Improve docs for `Stack`, `NonEmptyStack` and `SparseStack`.
2025-01-08 20:49:28 +00:00
Dunqing
fb389f724a refactor(transformer/arrow-function): create a new ident instead of clone (#8338)
There seems no reason to use a cloned identifier.
2025-01-08 19:43:53 +00:00