Don't change sequences that influence lexical binding in calls
Fixes #782
This commit is contained in:
@@ -1910,15 +1910,11 @@ merge(Compressor.prototype, {
|
|||||||
if (!compressor.option("side_effects"))
|
if (!compressor.option("side_effects"))
|
||||||
return self;
|
return self;
|
||||||
if (!self.car.has_side_effects(compressor)) {
|
if (!self.car.has_side_effects(compressor)) {
|
||||||
// we shouldn't compress (1,eval)(something) to
|
// we shouldn't compress (1,func)(something) to
|
||||||
// eval(something) because that changes the meaning of
|
// func(something) because that changes the meaning of
|
||||||
// eval (becomes lexical instead of global).
|
// the func (becomes lexical instead of global).
|
||||||
var p;
|
var p = compressor.parent();
|
||||||
if (!(self.cdr instanceof AST_SymbolRef
|
if (!(p instanceof AST_Call && p.expression === self)) {
|
||||||
&& self.cdr.name == "eval"
|
|
||||||
&& self.cdr.undeclared()
|
|
||||||
&& (p = compressor.parent()) instanceof AST_Call
|
|
||||||
&& p.expression === self)) {
|
|
||||||
return self.cdr;
|
return self.cdr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
test/compress/issue-782.js
Normal file
23
test/compress/issue-782.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
remove_redundant_sequence_items: {
|
||||||
|
options = { side_effects: true };
|
||||||
|
input: {
|
||||||
|
(0, 1, logThis)();
|
||||||
|
(0, 1, _decorators.logThis)();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(0, logThis)();
|
||||||
|
(0, _decorators.logThis)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dont_remove_lexical_binding_sequence: {
|
||||||
|
options = { side_effects: true };
|
||||||
|
input: {
|
||||||
|
(0, logThis)();
|
||||||
|
(0, _decorators.logThis)();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(0, logThis)();
|
||||||
|
(0, _decorators.logThis)();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user