fix corner cases in arrow functions & rests (#4667)

fixes #4666
This commit is contained in:
Alex Lam S.L
2021-02-19 00:26:57 +00:00
committed by GitHub
parent 10de27ca3d
commit 5f60c1b830
4 changed files with 41 additions and 3 deletions

View File

@@ -762,10 +762,11 @@ merge(Compressor.prototype, {
return arg || make_node(AST_Undefined, iife);
}, visit);
});
if (fn.rest) scan_declaration(tw, compressor, fn.rest, compressor.option("rests") && function() {
return make_node(AST_Array, fn, {
var rest = fn.rest;
if (rest) scan_declaration(tw, compressor, rest, compressor.option("rests") && function() {
return fn.rest === rest ? make_node(AST_Array, fn, {
elements: iife.args.slice(fn.argnames.length),
});
}) : rest;
}, visit);
walk_lambda(fn, tw);
var safe_ids = tw.safe_ids;

View File

@@ -1198,6 +1198,7 @@ function parse($TEXT, options) {
}
} else {
body = [];
handle_regexp();
value = maybe_assign();
}
S.input.pop_directives_stack();

View File

@@ -694,3 +694,12 @@ issue_4476: {
expect_stdout: "foo bar"
node_version: ">=4"
}
issue_4666: {
input: {
console.log((a => /[0-9]/.test(a))(42));
}
expect_exact: "console.log((a=>/[0-9]/.test(a))(42));"
expect_stdout: "true"
node_version: ">=4"
}

View File

@@ -757,3 +757,30 @@ issue_4644_2: {
expect_stdout: "PASS 0 undefined"
node_version: ">=6"
}
issue_4666: {
options = {
evaluate: true,
reduce_vars: true,
rests: true,
toplevel: true,
unsafe: true,
unused: true,
}
input: {
var a = 0, b = 0;
var o = ((...c) => a++ + c)(b);
for (var k in o)
b++;
console.log(a, b);
}
expect: {
var a = 0, b = 0;
var o = (c => +a + c)([ b ]);
for(var k in o)
b++;
console.log(1, b);
}
expect_stdout: "1 2"
node_version: ">=6"
}