prettier 1.13.1 → 1.13.5

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.1";
8
+ var version$1 = "1.13.5";
9
9
  var description = "Prettier is an opinionated code formatter";
10
10
  var bin = {
11
11
  "prettier": "./bin/prettier.js"
@@ -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.0",
82
+ "prettier": "1.13.4",
83
83
  "prettylint": "1.0.0",
84
84
  "rimraf": "2.6.2",
85
85
  "rollup": "0.47.6",
@@ -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;
@@ -14817,28 +14823,17 @@ function shouldGroupFirstArg(args) {
14817
14823
  return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && !couldGroupArg(secondArg);
14818
14824
  }
14819
14825
 
14820
- var functionCompositionFunctionNames = {
14821
- pipe: true,
14822
- // RxJS, Ramda
14823
- pipeP: true,
14824
- // Ramda
14825
- pipeK: true,
14826
- // Ramda
14827
- compose: true,
14828
- // Ramda, Redux
14829
- composeFlipped: true,
14830
- // Not from any library, but common in Haskell, so supported
14831
- composeP: true,
14832
- // Ramda
14833
- composeK: true,
14834
- // Ramda
14835
- flow: true,
14836
- // Lodash
14837
- flowRight: true,
14838
- // Lodash
14839
- connect: true // Redux
14840
-
14841
- };
14826
+ var functionCompositionFunctionNames = new Set(["pipe", // RxJS, Ramda
14827
+ "pipeP", // Ramda
14828
+ "pipeK", // Ramda
14829
+ "compose", // Ramda, Redux
14830
+ "composeFlipped", // Not from any library, but common in Haskell, so supported
14831
+ "composeP", // Ramda
14832
+ "composeK", // Ramda
14833
+ "flow", // Lodash
14834
+ "flowRight", // Lodash
14835
+ "connect" // Redux
14836
+ ]);
14842
14837
 
14843
14838
  function isFunctionCompositionFunction(node) {
14844
14839
  switch (node.type) {
@@ -14850,13 +14845,13 @@ function isFunctionCompositionFunction(node) {
14850
14845
 
14851
14846
  case "Identifier":
14852
14847
  {
14853
- return functionCompositionFunctionNames[node.name];
14848
+ return functionCompositionFunctionNames.has(node.name);
14854
14849
  }
14855
14850
 
14856
14851
  case "StringLiteral":
14857
14852
  case "Literal":
14858
14853
  {
14859
- return functionCompositionFunctionNames[node.value];
14854
+ return functionCompositionFunctionNames.has(node.value);
14860
14855
  }
14861
14856
  }
14862
14857
  }
@@ -15550,12 +15545,13 @@ function printMemberChain(path, options, print) {
15550
15545
  // .map(x => x)
15551
15546
  //
15552
15547
  // In order to detect those cases, we use an heuristic: if the first
15553
- // node is an identifier with the name starting with a capital letter.
15554
- // The rationale is that they are likely to be factories.
15548
+ // node is an identifier with the name starting with a capital
15549
+ // letter or just a sequence of _$. The rationale is that they are
15550
+ // likely to be factories.
15555
15551
 
15556
15552
 
15557
15553
  function isFactory(name) {
15558
- return /^[A-Z]/.test(name);
15554
+ return /^[A-Z]|^[_$]+$/.test(name);
15559
15555
  } // In case the Identifier is shorter than tab width, we can keep the
15560
15556
  // first call in a single line, if it's an ExpressionStatement.
15561
15557
  //
@@ -16697,6 +16693,10 @@ function genericPrint$2(path, options, print) {
16697
16693
 
16698
16694
  case "Identifier":
16699
16695
  return JSON.stringify(node.name);
16696
+
16697
+ default:
16698
+ /* istanbul ignore next */
16699
+ throw new Error("unknown type: " + JSON.stringify(node.type));
16700
16700
  }
16701
16701
  }
16702
16702
 
@@ -17010,6 +17010,8 @@ function cleanCSSStrings(value) {
17010
17010
 
17011
17011
  var clean_1$2 = clean$3;
17012
17012
 
17013
+ var colorAdjusterFunctions = ["red", "green", "blue", "alpha", "a", "rgb", "hue", "h", "saturation", "s", "lightness", "l", "whiteness", "w", "blackness", "b", "tint", "shade", "blend", "blenda", "contrast", "hsl", "hsla", "hwb", "hwba"];
17014
+
17013
17015
  function getAncestorCounter(path, typeOrTypes) {
17014
17016
  var types = [].concat(typeOrTypes);
17015
17017
  var counter = -1;
@@ -17249,6 +17251,14 @@ function isMediaAndSupportsKeywords$1(node) {
17249
17251
  return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
17250
17252
  }
17251
17253
 
17254
+ function isColorAdjusterFuncNode$1(node) {
17255
+ if (node.type !== "value-func") {
17256
+ return false;
17257
+ }
17258
+
17259
+ return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
17260
+ }
17261
+
17252
17262
  var utils$4 = {
17253
17263
  getAncestorCounter: getAncestorCounter,
17254
17264
  getAncestorNode: getAncestorNode$1,
@@ -17292,7 +17302,8 @@ var utils$4 = {
17292
17302
  isRightCurlyBraceNode: isRightCurlyBraceNode$1,
17293
17303
  isWordNode: isWordNode$1,
17294
17304
  isColonNode: isColonNode$1,
17295
- isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1
17305
+ isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1,
17306
+ isColorAdjusterFuncNode: isColorAdjusterFuncNode$1
17296
17307
  };
17297
17308
 
17298
17309
  var printNumber$2 = util.printNumber;
@@ -17351,6 +17362,7 @@ var isRightCurlyBraceNode = utils$4.isRightCurlyBraceNode;
17351
17362
  var isWordNode = utils$4.isWordNode;
17352
17363
  var isColonNode = utils$4.isColonNode;
17353
17364
  var isMediaAndSupportsKeywords = utils$4.isMediaAndSupportsKeywords;
17365
+ var isColorAdjusterFuncNode = utils$4.isColorAdjusterFuncNode;
17354
17366
 
17355
17367
  function shouldPrintComma$1(options) {
17356
17368
  switch (options.trailingComma) {
@@ -17596,6 +17608,7 @@ function genericPrint$3(path, options, print) {
17596
17608
  {
17597
17609
  var _parentNode2 = path.getParentNode();
17598
17610
 
17611
+ var parentParentNode = path.getParentNode(1);
17599
17612
  var declAncestorProp = getPropOfDeclNode(path);
17600
17613
  var isGridValue = declAncestorProp && _parentNode2.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
17601
17614
  var atRuleAncestorNode = getAncestorNode(path, "css-atrule");
@@ -17686,12 +17699,15 @@ function genericPrint$3(path, options, print) {
17686
17699
 
17687
17700
  if (insideValueFunctionNode(path, "calc") && (isAdditionNode(iNode) || isAdditionNode(iNextNode) || isSubtractionNode(iNode) || isSubtractionNode(iNextNode)) && hasEmptyRawBefore(iNextNode)) {
17688
17701
  continue;
17689
- }
17702
+ } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
17703
+ // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
17704
+
17690
17705
 
17706
+ var isColorAdjusterNode = (isAdditionNode(iNode) || isSubtractionNode(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode(parentParentNode) && !hasEmptyRawBefore(iNextNode);
17691
17707
  var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode(iNextNextNode) || iNode.type === "value-func" || isWordNode(iNode);
17692
17708
  var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode(iPrevNode); // Formatting `/`, `+`, `-` sign
17693
17709
 
17694
- if (!(isMultiplicationNode(iNextNode) || isMultiplicationNode(iNode)) && !insideValueFunctionNode(path, "calc") && (isDivisionNode(iNextNode) && !requireSpaceBeforeOperator || isDivisionNode(iNode) && !requireSpaceAfterOperator || isAdditionNode(iNextNode) && !requireSpaceBeforeOperator || isAdditionNode(iNode) && !requireSpaceAfterOperator || isSubtractionNode(iNextNode) || isSubtractionNode(iNode)) && (hasEmptyRawBefore(iNextNode) || isMathOperator && (!iPrevNode || iPrevNode && isMathOperatorNode(iPrevNode)))) {
17710
+ if (!(isMultiplicationNode(iNextNode) || isMultiplicationNode(iNode)) && !insideValueFunctionNode(path, "calc") && !isColorAdjusterNode && (isDivisionNode(iNextNode) && !requireSpaceBeforeOperator || isDivisionNode(iNode) && !requireSpaceAfterOperator || isAdditionNode(iNextNode) && !requireSpaceBeforeOperator || isAdditionNode(iNode) && !requireSpaceAfterOperator || isSubtractionNode(iNextNode) || isSubtractionNode(iNode)) && (hasEmptyRawBefore(iNextNode) || isMathOperator && (!iPrevNode || iPrevNode && isMathOperatorNode(iPrevNode)))) {
17695
17711
  continue;
17696
17712
  } // Ignore inline comment, they already contain newline at end (i.e. `// Comment`)
17697
17713
  // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
@@ -18021,13 +18037,16 @@ function genericPrint$4(path, options, print) {
18021
18037
  var parts = [];
18022
18038
  path.map(function (pathChild, index) {
18023
18039
  parts.push(concat$8([pathChild.call(print)]));
18024
- parts.push(hardline$7);
18025
18040
 
18026
- if (index !== n.definitions.length - 1 && isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
18041
+ if (index !== n.definitions.length - 1) {
18027
18042
  parts.push(hardline$7);
18043
+
18044
+ if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
18045
+ parts.push(hardline$7);
18046
+ }
18028
18047
  }
18029
18048
  }, "definitions");
18030
- return concat$8(parts, hardline$7);
18049
+ return concat$8([concat$8(parts), hardline$7]);
18031
18050
  }
18032
18051
 
18033
18052
  case "OperationDefinition":
@@ -18332,9 +18351,9 @@ var languageGraphql = {
18332
18351
 
18333
18352
  var _require$$0$builders$5 = doc.builders;
18334
18353
  var hardline$9 = _require$$0$builders$5.hardline;
18335
- var literalline$3 = _require$$0$builders$5.literalline;
18354
+ var literalline$4 = _require$$0$builders$5.literalline;
18336
18355
  var concat$10 = _require$$0$builders$5.concat;
18337
- var markAsRoot$1 = _require$$0$builders$5.markAsRoot;
18356
+ var markAsRoot$2 = _require$$0$builders$5.markAsRoot;
18338
18357
  var mapDoc$4 = doc.utils.mapDoc;
18339
18358
 
18340
18359
  function embed$2(path, print, textToDoc, options) {
@@ -18351,7 +18370,7 @@ function embed$2(path, print, textToDoc, options) {
18351
18370
  var doc$$2 = textToDoc(node.value, {
18352
18371
  parser: parser
18353
18372
  });
18354
- return markAsRoot$1(concat$10([style, node.lang, hardline$9, replaceNewlinesWithLiterallines(doc$$2), style]));
18373
+ return markAsRoot$2(concat$10([style, node.lang, hardline$9, replaceNewlinesWithLiterallines(doc$$2), style]));
18355
18374
  }
18356
18375
  }
18357
18376
 
@@ -18377,7 +18396,7 @@ function embed$2(path, print, textToDoc, options) {
18377
18396
  function replaceNewlinesWithLiterallines(doc$$2) {
18378
18397
  return mapDoc$4(doc$$2, function (currentDoc) {
18379
18398
  return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$10(currentDoc.split(/(\n)/g).map(function (v, i) {
18380
- return i % 2 === 0 ? v : literalline$3;
18399
+ return i % 2 === 0 ? v : literalline$4;
18381
18400
  })) : currentDoc;
18382
18401
  });
18383
18402
  }
@@ -18441,6 +18460,8 @@ var _require$$0$builders$4 = doc.builders;
18441
18460
  var concat$9 = _require$$0$builders$4.concat;
18442
18461
  var join$7 = _require$$0$builders$4.join;
18443
18462
  var line$6 = _require$$0$builders$4.line;
18463
+ var literalline$3 = _require$$0$builders$4.literalline;
18464
+ var markAsRoot$1 = _require$$0$builders$4.markAsRoot;
18444
18465
  var hardline$8 = _require$$0$builders$4.hardline;
18445
18466
  var softline$5 = _require$$0$builders$4.softline;
18446
18467
  var fill$4 = _require$$0$builders$4.fill;
@@ -18573,7 +18594,9 @@ function genericPrint$5(path, options, print) {
18573
18594
  {
18574
18595
  var _parentNode2 = path.getParentNode();
18575
18596
 
18576
- return replaceNewlinesWithHardlines(_parentNode2.type === "root" && util.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value);
18597
+ var value = _parentNode2.type === "root" && util.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
18598
+ var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
18599
+ return replaceNewlinesWith(value, isHtmlComment ? hardline$8 : markAsRoot$1(literalline$3));
18577
18600
  }
18578
18601
 
18579
18602
  case "list":
@@ -18651,10 +18674,10 @@ function genericPrint$5(path, options, print) {
18651
18674
  return printChildren(path, options, print);
18652
18675
 
18653
18676
  case "break":
18654
- return concat$9([/\s/.test(options.originalText[node.position.start.offset]) ? " " : "\\", hardline$8]);
18677
+ return /\s/.test(options.originalText[node.position.start.offset]) ? concat$9([" ", markAsRoot$1(literalline$3)]) : concat$9(["\\", hardline$8]);
18655
18678
 
18656
18679
  case "liquidNode":
18657
- return replaceNewlinesWithHardlines(node.value);
18680
+ return replaceNewlinesWith(node.value, hardline$8);
18658
18681
 
18659
18682
  case "tableRow": // handled in "table"
18660
18683
 
@@ -18698,8 +18721,8 @@ function getNthListSiblingIndex(node, parentNode) {
18698
18721
  });
18699
18722
  }
18700
18723
 
18701
- function replaceNewlinesWithHardlines(str) {
18702
- return join$7(hardline$8, str.split("\n"));
18724
+ function replaceNewlinesWith(str, doc$$2) {
18725
+ return join$7(doc$$2, str.split("\n"));
18703
18726
  }
18704
18727
 
18705
18728
  function getNthSiblingIndex(node, parentNode, condition) {
@@ -18970,7 +18993,8 @@ function shouldPrePrintDoubleHardline(node, data) {
18970
18993
  var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
18971
18994
  var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
18972
18995
  var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
18973
- return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore);
18996
+ var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
18997
+ return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
18974
18998
  }
18975
18999
 
18976
19000
  function shouldPrePrintTripleHardline(node, data) {