fix side_effects on AST_Expansion (#2165)

fixes #2163
This commit is contained in:
Alex Lam S.L
2017-06-27 01:13:00 +08:00
committed by GitHub
parent 26be15f111
commit ad139aa34d
3 changed files with 21 additions and 1 deletions

View File

@@ -345,7 +345,7 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
var AST_Expansion = DEFNODE("Expansion", "expression", {
$documentation: "An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list",
$propdoc: {
expression: "AST_Symbol the thing to be expanded"
expression: "[AST_Node] the thing to be expanded"
},
_walk: function(visitor) {
var self = this;

View File

@@ -2672,6 +2672,9 @@ merge(Compressor.prototype, {
if (expr) merge_sequence(expressions, expr);
return make_sequence(this, expressions);
});
def(AST_Expansion, function(compressor, first_in_statement){
return this.expression.drop_side_effect_free(compressor, first_in_statement);
});
})(function(node, func){
node.DEFMETHOD("drop_side_effect_free", func);
});

View File

@@ -1409,3 +1409,20 @@ issue_2136_3: {
expect_stdout: "2"
node_version: ">=6"
}
issue_2163: {
options = {
pure_funcs: [ "pure" ],
side_effects: true,
}
input: {
var c;
/*@__PURE__*/f(...a);
pure(b, ...c);
}
expect: {
var c;
a;
b;
}
}