Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9676167aac | ||
|
|
1840a0b282 | ||
|
|
ace8aaa0f4 | ||
|
|
0c003c92a8 | ||
|
|
85fbf86d7b | ||
|
|
aa82027a17 |
@@ -1056,31 +1056,37 @@ merge(Compressor.prototype, {
|
||||
throw def;
|
||||
});
|
||||
def(AST_Binary, function(c){
|
||||
var left = this.left, right = this.right;
|
||||
var left = this.left, right = this.right, result;
|
||||
switch (this.operator) {
|
||||
case "&&" : return ev(left, c) && ev(right, c);
|
||||
case "||" : return ev(left, c) || ev(right, c);
|
||||
case "|" : return ev(left, c) | ev(right, c);
|
||||
case "&" : return ev(left, c) & ev(right, c);
|
||||
case "^" : return ev(left, c) ^ ev(right, c);
|
||||
case "+" : return ev(left, c) + ev(right, c);
|
||||
case "*" : return ev(left, c) * ev(right, c);
|
||||
case "/" : return ev(left, c) / ev(right, c);
|
||||
case "%" : return ev(left, c) % ev(right, c);
|
||||
case "-" : return ev(left, c) - ev(right, c);
|
||||
case "<<" : return ev(left, c) << ev(right, c);
|
||||
case ">>" : return ev(left, c) >> ev(right, c);
|
||||
case ">>>" : return ev(left, c) >>> ev(right, c);
|
||||
case "==" : return ev(left, c) == ev(right, c);
|
||||
case "===" : return ev(left, c) === ev(right, c);
|
||||
case "!=" : return ev(left, c) != ev(right, c);
|
||||
case "!==" : return ev(left, c) !== ev(right, c);
|
||||
case "<" : return ev(left, c) < ev(right, c);
|
||||
case "<=" : return ev(left, c) <= ev(right, c);
|
||||
case ">" : return ev(left, c) > ev(right, c);
|
||||
case ">=" : return ev(left, c) >= ev(right, c);
|
||||
case "&&" : result = ev(left, c) && ev(right, c); break;
|
||||
case "||" : result = ev(left, c) || ev(right, c); break;
|
||||
case "|" : result = ev(left, c) | ev(right, c); break;
|
||||
case "&" : result = ev(left, c) & ev(right, c); break;
|
||||
case "^" : result = ev(left, c) ^ ev(right, c); break;
|
||||
case "+" : result = ev(left, c) + ev(right, c); break;
|
||||
case "*" : result = ev(left, c) * ev(right, c); break;
|
||||
case "/" : result = ev(left, c) / ev(right, c); break;
|
||||
case "%" : result = ev(left, c) % ev(right, c); break;
|
||||
case "-" : result = ev(left, c) - ev(right, c); break;
|
||||
case "<<" : result = ev(left, c) << ev(right, c); break;
|
||||
case ">>" : result = ev(left, c) >> ev(right, c); break;
|
||||
case ">>>" : result = ev(left, c) >>> ev(right, c); break;
|
||||
case "==" : result = ev(left, c) == ev(right, c); break;
|
||||
case "===" : result = ev(left, c) === ev(right, c); break;
|
||||
case "!=" : result = ev(left, c) != ev(right, c); break;
|
||||
case "!==" : result = ev(left, c) !== ev(right, c); break;
|
||||
case "<" : result = ev(left, c) < ev(right, c); break;
|
||||
case "<=" : result = ev(left, c) <= ev(right, c); break;
|
||||
case ">" : result = ev(left, c) > ev(right, c); break;
|
||||
case ">=" : result = ev(left, c) >= ev(right, c); break;
|
||||
default:
|
||||
throw def;
|
||||
}
|
||||
throw def;
|
||||
if (isNaN(result) && c.find_parent(AST_With)) {
|
||||
// leave original expression as is
|
||||
throw def;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
def(AST_Conditional, function(compressor){
|
||||
return ev(this.condition, compressor)
|
||||
@@ -2599,13 +2605,16 @@ merge(Compressor.prototype, {
|
||||
if (defines && HOP(defines, self.name)) {
|
||||
return make_node_from_constant(compressor, defines[self.name], self);
|
||||
}
|
||||
switch (self.name) {
|
||||
case "undefined":
|
||||
return make_node(AST_Undefined, self);
|
||||
case "NaN":
|
||||
return make_node(AST_NaN, self).transform(compressor);
|
||||
case "Infinity":
|
||||
return make_node(AST_Infinity, self).transform(compressor);
|
||||
// testing against !self.scope.uses_with first is an optimization
|
||||
if (!self.scope.uses_with || !compressor.find_parent(AST_With)) {
|
||||
switch (self.name) {
|
||||
case "undefined":
|
||||
return make_node(AST_Undefined, self);
|
||||
case "NaN":
|
||||
return make_node(AST_NaN, self).transform(compressor);
|
||||
case "Infinity":
|
||||
return make_node(AST_Infinity, self).transform(compressor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
@@ -2737,7 +2746,7 @@ merge(Compressor.prototype, {
|
||||
if (consequent.is_constant(compressor)
|
||||
&& alternative.is_constant(compressor)
|
||||
&& consequent.equivalent_to(alternative)) {
|
||||
var consequent_value = consequent.constant_value();
|
||||
var consequent_value = consequent.constant_value(compressor);
|
||||
if (self.condition.has_side_effects(compressor)) {
|
||||
return AST_Seq.from_array([self.condition, make_node_from_constant(compressor, consequent_value, self)]);
|
||||
} else {
|
||||
|
||||
@@ -404,7 +404,7 @@ function OutputStream(options) {
|
||||
|
||||
AST_Node.DEFMETHOD("print", function(stream, force_parens){
|
||||
var self = this, generator = self._codegen, prev_use_asm = use_asm;
|
||||
if (self instanceof AST_Directive && self.value == "use asm") {
|
||||
if (self instanceof AST_Directive && self.value == "use asm" && stream.parent() instanceof AST_Scope) {
|
||||
use_asm = true;
|
||||
}
|
||||
function doit() {
|
||||
@@ -419,7 +419,7 @@ function OutputStream(options) {
|
||||
doit();
|
||||
}
|
||||
stream.pop_node();
|
||||
if (self instanceof AST_Lambda) {
|
||||
if (self instanceof AST_Scope) {
|
||||
use_asm = prev_use_asm;
|
||||
}
|
||||
});
|
||||
@@ -1221,7 +1221,7 @@ function OutputStream(options) {
|
||||
output.print_string(self.getValue(), self.quote, in_directive);
|
||||
});
|
||||
DEFPRINT(AST_Number, function(self, output){
|
||||
if (use_asm && self.start.raw != null) {
|
||||
if (use_asm && self.start && self.start.raw != null) {
|
||||
output.print(self.start.raw);
|
||||
} else {
|
||||
output.print(make_num(self.getValue()));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"homepage": "http://lisperator.net/uglifyjs",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "2.6.3",
|
||||
"version": "2.6.4",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
|
||||
@@ -868,3 +868,41 @@ trivial_boolean_ternary_expressions : {
|
||||
f(!(x >= y));
|
||||
}
|
||||
}
|
||||
|
||||
issue_1154: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
evaluate : true,
|
||||
booleans : true,
|
||||
};
|
||||
input: {
|
||||
function f1(x) { return x ? -1 : -1; }
|
||||
function f2(x) { return x ? +2 : +2; }
|
||||
function f3(x) { return x ? ~3 : ~3; }
|
||||
function f4(x) { return x ? !4 : !4; }
|
||||
function f5(x) { return x ? void 5 : void 5; }
|
||||
function f6(x) { return x ? typeof 6 : typeof 6; }
|
||||
|
||||
function g1() { return g() ? -1 : -1; }
|
||||
function g2() { return g() ? +2 : +2; }
|
||||
function g3() { return g() ? ~3 : ~3; }
|
||||
function g4() { return g() ? !4 : !4; }
|
||||
function g5() { return g() ? void 5 : void 5; }
|
||||
function g6() { return g() ? typeof 6 : typeof 6; }
|
||||
}
|
||||
expect: {
|
||||
function f1(x) { return -1; }
|
||||
function f2(x) { return 2; }
|
||||
function f3(x) { return -4; }
|
||||
function f4(x) { return !1; }
|
||||
function f5(x) { return; }
|
||||
function f6(x) { return "number"; }
|
||||
|
||||
function g1() { return g(), -1; }
|
||||
function g2() { return g(), 2; }
|
||||
function g3() { return g(), -4; }
|
||||
function g4() { return g(), !1; }
|
||||
function g5() { return g(), void 0; }
|
||||
function g6() { return g(), "number"; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,4 +144,97 @@ check_drop_unused_in_peer_function: {
|
||||
bar();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Infinity_not_in_with_scope: {
|
||||
options = {
|
||||
unused: true
|
||||
}
|
||||
input: {
|
||||
var o = { Infinity: 'oInfinity' };
|
||||
var vInfinity = "Infinity";
|
||||
vInfinity = Infinity;
|
||||
}
|
||||
expect: {
|
||||
var o = { Infinity: 'oInfinity' }
|
||||
var vInfinity = "Infinity"
|
||||
vInfinity = 1/0
|
||||
}
|
||||
}
|
||||
|
||||
Infinity_in_with_scope: {
|
||||
options = {
|
||||
unused: true
|
||||
}
|
||||
input: {
|
||||
var o = { Infinity: 'oInfinity' };
|
||||
var vInfinity = "Infinity";
|
||||
with (o) { vInfinity = Infinity; }
|
||||
}
|
||||
expect: {
|
||||
var o = { Infinity: 'oInfinity' }
|
||||
var vInfinity = "Infinity"
|
||||
with (o) vInfinity = Infinity
|
||||
}
|
||||
}
|
||||
|
||||
assorted_Infinity_NaN_undefined_in_with_scope: {
|
||||
options = {
|
||||
unused: true,
|
||||
evaluate: true,
|
||||
dead_code: true,
|
||||
conditionals: true,
|
||||
comparisons: true,
|
||||
booleans: true,
|
||||
hoist_funs: true,
|
||||
keep_fargs: true,
|
||||
if_return: true,
|
||||
join_vars: true,
|
||||
cascade: true,
|
||||
side_effects: true,
|
||||
sequences: false,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
undefined : 3,
|
||||
NaN : 4,
|
||||
Infinity : 5,
|
||||
}
|
||||
if (o) {
|
||||
f(undefined, void 0);
|
||||
f(NaN, 0/0);
|
||||
f(Infinity, 1/0);
|
||||
f(-Infinity, -(1/0));
|
||||
f(2 + 7 + undefined, 2 + 7 + void 0);
|
||||
}
|
||||
with (o) {
|
||||
f(undefined, void 0);
|
||||
f(NaN, 0/0);
|
||||
f(Infinity, 1/0);
|
||||
f(-Infinity, -(1/0));
|
||||
f(2 + 7 + undefined, 2 + 7 + void 0);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
undefined : 3,
|
||||
NaN : 4,
|
||||
Infinity : 5
|
||||
}
|
||||
if (o) {
|
||||
f(void 0, void 0);
|
||||
f(NaN, NaN);
|
||||
f(1/0, 1/0);
|
||||
f(-(1/0), -(1/0));
|
||||
f(NaN, NaN);
|
||||
}
|
||||
with (o) {
|
||||
f(undefined, void 0);
|
||||
f(NaN, 0/0);
|
||||
f(Infinity, 1/0);
|
||||
f(-Infinity, -(1/0));
|
||||
f(9 + undefined, 9 + void 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ describe("Directives", function() {
|
||||
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
assert.strictEqual(
|
||||
uglify.minify(tests[i][0], {fromString: true, quote_style: 3, compress: false}).code,
|
||||
uglify.minify(tests[i][0], {fromString: true, quote_style: 3, compress: false, mangle: false}).code,
|
||||
tests[i][1],
|
||||
tests[i][0]
|
||||
);
|
||||
|
||||
@@ -18,6 +18,6 @@ exports["tokenizer"] = tokenizer;
|
||||
exports["is_identifier"] = is_identifier;
|
||||
exports["SymbolDef"] = SymbolDef;
|
||||
|
||||
if (DEBUG) {
|
||||
if (typeof DEBUG !== "undefined" && DEBUG) {
|
||||
exports["EXPECT_DIRECTIVE"] = EXPECT_DIRECTIVE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user