workaround pure_getters=true when dropping unused assignments

fixes #2938
This commit is contained in:
alexlamsl 2018-02-20 16:29:15 +08:00
parent 70474310f3
commit 8a69e0bdb0
2 changed files with 32 additions and 3 deletions

View File

@ -3028,10 +3028,12 @@ merge(Compressor.prototype, {
} else if (node instanceof AST_Unary && node.write_only) { } else if (node instanceof AST_Unary && node.write_only) {
sym = node.expression; sym = node.expression;
} }
if (/strict/.test(compressor.option("pure_getters"))) {
while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) { while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
if (sym instanceof AST_Sub) props.unshift(sym.property); if (sym instanceof AST_Sub) props.unshift(sym.property);
sym = sym.expression; sym = sym.expression;
} }
}
return sym; return sym;
}; };
var in_use = []; var in_use = [];

View File

@ -721,3 +721,30 @@ issue_2838: {
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
issue_2938: {
options = {
pure_getters: true,
toplevel: true,
unused: true,
}
input: {
var Parser = function Parser() {};
var p = Parser.prototype;
p.initialContext = function initialContext() {
console.log("PASS");
};
p.braceIsBlock = function() {};
(new Parser).initialContext();
}
expect: {
var Parser = function() {};
var p = Parser.prototype;
p.initialContext = function() {
console.log("PASS");
};
p.braceIsBlock = function() {};
(new Parser).initialContext();
}
expect_stdout: "PASS"
}