diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 96019523..b84cb60a 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -2491,10 +2491,8 @@ function printPathNoParens(path, options, print, args) { // expression inside at the beginning of ${ instead of the beginning // of the `. const tabWidth = options.tabWidth; - const indentSize = getIndentSize( - childPath.getValue().value.raw, - tabWidth - ); + const quasi = childPath.getValue(); + const indentSize = getIndentSize(quasi.value.raw, tabWidth); let printed = expressions[i]; @@ -2507,7 +2505,10 @@ function printPathNoParens(path, options, print, args) { printed = concat([indent(concat([softline, printed])), softline]); } - const aligned = addAlignmentToDoc(printed, indentSize, tabWidth); + const aligned = + indentSize === 0 && quasi.value.raw.endsWith("\n") + ? align(-Infinity, printed) + : addAlignmentToDoc(printed, indentSize, tabWidth); parts.push(group(concat(["${", aligned, lineSuffixBoundary, "}"]))); } diff --git a/tests/template/__snapshots__/jsfmt.spec.js.snap b/tests/template/__snapshots__/jsfmt.spec.js.snap index 5c01b016..8fd4c040 100644 --- a/tests/template/__snapshots__/jsfmt.spec.js.snap +++ b/tests/template/__snapshots__/jsfmt.spec.js.snap @@ -187,6 +187,59 @@ module.exports = Relay.createContainer( ================================================================================ `; +exports[`indent.js 1`] = ` +====================================options===================================== +parsers: ["flow", "babylon"] +printWidth: 80 + | printWidth +=====================================input====================================== +const foo = () => { + { + { + { + return \` +line 1 +line 2 +... +line n +\${foo({ + many: keys, + many: keys +})} +line n + 1 +line n + 2 +line n + n +\`; + } + } + } +}; +=====================================output===================================== +const foo = () => { + { + { + { + return \` +line 1 +line 2 +... +line n +\${foo({ + many: keys, + many: keys +})} +line n + 1 +line n + 2 +line n + n +\`; + } + } + } +}; + +================================================================================ +`; + exports[`inline.js 1`] = ` ====================================options===================================== parsers: ["flow", "babylon"] diff --git a/tests/template/indent.js b/tests/template/indent.js new file mode 100644 index 00000000..a2dc7013 --- /dev/null +++ b/tests/template/indent.js @@ -0,0 +1,21 @@ +const foo = () => { + { + { + { + return ` +line 1 +line 2 +... +line n +${foo({ + many: keys, + many: keys +})} +line n + 1 +line n + 2 +line n + n +`; + } + } + } +}; \ No newline at end of file