prettier 1.13.3 → 1.13.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/standalone.js CHANGED
@@ -5,7 +5,7 @@
5
5
  }(this, (function () { 'use strict';
6
6
 
7
7
  var name = "prettier";
8
- var version$1 = "1.13.3";
8
+ var version$1 = "1.13.7";
9
9
  var description = "Prettier is an opinionated code formatter";
10
10
  var bin = {
11
11
  "prettier": "./bin/prettier.js"
@@ -36,7 +36,7 @@ var dependencies = {
36
36
  "esutils": "2.0.2",
37
37
  "find-parent-dir": "0.3.0",
38
38
  "find-project-root": "1.1.1",
39
- "flow-parser": "0.73.0",
39
+ "flow-parser": "0.75.0",
40
40
  "get-stream": "3.0.0",
41
41
  "globby": "6.1.0",
42
42
  "graphql": "0.13.2",
@@ -60,7 +60,7 @@ var dependencies = {
60
60
  "semver": "5.4.1",
61
61
  "string-width": "2.1.1",
62
62
  "typescript": "2.9.0-dev.20180421",
63
- "typescript-eslint-parser": "eslint/typescript-eslint-parser#2960b002746c01fb9cb15bb5f4c1e7e925c6519a",
63
+ "typescript-eslint-parser": "16.0.0",
64
64
  "unicode-regex": "1.0.1",
65
65
  "unified": "6.1.6"
66
66
  };
@@ -79,7 +79,7 @@ var devDependencies = {
79
79
  "eslint-plugin-react": "7.7.0",
80
80
  "jest": "21.1.0",
81
81
  "mkdirp": "0.5.1",
82
- "prettier": "1.13.2",
82
+ "prettier": "1.13.4",
83
83
  "prettylint": "1.0.0",
84
84
  "rimraf": "2.6.2",
85
85
  "rollup": "0.47.6",
@@ -7274,7 +7274,7 @@ function resolveParser$1(opts, parsers) {
7274
7274
 
7275
7275
  try {
7276
7276
  return {
7277
- parse: eval("require")(path$4.resolve(process.cwd(), opts.parser)),
7277
+ parse: require(path$4.resolve(process.cwd(), opts.parser)),
7278
7278
  astFormat: "estree",
7279
7279
  locStart: locStart,
7280
7280
  locEnd: locEnd
@@ -9148,8 +9148,7 @@ function printDocToString(doc, options) {
9148
9148
  out.pop();
9149
9149
  }
9150
9150
 
9151
- if (out.length && typeof out[out.length - 1] === "string" && (options.parser !== "markdown" || // preserve markdown's `break` node (two trailing spaces)
9152
- !/\S {2}$/.test(out[out.length - 1]))) {
9151
+ if (out.length && typeof out[out.length - 1] === "string") {
9153
9152
  out[out.length - 1] = out[out.length - 1].replace(/[^\S\n]*$/, "");
9154
9153
  }
9155
9154
  }
@@ -10507,6 +10506,13 @@ function attachComments(text, ast, opts) {
10507
10506
  }
10508
10507
 
10509
10508
  function coreFormat(text, opts, addAlignmentSize) {
10509
+ if (!text || !text.trim().length) {
10510
+ return {
10511
+ formatted: "",
10512
+ cursorOffset: 0
10513
+ };
10514
+ }
10515
+
10510
10516
  addAlignmentSize = addAlignmentSize || 0;
10511
10517
  var parsed = parser.parse(text, opts);
10512
10518
  var ast = parsed.ast;
@@ -11902,12 +11908,22 @@ var comments$3 = {
11902
11908
  isBlockComment: isBlockComment
11903
11909
  };
11904
11910
 
11905
- function hasClosureCompilerTypeCastComment(text, node, locEnd) {
11911
+ function hasClosureCompilerTypeCastComment(text, path, locStart, locEnd) {
11906
11912
  // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
11907
11913
  // Syntax example: var x = /** @type {string} */ (fruit);
11908
- return node.comments && node.comments.some(function (comment) {
11909
- return comment.leading && comments$3.isBlockComment(comment) && comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) && util.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
11910
- });
11914
+ var n = path.getValue();
11915
+ return util.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
11916
+
11917
+ function hasAncestorTypeCastComment(index) {
11918
+ var ancestor = path.getParentNode(index);
11919
+ return ancestor && util.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
11920
+ }
11921
+
11922
+ function hasTypeCastComment(node) {
11923
+ return node.comments && node.comments.some(function (comment) {
11924
+ return comment.leading && comments$3.isBlockComment(comment) && comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) && util.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
11925
+ });
11926
+ }
11911
11927
  }
11912
11928
 
11913
11929
  function needsParens(path, options) {
@@ -11933,7 +11949,7 @@ function needsParens(path, options) {
11933
11949
  // parentheses.
11934
11950
 
11935
11951
 
11936
- if (hasClosureCompilerTypeCastComment(options.originalText, node, options.locEnd)) {
11952
+ if (hasClosureCompilerTypeCastComment(options.originalText, path, options.locStart, options.locEnd)) {
11937
11953
  return true;
11938
11954
  } // Identifiers never need parentheses.
11939
11955
 
@@ -14078,7 +14094,6 @@ function printPathNoParens(path, options, print, args) {
14078
14094
 
14079
14095
  case "DeclareInterface":
14080
14096
  case "InterfaceDeclaration":
14081
- case "InterfaceType":
14082
14097
  case "InterfaceTypeAnnotation":
14083
14098
  {
14084
14099
  if (n.type === "DeclareInterface" || isNodeStartingWithDeclare(n, options)) {
@@ -14483,7 +14498,7 @@ function printPathNoParens(path, options, print, args) {
14483
14498
 
14484
14499
  case "TSLastTypeNode":
14485
14500
  // TSImportType
14486
- return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path.call(print, "argument"), ")", !n.qualifier ? "" : concat$4([".", path.call(print, "qualifier")])]);
14501
+ return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path.call(print, "argument"), ")", !n.qualifier ? "" : concat$4([".", path.call(print, "qualifier")]), printTypeParameters(path, options, print, "typeParameters")]);
14487
14502
 
14488
14503
  case "TSLiteralType":
14489
14504
  return path.call(print, "literal");
@@ -15539,12 +15554,13 @@ function printMemberChain(path, options, print) {
15539
15554
  // .map(x => x)
15540
15555
  //
15541
15556
  // In order to detect those cases, we use an heuristic: if the first
15542
- // node is an identifier with the name starting with a capital letter.
15543
- // The rationale is that they are likely to be factories.
15557
+ // node is an identifier with the name starting with a capital
15558
+ // letter or just a sequence of _$. The rationale is that they are
15559
+ // likely to be factories.
15544
15560
 
15545
15561
 
15546
15562
  function isFactory(name) {
15547
- return /^[A-Z]/.test(name);
15563
+ return /^[A-Z]|^[_$]+$/.test(name);
15548
15564
  } // In case the Identifier is shorter than tab width, we can keep the
15549
15565
  // first call in a single line, if it's an ExpressionStatement.
15550
15566
  //
@@ -16686,6 +16702,10 @@ function genericPrint$2(path, options, print) {
16686
16702
 
16687
16703
  case "Identifier":
16688
16704
  return JSON.stringify(node.name);
16705
+
16706
+ default:
16707
+ /* istanbul ignore next */
16708
+ throw new Error("unknown type: " + JSON.stringify(node.type));
16689
16709
  }
16690
16710
  }
16691
16711
 
@@ -18026,13 +18046,16 @@ function genericPrint$4(path, options, print) {
18026
18046
  var parts = [];
18027
18047
  path.map(function (pathChild, index) {
18028
18048
  parts.push(concat$8([pathChild.call(print)]));
18029
- parts.push(hardline$7);
18030
18049
 
18031
- if (index !== n.definitions.length - 1 && isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
18050
+ if (index !== n.definitions.length - 1) {
18032
18051
  parts.push(hardline$7);
18052
+
18053
+ if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
18054
+ parts.push(hardline$7);
18055
+ }
18033
18056
  }
18034
18057
  }, "definitions");
18035
- return concat$8(parts, hardline$7);
18058
+ return concat$8([concat$8(parts), hardline$7]);
18036
18059
  }
18037
18060
 
18038
18061
  case "OperationDefinition":
@@ -18337,9 +18360,9 @@ var languageGraphql = {
18337
18360
 
18338
18361
  var _require$$0$builders$5 = doc.builders;
18339
18362
  var hardline$9 = _require$$0$builders$5.hardline;
18340
- var literalline$3 = _require$$0$builders$5.literalline;
18363
+ var literalline$4 = _require$$0$builders$5.literalline;
18341
18364
  var concat$10 = _require$$0$builders$5.concat;
18342
- var markAsRoot$1 = _require$$0$builders$5.markAsRoot;
18365
+ var markAsRoot$2 = _require$$0$builders$5.markAsRoot;
18343
18366
  var mapDoc$4 = doc.utils.mapDoc;
18344
18367
 
18345
18368
  function embed$2(path, print, textToDoc, options) {
@@ -18356,7 +18379,7 @@ function embed$2(path, print, textToDoc, options) {
18356
18379
  var doc$$2 = textToDoc(node.value, {
18357
18380
  parser: parser
18358
18381
  });
18359
- return markAsRoot$1(concat$10([style, node.lang, hardline$9, replaceNewlinesWithLiterallines(doc$$2), style]));
18382
+ return markAsRoot$2(concat$10([style, node.lang, hardline$9, replaceNewlinesWithLiterallines(doc$$2), style]));
18360
18383
  }
18361
18384
  }
18362
18385
 
@@ -18382,7 +18405,7 @@ function embed$2(path, print, textToDoc, options) {
18382
18405
  function replaceNewlinesWithLiterallines(doc$$2) {
18383
18406
  return mapDoc$4(doc$$2, function (currentDoc) {
18384
18407
  return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$10(currentDoc.split(/(\n)/g).map(function (v, i) {
18385
- return i % 2 === 0 ? v : literalline$3;
18408
+ return i % 2 === 0 ? v : literalline$4;
18386
18409
  })) : currentDoc;
18387
18410
  });
18388
18411
  }
@@ -18446,6 +18469,8 @@ var _require$$0$builders$4 = doc.builders;
18446
18469
  var concat$9 = _require$$0$builders$4.concat;
18447
18470
  var join$7 = _require$$0$builders$4.join;
18448
18471
  var line$6 = _require$$0$builders$4.line;
18472
+ var literalline$3 = _require$$0$builders$4.literalline;
18473
+ var markAsRoot$1 = _require$$0$builders$4.markAsRoot;
18449
18474
  var hardline$8 = _require$$0$builders$4.hardline;
18450
18475
  var softline$5 = _require$$0$builders$4.softline;
18451
18476
  var fill$4 = _require$$0$builders$4.fill;
@@ -18578,7 +18603,9 @@ function genericPrint$5(path, options, print) {
18578
18603
  {
18579
18604
  var _parentNode2 = path.getParentNode();
18580
18605
 
18581
- return replaceNewlinesWithHardlines(_parentNode2.type === "root" && util.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value);
18606
+ var value = _parentNode2.type === "root" && util.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
18607
+ var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
18608
+ return replaceNewlinesWith(value, isHtmlComment ? hardline$8 : markAsRoot$1(literalline$3));
18582
18609
  }
18583
18610
 
18584
18611
  case "list":
@@ -18656,10 +18683,10 @@ function genericPrint$5(path, options, print) {
18656
18683
  return printChildren(path, options, print);
18657
18684
 
18658
18685
  case "break":
18659
- return concat$9([/\s/.test(options.originalText[node.position.start.offset]) ? " " : "\\", hardline$8]);
18686
+ return /\s/.test(options.originalText[node.position.start.offset]) ? concat$9([" ", markAsRoot$1(literalline$3)]) : concat$9(["\\", hardline$8]);
18660
18687
 
18661
18688
  case "liquidNode":
18662
- return replaceNewlinesWithHardlines(node.value);
18689
+ return replaceNewlinesWith(node.value, hardline$8);
18663
18690
 
18664
18691
  case "tableRow": // handled in "table"
18665
18692
 
@@ -18703,8 +18730,8 @@ function getNthListSiblingIndex(node, parentNode) {
18703
18730
  });
18704
18731
  }
18705
18732
 
18706
- function replaceNewlinesWithHardlines(str) {
18707
- return join$7(hardline$8, str.split("\n"));
18733
+ function replaceNewlinesWith(str, doc$$2) {
18734
+ return join$7(doc$$2, str.split("\n"));
18708
18735
  }
18709
18736
 
18710
18737
  function getNthSiblingIndex(node, parentNode, condition) {
@@ -18975,7 +19002,8 @@ function shouldPrePrintDoubleHardline(node, data) {
18975
19002
  var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
18976
19003
  var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
18977
19004
  var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
18978
- return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore);
19005
+ var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
19006
+ return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
18979
19007
  }
18980
19008
 
18981
19009
  function shouldPrePrintTripleHardline(node, data) {
Binary file