Merge pull request #3324 from zjmiller/master
Parenthize "in" in for-loop init, even when init has nested for-loop
This commit is contained in:
commit
4e619db873
@ -156,7 +156,7 @@ export function AssignmentPattern(node: Object) {
|
|||||||
export function AssignmentExpression(node: Object, parent: Object) {
|
export function AssignmentExpression(node: Object, parent: Object) {
|
||||||
// Somewhere inside a for statement `init` node but doesn't usually
|
// Somewhere inside a for statement `init` node but doesn't usually
|
||||||
// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
|
// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
|
||||||
let parens = this._inForStatementInit && node.operator === "in" &&
|
let parens = this._inForStatementInitCounter && node.operator === "in" &&
|
||||||
!n.needsParens(node, parent);
|
!n.needsParens(node, parent);
|
||||||
|
|
||||||
if (parens) {
|
if (parens) {
|
||||||
|
|||||||
@ -52,9 +52,9 @@ export function ForStatement(node: Object) {
|
|||||||
this.keyword("for");
|
this.keyword("for");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
|
|
||||||
this._inForStatementInit = true;
|
this._inForStatementInitCounter++;
|
||||||
this.print(node.init, node);
|
this.print(node.init, node);
|
||||||
this._inForStatementInit = false;
|
this._inForStatementInitCounter--;
|
||||||
this.push(";");
|
this.push(";");
|
||||||
|
|
||||||
if (node.test) {
|
if (node.test) {
|
||||||
|
|||||||
@ -28,6 +28,7 @@ export class CodeGenerator extends Printer {
|
|||||||
this.format = format;
|
this.format = format;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this.ast = ast;
|
this.ast = ast;
|
||||||
|
this._inForStatementInitCounter = 0;
|
||||||
|
|
||||||
this.whitespace = new Whitespace(tokens);
|
this.whitespace = new Whitespace(tokens);
|
||||||
this.map = new SourceMap(position, opts, code);
|
this.map = new SourceMap(position, opts, code);
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
for ((a in b) ? a : b; i;);
|
for ((a in b) ? a : b; i;);
|
||||||
|
for (function(){for(;;);} && (a in b);;);
|
||||||
|
|||||||
@ -1 +1,4 @@
|
|||||||
for ((a in b) ? a : b; i;);
|
for ((a in b) ? a : b; i;);
|
||||||
|
for (function () {
|
||||||
|
for (;;);
|
||||||
|
} && (a in b);;);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user