diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 36c3b685c351..124fa0d77f3f 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -2839,8 +2839,12 @@ function printPathNoParens(path, options, print, args) { return join(" | ", printed); } + const shouldAddStartLine = + shouldIndent && + !hasLeadingOwnLineComment(options.originalText, n, options); + const code = concat([ - ifBreak(concat([shouldIndent ? line : "", "| "])), + ifBreak(concat([shouldAddStartLine ? line : "", "| "])), join(concat([line, "| "]), printed) ]); diff --git a/tests/flow_union/__snapshots__/jsfmt.spec.js.snap b/tests/flow_union/__snapshots__/jsfmt.spec.js.snap index 0818a8c2920f..39a4eeb6f651 100644 --- a/tests/flow_union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow_union/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,27 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`comment.js 1`] = ` +====================================options===================================== +parsers: ["flow", "babylon"] +printWidth: 80 + | printWidth +=====================================input====================================== +const myValue = (callcallcallcallcallcall(87689769876876897698768768976987687689769876): + // Comment + one | two| thre | jdkxhflksjdhfglkjsdhfglkjhsdkfljghskdjhfgkljshdfgkjhsdkljfhgkljshdfgjdfklgjhklj ); + +=====================================output===================================== +const myValue = (callcallcallcallcallcall( + 87689769876876897698768768976987687689769876 +): // Comment +| one + | two + | thre + | jdkxhflksjdhfglkjsdhfglkjhsdkfljghskdjhfgkljshdfgkjhsdkljfhgkljshdfgjdfklgjhklj); + +================================================================================ +`; + exports[`union.js 1`] = ` ====================================options===================================== parsers: ["flow", "babylon"] diff --git a/tests/flow_union/comment.js b/tests/flow_union/comment.js new file mode 100644 index 000000000000..8deb0144d286 --- /dev/null +++ b/tests/flow_union/comment.js @@ -0,0 +1,3 @@ +const myValue = (callcallcallcallcallcall(87689769876876897698768768976987687689769876): + // Comment + one | two| thre | jdkxhflksjdhfglkjsdhfglkjhsdkfljghskdjhfgkljshdfgkjhsdkljfhgkljshdfgjdfklgjhklj );