Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a57b069409 | ||
|
|
4454656c3b | ||
|
|
fa43768ce0 | ||
|
|
a74e600fa0 | ||
|
|
4b21526310 | ||
|
|
a7a7b1daed | ||
|
|
7436977aa5 |
@@ -2246,7 +2246,11 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
def(AST_SymbolRef, function() {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_truthy();
|
||||
if (!fixed) return false;
|
||||
this.is_truthy = return_false;
|
||||
var result = fixed.is_truthy();
|
||||
delete this.is_truthy;
|
||||
return result;
|
||||
});
|
||||
})(function(node, func) {
|
||||
node.DEFMETHOD("is_truthy", func);
|
||||
@@ -2300,7 +2304,11 @@ merge(Compressor.prototype, {
|
||||
if (is_undeclared_ref(this) && this.is_declared(compressor)) return false;
|
||||
if (this.is_immutable()) return false;
|
||||
var fixed = this.fixed_value();
|
||||
return !fixed || fixed._dot_throw(compressor);
|
||||
if (!fixed) return true;
|
||||
this._dot_throw = return_true;
|
||||
var result = fixed._dot_throw(compressor);
|
||||
delete this._dot_throw;
|
||||
return result;
|
||||
});
|
||||
def(AST_UnaryPrefix, function() {
|
||||
return this.operator == "void";
|
||||
@@ -2342,7 +2350,11 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
def(AST_SymbolRef, function(compressor) {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_boolean(compressor);
|
||||
if (!fixed) return false;
|
||||
this.is_boolean = return_false;
|
||||
var result = fixed.is_boolean(compressor);
|
||||
delete this.is_boolean;
|
||||
return result;
|
||||
});
|
||||
var unary = makePredicate("! delete");
|
||||
def(AST_UnaryPrefix, function() {
|
||||
@@ -2427,7 +2439,11 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
def(AST_SymbolRef, function(compressor) {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_number(compressor);
|
||||
if (!fixed) return false;
|
||||
this.is_number = return_false;
|
||||
var result = fixed.is_number(compressor);
|
||||
delete this.is_number;
|
||||
return result;
|
||||
});
|
||||
var unary = makePredicate("+ - ~ ++ --");
|
||||
def(AST_Unary, function() {
|
||||
@@ -2456,7 +2472,11 @@ merge(Compressor.prototype, {
|
||||
def(AST_String, return_true);
|
||||
def(AST_SymbolRef, function(compressor) {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_string(compressor);
|
||||
if (!fixed) return false;
|
||||
this.is_string = return_false;
|
||||
var result = fixed.is_string(compressor);
|
||||
delete this.is_string;
|
||||
return result;
|
||||
});
|
||||
def(AST_UnaryPrefix, function() {
|
||||
return this.operator == "typeof";
|
||||
|
||||
18
lib/scope.js
18
lib/scope.js
@@ -198,24 +198,20 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
}
|
||||
if (node instanceof AST_SymbolLambda) {
|
||||
var def = node.thedef;
|
||||
if (def.orig.length == 1) {
|
||||
redefine(node, node.scope.parent_scope);
|
||||
node.thedef.init = def.init;
|
||||
}
|
||||
redefine(node, node.scope.parent_scope);
|
||||
node.thedef.init = def.init;
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
|
||||
function redefine(node, scope) {
|
||||
var name = node.name;
|
||||
var refs = node.thedef.references;
|
||||
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||
refs.forEach(function(ref) {
|
||||
ref.thedef = def;
|
||||
ref.reference(options);
|
||||
var old_def = node.thedef;
|
||||
var new_def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||
old_def.orig.concat(old_def.references).forEach(function(node) {
|
||||
node.thedef = new_def;
|
||||
node.reference(options);
|
||||
});
|
||||
node.thedef = def;
|
||||
node.reference(options);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "3.5.1",
|
||||
"version": "3.5.4",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
@@ -23,12 +23,12 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"dependencies": {
|
||||
"commander": "~2.19.0",
|
||||
"commander": "~2.20.0",
|
||||
"source-map": "~0.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn": "~6.1.1",
|
||||
"semver": "~5.6.0"
|
||||
"semver": "~6.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/run-tests.js"
|
||||
|
||||
@@ -1124,14 +1124,14 @@ issue_2207_1: {
|
||||
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
||||
console.log(Math.cos(1.2345));
|
||||
console.log(Math.cos(1.2345) - Math.sin(4.321));
|
||||
console.log(Math.pow(Math.PI, Math.E - Math.LN10));
|
||||
console.log(Math.pow(Math.PI, Math.E - Math.LN10).toFixed(15));
|
||||
}
|
||||
expect: {
|
||||
console.log("A");
|
||||
console.log(7);
|
||||
console.log(Math.cos(1.2345));
|
||||
console.log(1.2543732512566947);
|
||||
console.log(1.6093984514472044);
|
||||
console.log("1.609398451447204");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -861,3 +861,111 @@ issue_3215_4: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3355_1: {
|
||||
mangle = {
|
||||
ie8: false,
|
||||
}
|
||||
input: {
|
||||
(function f() {
|
||||
var f;
|
||||
})();
|
||||
(function g() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect: {
|
||||
(function o() {
|
||||
var o;
|
||||
})();
|
||||
(function o() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_3355_2: {
|
||||
mangle = {
|
||||
ie8: true,
|
||||
}
|
||||
input: {
|
||||
(function f() {
|
||||
var f;
|
||||
})();
|
||||
(function g() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect: {
|
||||
(function f() {
|
||||
var f;
|
||||
})();
|
||||
(function g() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_3355_3: {
|
||||
mangle = {
|
||||
ie8: false,
|
||||
}
|
||||
input: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var b = function c() {
|
||||
var c = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var o = function a() {
|
||||
var a = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3355_4: {
|
||||
mangle = {
|
||||
ie8: true,
|
||||
}
|
||||
input: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var b = function c() {
|
||||
var c = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var o = function n() {
|
||||
var n = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user