prettier 1.16.0 → 1.16.4

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.16.0";
8
+ var version$1 = "1.16.4";
9
9
  var description = "Prettier is an opinionated code formatter";
10
10
  var bin = {
11
11
  "prettier": "./bin/prettier.js"
@@ -47,6 +47,7 @@ var dependencies = {
47
47
  "html-styles": "1.0.0",
48
48
  "html-tag-names": "1.1.2",
49
49
  "ignore": "3.3.7",
50
+ "is-ci": "2.0.0",
50
51
  "jest-docblock": "23.2.0",
51
52
  "json-stable-stringify": "1.0.1",
52
53
  "leven": "2.1.0",
@@ -100,7 +101,7 @@ var devDependencies = {
100
101
  "jest-snapshot-serializer-raw": "1.1.0",
101
102
  "jest-watch-typeahead": "0.1.0",
102
103
  "mkdirp": "0.5.1",
103
- "prettier": "1.15.3",
104
+ "prettier": "1.16.3",
104
105
  "prettylint": "1.0.0",
105
106
  "rimraf": "2.6.2",
106
107
  "rollup": "0.47.6",
@@ -6495,6 +6496,7 @@ function getSupportInfo$2(version, opts) {
6495
6496
  });
6496
6497
  });
6497
6498
  var usePostCssParser = semver.lt(version, "1.7.1");
