improve usability of mangle.properties (#5683)

fixes #5682
This commit is contained in:
Alex Lam S.L
2022-09-27 06:52:58 +01:00
committed by GitHub
parent 8e65413b99
commit 3fa2086681
7 changed files with 260 additions and 41 deletions

View File

@@ -12,17 +12,16 @@ describe("let", function() {
s += '}';
var result = UglifyJS.minify(s, {
compress: false,
}).code;
});
if (result.error) throw result.error;
// Verify that select keywords and reserved keywords not produced
[
"do",
"let",
"var",
].forEach(function(name) {
assert.strictEqual(result.indexOf("var " + name + "="), -1);
assert.strictEqual(result.code.indexOf("var " + name + "="), -1);
});
// Verify that the variable names that appeared immediately before
// and after the erroneously generated variable name still exist
// to show the test generated enough symbols.
@@ -31,27 +30,27 @@ describe("let", function() {
"eet", "fet",
"rar", "oar",
].forEach(function(name) {
assert.notStrictEqual(result.indexOf("var " + name + "="), -1);
assert.notStrictEqual(result.code.indexOf("var " + name + "="), -1);
});
});
it("Should quote mangled properties that are reserved keywords", function() {
var s = '"rrrrrnnnnniiiiiaaaaa";';
for (var i = 0; i < 18000; i++) {
s += "v.b" + i + ";";
s += "v.b" + i + "=v;";
}
var result = UglifyJS.minify(s, {
compress: false,
ie: true,
mangle: {
properties: true,
}
}).code;
},
});
if (result.error) throw result.error;
[
"in",
"var",
].forEach(function(name) {
assert.notStrictEqual(result.indexOf(name), -1);
assert.notStrictEqual(result.indexOf('v["' + name + '"]'), -1);
assert.notStrictEqual(result.code.indexOf('v["' + name + '"]'), -1);
});
});
it("Should parse `let` as name correctly", function() {