enhance unused (#5511)

This commit is contained in:
Alex Lam S.L
2022-06-12 14:24:42 +01:00
committed by GitHub
parent 5d69545299
commit b6f250f5c9
4 changed files with 239 additions and 11 deletions

View File

@@ -1283,6 +1283,88 @@ instanceof_lambda: {
node_version: ">=4"
}
drop_instanceof: {
options = {
booleans: true,
toplevel: true,
unused: true,
}
input: {
"use strict";
class A {}
console.log({} instanceof A, Math instanceof A);
}
expect: {
"use strict";
console.log(!1, (Math, !1));
}
expect_stdout: "false false"
node_version: ">=4"
}
keep_instanceof_1: {
options = {
toplevel: true,
unused: true,
}
input: {
"use strict";
class A {}
var A;
console.log({} instanceof A, Math instanceof A);
}
expect: {
"use strict";
class A {}
var A;
console.log({} instanceof A, Math instanceof A);
}
expect_stdout: SyntaxError("Identifier has already been declared")
node_version: ">=4"
}
keep_instanceof_2: {
options = {
toplevel: true,
unused: true,
}
input: {
"use strict";
var A = Object;
class A {}
console.log({} instanceof A, Math instanceof A);
}
expect: {
"use strict";
var A = Object;
class A {}
console.log({} instanceof A, Math instanceof A);
}
expect_stdout: SyntaxError("Identifier has already been declared")
node_version: ">=4"
}
keep_instanceof_3: {
options = {
toplevel: true,
unused: true,
}
input: {
"use strict";
class A {}
A = Object;
console.log({} instanceof A, Math instanceof A);
}
expect: {
"use strict";
class A {}
A = Object;
console.log({} instanceof A, Math instanceof A);
}
expect_stdout: "true true"
node_version: ">=4"
}
issue_805_1: {
options = {
inline: true,

View File

@@ -671,6 +671,76 @@ iife: {
}
}
drop_instanceof: {
options = {
booleans: true,
toplevel: true,
unused: true,
}
input: {
function f() {}
console.log({} instanceof f, Math instanceof f);
}
expect: {
console.log(!1, (Math, !1));
}
expect_stdout: "false false"
}
keep_instanceof_1: {
options = {
toplevel: true,
unused: true,
}
input: {
function f() {}
var f;
console.log({} instanceof f, Math instanceof f);
}
expect: {
function f() {}
var f;
console.log({} instanceof f, Math instanceof f);
}
expect_stdout: "false false"
}
keep_instanceof_2: {
options = {
toplevel: true,
unused: true,
}
input: {
function f() {}
var f = Object;
console.log({} instanceof f, Math instanceof f);
}
expect: {
function f() {}
var f = Object;
console.log({} instanceof f, Math instanceof f);
}
expect_stdout: "true true"
}
keep_instanceof_3: {
options = {
toplevel: true,
unused: true,
}
input: {
f = Object;
function f() {}
console.log({} instanceof f, Math instanceof f);
}
expect: {
f = Object;
function f() {}
console.log({} instanceof f, Math instanceof f);
}
expect_stdout: "true true"
}
issue_1539: {
options = {
collapse_vars: true,

View File

@@ -417,6 +417,46 @@ hoist_funs: {
expect_exact: "export function f(){}export default async function*g(){}"
}
instanceof_default_class: {
options = {
toplevel: true,
unused: true,
}
input: {
export default class A {
f(a) {
return a instanceof A;
}
}
}
expect: {
export default class A {
f(a) {
return a instanceof A;
}
}
}
}
instanceof_default_function: {
options = {
toplevel: true,
unused: true,
}
input: {
export default function f() {
if (!(this instanceof f))
throw new Error("must instantiate");
}
}
expect: {
export default function f() {
if (!(this instanceof f))
throw new Error("must instantiate");
}
}
}
issue_4742_join_vars_1: {
options = {
join_vars: true,