fix corner cases in rests & unused (#5063)
This commit is contained in:
@@ -5507,7 +5507,7 @@ merge(Compressor.prototype, {
|
|||||||
if (!(fn.rest instanceof AST_DestructuredArray)) return;
|
if (!(fn.rest instanceof AST_DestructuredArray)) return;
|
||||||
if (!compressor.drop_fargs(fn, compressor.parent())) return;
|
if (!compressor.drop_fargs(fn, compressor.parent())) return;
|
||||||
fn.argnames = fn.argnames.concat(fn.rest.elements);
|
fn.argnames = fn.argnames.concat(fn.rest.elements);
|
||||||
fn.rest = null;
|
fn.rest = fn.rest.rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPT(AST_Lambda, function(self, compressor) {
|
OPT(AST_Lambda, function(self, compressor) {
|
||||||
@@ -6428,12 +6428,16 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
if (!(node instanceof AST_Accessor)) {
|
if (!(node instanceof AST_Accessor)) {
|
||||||
if (node.rest) {
|
if (node.rest) {
|
||||||
node.rest = node.rest.transform(trimmer);
|
var rest = node.rest.transform(trimmer);
|
||||||
if (!(node.uses_arguments && !tt.has_directive("use strict"))
|
if (rest instanceof AST_Destructured && !rest.rest
|
||||||
&& (node.rest instanceof AST_DestructuredArray && node.rest.elements.length == 0
|
&& (!node.uses_arguments || tt.has_directive("use strict"))) {
|
||||||
|| node.rest instanceof AST_DestructuredObject && node.rest.properties.length == 0)) {
|
if (rest instanceof AST_DestructuredArray) {
|
||||||
node.rest = null;
|
if (rest.elements.length == 0) rest = null;
|
||||||
|
} else if (rest.properties.length == 0) {
|
||||||
|
rest = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
node.rest = rest;
|
||||||
}
|
}
|
||||||
var argnames = node.argnames;
|
var argnames = node.argnames;
|
||||||
var trim = compressor.drop_fargs(node, parent) && !node.rest;
|
var trim = compressor.drop_fargs(node, parent) && !node.rest;
|
||||||
@@ -12125,7 +12129,7 @@ merge(Compressor.prototype, {
|
|||||||
OPT(AST_DestructuredArray, function(self, compressor) {
|
OPT(AST_DestructuredArray, function(self, compressor) {
|
||||||
if (compressor.option("rests") && self.rest instanceof AST_DestructuredArray) {
|
if (compressor.option("rests") && self.rest instanceof AST_DestructuredArray) {
|
||||||
self.elements = self.elements.concat(self.rest.elements);
|
self.elements = self.elements.concat(self.rest.elements);
|
||||||
self.rest = null;
|
self.rest = self.rest.rest;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -491,7 +491,7 @@ drop_rest_array: {
|
|||||||
rests: true,
|
rests: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var [ ...[ a ]] = [ "PASS" ];
|
var [ ...[ a ] ] = [ "PASS" ];
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
@@ -542,6 +542,82 @@ drop_rest_lambda: {
|
|||||||
node_version: ">=6"
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keep_rest_array: {
|
||||||
|
options = {
|
||||||
|
rests: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var [ ...[ ...a ] ] = "PASS";
|
||||||
|
console.log(a.join(""));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var [ ...a ] = "PASS";
|
||||||
|
console.log(a.join(""));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
keep_rest_arrow: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
rests: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(((...[ ...a ]) => a.join(""))("PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(((...a) => a.join(""))("PASS"));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
keep_rest_lambda_1: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
rests: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(...[ ...a ]) {
|
||||||
|
return a.join("");
|
||||||
|
}
|
||||||
|
console.log(f("PASS"), f([ 42 ]));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(...a) {
|
||||||
|
return a.join("");
|
||||||
|
}
|
||||||
|
console.log(f("PASS"), f([ 42 ]));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 42"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
keep_rest_lambda_2: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(...[ ...a ]) {
|
||||||
|
return a.join("");
|
||||||
|
}
|
||||||
|
console.log(f("PASS"), f([ 42 ]));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(...[ ...a ]) {
|
||||||
|
return a.join("");
|
||||||
|
}
|
||||||
|
console.log(f("PASS"), f([ 42 ]));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 42"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
issue_4525_1: {
|
issue_4525_1: {
|
||||||
options = {
|
options = {
|
||||||
arguments: true,
|
arguments: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user