diff --git a/CHANGELOG.md b/CHANGELOG.md index dc9e03f5e..d3a234981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.3.1 + +* Respect template inline-ness (#1497) + # 1.3.0 [link](https://github.com/jlongster/prettier/compare/1.2.2...1.3.0) diff --git a/docs/prettier.min.js b/docs/prettier.min.js index 7c7c7b776..e58b2a037 100644 --- a/docs/prettier.min.js +++ b/docs/prettier.min.js @@ -10022,7 +10022,7 @@ function printComments(path, print, options, needsSemi) { var comments$1 = { attach, printComments, printDanglingComments }; var name = "prettier"; -var version$2 = "1.3.0"; +var version$2 = "1.3.1"; var description = "Prettier is an opinionated JavaScript formatter"; var bin = {"prettier":"./bin/prettier.js"}; var repository = "prettier/prettier"; @@ -11156,8 +11156,7 @@ function genericPrintNoParens(path, options, print, args) { n.body.type === "ObjectExpression" || n.body.type === "JSXElement" || n.body.type === "BlockStatement" || - n.body.type === "TaggedTemplateExpression" || - n.body.type === "TemplateLiteral" || + isTemplateOnItsOwnLine(n.body, options.originalText) || n.body.type === "ArrowFunctionExpression" ) { return group$1(collapsed); @@ -11479,7 +11478,8 @@ function genericPrintNoParens(path, options, print, args) { // We want to keep require calls as a unit (n.callee.type === "Identifier" && n.callee.name === "require") || // Template literals as single arguments - n.arguments.length === 1 && n.arguments[0].type === "TemplateLiteral" || + (n.arguments.length === 1 && + isTemplateOnItsOwnLine(n.arguments[0], options.originalText)) || // Keep test declarations on a single line // e.g. `it('long name', () => {` (n.callee.type === "Identifier" && @@ -14708,6 +14708,22 @@ function shouldHugArguments(fun) { ); } +function templateLiteralHasNewLines(template) { + return template.quasis.some(quasi => quasi.value.raw.includes('\n')); +} + +function isTemplateOnItsOwnLine(n, text) { + return ( + (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || + n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && + !util$4.hasNewline( + text, + util$4.locStart(n), + {backwards: true} + ) + ); +} + function printArrayItems(path, options, printPath, print) { const printedElements = []; let separatorParts = []; diff --git a/package.json b/package.json index 6326c44b1..0e5ca0ef7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prettier", - "version": "1.3.0", + "version": "1.3.1", "description": "Prettier is an opinionated JavaScript formatter", "bin": { "prettier": "./bin/prettier.js"