diff --git a/src/language-js/embed.js b/src/language-js/embed.js index a47585906179..a338e4c406a8 100644 --- a/src/language-js/embed.js +++ b/src/language-js/embed.js @@ -582,6 +582,10 @@ function printHtmlTemplateLiteral(path, print, textToDoc, parser) { const expressionDocs = path.map(print, "expressions"); + if (expressionDocs.length === 0 && text.trim().length === 0) { + return "``"; + } + const contentDoc = mapDoc( stripTrailingHardline(textToDoc(text, { parser })), doc => { @@ -626,7 +630,9 @@ function printHtmlTemplateLiteral(path, print, textToDoc, parser) { } ); - return concat(["`", indent(concat([hardline, contentDoc])), softline, "`"]); + return group( + concat(["`", indent(concat([hardline, group(contentDoc)])), softline, "`"]) + ); } module.exports = embed; diff --git a/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap b/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap index 4f01fba7a1c2..1bf9d50f0800 100644 --- a/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap +++ b/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap @@ -45,6 +45,8 @@ customElements.define('my-element', MyElement); const someHtml1 = html\`