Make sure empty for loops generate valid code (#224)
```js for (;;); function f() {} ``` The `;` was dropped meaning that the line right after was executed within the for loop which is not correct. I tried to return `;` but it looks like ```js for (;;) ; ``` which looks super weird so I ended up printing `{}` which looks like ```js for (;;) {} ```master
parent
65a2a150b5
commit
f603ca4688
|
@ -799,8 +799,8 @@ function genericPrintNoParens(path, options, print) {
|
|||
return concat([
|
||||
"with (",
|
||||
path.call(print, "object"),
|
||||
") ",
|
||||
path.call(print, "body")
|
||||
")",
|
||||
adjustClause(path.call(print, "body"), options)
|
||||
]);
|
||||
case "IfStatement":
|
||||
const con = adjustClause(path.call(print, "consequent"), options);
|
||||
|
@ -2111,6 +2111,10 @@ function printJSXElement(path, options, print) {
|
|||
}
|
||||
|
||||
function adjustClause(clause, options, forceSpace) {
|
||||
if (clause === "") {
|
||||
return ";";
|
||||
}
|
||||
|
||||
if (isCurlyBracket(clause) || forceSpace) {
|
||||
return concat([ " ", clause ]);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
exports[`test body.js 1`] = `
|
||||
"with (a);
|
||||
if (1); else if (2); else;
|
||||
for (;;);
|
||||
while (1);
|
||||
for (var i in o);
|
||||
for (var i of o);
|
||||
do; while(1);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
with (a);
|
||||
if (1);
|
||||
else if (2);
|
||||
else;
|
||||
for (;;);
|
||||
while (1);
|
||||
for (var i in o);
|
||||
for (var i of o);
|
||||
do;
|
||||
while (1);
|
||||
"
|
||||
`;
|
|
@ -0,0 +1,7 @@
|
|||
with (a);
|
||||
if (1); else if (2); else;
|
||||
for (;;);
|
||||
while (1);
|
||||
for (var i in o);
|
||||
for (var i of o);
|
||||
do; while(1);
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname);
|
Loading…
Reference in New Issue