From 3b3f861767beff28537f4b22fc70e6ddaaf14370 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sat, 24 Jan 2026 18:03:04 +0800 Subject: [PATCH] Add test for comments in VariableDeclaration (#18739) --- .../no-semi/__snapshots__/format.test.js.snap | 86 ++++++++++++++++--- tests/format/js/no-semi/comments.js | 15 ++++ tests/format/js/no-semi/format.test.js | 4 +- 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/tests/format/js/no-semi/__snapshots__/format.test.js.snap b/tests/format/js/no-semi/__snapshots__/format.test.js.snap index 88081e490..19966a666 100644 --- a/tests/format/js/no-semi/__snapshots__/format.test.js.snap +++ b/tests/format/js/no-semi/__snapshots__/format.test.js.snap @@ -2,7 +2,7 @@ exports[`class.js - {"semi":false} format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 semi: false | printWidth @@ -249,7 +249,7 @@ class G4 { exports[`class.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 | printWidth =====================================input====================================== @@ -495,7 +495,7 @@ class G4 { exports[`comments.js - {"semi":false} format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 semi: false | printWidth @@ -512,6 +512,21 @@ x; [].response = response; /* comment */ + +{ + let foo + + // comment + ;[foo] = [1] +} + +{ + let foo = 42 + + // comment + ;[foo] = [1] +} + =====================================output===================================== let error = new Error(response.statusText) // comment @@ -525,12 +540,26 @@ x ;[].response = response /* comment */ +{ + let foo + + // comment + ;[foo] = [1] +} + +{ + let foo = 42 + + // comment + ;[foo] = [1] +} + ================================================================================ `; exports[`comments.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 | printWidth =====================================input====================================== @@ -546,6 +575,21 @@ x; [].response = response; /* comment */ + +{ + let foo + + // comment + ;[foo] = [1] +} + +{ + let foo = 42 + + // comment + ;[foo] = [1] +} + =====================================output===================================== let error = new Error(response.statusText); // comment @@ -559,12 +603,26 @@ x; [].response = response; /* comment */ +{ + let foo; + + // comment + [foo] = [1]; +} + +{ + let foo = 42; + + // comment + [foo] = [1]; +} + ================================================================================ `; exports[`imports.js - {"semi":false} format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 semi: false | printWidth @@ -625,7 +683,7 @@ export { foo as bar } // 1 exports[`imports.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 | printWidth =====================================input====================================== @@ -685,7 +743,7 @@ export { foo as bar }; // 1 exports[`issue-1510.js - {"semi":false} format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 semi: false | printWidth @@ -724,7 +782,7 @@ a exports[`issue-1510.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 | printWidth =====================================input====================================== @@ -762,7 +820,7 @@ a; exports[`issue2006.js - {"semi":false} format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 semi: false | printWidth @@ -791,7 +849,7 @@ var c = a.e exports[`issue2006.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 | printWidth =====================================input====================================== @@ -819,7 +877,7 @@ var c = a.e; exports[`no-semi.js - {"semi":false} format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 semi: false | printWidth @@ -1003,7 +1061,7 @@ aReallyLongLine012345678901234567890123456789012345678901234567890123456789 * exports[`no-semi.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 | printWidth =====================================input====================================== @@ -1186,7 +1244,7 @@ aReallyLongLine012345678901234567890123456789012345678901234567890123456789 * exports[`private-field.js - {"semi":false} format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 semi: false | printWidth @@ -1207,7 +1265,7 @@ class C { exports[`private-field.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "flow"] +parsers: ["babel", "typescript", "flow"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/js/no-semi/comments.js b/tests/format/js/no-semi/comments.js index 9ada40721..ec3e06524 100644 --- a/tests/format/js/no-semi/comments.js +++ b/tests/format/js/no-semi/comments.js @@ -9,3 +9,18 @@ x; x; [].response = response; /* comment */ + + +{ + let foo + + // comment + ;[foo] = [1] +} + +{ + let foo = 42 + + // comment + ;[foo] = [1] +} diff --git a/tests/format/js/no-semi/format.test.js b/tests/format/js/no-semi/format.test.js index 1f6c4a35a..ff8fda0c2 100644 --- a/tests/format/js/no-semi/format.test.js +++ b/tests/format/js/no-semi/format.test.js @@ -1,2 +1,2 @@ -runFormatTest(import.meta, ["babel", "flow"], {}); -runFormatTest(import.meta, ["babel", "flow"], { semi: false }); +runFormatTest(import.meta, ["babel", "typescript", "flow"], {}); +runFormatTest(import.meta, ["babel", "typescript", "flow"], { semi: false });