mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 18:31:35 +03:00
fix(es/minifier): typeof
class should be function
(#9522)
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
**Related issue:** Closes https://github.com/swc-project/swc/issues/9453
This commit is contained in:
parent
6bdc4f7e5e
commit
c7fdd6b69b
6
.changeset/six-hounds-hammer.md
Normal file
6
.changeset/six-hounds-hammer.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
swc_core: patch
|
||||
swc_ecma_minifier: patch
|
||||
---
|
||||
|
||||
fix(es/minifier): typeof class should be function rather than object
|
@ -156,7 +156,7 @@ impl Optimizer<'_> {
|
||||
|
||||
if !usage.reassigned {
|
||||
match init {
|
||||
Expr::Fn(..) | Expr::Arrow(..) => {
|
||||
Expr::Fn(..) | Expr::Arrow(..) | Expr::Class(..) => {
|
||||
self.typeofs.insert(ident.to_id(), "function".into());
|
||||
}
|
||||
Expr::Array(..) | Expr::Object(..) => {
|
||||
@ -569,12 +569,9 @@ impl Optimizer<'_> {
|
||||
if !usage.reassigned {
|
||||
trace_op!("typeofs: Storing typeof `{}{:?}`", i.sym, i.ctxt);
|
||||
match &*decl {
|
||||
Decl::Fn(..) => {
|
||||
Decl::Fn(..) | Decl::Class(..) => {
|
||||
self.typeofs.insert(i.to_id(), "function".into());
|
||||
}
|
||||
Decl::Class(..) => {
|
||||
self.typeofs.insert(i.to_id(), "object".into());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ impl Optimizer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Arrow(..) | Expr::Fn(..) => {
|
||||
Expr::Arrow(..) | Expr::Fn(..) | Expr::Class(..) => {
|
||||
report_change!("Converting typeof to 'function' as we know the value");
|
||||
self.changed = true;
|
||||
*e = Lit::Str(Str {
|
||||
|
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
class x {}
|
||||
const y = x;
|
||||
const z = class {};
|
||||
console.log(typeof x);
|
||||
console.log(typeof y);
|
||||
console.log(typeof z);
|
||||
console.log(typeof class {});
|
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
console.log("function"), console.log("function"), console.log("function"), console.log("function");
|
Loading…
Reference in New Issue
Block a user