Comparing version
@@ -0,1 +1,29 @@ | ||
# 0.15.0 | ||
[link](https://github.com/jlongster/prettier/compare/0.14.1...0.15.0) | ||
* Fix syntax error in empty object with dangling comment (#533) | ||
* Fix closing call expression commented out (#530) | ||
* Update `bracketSpacing` comment to say it's about {} (#529) | ||
* Add 0.14.1 to CHANGELOG (#525) | ||
* Print \x and \u escapes in strings and regexes lowercase (#522) | ||
* Fix Jetbrains example screenshot url. (#534) | ||
* Preserve next line with trailing comment (#535) | ||
* Break nested calls (#517) | ||
* Update snapshot tests from conflicting PRs | ||
* Reimplement MemberExpression printing (#469) | ||
* Remove spurious test.js | ||
* Fix small typo on Jetbrains section (#552) | ||
* [JSX] Handle non-breaking space (#557) | ||
* Make comments between if & else to look good (#544) | ||
* Whitelist UnaryExpression for parentless objects (#545) | ||
* Make comments inside of MemberExpression look good (#556) | ||
# 0.14.1 | ||
[link](https://github.com/jlongster/prettier/compare/0.14.0...0.14.1) | ||
* Fix range for object newline detection (#520) | ||
* a bugfix for "Keep expanded objects expanded" (#495) | ||
# 0.14.0 | ||
@@ -2,0 +30,0 @@ |
@@ -11,3 +11,3 @@ ### Configure External Tool | ||
 | ||
 | ||
@@ -18,4 +18,4 @@ If on the other hand you have `prettier` installed locally, replace the **Program** with `./node_modules/.bin/prettier` (on OS X and Linux) or `.\node_modules\.bin\prettier.cmd` (on Windows). | ||
Now when you setup **Extarnal Tool** I guess you what to add hotkey for it. Go to *File | Settings | Keymap* for Windows and Linux *WebStorm | Preferences | Keymap* and type external tool name in search box. | ||
Now when you setup **External Tool** I guess you what to add hotkey for it. Go to *File | Settings | Keymap* for Windows and Linux *WebStorm | Preferences | Keymap* and type external tool name in search box. | ||
See [this documentation](https://www.jetbrains.com/help/webstorm/configuring-keyboard-shortcuts.html) about configuring keyboard shortcuts. | ||
See [this documentation](https://www.jetbrains.com/help/webstorm/configuring-keyboard-shortcuts.html) about configuring keyboard shortcuts. |
{ | ||
"name": "prettier", | ||
"version": "0.14.1", | ||
"version": "0.15.0", | ||
"description": "Prettier is an opinionated JavaScript formatter", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -148,3 +148,3 @@ # Prettier | ||
// Controls the printing of spaces inside array and objects | ||
// Controls the printing of spaces inside object literals | ||
bracketSpacing: true, | ||
@@ -151,0 +151,0 @@ |
@@ -154,4 +154,6 @@ var assert = require("assert"); | ||
// We also need to check if it's the first line of the file. | ||
if (followingNode) { | ||
if (handleMemberExpressionComment(enclosingNode, followingNode, comment) || | ||
handleIfStatementComments(enclosingNode, followingNode, comment)) { | ||
// We're good | ||
} else if (followingNode) { | ||
// Always a leading comment. | ||
@@ -282,2 +284,60 @@ addLeadingComment(followingNode, comment); | ||
function addBlockStatementFirstComment(node, comment) { | ||
if (node.body.length === 0) { | ||
addDanglingComment(node, comment); | ||
} else { | ||
addLeadingComment(node.body[0], comment); | ||
} | ||
} | ||
// There are often comments before the else clause of if statements like | ||
// | ||
// if (1) { ... } | ||
// // comment | ||
// else { ... } | ||
// | ||
// They are being attached as leading comments of the BlockExpression which | ||
// is not well printed. What we want is to instead move the comment inside | ||
// of the block and make it leadingComment of the first element of the block | ||
// or dangling comment of the block if there is nothing inside | ||
// | ||
// if (1) { ... } | ||
// else { | ||
// // comment | ||
// ... | ||
// } | ||
function handleIfStatementComments(enclosingNode, followingNode, comment) { | ||
if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) { | ||
return false; | ||
} | ||
if (followingNode.type === "BlockStatement") { | ||
addBlockStatementFirstComment(followingNode, comment); | ||
return true; | ||
} | ||
if (followingNode.type === "IfStatement") { | ||
if (followingNode.consequent.type === "BlockStatement") { | ||
addBlockStatementFirstComment(followingNode.consequent, comment); | ||
} else { | ||
addLeadingComment(followingNode.consequent, comment); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
function handleMemberExpressionComment(enclosingNode, followingNode, comment) { | ||
if (enclosingNode && | ||
enclosingNode.type === "MemberExpression" && | ||
followingNode && | ||
followingNode.type === "Identifier") { | ||
addLeadingComment(enclosingNode, comment); | ||
return true; | ||
} | ||
return false; | ||
} | ||
function printComment(commentPath) { | ||
@@ -284,0 +344,0 @@ const comment = commentPath.getValue(); |
@@ -128,3 +128,30 @@ "use strict"; | ||
const skipToLineEnd = skip("; \t"); | ||
const skipEverythingButNewLine = skip(/[^\r\n]/); | ||
function skipInlineComment(text, index) { | ||
if (index === false) { | ||
return false; | ||
} | ||
if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") { | ||
for (var i = index + 2; i < text.length; ++i) { | ||
if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") { | ||
return i + 2; | ||
} | ||
} | ||
} | ||
return index; | ||
} | ||
function skipTrailingComment(text, index) { | ||
if (index === false) { | ||
return false; | ||
} | ||
if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") { | ||
return skipEverythingButNewLine(text, index); | ||
} | ||
return index; | ||
} | ||
// This one doesn't use the above helper function because it wants to | ||
@@ -173,4 +200,12 @@ // test \r\n in order and `skip` doesn't support ordering and we only | ||
function isNextLineEmpty(text, node) { | ||
let oldIdx = null; | ||
let idx = locEnd(node); | ||
idx = skipToLineEnd(text, idx); | ||
while (idx !== oldIdx) { | ||
// We need to skip all the potential trailing inline comments | ||
oldIdx = idx; | ||
idx = skipInlineComment(text, idx); | ||
idx = skipSpaces(text, idx); | ||
} | ||
idx = skipTrailingComment(text, idx); | ||
idx = skipNewline(text, idx); | ||
@@ -177,0 +212,0 @@ return hasNewline(text, idx); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1045572
0.77%30
3.45%7116
2.55%