Commit graph

7739 commits

Author SHA1 Message Date
Boshen
3c9354983d fix(minifier): dce if statement should keep side effects and vars (#8433)
closes #7209

Note: Current output is sub-optimal.
2025-01-11 14:02:12 +00:00
Dunqing
9a03bd23b9 fix(transformer/typescript): remove type-only import = when only_remove_type_imports is true (#8275)
close: https://github.com/oxc-project/oxc/issues/8230
close: https://github.com/rolldown/rolldown/issues/3287

Related PR in Babel: https://github.com/oxc-project/oxc/issues/8230

I have compared our output with TypeScript, and it is the same as `TypeScript`, Babel's implementation currently hasn't removed imports referenced by type-only `TSImportEqualsDeclaration`
2025-01-11 08:42:51 +00:00
sapphi-red
d56020b84c
feat(minifier): drop 0 from new Int8Array(0) and other TypedArrays (#8431)
Compresses `new Int8Array(0)` into `new Int8Array()`. (then will be compress into `new Int8Array`).

Partial quote from the [spec](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-typedarray):

> 5. If numberOfArgs = 0, then
>   a. Return ? AllocateTypedArray(constructorName, NewTarget, proto, 0).
> 6. Else,
>   c. Else,
>       ii. Let elementLength be ? ToIndex(firstArgument).
>      iii. Return ? AllocateTypedArray(constructorName, NewTarget, proto, elementLength).
2025-01-11 07:45:36 +00:00
sapphi-red
f935d9434f
feat(minifier): remove new from NativeErrors / AggregateError (#8430)
Remove `new` in the some cases:

- NativeErrors (e.g. `new EvalError(...)` -> `EvalError(...)`): [spec](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-nativeerror-constructors:~:text=the%20function%20call%20NativeError(%E2%80%A6)%20is%20equivalent%20to%20the%20object%20creation%20expression%20new%20NativeError(%E2%80%A6)%20with%20the%20same%20arguments.), [the list of NativeErrors in spec](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-native-error-types-used-in-this-standard)
- `new AggregateError(...)` -> `AggregateError(...)`: [spec](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-aggregate-error-constructor:~:text=the%20function%20call%20AggregateError(%E2%80%A6)%20is%20equivalent%20to%20the%20object%20creation%20expression%20new%20AggregateError(%E2%80%A6)%20with%20the%20same%20arguments.)
2025-01-11 07:23:07 +00:00
overlookmotel
91b01345fc refactor(ast_tools): derives for ContentEq and ContentHash use same ignore list (#8427)
Pure refactor. Share the same field ignore list between the codegens for deriving `ContentEq` and `ContentHash` to prevent them getting out of sync.
2025-01-11 07:18:05 +00:00
Boshen
dab7a51e78 feat(minifier): minimize not !(x === undefined) -> x !== undefined (#8429) 2025-01-11 06:30:36 +00:00
overlookmotel
7f69561caf refactor(ast)!: oxc_ast do not export BigUint (#8428)
This is an artefact of the past. The AST no longer contains `BigUint`, so don't export it from `oxc_ast`.
2025-01-11 02:47:03 +00:00
overlookmotel
97a7992335 fix(ast): fix ContentEq and ContentHash impls for literal types (#8426)
Fix implementations of `ContentEq` and `ContentHash` for literal AST types:

* `NullLiteral::content_hash` is a no-op, same as other types which only contain a `Span`.
* `NumericLiteral::content_eq` and `content_hash` ignore `base` field.
* `NumericLiteral::content_hash` works around `0.0 == -0.0`.
* `BigIntLiteral::content_eq` and `content_hash` ignore `base` field.
* `StringLiteral::content_hash` ignore `raw` field.
* `RegExpLiteral::content_eq` and `content_hash` consider 2 `RegExp`s to be equal if they are printed the same (regardless of whether they were parsed by `oxc_regular_expression` or not).

Additionally, implement `StringLiteral::content_eq` manually to avoid "special case" logic in `oxc_ast_tools`.
2025-01-11 02:42:05 +00:00
overlookmotel
9c1844a8a7 refactor(data_structures): remove NonNull shim (#8423)
The `NonNull` shim in `oxc_data_structures` was just to emulate native APIs which only became stable in Rust 1.80.0. #8407 bumped our MSRV to 1.80.0, so now we can remove the shim and use `std::ptr::NonNull` directly.
2025-01-11 01:18:53 +00:00
camc314
52f88c0e9c fix(minifier): rotate associative operators to make it more idempotent (#8424)
another **massive** pain to debug

~~https://github.com/oxc-project/monitor-oxc/actions/runs/12717213600~~

https://github.com/oxc-project/monitor-oxc/actions/runs/12717978983/job/35455601146
2025-01-11 01:12:10 +00:00
camc314
a80460c6fe fix(minifier): correctly set self.changed when minimizing if stmts (#8420)
Before:

```
==== Input ====
require('./index.js')(function (e, os) {
  if (e) return console.log(e)
  return console.log(JSON.stringify(os))
})

==== First Minification
require("./index.js")(function(e, os) {
        return console.log(e ? e : JSON.stringify(os));
});

==== Second Minification ====
require("./index.js")(function(e, os) {
        return console.log(e || JSON.stringify(os));
});

same = false
```

After:
```
==== Input ====
require('./index.js')(function (e, os) {
  if (e) return console.log(e)
  return console.log(JSON.stringify(os))
})

==== First Minification ====
require("./index.js")(function(e, os) {
        return console.log(e || JSON.stringify(os));
});

==== Second Minification ====
require("./index.js")(function(e, os) {
        return console.log(e || JSON.stringify(os));
});

same = true
```
2025-01-11 01:12:09 +00:00
overlookmotel
b29655f7d9 refactor(ast): rearrange impls for literal types in same order as they are defined (#8425)
Pure refactor. Just move `impl StringLiteral` higher up in `ast_impl/literal.rs`, so the order of impls in `ast_impl/literal.rs` matches the order of type defs in `ast/literal.rs`.
2025-01-10 22:40:17 +00:00
Boshen
0e7bab887f feat(minifier): remove if(false){} in a single pass (#8421) 2025-01-10 16:22:09 +00:00
Boshen
d4ca8d4f5c fix(minifier): !!x is not idempotent in RemoveDeadCode (#8419) 2025-01-10 15:31:11 +00:00
Boshen
0550e81da6 chore(minifier): add oxc_minifier/examples/dce.rs (#8418) 2025-01-10 15:05:36 +00:00
Boshen
3212bcdaee feat(ast_tools): ignore raw field of NumericLiteral and StringLiteral in ContentEq (#8417)
We use `content_eq` in the minifier, where raw value can become `None`.

`raw` cannot be removed from other literals, they will always be equal otherwise.
2025-01-10 14:43:07 +00:00
Boshen
357b61d179 fix(minifier): do not minify Object.defineProperty in sequence expressions (#8416) 2025-01-10 12:04:39 +00:00
Boshen
5b5b8443f4
feat(minifier): fold ambiguous if else (#8415) 2025-01-10 19:51:31 +08:00
Boshen
fb2acd87b3 refactor(minifier): change minimize conditionals into a loop (#8413) 2025-01-10 09:49:09 +00:00
Boshen
baaec6020c refactor(minifier): remove the buggy ?? transform (#8411)
e.g. `(a != null ? a : b);` is not `a ?? b`

There are also no unit tests.
2025-01-10 09:33:09 +00:00
Yuji Sugiura
a93e27aca0
refactor(prettier): Verify current implementation with refactoring (#8412)
Part of #5068 

I think I will be able to grasp the current implementation status after
a few more iterations... 🏃🏻
2025-01-10 17:31:33 +08:00
Boshen
0efc845c97 fix(minifier): +0n produces TypeError (#8410) 2025-01-10 07:18:06 +00:00
翠 / green
5c63414c23
fix(mangler): keep exported symbols for top_level: true (#7927)
~~I'm not going to work on a fix for a while so feel free to fix it if
anyone wants to work on it.~~

Exported symbols are now not mangled.
2025-01-10 15:14:30 +08:00
Boshen
d15c856b13 chore(rust): update clippy rules (#8408) 2025-01-10 06:41:53 +00:00
Boshen
a006955fcb build(rust): incompatible-rust-versions = "fallback" + cargo update (#8407) 2025-01-10 06:41:51 +00:00
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