diff --git a/src/printer.js b/src/printer.js index cd91c89d..b79c9fb8 100644 --- a/src/printer.js +++ b/src/printer.js @@ -3013,7 +3013,11 @@ function printBinaryishExpressions(path, parts, print, options, isNested) { // the other ones since we don't call the normal print on BinaryExpression, // only for the left and right parts if (isNested && node.comments) { - parts.push(comments.printComments(path, p => "", options)); + parts.splice( + 0, + parts.length, + comments.printComments(path, p => concat(parts.slice()), options) + ); } } else { // Our stopping case. Simply print the node normally. diff --git a/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap b/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap index acb94da4..09286db6 100644 --- a/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap @@ -19,6 +19,21 @@ function f() { " `; +exports[`comment.js 1`] = ` +"a = ( + // Commment 1 + (Math.random() * (yRange * (1 - minVerticalFraction))) + + (minVerticalFraction * yRange) +) - offset; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +a = + // Commment 1 + Math.random() * (yRange * (1 - minVerticalFraction)) + + minVerticalFraction * yRange - + offset; +" +`; + exports[`exp.js 1`] = ` "a ** b ** c; (a ** b) ** c; diff --git a/tests/binary-expressions/comment.js b/tests/binary-expressions/comment.js new file mode 100644 index 00000000..242ab169 --- /dev/null +++ b/tests/binary-expressions/comment.js @@ -0,0 +1,5 @@ +a = ( + // Commment 1 + (Math.random() * (yRange * (1 - minVerticalFraction))) + + (minVerticalFraction * yRange) +) - offset; diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap index 5c4bdb77..675a0790 100644 --- a/tests/comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap @@ -712,10 +712,10 @@ export type AsyncExecuteOptions = child_process$execFileOpts & { // optional trailing comma gets moved all the way to the beginning const regex = new RegExp( \\"^\\\\\\\\s*\\" + // beginning of the line - \\"name\\\\\\\\s*=\\\\\\\\s*\\" + // name = - \\"['\\\\\\"]\\" + // opening quotation mark - escapeStringRegExp(target.name) + // target name - \\"['\\\\\\"]\\" + // closing quotation mark + \\"name\\\\\\\\s*=\\\\\\\\s*\\" + // name = + \\"['\\\\\\"]\\" + // opening quotation mark + escapeStringRegExp(target.name) + // target name + \\"['\\\\\\"]\\" + // closing quotation mark \\",?$\\" // optional trailing comma ); @@ -938,10 +938,10 @@ export type AsyncExecuteOptions = child_process$execFileOpts & { // optional trailing comma gets moved all the way to the beginning const regex = new RegExp( \\"^\\\\\\\\s*\\" + // beginning of the line - \\"name\\\\\\\\s*=\\\\\\\\s*\\" + // name = - \\"['\\\\\\"]\\" + // opening quotation mark - escapeStringRegExp(target.name) + // target name - \\"['\\\\\\"]\\" + // closing quotation mark + \\"name\\\\\\\\s*=\\\\\\\\s*\\" + // name = + \\"['\\\\\\"]\\" + // opening quotation mark + escapeStringRegExp(target.name) + // target name + \\"['\\\\\\"]\\" + // closing quotation mark \\",?$\\" // optional trailing comma );