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 d237ab7
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: test/unitCases/__snapshots__/syntax-printer.unittest.js.snap
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,10 @@ Array [
74
74
]
75
75
`;
76
76
77
+
exports[`syntax-printer improve phase should keep a function called in place whose \`var\`, its name taken, a class in a block there also names 1`] = `"function f(x){var a=g();!function(){var x=typeof a;{class x{}console.log(x.name)}console.log(x)}(),console.log(x,a)}function g(){return 1}f(\\"o\\");"`;
78
+
79
+
exports[`syntax-printer improve phase should keep a function called in place whose \`var\`s, more than one, take names already taken 1`] = `"function f(x){var a=g(),b=g();console.log(x),function(){if(x){var a=console.log.name,b=typeof x;console.log(a,a,b,b)}}(),console.log(a,b)}function g(){return\\"o\\"}f(1),f(0);"`;
80
+
77
81
exports[`syntax-printer improve phase should write the \`const\` declarations of a body moved up in place as one \`let\` 1`] = `"export function f(a){let b=a.x(),c=a.y();return a.z(b,c),b+c}"`;
78
82
79
83
exports[`syntax-printer printEstree should map as terser does: "a directive"; debugger; {} ;\\nlabel: for (;;) { break label; 1`] = `
Copy file name to clipboardExpand all lines: test/unitCases/syntax-printer.unittest.js
+35-2Lines changed: 35 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -304,6 +304,21 @@ const IMPROVED_CASES = [
304
304
"function f(x) { console.log(x); (function () { if (x) { var a = console.log.name; console.log(a, a); } })(); } f(1); f(0);",
305
305
{compress: {},mangle: false}
306
306
],
307
+
[
308
+
"a `var` moving to the function around the call under a name of its own, where that name is taken",
309
+
"function f(x) { var a = g(); console.log(x); (function () { if (x) { var a = console.log.name; console.log(a, a); } })(); (function () { if (!x) { var a = typeof x; console.log(a, a); } })(); console.log(a); } function g() { return 'outer'; } f(1); f(0);",
310
+
{compress: {},mangle: false}
311
+
],
312
+
[
313
+
"a `var` moving to the function around the call under a name of its own, where that function names it elsewhere",
314
+
'var a = "g"; function f(x) { (function () { if (x) { var a = console.log.name; console.log(a, a); } })(); console.log(a); } f(1);',
315
+
{compress: {},mangle: false}
316
+
],
317
+
[
318
+
"two functions called in place each declaring one `var` a closure keeps, or reading a name the other declares, moving under names of their own",
319
+
'function h(x, r) { (function () { if (x) { var a = x.p; r.push(() => a + a); } })(); (function () { if (x) { var a = x.q; r.push(() => a + a); } })(); } function k(x) { (function () { if (x) { var b = x.q; console.log(a, b, b); } })(); (function () { if (x) { var a = x.p; console.log(a, a); } })(); } var a = "outer", r = []; h({ p: 1, q: 2 }, r); k({ p: 1, q: 2 }); console.log(r.map((f) => f()));',
320
+
{compress: {},mangle: false}
321
+
],
307
322
[
308
323
"a `var` moving into a function called in place, which then stays one",
309
324
"function f(x) { (function () { if (x) { var a = console.log.name; console.log(a, a); } (function () { if (x) { var b = console.log.name; console.log(b, b); } })(); })(); } f(1);",
@@ -1220,8 +1235,7 @@ const KEPT_CASES = [
1220
1235
["a `var` copying a parameter, read in a block declaring the parameter's name, or in a class of that name","function f(b) { var a = b; g(b); { let b = 9; g(b); return [a, b]; } } function h(b) { var a = b; g(b); return new (class b { m() { return a; } })().m(); } function g() {} console.log(f(1), h(1));"],
1221
1236
["a `var` copying a `var` a loop sets again, read by a function inside","var fns = []; function f(n) { for (var i = 0; i < n; i++) { var b = i * 2; var a = b; g(b); fns.push(function () { return a; }); } } function g() {} f(2); console.log(fns.map(function (h) { return h(); }));"],
1222
1237
["a `var` copying a `let` a loop declares each time round, read by a function inside","var fns = []; function f(list) { for (let b of list) { var a = b; g(b); fns.push(function () { return a; }); } } function g() {} f([1, 2]); console.log(fns.map(function (h) { return h(); }));"],
1223
-
["a `var` the function around the call names elsewhere, or a call it repeats",'var a = "g"; function f(x) { (function () { if (x) { var a = console.log.name; console.log(a, a); } })(); console.log(a); for (var i = 0; i < 2; i++) (function () { var b; if (i) b = i; console.log(b); })(); } f(1);'],
1224
-
["two functions called in place declaring one `var` a closure keeps, or reading a name the other declares",'function h(x, r) { (function () { if (x) { var a = x.p; r.push(() => a + a); } })(); (function () { if (x) { var a = x.q; r.push(() => a + a); } })(); } function k(x) { (function () { if (x) { var b = x.q; console.log(a, b, b); } })(); (function () { if (x) { var a = x.p; console.log(a, a); } })(); } var a = "outer", r = []; h({ p: 1, q: 2 }, r); k({ p: 1, q: 2 }); console.log(r.map((f) => f()));'],
1238
+
["a call a loop repeats","function f() { for (var i = 0; i < 2; i++) (function () { var b; if (i) b = i; console.log(b); })(); } f();"],
1225
1239
["a function called in place inside `with`, whose `var` the object could answer for",'function f(o) { with (o) { (function () { if (o) { var a = r.length + 1; r.push(() => a + a); } })(); } return o.r.map((g) => g()); } console.log(f({ a: 2, r: [] }));'],
1226
1240
["a `return`",`!function () { for (let x of [1, 2]) { ${TRY} if (x) return; } console.log(2); }();`],
it("should keep a function called in place whose `var`s, more than one, take names already taken",async()=>{
7674
+
const{ minify }=awaitload();
7675
+
constinput=
7676
+
"function f(x) { var a = g(), b = g(); console.log(x); (function () { if (x) { var a = console.log.name, b = typeof x; console.log(a, a, b, b); } })(); console.log(a, b); } function g() { return \"o\"; } f(1); f(0);";
it("should keep a function called in place whose `var`, its name taken, a class in a block there also names",async()=>{
7684
+
const{ minify }=awaitload();
7685
+
constinput=
7686
+
"function f(x) { var a = g(); (function () { var x = typeof a; { class x {} console.log(x.name); } console.log(x); })(); console.log(x, a); } function g() { return 1; } f('o');";
0 commit comments