speed up has_parens() (take 2) (#3052)

fixes #3050
This commit is contained in:
Alex Lam S.L
2018-04-05 04:12:04 +08:00
committed by GitHub
parent 81603ecd15
commit b5bab254ce
2 changed files with 24 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
var assert = require("assert");
var uglify = require("../../");
describe("New", function() {
describe("parentheses", function() {
it("Should add trailing parentheses for new expressions with zero arguments in beautify mode", function() {
var tests = [
"new x(1);",
@@ -83,4 +83,23 @@ describe("New", function() {
);
}
});
});
it("Should compress leading parenthesis with reasonable performance", function() {
this.timeout(30000);
var code = [
"({}?0:1)&&x();",
"(function(){}).name;",
];
for (var i = 16; --i >= 0;) {
[].push.apply(code, code);
}
code = code.join("");
var result = uglify.minify(code, {
compress: false,
mangle: false,
});
if (result.error) throw result.error;
// Dismal performance for `assert.strictEqual()` in Node.js 6
assert.ok(result.code === code);
});
});