add missing LHS cases which global_defs should avoid

This commit is contained in:
alexlamsl
2017-01-17 17:33:40 +08:00
committed by Richard van Velzen
parent ec2e5fa3a2
commit 48284844a4
3 changed files with 30 additions and 15 deletions

View File

@@ -970,6 +970,11 @@ merge(Compressor.prototype, {
node.DEFMETHOD("is_string", func);
});
function isLHS(node, parent) {
return parent instanceof AST_Unary && (parent.operator === "++" || parent.operator === "--")
|| parent instanceof AST_Assign && parent.left === node;
}
function best_of(ast1, ast2) {
return ast1.print_to_string().length >
ast2.print_to_string().length
@@ -2608,14 +2613,6 @@ merge(Compressor.prototype, {
});
OPT(AST_SymbolRef, function(self, compressor){
function isLHS(symbol, parent) {
return (
parent instanceof AST_Binary &&
parent.operator === '=' &&
parent.left === symbol
);
}
if (self.undeclared() && !isLHS(self, compressor.parent())) {
var defines = compressor.option("global_defs");
if (defines && HOP(defines, self.name)) {

View File

@@ -220,7 +220,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
sym = g;
}
node.thedef = sym;
if (parent instanceof AST_Unary && (parent.operator === '++' || parent.operator === '--')
if (parent instanceof AST_Unary && (parent.operator === "++" || parent.operator === "--")
|| parent instanceof AST_Assign && parent.left === node) {
sym.modified = true;
}