6499
+ var useBabylonParser = semver.lt(version, "1.16.0");
6498
6500
  var languages = plugins.reduce(function (all, plugin) {
6499
6501
  return all.concat(plugin.languages || []);
6500
6502
  }, []).filter(filterSince).map(function (language) {
@@ -6509,6 +6511,15 @@ function getSupportInfo$2(version, opts) {
6509
6511
  return Object.assign({}, language, {
6510
6512
  parsers: ["typescript"]
6511
6513
  });
6514
+ } // "babylon" was renamed to "babel" in 1.16.0
6515
+
6516
+
6517
+ if (useBabylonParser && language.parsers.indexOf("babel") !== -1) {
6518
+ return Object.assign({}, language, {
6519
+ parsers: language.parsers.map(function (parser) {
6520
+ return parser === "babel" ? "babylon" : parser;
6521
+ })
6522
+ });
6512
6523
  }
6513
6524
 
6514
6525
  if (usePostCssParser && (language.name === "CSS" || language.group === "CSS")) {
@@ -21152,8 +21163,8 @@ function printClosingTagEndMarker(node, options) {
21152
21163
 
21153
21164
  function getTextValueParts(node) {
21154
21165
  var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : node.value;
21155
- return node.parent.isWhitespaceSensitive ? node.parent.isIndentationSensitive ? replaceEndOfLineWith$1(value, literalline$2) : replaceEndOfLineWith$1(dedentString(value.replace(/^\s*?\n|\n\s*?$/g, "")), hardline$7) : // non-breaking whitespace: 0xA0
21156
- join$5(line$6, value.split(/[^\S\xA0]+/)).parts;
21166
+ return node.parent.isWhitespaceSensitive ? node.parent.isIndentationSensitive ? replaceEndOfLineWith$1(value, literalline$2) : replaceEndOfLineWith$1(dedentString(value.replace(/^\s*?\n|\n\s*?$/g, "")), hardline$7) : // https://infra.spec.whatwg.org/#ascii-whitespace
21167
+ join$5(line$6, value.split(/[\t\n\f\r ]+/)).parts;
21157
21168
  }
21158
21169
 
21159
21170
  function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
@@ -22705,9 +22716,62 @@ function hasClosureCompilerTypeCastComment(text, path, locStart, locEnd) {
22705
22716
 
22706
22717
  function hasTypeCastComment(node) {
22707
22718
  return node.comments && node.comments.some(function (comment) {
22708
- return comment.leading && comments$3.isBlockComment(comment) && comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) && util.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
22719
+ return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value) && util.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
22709
22720
  });
22710
22721
  }
22722
+
22723
+ function isTypeCastComment(comment) {
22724
+ var trimmed = comment.trim();
22725
+
22726
+ if (!/^\*\s*@type\s*\{[^]+\}$/.test(trimmed)) {
22727
+ return false;
22728
+ }
22729
+
22730
+ var isCompletelyClosed = false;
22731
+ var unpairedBracketCount = 0;
22732
+ var _iteratorNormalCompletion = true;
22733
+ var _didIteratorError = false;
22734
+ var _iteratorError = undefined;
22735
+
22736
+ try {
22737
+ for (var _iterator = trimmed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
22738
+ var char = _step.value;
22739
+
22740
+ if (char === "{") {
22741
+ if (isCompletelyClosed) {
22742
+ return false;
22743
+ }
22744
+
22745
+ unpairedBracketCount++;
22746
+ } else if (char === "}") {
22747
+ if (unpairedBracketCount === 0) {
22748
+ return false;
22749
+ }
22750
+
22751
+ unpairedBracketCount--;
22752
+
22753
+ if (unpairedBracketCount === 0) {
22754
+ isCompletelyClosed = true;
22755
+ }
22756
+ }
22757
+ }
22758
+ } catch (err) {
22759
+ _didIteratorError = true;
22760
+ _iteratorError = err;
22761
+ } finally {
22762
+ try {
22763
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
22764
+ _iterator.return();
22765
+ }
22766
+ } finally {
22767
+ if (_didIteratorError) {
22768
+ throw _iteratorError;
22769
+ }
22770
+ }
22771
+ }
22772
+
22773
+ return unpairedBracketCount === 0;
22774
+ }
22711
22775
  }
22712
22776
 
22713
22777
  function needsParens(path, options) {
@@ -22764,6 +22828,42 @@ function needsParens(path, options) {
22764
22828
  return true;
22765
22829
  }
22766
22830
 
22831
+ if (parent.type === "Decorator" && parent.expression === node) {
22832
+ var hasCallExpression = false;
22833
+ var hasMemberExpression = false;
22834
+ var current = node;
22835
+
22836
+ while (current) {
22837
+ switch (current.type) {
22838
+ case "MemberExpression":
22839
+ hasMemberExpression = true;
22840
+ current = current.object;
22841
+ break;
22842
+
22843
+ case "CallExpression":
22844
+ if (
22845
+ /** @(x().y) */
22846
+ hasMemberExpression ||
22847
+ /** @(x().y()) */
22848
+ hasCallExpression) {
22849
+ return true;
22850
+ }
22851
+
22852
+ hasCallExpression = true;
22853
+ current = current.callee;
22854
+ break;
22855
+
22856
+ case "Identifier":
22857
+ return false;
22858
+
22859
+ default:
22860
+ return true;
22861
+ }
22862
+ }
22863
+
22864
+ return true;
22865
+ }
22866
+
22767
22867
  if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
22768
22868
  util.startsWithNoLookaheadToken(node,
22769
22869
  /* forbidFunctionClassAndDoExpr */
@@ -22900,9 +23000,6 @@ function needsParens(path, options) {
22900
23000
  case "AssignmentExpression":
22901
23001
  return parent.left === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression");
22902
23002
 
22903
- case "Decorator":
22904
- return parent.expression === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression");
22905
-
22906
23003
  case "BinaryExpression":
22907
23004
  case "LogicalExpression":
22908
23005
  {
@@ -22952,6 +23049,14 @@ function needsParens(path, options) {
22952
23049
  case "TSParenthesizedType":
22953
23050
  {
22954
23051
  var grandParent = path.getParentNode(1);
23052
+ /**
23053
+ * const foo = (): (() => void) => (): void => null;
23054
+ * ^ ^
23055
+ */
23056
+
23057
+ if (getUnparenthesizedNode(node).type === "TSFunctionType" && parent.type === "TSTypeAnnotation" && grandParent.type === "ArrowFunctionExpression" && grandParent.returnType === parent) {
23058
+ return true;
23059
+ }
22955
23060
 
22956
23061
  if ((parent.type === "TSTypeParameter" || parent.type === "TypeParameter" || parent.type === "TSTypeAliasDeclaration" || parent.type === "TSTypeAnnotation" || parent.type === "TSParenthesizedType" || parent.type === "TSTypeParameterInstantiation") && grandParent.type !== "TSTypeOperator" && grandParent.type !== "TSOptionalType") {
22957
23062
  return false;
@@ -23212,6 +23317,10 @@ function isStatement(node) {
23212
23317
  return node.type === "BlockStatement" || node.type === "BreakStatement" || node.type === "ClassBody" || node.type === "ClassDeclaration" || node.type === "ClassMethod" || node.type === "ClassProperty" || node.type === "ClassPrivateProperty" || node.type === "ContinueStatement" || node.type === "DebuggerStatement" || node.type === "DeclareClass" || node.type === "DeclareExportAllDeclaration" || node.type === "DeclareExportDeclaration" || node.type === "DeclareFunction" || node.type === "DeclareInterface" || node.type === "DeclareModule" || node.type === "DeclareModuleExports" || node.type === "DeclareVariable" || node.type === "DoWhileStatement" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExpressionStatement" || node.type === "ForAwaitStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || node.type === "FunctionDeclaration" || node.type === "IfStatement" || node.type === "ImportDeclaration" || node.type === "InterfaceDeclaration" || node.type === "LabeledStatement" || node.type === "MethodDefinition" || node.type === "ReturnStatement" || node.type === "SwitchStatement" || node.type === "ThrowStatement" || node.type === "TryStatement" || node.type === "TSAbstractClassDeclaration" || node.type === "TSDeclareFunction" || node.type === "TSEnumDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSModuleDeclaration" || node.type === "TSNamespaceExportDeclaration" || node.type === "TypeAlias" || node.type === "VariableDeclaration" || node.type === "WhileStatement" || node.type === "WithStatement";
23213
23318
  }
23214
23319
 
23320
+ function getUnparenthesizedNode(node) {
23321
+ return node.type === "TSParenthesizedType" ? getUnparenthesizedNode(node.typeAnnotation) : node;
23322
+ }
23323
+
23215
23324
  function endsWithRightBracket(node) {
23216
23325
  switch (node.type) {
23217
23326
  case "ObjectExpression":
@@ -26125,7 +26234,7 @@ function printArgumentsList(path, options, print) {
26125
26234
  } // useEffect(() => { ... }, [foo, bar, baz])
26126
26235
 
26127
26236
 
26128
- if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.find(function (arg) {
26237
+ if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].params.length === 0 && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.find(function (arg) {
26129
26238
  return arg.leadingComments || arg.trailingComments;
26130
26239
  })) {
26131
26240
  return concat$11(["(", path.call(print, "arguments", 0), ", ", path.call(print, "arguments", 1), ")"]);
@@ -28453,6 +28562,8 @@ var cjkPattern = json$9.cjkPattern;
28453
28562
  var kPattern = json$9.kPattern;
28454
28563
  var punctuationPattern$1 = json$9.punctuationPattern;
28455
28564
  var getLast$5 = util.getLast;
28565
+ var INLINE_NODE_TYPES$1 = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
28566
+ var INLINE_NODE_WRAPPER_TYPES$1 = INLINE_NODE_TYPES$1.concat(["tableCell", "paragraph", "heading"]);
28456
28567
  var kRegex = new RegExp(kPattern);
28457
28568
  var punctuationRegex = new RegExp(punctuationPattern$1);
28458
28569
  /**
@@ -28604,7 +28715,9 @@ var utils$10 = {
28604
28715
  splitText: splitText$1,
28605
28716
  punctuationPattern: punctuationPattern$1,
28606
28717
  getFencedCodeBlockValue: getFencedCodeBlockValue$2,
28607
- getOrderedListItemInfo: getOrderedListItemInfo$1
28718
+ getOrderedListItemInfo: getOrderedListItemInfo$1,
28719
+ INLINE_NODE_TYPES: INLINE_NODE_TYPES$1,
28720
+ INLINE_NODE_WRAPPER_TYPES: INLINE_NODE_WRAPPER_TYPES$1
28608
28721
  };
28609
28722
 
28610
28723
  var _require$$0$builders$9 = doc.builders;
@@ -28998,12 +29111,12 @@ var getFencedCodeBlockValue = utils$10.getFencedCodeBlockValue;
28998
29111
  var getOrderedListItemInfo = utils$10.getOrderedListItemInfo;
28999
29112
  var splitText = utils$10.splitText;
29000
29113
  var punctuationPattern = utils$10.punctuationPattern;
29114
+ var INLINE_NODE_TYPES = utils$10.INLINE_NODE_TYPES;
29115
+ var INLINE_NODE_WRAPPER_TYPES = utils$10.INLINE_NODE_WRAPPER_TYPES;
29001
29116
  var replaceEndOfLineWith$2 = util.replaceEndOfLineWith;
29002
29117
  var TRAILING_HARDLINE_NODES = ["importExport"];
29003
29118
  var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
29004
29119
  var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
29005
- var INLINE_NODE_TYPES = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
29006
- var INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat(["tableCell", "paragraph", "heading"]);
29007
29120
 
29008
29121
  function genericPrint$5(path, options, print) {
29009
29122
  var node = path.getValue();