enhance compress on arrow and async functions (#4616)

This commit is contained in:
Alex Lam S.L
2021-02-06 04:39:46 +00:00
committed by GitHub
parent 739fa266f8
commit 5359900b78
5 changed files with 232 additions and 8 deletions

View File

@@ -434,6 +434,46 @@ collapse_value: {
node_version: ">=4"
}
collapse_property_lambda: {
options = {
collapse_vars: true,
pure_getters: "strict",
}
input: {
console.log(function f() {
f.g = () => 42;
return f.g();
}());
}
expect: {
console.log(function f() {
return (f.g = () => 42)();
}());
}
expect_stdout: "42"
node_version: ">=4"
}
drop_return: {
options = {
side_effects: true,
}
input: {
(a => {
while (!console);
return console.log(a);
})(42);
}
expect: {
(a => {
while (!console);
console.log(a);
})(42);
}
expect_stdout: "42"
node_version: ">=4"
}
reduce_iife_1: {
options = {
evaluate: true,

View File

@@ -519,6 +519,160 @@ collapse_vars_3: {
node_version: ">=8"
}
collapse_property_lambda: {
options = {
collapse_vars: true,
pure_getters: "strict",
}
input: {
(async function f() {
f.g = () => 42;
return f.g();
})().then(console.log);
}
expect: {
(async function f() {
return (f.g = () => 42)();
})().then(console.log);
}
expect_stdout: "42"
node_version: ">=8"
}
drop_return: {
options = {
side_effects: true,
}
input: {
(async function(a) {
while (!console);
return console.log(a);
})(42);
}
expect: {
(async function(a) {
while (!console);
console.log(a);
})(42);
}
expect_stdout: "42"
node_version: ">=8"
}
functions: {
options = {
functions: true,
reduce_vars: true,
unused: true,
}
input: {
!async function() {
var a = async function a() {
return a && "a";
};
var b = async function x() {
return !!x;
};
var c = async function(c) {
return c;
};
if (await c(await b(await a()))) {
var d = async function() {};
var e = async function y() {
return typeof y;
};
var f = async function(f) {
return f;
};
console.log(await a(await d()), await b(await e()), await c(await f(42)), typeof d, await e(), typeof f);
}
}();
}
expect: {
!async function() {
async function a() {
return a && "a";
}
async function b() {
return !!b;
}
var c = async function(c) {
return c;
};
if (await c(await b(await a()))) {
async function d() {}
async function e() {
return typeof e;
}
var f = async function(f) {
return f;
};
console.log(await a(await d()), await b(await e()), await c(await f(42)), typeof d, await e(), typeof f);
}
}();
}
expect_stdout: "a true 42 function function function"
node_version: ">=8"
}
functions_use_strict: {
options = {
functions: true,
reduce_vars: true,
unused: true,
}
input: {
"use strict";
!async function() {
var a = async function a() {
return a && "a";
};
var b = async function x() {
return !!x;
};
var c = async function(c) {
return c;
};
if (await c(await b(await a()))) {
var d = async function() {};
var e = async function y() {
return typeof y;
};
var f = async function(f) {
return f;
};
console.log(await a(await d()), await b(await e()), await c(await f(42)), typeof d, await e(), typeof f);
}
}();
}
expect: {
"use strict";
!async function() {
async function a() {
return a && "a";
}
async function b() {
return !!b;
}
var c = async function(c) {
return c;
};
if (await c(await b(await a()))) {
var d = async function() {};
var e = async function y() {
return typeof y;
};
var f = async function(f) {
return f;
};
console.log(await a(await d()), await b(await e()), await c(await f(42)), typeof d, await e(), typeof f);
}
}();
}
expect_stdout: "a true 42 function function function"
node_version: ">=8"
}
issue_4335_1: {
options = {
inline: true,

View File

@@ -703,6 +703,7 @@ prototype_function: {
var g = 0();
var h = 0();
}
expect_stdout: true
}
call_args: {
@@ -2800,7 +2801,7 @@ operator_in: {
console.log("PASS" in { });
console.log("FAIL" in { });
console.log("toString" in { });
console.log(true);
console.log("toString" in { toString: 3 });
}
expect_stdout: [
"true",

View File

@@ -248,6 +248,35 @@ issue_2110_2: {
expect_stdout: "function"
}
issue_2110_3: {
options = {
collapse_vars: true,
pure_getters: "strict",
reduce_vars: true,
}
input: {
function g() {
return this;
}
console.log(typeof function() {
function f() {}
f.g = g;
return f.g();
}());
}
expect: {
function g() {
return this;
}
console.log(typeof function() {
function f() {}
f.g = g;
return f.g();
}());
}
expect_stdout: "function"
}
set_immutable_1: {
options = {
collapse_vars: true,