node_modules/prettier/index.js in prettier-0.12.2 vs node_modules/prettier/index.js in prettier-0.12.3
- old
+ new
@@ -10,11 +10,11 @@
var events = _interopDefault(require('events'));
var thirdParty = require('./third-party');
var thirdParty__default = thirdParty['default'];
var name = "prettier";
-var version$1 = "1.17.0";
+var version$1 = "1.17.1";
var description = "Prettier is an opinionated code formatter";
var bin = {
"prettier": "./bin/prettier.js"
};
var repository = "prettier/prettier";
@@ -106,11 +106,11 @@
"jest-junit": "5.0.0",
"jest-snapshot-serializer-ansi": "1.0.0",
"jest-snapshot-serializer-raw": "1.1.0",
"jest-watch-typeahead": "0.1.0",
"mkdirp": "0.5.1",
- "prettier": "1.16.4",
+ "prettier": "1.17.0",
"prettylint": "1.0.0",
"rimraf": "2.6.2",
"rollup": "0.47.6",
"rollup-plugin-alias": "1.4.0",
"rollup-plugin-babel": "4.0.0-beta.4",
@@ -13961,11 +13961,10 @@
var indentString = text.slice(rangeStart2, rangeStart);
var alignmentSize = util$1.getAlignmentSize(indentString, opts.tabWidth);
var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
rangeStart: 0,
rangeEnd: Infinity,
- printWidth: opts.printWidth - alignmentSize,
// track the cursor offset only if it's within our range
cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
}), alignmentSize); // Since the range contracts to avoid trailing whitespace,
// we need to remove the newline that was inserted by the `format` call.
@@ -22823,42 +22822,51 @@
hasFlowAnnotationComment: hasFlowAnnotationComment$1
};
var hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment;
-function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
+function hasClosureCompilerTypeCastComment(text, path$$1) {
// https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
// Syntax example: var x = /** @type {string} */ (fruit);
var n = path$$1.getValue();
- return util$1.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
+ return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
function hasAncestorTypeCastComment(index) {
var ancestor = path$$1.getParentNode(index);
- return ancestor && util$1.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
+ return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
}
function hasTypeCastComment(node) {
return node.comments && node.comments.some(function (comment) {
- return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
+ return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
});
}
+ function isParenthesized(node) {
+ // Closure typecast comments only really make sense when _not_ using
+ // typescript or flow parsers, so we take advantage of the babel parser's
+ // parenthesized expressions.
+ return node.extra && node.extra.parenthesized;
+ }
+
function isTypeCastComment(comment) {
- var trimmed = comment.trim();
+ var cleaned = comment.trim().split("\n").map(function (line) {
+ return line.replace(/^[\s*]+/, "");
+ }).join(" ").trim();
- if (!/^\*\s*@type\s*\{[^]+\}$/.test(trimmed)) {
+ if (!/^@type\s+\{[^]+\}$/.test(cleaned)) {
return false;
}
var isCompletelyClosed = false;
var unpairedBracketCount = 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
- for (var _iterator = trimmed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
+ for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var char = _step.value;
if (char === "{") {
if (isCompletelyClosed) {
return false;
@@ -22922,11 +22930,11 @@
return false;
} // Closure compiler requires that type casted expressions to be surrounded by
// parentheses.
- if (hasClosureCompilerTypeCastComment(options.originalText, path$$1, options.locStart, options.locEnd)) {
+ if (hasClosureCompilerTypeCastComment(options.originalText, path$$1)) {
return true;
}
if ( // Preserve parens if we have a Flow annotation comment, unless we're using the Flow
// parser. The Flow parser turns Flow comments into type annotation nodes in its
@@ -23233,10 +23241,11 @@
case "SpreadElement":
case "SpreadProperty":
case "TSAsExpression":
case "TSNonNullExpression":
case "BindExpression":
+ case "OptionalMemberExpression":
return true;
case "MemberExpression":
return parent.object === node;
@@ -30226,11 +30235,11 @@
}
case "BlockStatement":
{
var pp = path$$1.getParentNode(1);
- var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
- var hasElseIf = n.inverse && n.inverse.body[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
+ var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
+ var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
var indentElse = hasElseIf ? function (a) {
return a;
} : indent$6;
if (n.inverse) {