Handle dangling comments in SwitchStatement (#19581)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-07-09 11:28:31 +08:00
1 parent 943a475c35
commit 908503e9ee
9 files changed
+338 -1

No files matched your search

@@ -13,6 +13,10 @@ if(
if(true)// 2
{}
if(true)
// 22
{}
if(true){}// 3
if(true)/*4*/{}
@@ -29,6 +33,17 @@ if(true) /* 7 */ ++x;
if(1) // 8
foo();
if (0) {// comment
}
if (0) {
// comment
}
if (0) {/* comment */}
if ((0, 0/* comment */)) {}
=====================================output=====================================
if (
true
@@ -40,6 +55,11 @@ if (true) // 2
{
}
if (true)
// 22
{
}
if (true) {
} // 3
@@ -61,6 +81,111 @@ if (1)
// 8
foo();
if (0) {
// comment
}
if (0) {
// comment
}
if (0) {
/* comment */
}
if ((0, 0) /* comment */) {
}
================================================================================
`;
exports[`switch.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80 (default) |
=====================================input======================================
switch(
true
// 1
) {}
switch(true)// 2
{}
switch(true)
// 22
{}
switch(true){}// 3
switch(true)/*4*/{}
switch(
true // 5
&& true // 52
){}
switch(true) {} // 6
switch (0) {// comment
}
switch (0) {
// comment
}
switch (0) {/* comment */}
switch ((0, 0/* comment */)) {}
=====================================output=====================================
switch (
true
// 1
) {
}
switch (
true // 2
) {
}
switch (
true
// 22
) {
}
switch (true) {
} // 3
switch (true /*4*/) {
}
switch (
true && // 5
true // 52
) {
}
switch (true) {
} // 6
switch (0) {
// comment
}
switch (0) {
// comment
}
switch (0) {
/* comment */
}
switch ((0, 0) /* comment */) {
}
================================================================================
`;
@@ -77,6 +202,10 @@ while(
while(true)// 2
{}
while(true)
// 22
{}
while(true){}// 3
while(true)/*4*/{}
@@ -93,6 +222,17 @@ while(true) /* 7 */ ++x;
while(1) // 8
foo();
while (0) {// comment
}
while (0) {
// comment
}
while (0) {/* comment */}
while ((0, 0/* comment */)) {}
=====================================output=====================================
while (
true
@@ -102,6 +242,10 @@ while (
while (true) // 2
{}
while (true)
// 22
{}
while (true) {} // 3
while (true) /*4*/ {}
@@ -119,6 +263,20 @@ while (1)
// 8
foo();
while (0) {
// comment
}
while (0) {
// comment
}
while (0) {
/* comment */
}
while ((0, 0) /* comment */) {}
================================================================================
`;
@@ -135,6 +293,10 @@ with(
with(foo)// 2
{}
with(foo)
// 22
{}
with(foo){}// 3
with(foo)/*4*/{}
@@ -151,6 +313,17 @@ with(foo) /* 7 */ ++x;
with(1) // 8
foo();
with (0) {// comment
}
with (0) {
// comment
}
with (0) {/* comment */}
with ((0, 0/* comment */)) {}
=====================================output=====================================
with (
foo
@@ -162,6 +335,11 @@ with (foo) // 2
{
}
with (foo)
// 22
{
}
with (foo) {
} // 3
@@ -183,5 +361,20 @@ with (1)
// 8
foo();
with (0) {
// comment
}
with (0) {
// comment
}
with (0) {
/* comment */
}
with ((0, 0) /* comment */) {
}
================================================================================
`;
+15
View File
@@ -6,6 +6,10 @@ if(
if(true)// 2
{}
if(true)
// 22
{}
if(true){}// 3
if(true)/*4*/{}
@@ -21,3 +25,14 @@ if(true) /* 7 */ ++x;
if(1) // 8
foo();
if (0) {// comment
}
if (0) {
// comment
}
if (0) {/* comment */}
if ((0, 0/* comment */)) {}
@@ -0,0 +1,33 @@
switch(
true
// 1
) {}
switch(true)// 2
{}
switch(true)
// 22
{}
switch(true){}// 3
switch(true)/*4*/{}
switch(
true // 5
&& true // 52
){}
switch(true) {} // 6
switch (0) {// comment
}
switch (0) {
// comment
}
switch (0) {/* comment */}
switch ((0, 0/* comment */)) {}
@@ -6,6 +6,10 @@ while(
while(true)// 2
{}
while(true)
// 22
{}
while(true){}// 3
while(true)/*4*/{}
@@ -21,3 +25,14 @@ while(true) /* 7 */ ++x;
while(1) // 8
foo();
while (0) {// comment
}
while (0) {
// comment
}
while (0) {/* comment */}
while ((0, 0/* comment */)) {}
@@ -6,6 +6,10 @@ with(
with(foo)// 2
{}
with(foo)
// 22
{}
with(foo){}// 3
with(foo)/*4*/{}
@@ -21,3 +25,14 @@ with(foo) /* 7 */ ++x;
with(1) // 8
foo();
with (0) {// comment
}
with (0) {
// comment
}
with (0) {/* comment */}
with ((0, 0/* comment */)) {}