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/index.js CHANGED
@@ -12,7 +12,7 @@ var thirdParty = require('./third-party');
12
12
  var thirdParty__default = thirdParty['default'];
13
13
 
14
14
  var name = "prettier";
15
- var version$1 = "1.13.3";
15
+ var version$1 = "1.13.7";
16
16
  var description = "Prettier is an opinionated code formatter";
17
17
  var bin = {
18
18
  "prettier": "./bin/prettier.js"
@@ -43,7 +43,7 @@ var dependencies = {
43
43
  "esutils": "2.0.2",
44
44
  "find-parent-dir": "0.3.0",
45
45
  "find-project-root": "1.1.1",
46
- "flow-parser": "0.73.0",
46
+ "flow-parser": "0.75.0",
47
47
  "get-stream": "3.0.0",
48
48
  "globby": "6.1.0",
49
49
  "graphql": "0.13.2",
@@ -67,7 +67,7 @@ var dependencies = {
67
67
  "semver": "5.4.1",
68
68
  "string-width": "2.1.1",
69
69
  "typescript": "2.9.0-dev.20180421",
70
- "typescript-eslint-parser": "eslint/typescript-eslint-parser#2960b002746c01fb9cb15bb5f4c1e7e925c6519a",
70
+ "typescript-eslint-parser": "16.0.0",
71
71
  "unicode-regex": "1.0.1",
72
72
  "unified": "6.1.6"
73
73
  };
@@ -86,7 +86,7 @@ var devDependencies = {
86
86
  "eslint-plugin-react": "7.7.0",
87
87
  "jest": "21.1.0",
88
88
  "mkdirp": "0.5.1",
89
- "prettier": "1.13.2",
89
+ "prettier": "1.13.4",
90
90
  "prettylint": "1.0.0",
91
91
  "rimraf": "2.6.2",
92
92
  "rollup": "0.47.6",
@@ -6962,7 +6962,7 @@ function resolveParser$1(opts, parsers) {
6962
6962
 
6963
6963
  try {
6964
6964
  return {
6965
- parse: eval("require")(path.resolve(process.cwd(), opts.parser)),
6965
+ parse: require(path.resolve(process.cwd(), opts.parser)),
6966
6966
  astFormat: "estree",
6967
6967
  locStart,
6968
6968
  locEnd
@@ -8827,8 +8827,7 @@ function printDocToString$1(doc, options) {
8827
8827
  out.pop();
8828
8828
  }
8829
8829
 
8830
- if (out.length && typeof out[out.length - 1] === "string" && (options.parser !== "markdown" || // preserve markdown's `break` node (two trailing spaces)
8831
- !/\S {2}$/.test(out[out.length - 1]))) {
8830
+ if (out.length && typeof out[out.length - 1] === "string") {
8832
8831
  out[out.length - 1] = out[out.length - 1].replace(/[^\S\n]*$/, "");
8833
8832
  }
8834
8833
  }
@@ -10186,6 +10185,13 @@ function attachComments(text, ast, opts) {
10186
10185
  }
10187
10186
 
10188
10187
  function coreFormat(text, opts, addAlignmentSize) {
10188
+ if (!text || !text.trim().length) {
10189
+ return {
10190
+ formatted: "",
10191
+ cursorOffset: 0
10192
+ };
10193
+ }
10194
+
10189
10195
  addAlignmentSize = addAlignmentSize || 0;
10190
10196
  var parsed = parser.parse(text, opts);
10191
10197
  var ast = parsed.ast;
@@ -10776,22 +10782,76 @@ typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32
10776
10782
  };
10777
10783
  }
10778
10784
 
10779
- function createIgnorer(ignorePath, withNodeModules) {
10780
- var ignoreText = "";
10785
+ /**
10786
+ * @param {string} filename
10787
+ * @returns {Promise<null | string>}
10788
+ */
10781
10789
 
10782
- if (ignorePath) {
10783
- var resolvedIgnorePath = path.resolve(ignorePath);
10784
10790
 
10785
- try {
10786
- ignoreText = fs.readFileSync(resolvedIgnorePath, "utf8");
10787
- } catch (readError) {
10788
- if (readError.code !== "ENOENT") {
10789
- throw new Error(`Unable to read ${resolvedIgnorePath}: ${readError.message}`);
10791
+ function getFileContentOrNull(filename) {
10792
+ return new Promise(function (resolve, reject) {
10793
+ fs.readFile(filename, "utf8", function (error, data) {
10794
+ if (error && error.code !== "ENOENT") {
10795
+ reject(createError(filename, error));
10796
+ } else {
10797
+ resolve(error ? null : data);
10790
10798
  }
10799
+ });
10800
+ });
10801
+ }
10802
+ /**
10803
+ * @param {string} filename
10804
+ * @returns {null | string}
10805
+ */
10806
+
10807
+
10808
+ getFileContentOrNull.sync = function (filename) {
10809
+ try {
10810
+ return fs.readFileSync(filename, "utf8");
10811
+ } catch (error) {
10812
+ if (error && error.code === "ENOENT") {
10813
+ return null;
10791
10814
  }
10815
+
10816
+ throw createError(filename, error);
10792
10817
  }
10818
+ };
10819
+
10820
+ function createError(filename, error) {
10821
+ return new Error(`Unable to read ${filename}: ${error.message}`);
10822
+ }
10823
+
10824
+ var getFileContentOrNull_1 = getFileContentOrNull;
10825
+
10826
+ /**
10827
+ * @param {undefined | string} ignorePath
10828
+ * @param {undefined | boolean} withNodeModules
10829
+ */
10830
+
10831
+
10832
+ function createIgnorer(ignorePath, withNodeModules) {
10833
+ return (!ignorePath ? Promise.resolve(null) : getFileContentOrNull_1(path.resolve(ignorePath))).then(function (ignoreContent) {
10834
+ return _createIgnorer(ignoreContent, withNodeModules);
10835
+ });
10836
+ }
10837
+ /**
10838
+ * @param {undefined | string} ignorePath
10839
+ * @param {undefined | boolean} withNodeModules
10840
+ */
10841
+
10842
+
10843
+ createIgnorer.sync = function (ignorePath, withNodeModules) {
10844
+ var ignoreContent = !ignorePath ? null : getFileContentOrNull_1.sync(path.resolve(ignorePath));
10845
+ return _createIgnorer(ignoreContent, withNodeModules);
10846
+ };
10847
+ /**
10848
+ * @param {null | string} ignoreContent
10849
+ * @param {undefined | boolean} withNodeModules
10850
+ */
10793
10851
 
10794
- var ignorer = ignore().add(ignoreText);
10852
+
10853
+ function _createIgnorer(ignoreContent, withNodeModules) {
10854
+ var ignorer = ignore().add(ignoreContent || "");
10795
10855
 
10796
10856
  if (!withNodeModules) {
10797
10857
  ignorer.add("node_modules");
@@ -10802,9 +10862,15 @@ function createIgnorer(ignorePath, withNodeModules) {
10802
10862
 
10803
10863
  var createIgnorer_1 = createIgnorer;
10804
10864
 
10865
+ /**
10866
+ * @typedef {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} FileInfoOptions
10867
+ * @typedef {{ ignored: boolean, inferredParser: string | null }} FileInfoResult
10868
+ */
10869
+
10805
10870
  /**
10806
10871
  * @param {string} filePath
10807
- * @param {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} opts
10872
+ * @param {FileInfoOptions} opts
10873
+ * @returns {Promise<FileInfoResult>}
10808
10874
  *
10809
10875
  * Please note that prettier.getFileInfo() expects opts.plugins to be an array of paths,
10810
10876
  * not an object. A transformation from this array to an object is automatically done
@@ -10812,25 +10878,32 @@ var createIgnorer_1 = createIgnorer;
10812
10878
  */
10813
10879
 
10814
10880
 
10815
- function _getFileInfo(filePath, opts) {
10816
- var ignored = false;
10817
- var ignorer = createIgnorer_1(opts.ignorePath, opts.withNodeModules);
10818
- ignored = ignorer.ignores(filePath);
10819
- var inferredParser = options.inferParser(filePath, opts.plugins) || null;
10881
+ function getFileInfo(filePath, opts) {
10882
+ return createIgnorer_1(opts.ignorePath, opts.withNodeModules).then(function (ignorer) {
10883
+ return _getFileInfo(ignorer, filePath, opts.plugins);
10884
+ });
10885
+ }
10886
+ /**
10887
+ * @param {string} filePath
10888
+ * @param {FileInfoOptions} opts
10889
+ * @returns {FileInfoResult}
10890
+ */
10891
+
10892
+
10893
+ getFileInfo.sync = function (filePath, opts) {
10894
+ var ignorer = createIgnorer_1.sync(opts.ignorePath, opts.withNodeModules);
10895
+ return _getFileInfo(ignorer, filePath, opts.plugins);
10896
+ };
10897
+
10898
+ function _getFileInfo(ignorer, filePath, plugins) {
10899
+ var ignored = ignorer.ignores(filePath);
10900
+ var inferredParser = options.inferParser(filePath, plugins) || null;
10820
10901
  return {
10821
10902
  ignored,
10822
10903
  inferredParser
10823
10904
  };
10824
- } // the method has been implemented as asynchronous to avoid possible breaking changes in future
10825
-
10826
-
10827
- function getFileInfo(filePath, opts) {
10828
- return Promise.resolve().then(function () {
10829
- return _getFileInfo(filePath, opts);
10830
- });
10831
10905
  }
10832
10906
 
10833
- getFileInfo.sync = _getFileInfo;
10834
10907
  var getFileInfo_1 = getFileInfo;
10835
10908
 
10836
10909
  var lodash_uniqby = createCommonjsModule(function (module, exports) {
@@ -18723,12 +18796,22 @@ var comments$3 = {
18723
18796
  isBlockComment
18724
18797
  };
18725
18798
 
18726
- function hasClosureCompilerTypeCastComment(text, node, locEnd) {
18799
+ function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
18727
18800
  // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
18728
18801
  // Syntax example: var x = /** @type {string} */ (fruit);
18729
- return node.comments && node.comments.some(function (comment) {
18730
- return comment.leading && comments$3.isBlockComment(comment) && comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
18731
- });
18802
+ var n = path$$1.getValue();
18803
+ return util$1.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
18804
+
18805
+ function hasAncestorTypeCastComment(index) {
18806
+ var ancestor = path$$1.getParentNode(index);
18807
+ return ancestor && util$1.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
18808
+ }
18809
+
18810
+ function hasTypeCastComment(node) {
18811
+ return node.comments && node.comments.some(function (comment) {
18812
+ return comment.leading && comments$3.isBlockComment(comment) && comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
18813
+ });
18814
+ }
18732
18815
  }
18733
18816
 
18734
18817
  function needsParens(path$$1, options) {
@@ -18754,7 +18837,7 @@ function needsParens(path$$1, options) {
18754
18837
  // parentheses.
18755
18838
 
18756
18839
 
18757
- if (hasClosureCompilerTypeCastComment(options.originalText, node, options.locEnd)) {
18840
+ if (hasClosureCompilerTypeCastComment(options.originalText, path$$1, options.locStart, options.locEnd)) {
18758
18841
  return true;
18759
18842
  } // Identifiers never need parentheses.
18760
18843
 
@@ -20899,7 +20982,6 @@ function printPathNoParens(path$$1, options, print, args) {
20899
20982
 
20900
20983
  case "DeclareInterface":
20901
20984
  case "InterfaceDeclaration":
20902
- case "InterfaceType":
20903
20985
  case "InterfaceTypeAnnotation":
20904
20986
  {
20905
20987
  if (n.type === "DeclareInterface" || isNodeStartingWithDeclare(n, options)) {
@@ -21304,7 +21386,7 @@ function printPathNoParens(path$$1, options, print, args) {
21304
21386
 
21305
21387
  case "TSLastTypeNode":
21306
21388
  // TSImportType
21307
- return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path$$1.call(print, "argument"), ")", !n.qualifier ? "" : concat$4([".", path$$1.call(print, "qualifier")])]);
21389
+ return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path$$1.call(print, "argument"), ")", !n.qualifier ? "" : concat$4([".", path$$1.call(print, "qualifier")]), printTypeParameters(path$$1, options, print, "typeParameters")]);
21308
21390
 
21309
21391
  case "TSLiteralType":
21310
21392
  return path$$1.call(print, "literal");
@@ -22360,12 +22442,13 @@ function printMemberChain(path$$1, options, print) {
22360
22442
  // .map(x => x)
22361
22443
  //
22362
22444
  // In order to detect those cases, we use an heuristic: if the first
22363
- // node is an identifier with the name starting with a capital letter.
22364
- // The rationale is that they are likely to be factories.
22445
+ // node is an identifier with the name starting with a capital
22446
+ // letter or just a sequence of _$. The rationale is that they are
22447
+ // likely to be factories.
22365
22448
 
22366
22449
 
22367
22450
  function isFactory(name) {
22368
- return /^[A-Z]/.test(name);
22451
+ return /^[A-Z]|^[_$]+$/.test(name);
22369
22452
  } // In case the Identifier is shorter than tab width, we can keep the
22370
22453
  // first call in a single line, if it's an ExpressionStatement.
22371
22454
  //
@@ -23507,6 +23590,10 @@ function genericPrint$2(path$$1, options, print) {
23507
23590
 
23508
23591
  case "Identifier":
23509
23592
  return JSON.stringify(node.name);
23593
+
23594
+ default:
23595
+ /* istanbul ignore next */
23596
+ throw new Error("unknown type: " + JSON.stringify(node.type));
23510
23597
  }
23511
23598
  }
23512
23599
 
@@ -25139,13 +25226,16 @@ function genericPrint$4(path$$1, options, print) {
25139
25226
  var parts = [];
25140
25227
  path$$1.map(function (pathChild, index) {
25141
25228
  parts.push(concat$9([pathChild.call(print)]));
25142
- parts.push(hardline$8);
25143
25229
 
25144
- if (index !== n.definitions.length - 1 && isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
25230
+ if (index !== n.definitions.length - 1) {
25145
25231
  parts.push(hardline$8);
25232
+
25233
+ if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
25234
+ parts.push(hardline$8);
25235
+ }
25146
25236
  }
25147
25237
  }, "definitions");
25148
- return concat$9(parts, hardline$8);
25238
+ return concat$9([concat$9(parts), hardline$8]);
25149
25239
  }
25150
25240
 
25151
25241
  case "OperationDefinition":
@@ -25450,9 +25540,9 @@ var languageGraphql = {
25450
25540
 
25451
25541
  var _require$$0$builders$6 = doc.builders;
25452
25542
  var hardline$10 = _require$$0$builders$6.hardline;
25453
- var literalline$3 = _require$$0$builders$6.literalline;
25543
+ var literalline$4 = _require$$0$builders$6.literalline;
25454
25544
  var concat$11 = _require$$0$builders$6.concat;
25455
- var markAsRoot$1 = _require$$0$builders$6.markAsRoot;
25545
+ var markAsRoot$2 = _require$$0$builders$6.markAsRoot;
25456
25546
  var mapDoc$4 = doc.utils.mapDoc;
25457
25547
 
25458
25548
  function embed$2(path$$1, print, textToDoc, options) {
@@ -25469,7 +25559,7 @@ function embed$2(path$$1, print, textToDoc, options) {
25469
25559
  var doc$$2 = textToDoc(node.value, {
25470
25560
  parser
25471
25561
  });
25472
- return markAsRoot$1(concat$11([style, node.lang, hardline$10, replaceNewlinesWithLiterallines(doc$$2), style]));
25562
+ return markAsRoot$2(concat$11([style, node.lang, hardline$10, replaceNewlinesWithLiterallines(doc$$2), style]));
25473
25563
  }
25474
25564
  }
25475
25565
 
@@ -25495,7 +25585,7 @@ function embed$2(path$$1, print, textToDoc, options) {
25495
25585
  function replaceNewlinesWithLiterallines(doc$$2) {
25496
25586
  return mapDoc$4(doc$$2, function (currentDoc) {
25497
25587
  return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$11(currentDoc.split(/(\n)/g).map(function (v, i) {
25498
- return i % 2 === 0 ? v : literalline$3;
25588
+ return i % 2 === 0 ? v : literalline$4;
25499
25589
  })) : currentDoc;
25500
25590
  });
25501
25591
  }
@@ -25559,6 +25649,8 @@ var _require$$0$builders$5 = doc.builders;
25559
25649
  var concat$10 = _require$$0$builders$5.concat;
25560
25650
  var join$8 = _require$$0$builders$5.join;
25561
25651
  var line$7 = _require$$0$builders$5.line;
25652
+ var literalline$3 = _require$$0$builders$5.literalline;
25653
+ var markAsRoot$1 = _require$$0$builders$5.markAsRoot;
25562
25654
  var hardline$9 = _require$$0$builders$5.hardline;
25563
25655
  var softline$6 = _require$$0$builders$5.softline;
25564
25656
  var fill$4 = _require$$0$builders$5.fill;
@@ -25691,7 +25783,9 @@ function genericPrint$5(path$$1, options, print) {
25691
25783
  {
25692
25784
  var _parentNode2 = path$$1.getParentNode();
25693
25785
 
25694
- return replaceNewlinesWithHardlines(_parentNode2.type === "root" && util$1.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value);
25786
+ var value = _parentNode2.type === "root" && util$1.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
25787
+ var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
25788
+ return replaceNewlinesWith(value, isHtmlComment ? hardline$9 : markAsRoot$1(literalline$3));
25695
25789
  }
25696
25790
 
25697
25791
  case "list":
@@ -25769,10 +25863,10 @@ function genericPrint$5(path$$1, options, print) {
25769
25863
  return printChildren(path$$1, options, print);
25770
25864
 
25771
25865
  case "break":
25772
- return concat$10([/\s/.test(options.originalText[node.position.start.offset]) ? " " : "\\", hardline$9]);
25866
+ return /\s/.test(options.originalText[node.position.start.offset]) ? concat$10([" ", markAsRoot$1(literalline$3)]) : concat$10(["\\", hardline$9]);
25773
25867
 
25774
25868
  case "liquidNode":
25775
- return replaceNewlinesWithHardlines(node.value);
25869
+ return replaceNewlinesWith(node.value, hardline$9);
25776
25870
 
25777
25871
  case "tableRow": // handled in "table"
25778
25872
 
@@ -25816,8 +25910,8 @@ function getNthListSiblingIndex(node, parentNode) {
25816
25910
  });
25817
25911
  }
25818
25912
 
25819
- function replaceNewlinesWithHardlines(str) {
25820
- return join$8(hardline$9, str.split("\n"));
25913
+ function replaceNewlinesWith(str, doc$$2) {
25914
+ return join$8(doc$$2, str.split("\n"));
25821
25915
  }
25822
25916
 
25823
25917
  function getNthSiblingIndex(node, parentNode, condition) {
@@ -26088,7 +26182,8 @@ function shouldPrePrintDoubleHardline(node, data) {
26088
26182
  var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
26089
26183
  var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
26090
26184
  var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
26091
- return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore);
26185
+ var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
26186
+ return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
26092
26187
  }
26093
26188
 
26094
26189
  function shouldPrePrintTripleHardline(node, data) {
@@ -26623,6 +26718,11 @@ var languageVue = {
26623
26718
  printers: printers$6
26624
26719
  };
26625
26720
 
26721
+ // plugin will look for `eval("require")()` and transform to `require()` in the bundle,
26722
+ // and rewrite the paths to require from the top-level.
26723
+ // We need to list the parsers and getters so we can load them only when necessary.
26724
+
26725
+
26626
26726
  var internalPlugins = [// JS
26627
26727
  languageJs, {
26628
26728
  parsers: {
@@ -26782,7 +26882,7 @@ function loadPlugins(plugins, pluginSearchDirs) {
26782
26882
  var externalPlugins = lodash_uniqby(externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), "requirePath").map(function (externalPluginInfo) {
26783
26883
  return Object.assign({
26784
26884
  name: externalPluginInfo.name
26785
- }, eval("require")(externalPluginInfo.requirePath));
26885
+ }, require(externalPluginInfo.requirePath));
26786
26886
  });
26787
26887
  return internalPlugins.concat(externalPlugins);
26788
26888
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier",
3
- "version": "1.13.3",
3
+ "version": "1.13.7",
4
4
  "description": "Prettier is an opinionated code formatter",
5
5
  "bin": "./bin-prettier.js",
6
6
  "repository": "prettier/prettier",
@@ -13,5 +13,8 @@
13
13
  },
14
14
  "scripts": {
15
15
  "prepublishOnly": "node -e \"assert.equal(require('.').version, require('..').version)\""
16
- }
16
+ },
17
+ "files": [
18
+ "*.js"
19
+ ]
17
20
  }