prettier 1.17.0 → 1.17.1
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/bin-prettier.js +22 -13
- package/index.js +22 -13
- package/package.json +1 -1
- package/standalone.js +22 -13
package/bin-prettier.js
CHANGED
|
@@ -14,7 +14,7 @@ var thirdParty__default = thirdParty['default'];
|
|
|
14
14
|
var readline = _interopDefault(require('readline'));
|
|
15
15
|
|
|
16
16
|
var name = "prettier";
|
|
17
|
-
var version$1 = "1.17.
|
|
17
|
+
var version$1 = "1.17.1";
|
|
18
18
|
var description = "Prettier is an opinionated code formatter";
|
|
19
19
|
var bin = {
|
|
20
20
|
"prettier": "./bin/prettier.js"
|
|
@@ -110,7 +110,7 @@ var devDependencies = {
|
|
|
110
110
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
111
111
|
"jest-watch-typeahead": "0.1.0",
|
|
112
112
|
"mkdirp": "0.5.1",
|
|
113
|
-
"prettier": "1.
|
|
113
|
+
"prettier": "1.17.0",
|
|
114
114
|
"prettylint": "1.0.0",
|
|
115
115
|
"rimraf": "2.6.2",
|
|
116
116
|
"rollup": "0.47.6",
|
|
@@ -13965,7 +13965,6 @@ function formatRange(text, opts) {
|
|
|
13965
13965
|
var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
|
|
13966
13966
|
rangeStart: 0,
|
|
13967
13967
|
rangeEnd: Infinity,
|
|
13968
|
-
printWidth: opts.printWidth - alignmentSize,
|
|
13969
13968
|
// track the cursor offset only if it's within our range
|
|
13970
13969
|
cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
|
|
13971
13970
|
}), alignmentSize); // Since the range contracts to avoid trailing whitespace,
|
|
@@ -22827,27 +22826,36 @@ var utils$4 = {
|
|
|
22827
22826
|
|
|
22828
22827
|
var hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment;
|
|
22829
22828
|
|
|
22830
|
-
function hasClosureCompilerTypeCastComment(text, path$$1
|
|
22829
|
+
function hasClosureCompilerTypeCastComment(text, path$$1) {
|
|
22831
22830
|
// https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
|
|
22832
22831
|
// Syntax example: var x = /** @type {string} */ (fruit);
|
|
22833
22832
|
var n = path$$1.getValue();
|
|
22834
|
-
return
|
|
22833
|
+
return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
|
|
22835
22834
|
|
|
22836
22835
|
function hasAncestorTypeCastComment(index) {
|
|
22837
22836
|
var ancestor = path$$1.getParentNode(index);
|
|
22838
|
-
return ancestor &&
|
|
22837
|
+
return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
|
|
22839
22838
|
}
|
|
22840
22839
|
|
|
22841
22840
|
function hasTypeCastComment(node) {
|
|
22842
22841
|
return node.comments && node.comments.some(function (comment) {
|
|
22843
|
-
return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value)
|
|
22842
|
+
return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
|
|
22844
22843
|
});
|
|
22845
22844
|
}
|
|
22846
22845
|
|
|
22846
|
+
function isParenthesized(node) {
|
|
22847
|
+
// Closure typecast comments only really make sense when _not_ using
|
|
22848
|
+
// typescript or flow parsers, so we take advantage of the babel parser's
|
|
22849
|
+
// parenthesized expressions.
|
|
22850
|
+
return node.extra && node.extra.parenthesized;
|
|
22851
|
+
}
|
|
22852
|
+
|
|
22847
22853
|
function isTypeCastComment(comment) {
|
|
22848
|
-
var
|
|
22854
|
+
var cleaned = comment.trim().split("\n").map(function (line) {
|
|
22855
|
+
return line.replace(/^[\s*]+/, "");
|
|
22856
|
+
}).join(" ").trim();
|
|
22849
22857
|
|
|
22850
|
-
if (
|
|
22858
|
+
if (!/^@type\s+\{[^]+\}$/.test(cleaned)) {
|
|
22851
22859
|
return false;
|
|
22852
22860
|
}
|
|
22853
22861
|
|
|
@@ -22858,7 +22866,7 @@ function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
|
|
|
22858
22866
|
var _iteratorError = undefined;
|
|
22859
22867
|
|
|
22860
22868
|
try {
|
|
22861
|
-
for (var _iterator =
|
|
22869
|
+
for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
22862
22870
|
var char = _step.value;
|
|
22863
22871
|
|
|
22864
22872
|
if (char === "{") {
|
|
@@ -22926,7 +22934,7 @@ function needsParens(path$$1, options) {
|
|
|
22926
22934
|
// parentheses.
|
|
22927
22935
|
|
|
22928
22936
|
|
|
22929
|
-
if (hasClosureCompilerTypeCastComment(options.originalText, path$$1
|
|
22937
|
+
if (hasClosureCompilerTypeCastComment(options.originalText, path$$1)) {
|
|
22930
22938
|
return true;
|
|
22931
22939
|
}
|
|
22932
22940
|
|
|
@@ -23237,6 +23245,7 @@ function needsParens(path$$1, options) {
|
|
|
23237
23245
|
case "TSAsExpression":
|
|
23238
23246
|
case "TSNonNullExpression":
|
|
23239
23247
|
case "BindExpression":
|
|
23248
|
+
case "OptionalMemberExpression":
|
|
23240
23249
|
return true;
|
|
23241
23250
|
|
|
23242
23251
|
case "MemberExpression":
|
|
@@ -30230,8 +30239,8 @@ function print(path$$1, options, print) {
|
|
|
30230
30239
|
case "BlockStatement":
|
|
30231
30240
|
{
|
|
30232
30241
|
var pp = path$$1.getParentNode(1);
|
|
30233
|
-
var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
|
|
30234
|
-
var hasElseIf = n.inverse && n.inverse.body
|
|
30242
|
+
var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
|
|
30243
|
+
var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
|
|
30235
30244
|
var indentElse = hasElseIf ? function (a) {
|
|
30236
30245
|
return a;
|
|
30237
30246
|
} : indent$6;
|
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.17.
|
|
15
|
+
var version$1 = "1.17.1";
|
|
16
16
|
var description = "Prettier is an opinionated code formatter";
|
|
17
17
|
var bin = {
|
|
18
18
|
"prettier": "./bin/prettier.js"
|
|
@@ -108,7 +108,7 @@ var devDependencies = {
|
|
|
108
108
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
109
109
|
"jest-watch-typeahead": "0.1.0",
|
|
110
110
|
"mkdirp": "0.5.1",
|
|
111
|
-
"prettier": "1.
|
|
111
|
+
"prettier": "1.17.0",
|
|
112
112
|
"prettylint": "1.0.0",
|
|
113
113
|
"rimraf": "2.6.2",
|
|
114
114
|
"rollup": "0.47.6",
|
|
@@ -13963,7 +13963,6 @@ function formatRange(text, opts) {
|
|
|
13963
13963
|
var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
|
|
13964
13964
|
rangeStart: 0,
|
|
13965
13965
|
rangeEnd: Infinity,
|
|
13966
|
-
printWidth: opts.printWidth - alignmentSize,
|
|
13967
13966
|
// track the cursor offset only if it's within our range
|
|
13968
13967
|
cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
|
|
13969
13968
|
}), alignmentSize); // Since the range contracts to avoid trailing whitespace,
|
|
@@ -22825,27 +22824,36 @@ var utils$4 = {
|
|
|
22825
22824
|
|
|
22826
22825
|
var hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment;
|
|
22827
22826
|
|
|
22828
|
-
function hasClosureCompilerTypeCastComment(text, path$$1
|
|
22827
|
+
function hasClosureCompilerTypeCastComment(text, path$$1) {
|
|
22829
22828
|
// https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
|
|
22830
22829
|
// Syntax example: var x = /** @type {string} */ (fruit);
|
|
22831
22830
|
var n = path$$1.getValue();
|
|
22832
|
-
return
|
|
22831
|
+
return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
|
|
22833
22832
|
|
|
22834
22833
|
function hasAncestorTypeCastComment(index) {
|
|
22835
22834
|
var ancestor = path$$1.getParentNode(index);
|
|
22836
|
-
return ancestor &&
|
|
22835
|
+
return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
|
|
22837
22836
|
}
|
|
22838
22837
|
|
|
22839
22838
|
function hasTypeCastComment(node) {
|
|
22840
22839
|
return node.comments && node.comments.some(function (comment) {
|
|
22841
|
-
return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value)
|
|
22840
|
+
return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
|
|
22842
22841
|
});
|
|
22843
22842
|
}
|
|
22844
22843
|
|
|
22844
|
+
function isParenthesized(node) {
|
|
22845
|
+
// Closure typecast comments only really make sense when _not_ using
|
|
22846
|
+
// typescript or flow parsers, so we take advantage of the babel parser's
|
|
22847
|
+
// parenthesized expressions.
|
|
22848
|
+
return node.extra && node.extra.parenthesized;
|
|
22849
|
+
}
|
|
22850
|
+
|
|
22845
22851
|
function isTypeCastComment(comment) {
|
|
22846
|
-
var
|
|
22852
|
+
var cleaned = comment.trim().split("\n").map(function (line) {
|
|
22853
|
+
return line.replace(/^[\s*]+/, "");
|
|
22854
|
+
}).join(" ").trim();
|
|
22847
22855
|
|
|
22848
|
-
if (
|
|
22856
|
+
if (!/^@type\s+\{[^]+\}$/.test(cleaned)) {
|
|
22849
22857
|
return false;
|
|
22850
22858
|
}
|
|
22851
22859
|
|
|
@@ -22856,7 +22864,7 @@ function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
|
|
|
22856
22864
|
var _iteratorError = undefined;
|
|
22857
22865
|
|
|
22858
22866
|
try {
|
|
22859
|
-
for (var _iterator =
|
|
22867
|
+
for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
22860
22868
|
var char = _step.value;
|
|
22861
22869
|
|
|
22862
22870
|
if (char === "{") {
|
|
@@ -22924,7 +22932,7 @@ function needsParens(path$$1, options) {
|
|
|
22924
22932
|
// parentheses.
|
|
22925
22933
|
|
|
22926
22934
|
|
|
22927
|
-
if (hasClosureCompilerTypeCastComment(options.originalText, path$$1
|
|
22935
|
+
if (hasClosureCompilerTypeCastComment(options.originalText, path$$1)) {
|
|
22928
22936
|
return true;
|
|
22929
22937
|
}
|
|
22930
22938
|
|
|
@@ -23235,6 +23243,7 @@ function needsParens(path$$1, options) {
|
|
|
23235
23243
|
case "TSAsExpression":
|
|
23236
23244
|
case "TSNonNullExpression":
|
|
23237
23245
|
case "BindExpression":
|
|
23246
|
+
case "OptionalMemberExpression":
|
|
23238
23247
|
return true;
|
|
23239
23248
|
|
|
23240
23249
|
case "MemberExpression":
|
|
@@ -30228,8 +30237,8 @@ function print(path$$1, options, print) {
|
|
|
30228
30237
|
case "BlockStatement":
|
|
30229
30238
|
{
|
|
30230
30239
|
var pp = path$$1.getParentNode(1);
|
|
30231
|
-
var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
|
|
30232
|
-
var hasElseIf = n.inverse && n.inverse.body
|
|
30240
|
+
var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
|
|
30241
|
+
var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
|
|
30233
30242
|
var indentElse = hasElseIf ? function (a) {
|
|
30234
30243
|
return a;
|
|
30235
30244
|
} : indent$6;
|
package/package.json
CHANGED
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.17.
|
|
8
|
+
var version$1 = "1.17.1";
|
|
9
9
|
var description = "Prettier is an opinionated code formatter";
|
|
10
10
|
var bin = {
|
|
11
11
|
"prettier": "./bin/prettier.js"
|
|
@@ -101,7 +101,7 @@ var devDependencies = {
|
|
|
101
101
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
102
102
|
"jest-watch-typeahead": "0.1.0",
|
|
103
103
|
"mkdirp": "0.5.1",
|
|
104
|
-
"prettier": "1.
|
|
104
|
+
"prettier": "1.17.0",
|
|
105
105
|
"prettylint": "1.0.0",
|
|
106
106
|
"rimraf": "2.6.2",
|
|
107
107
|
"rollup": "0.47.6",
|
|
@@ -16289,7 +16289,6 @@ function formatRange(text, opts) {
|
|
|
16289
16289
|
var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
|
|
16290
16290
|
rangeStart: 0,
|
|
16291
16291
|
rangeEnd: Infinity,
|
|
16292
|
-
printWidth: opts.printWidth - alignmentSize,
|
|
16293
16292
|
// track the cursor offset only if it's within our range
|
|
16294
16293
|
cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
|
|
16295
16294
|
}), alignmentSize); // Since the range contracts to avoid trailing whitespace,
|
|
@@ -18543,8 +18542,8 @@ function print(path, options, print) {
|
|
|
18543
18542
|
case "BlockStatement":
|
|
18544
18543
|
{
|
|
18545
18544
|
var pp = path.getParentNode(1);
|
|
18546
|
-
var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
|
|
18547
|
-
var hasElseIf = n.inverse && n.inverse.body
|
|
18545
|
+
var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
|
|
18546
|
+
var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
|
|
18548
18547
|
var indentElse = hasElseIf ? function (a) {
|
|
18549
18548
|
return a;
|
|
18550
18549
|
} : indent$4;
|
|
@@ -22707,27 +22706,36 @@ var utils$8 = {
|
|
|
22707
22706
|
|
|
22708
22707
|
var hasFlowShorthandAnnotationComment$1 = utils$8.hasFlowShorthandAnnotationComment;
|
|
22709
22708
|
|
|
22710
|
-
function hasClosureCompilerTypeCastComment(text, path
|
|
22709
|
+
function hasClosureCompilerTypeCastComment(text, path) {
|
|
22711
22710
|
// https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
|
|
22712
22711
|
// Syntax example: var x = /** @type {string} */ (fruit);
|
|
22713
22712
|
var n = path.getValue();
|
|
22714
|
-
return
|
|
22713
|
+
return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
|
|
22715
22714
|
|
|
22716
22715
|
function hasAncestorTypeCastComment(index) {
|
|
22717
22716
|
var ancestor = path.getParentNode(index);
|
|
22718
|
-
return ancestor &&
|
|
22717
|
+
return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
|
|
22719
22718
|
}
|
|
22720
22719
|
|
|
22721
22720
|
function hasTypeCastComment(node) {
|
|
22722
22721
|
return node.comments && node.comments.some(function (comment) {
|
|
22723
|
-
return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value)
|
|
22722
|
+
return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
|
|
22724
22723
|
});
|
|
22725
22724
|
}
|
|
22726
22725
|
|
|
22726
|
+
function isParenthesized(node) {
|
|
22727
|
+
// Closure typecast comments only really make sense when _not_ using
|
|
22728
|
+
// typescript or flow parsers, so we take advantage of the babel parser's
|
|
22729
|
+
// parenthesized expressions.
|
|
22730
|
+
return node.extra && node.extra.parenthesized;
|
|
22731
|
+
}
|
|
22732
|
+
|
|
22727
22733
|
function isTypeCastComment(comment) {
|
|
22728
|
-
var
|
|
22734
|
+
var cleaned = comment.trim().split("\n").map(function (line) {
|
|
22735
|
+
return line.replace(/^[\s*]+/, "");
|
|
22736
|
+
}).join(" ").trim();
|
|
22729
22737
|
|
|
22730
|
-
if (
|
|
22738
|
+
if (!/^@type\s+\{[^]+\}$/.test(cleaned)) {
|
|
22731
22739
|
return false;
|
|
22732
22740
|
}
|
|
22733
22741
|
|
|
@@ -22738,7 +22746,7 @@ function hasClosureCompilerTypeCastComment(text, path, locStart, locEnd) {
|
|
|
22738
22746
|
var _iteratorError = undefined;
|
|
22739
22747
|
|
|
22740
22748
|
try {
|
|
22741
|
-
for (var _iterator =
|
|
22749
|
+
for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
22742
22750
|
var char = _step.value;
|
|
22743
22751
|
|
|
22744
22752
|
if (char === "{") {
|
|
@@ -22806,7 +22814,7 @@ function needsParens(path, options) {
|
|
|
22806
22814
|
// parentheses.
|
|
22807
22815
|
|
|
22808
22816
|
|
|
22809
|
-
if (hasClosureCompilerTypeCastComment(options.originalText, path
|
|
22817
|
+
if (hasClosureCompilerTypeCastComment(options.originalText, path)) {
|
|
22810
22818
|
return true;
|
|
22811
22819
|
}
|
|
22812
22820
|
|
|
@@ -23117,6 +23125,7 @@ function needsParens(path, options) {
|
|
|
23117
23125
|
case "TSAsExpression":
|
|
23118
23126
|
case "TSNonNullExpression":
|
|
23119
23127
|
case "BindExpression":
|
|
23128
|
+
case "OptionalMemberExpression":
|
|
23120
23129
|
return true;
|
|
23121
23130
|
|
|
23122
23131
|
case "MemberExpression":
|