Merge branch 'master' into harmony-v3.0.21
This commit is contained in:
@@ -94,12 +94,9 @@ function Compressor(options, false_by_default) {
|
|||||||
var global_defs = this.options["global_defs"];
|
var global_defs = this.options["global_defs"];
|
||||||
if (typeof global_defs == "object") for (var key in global_defs) {
|
if (typeof global_defs == "object") for (var key in global_defs) {
|
||||||
if (/^@/.test(key) && HOP(global_defs, key)) {
|
if (/^@/.test(key) && HOP(global_defs, key)) {
|
||||||
var ast = parse(global_defs[key]);
|
global_defs[key.slice(1)] = parse(global_defs[key], {
|
||||||
if (ast.body.length == 1 && ast.body[0] instanceof AST_SimpleStatement) {
|
expression: true
|
||||||
global_defs[key.slice(1)] = ast.body[0].body;
|
});
|
||||||
} else throw new Error(string_template("Can't handle expression: {value}", {
|
|
||||||
value: global_defs[key]
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var pure_funcs = this.options["pure_funcs"];
|
var pure_funcs = this.options["pure_funcs"];
|
||||||
@@ -3284,7 +3281,7 @@ merge(Compressor.prototype, {
|
|||||||
// https://github.com/mishoo/UglifyJS2/issues/203
|
// https://github.com/mishoo/UglifyJS2/issues/203
|
||||||
// if the code argument is a constant, then we can minify it.
|
// if the code argument is a constant, then we can minify it.
|
||||||
try {
|
try {
|
||||||
var code = "NaN(function(" + self.args.slice(0, -1).map(function(arg) {
|
var code = "n(function(" + self.args.slice(0, -1).map(function(arg) {
|
||||||
return arg.value;
|
return arg.value;
|
||||||
}).join(",") + "){" + self.args[self.args.length - 1].value + "})";
|
}).join(",") + "){" + self.args[self.args.length - 1].value + "})";
|
||||||
var ast = parse(code);
|
var ast = parse(code);
|
||||||
@@ -3311,18 +3308,18 @@ merge(Compressor.prototype, {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
var args = fun.argnames.map(function(arg, i) {
|
|
||||||
return make_node(AST_String, self.args[i], {
|
|
||||||
value: arg.print_to_string()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
var code = OutputStream();
|
var code = OutputStream();
|
||||||
AST_BlockStatement.prototype._codegen.call(fun, fun, code);
|
AST_BlockStatement.prototype._codegen.call(fun, fun, code);
|
||||||
code = code.toString().replace(/^\{|\}$/g, "");
|
self.args = [
|
||||||
args.push(make_node(AST_String, self.args[self.args.length - 1], {
|
make_node(AST_String, self, {
|
||||||
value: code
|
value: fun.argnames.map(function(arg) {
|
||||||
}));
|
return arg.print_to_string();
|
||||||
self.args = args;
|
}).join(",")
|
||||||
|
}),
|
||||||
|
make_node(AST_String, self.args[self.args.length - 1], {
|
||||||
|
value: code.get().replace(/^\{|\}$/g, "")
|
||||||
|
})
|
||||||
|
];
|
||||||
return self;
|
return self;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (ex instanceof JS_Parse_Error) {
|
if (ex instanceof JS_Parse_Error) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.0.20",
|
"version": "3.0.21",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ issue_203: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var m = {};
|
var m = {};
|
||||||
var fn = Function("n", "o", "o.exports=42");
|
var fn = Function("n,o", "o.exports=42");
|
||||||
fn(null, m, m.exports);
|
fn(null, m, m.exports);
|
||||||
console.log(m.exports);
|
console.log(m.exports);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,3 +174,24 @@ issue_1986: {
|
|||||||
console.log(42);
|
console.log(42);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2167: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
global_defs: {
|
||||||
|
"@isDevMode": "function(){}",
|
||||||
|
},
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (isDevMode()) {
|
||||||
|
greetOverlord();
|
||||||
|
}
|
||||||
|
doWork();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
doWork();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ compress_new_function: {
|
|||||||
new Function("aa, bb", 'return aa;');
|
new Function("aa, bb", 'return aa;');
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
Function("n", "r", "return n");
|
Function("n,r", "return n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ compress_new_function_with_destruct: {
|
|||||||
new Function("[[aa]], [{bb}]", 'return aa;');
|
new Function("[[aa]], [{bb}]", 'return aa;');
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
Function("n", "[r]", "return n");
|
Function("n,[r]", "return n");
|
||||||
Function("n", "{bb:b}", "return n");
|
Function("n,{bb:b}", "return n");
|
||||||
Function("[[n]]", "[{bb:b}]", "return n");
|
Function("[[n]],[{bb:b}]", "return n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ compress_new_function_with_destruct_arrows: {
|
|||||||
new Function("[[aa]], [{bb}]", 'return aa;');
|
new Function("[[aa]], [{bb}]", 'return aa;');
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
Function("N", "[a]", 'return N');
|
Function("n,[a]", "return n");
|
||||||
Function("b", "{bb:N}", 'return b');
|
Function("b,{bb:n}", "return b");
|
||||||
Function("[[b]]", "[{bb:N}]", 'return b');
|
Function("[[b]],[{bb:n}]", "return b");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ describe("minify", function() {
|
|||||||
});
|
});
|
||||||
var err = result.error;
|
var err = result.error;
|
||||||
assert.ok(err instanceof Error);
|
assert.ok(err instanceof Error);
|
||||||
assert.strictEqual(err.stack.split(/\n/)[0], "Error: Can't handle expression: debugger");
|
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: keyword (debugger)");
|
||||||
});
|
});
|
||||||
it("should skip inherited properties", function() {
|
it("should skip inherited properties", function() {
|
||||||
var foo = Object.create({ skip: this });
|
var foo = Object.create({ skip: this });
|
||||||
|
|||||||
Reference in New Issue
Block a user