Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance evaluate #3339

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2727,19 +2727,25 @@ merge(Compressor.prototype, {
return typeof function(){};
}
if (!non_converting_unary[this.operator]) depth++;
e = e._eval(compressor, cached, depth);
if (e === this.expression) return this;
var v = e._eval(compressor, cached, depth);
if (v === this.expression) return this;
switch (this.operator) {
case "!": return !e;
case "!": return !v;
case "typeof":
// typeof <RegExp> returns "object" or "function" on different platforms
// so cannot evaluate reliably
if (e instanceof RegExp) return this;
return typeof e;
case "void": return void e;
case "~": return ~e;
case "-": return -e;
case "+": return +e;
if (v instanceof RegExp) return this;
return typeof v;
case "void": return void v;
case "~": return ~v;
case "-": return -v;
case "+": return +v;
case "++":
case "--":
if (e instanceof AST_SymbolRef) {
var refs = e.definition().references;
if (refs[refs.length - 1] === e) return v;
}
}
return this;
});
Expand Down
2 changes: 1 addition & 1 deletion test/compress/collapse_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ collapse_vars_misc1: {
function f8() { var b = window.a * window.z; return b + (b + 5) }
function f9() { var b = window.a * window.z; return bar() || b }
function f10(x) { var a = 5; return a += 3; }
function f11(x) { var a = 5, b = 3; return a += --b; }
function f11(x) { var a = 5; return a += 2; }
}
}

Expand Down