You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e7adf94
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: test/unitCases/syntax-printer.unittest.js
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -355,6 +355,12 @@ const IMPROVED_CASES = [
355
355
"function f(a, b) { var x = a ? 1 : 0, y = a ? 0 : 1; return [x, y, a < b ? 1 : 0, !a ? 1 : 0, b + (a ? 1 : 0), b - (a ? 0 : 1), (a ? 1 : 0).toFixed(1), -(a ? 1 : 0), typeof (a ? 1 : 0)]; } for (var v of [0, 1, \"\", \"x\", NaN, null, {}, 0n, 2n]) console.log(f(v, 1), f(v, \"s\"));",
356
356
{compress: {},mangle: false}
357
357
],
358
+
[
359
+
"a conditional choosing a boolean, kept where `!` would parenthesize its test",
360
+
"function f(a, b, c, d, e) { var r = [a & b ? true : c, a & b ? c : false, a + b ? false : c, a | b ? e() : true, a && b ? c : false, a || b ? c : false, a < b && c ? false : d, (a & b ? true : c) + 1, -(a & b ? c : false), (a & b ? c : false) ?? d, a & b ? (e(), c) : false, a & b ? true : c ? 1 : 2, a & b ? false : c ?? d, a & b ? c && d : false, a & b ? c || d : true]; return [r, a ^ b ? c : false]; } function* g(a, b) { yield a & b ? true : b; } function h(a, b, c) { switch (c) { case a & b ? c : false: return -a & b ? c : false; case 2: return 2; } } function k() { return 5; } for (var v of [0, 1, 2, NaN, \"\", \"x\", null]) console.log(f(v, 3, \"c\", 4, k), f(v, 0, null, 4, k), [...g(v, 1)], h(v, 1, 1), h(v, 2, false));",
["consecutive `if`s alike whose branch does not always leave",'function f(a, b) { for (var i = 0; i < 3; i++) { if (a === i) try { g(i); } finally { console.log(i); } if (b === i) try { g(i); } finally { console.log(i); } console.log(i); } } function g(i) { console.log("g", i); } f(0, 1); f(1, 1);'],
887
893
["an array literal joining to a string longer than it",'console.log([!0, !0, !0] + "");'],
888
894
["a conditional choosing `1` or `0` that a number conversion writes no shorter, or choosing `-0`","function f(a, b) { return [a < b ? 0 : 1, a + b ? 1 : 0, a in b ? 0 : 1, a ? 1 : -0, a ? 2 : 0, a ? -1 : 0]; } console.log(f(1, {}), f(0, { 0: 1 }));"],
895
+
["a logical expression negating what needs no parentheses, in a condition, or no shorter as a conditional","var r; function f(a, b, c, d, e) { if (!(a & b) && c) e(); while (!(a & b) && c) c = e(); return [!!a && b, !a || b, (!(a & b) && c) || d, (r = a) ? true : c]; } function g(a, b, c) { return a & b ? false : c; } function k() { return 0; } console.log(f(1, 2, 0, 4, k), f(0, 1, 2, 4, k), g(1, 2, 3), r);"],
889
896
["`+` and `~` of what a literal does not give","function f(a) { return [+[a], ~a !== 0 ? 1 : 2]; } console.log(f(1), f(1n));"],
890
897
["a string literal indexed past its end, by no constant or as a target",'function f(i) { var s = "abc"; "abc"[0] = 1; return ["abc"[5], "abc"[i], "abc"[1.5], "abc"[-1]]; } console.log(f(1));'],
891
898
["a `new` whose constructor reads `arguments` or a rest, extends a class, or is rebound",'function f(h) { function Z(a) { this.n = arguments.length; } function R(...a) { this.n = a.length; } class B { constructor(a) { this.n = arguments.length; } } class C extends B {} var V = function (a) { this.n = 1; }; if (h) V = function () { this.n = arguments.length; }; return [new Z(1, 2).n, new R(1, 2).n, new C(1, 2).n, new V(1, 2).n]; } console.log(f(0), f(1));'],
0 commit comments