Skip to content

Commit 79c3361

Browse files
committed
test: sweep every constructor built-in, more assignment forms and locals of the name
1 parent bcfef74 commit 79c3361

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9036,15 +9036,31 @@ describe("syntax-printer", () => {
90369036
(name) => `[${name}] = [${replacement}];`,
90379037
(name) => `({ ${name} } = { ${name}: ${replacement} });`,
90389038
(name) => `for (${name} of [${replacement}]);`,
9039-
(name) => `${name}++; ${name} = ${replacement};`
9039+
(name) => `${name}++; ${name} = ${replacement};`,
9040+
(name) => `for (${name} in { k: 1 }); ${name} = ${replacement};`,
9041+
(name) => `${name} += ""; ${name} = ${replacement};`,
9042+
(name) => `${name} = 0; ${name} ||= ${replacement};`,
9043+
(name) => `[...${name}] = [${replacement}]; ${name} = ${name}[0];`,
9044+
(name) => `[{ ${name} }] = [{ ${name}: ${replacement} }];`,
9045+
(name) => `({ x: ${name} } = { x: ${replacement} });`,
9046+
(name) => `[${name} = ${replacement}] = [];`
90409047
];
9041-
for (const [name, argument] of [
9042-
["Error", '"x"'],
9043-
["TypeError", '"x"'],
9048+
/** @type {[string, string][]} */
9049+
const builtIns = [
9050+
["AggregateError", "[]"],
90449051
["Array", "3"],
9052+
["Error", '"x"'],
9053+
["EvalError", '"x"'],
9054+
["Function", '"return 1"'],
90459055
["Object", "1"],
9046-
["Function", '"return 1"']
9047-
]) {
9056+
["RangeError", '"x"'],
9057+
["ReferenceError", '"x"'],
9058+
["RegExp", '"a"'],
9059+
["SyntaxError", '"x"'],
9060+
["TypeError", '"x"'],
9061+
["URIError", '"x"']
9062+
];
9063+
for (const [name, argument] of builtIns) {
90489064
for (const assign of assignments) {
90499065
for (const call of [`new ${name}(${argument})`, `${name}(${argument})`]) {
90509066
const input = `${assign(name)} var v = ${call}; console.log(typeof v, v && v.m);`;
@@ -9058,6 +9074,23 @@ describe("syntax-printer", () => {
90589074
}
90599075
}
90609076
}
9077+
// a local of the name leaves the global the built-in it was
9078+
for (const [name, argument] of builtIns) {
9079+
for (const local of [
9080+
`function f() { var ${name} = 1; ${name} = 2; return ${name}; } f();`,
9081+
`function f(${name}) { [${name}] = [1]; return ${name}; } f();`
9082+
]) {
9083+
const input = `${local} var v = new ${name}(${argument}); console.log(String(v).slice(0, 9));`;
9084+
const { code } = await minify(input, {
9085+
compress: { passes: 2 },
9086+
mangle: true
9087+
});
9088+
expect(code).not.toContain(`new ${name}(`);
9089+
expect(runProgram(/** @type {string} */ (code))).toBe(
9090+
runProgram(input)
9091+
);
9092+
}
9093+
}
90619094
// Babel's rest parameter, read as a spread of `arguments` at ES2015
90629095
const rest =
90639096
"Array = function (n) { return { fake: n }; }; function g() { for (var n = arguments.length, a = Array(n), i = 0; i < n; i++) a[i] = arguments[i]; return a; } console.log(JSON.stringify(g(1, 2)));";

0 commit comments

Comments
 (0)