prettier 2.0.3 → 2.0.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/bin-prettier.js +21 -46
- package/index.js +21 -46
- package/package.json +1 -1
- package/standalone.js +21 -46
package/bin-prettier.js
CHANGED
|
@@ -50,7 +50,7 @@ var pleaseUpgradeNode = function pleaseUpgradeNode(pkg, opts) {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
var name = "prettier";
|
|
53
|
-
var version = "2.0.
|
|
53
|
+
var version = "2.0.4";
|
|
54
54
|
var description = "Prettier is an opinionated code formatter";
|
|
55
55
|
var bin = "./bin/prettier.js";
|
|
56
56
|
var repository = "prettier/prettier";
|
|
@@ -147,7 +147,7 @@ var devDependencies = {
|
|
|
147
147
|
"jest-snapshot-serializer-ansi": "1.0.0",
|
|
148
148
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
149
149
|
"jest-watch-typeahead": "0.5.0",
|
|
150
|
-
prettier: "2.0.
|
|
150
|
+
prettier: "2.0.3",
|
|
151
151
|
rimraf: "3.0.2",
|
|
152
152
|
rollup: "2.3.2",
|
|
153
153
|
"rollup-plugin-babel": "4.4.0",
|
|
@@ -36573,7 +36573,7 @@ function isTypeAnnotationAFunction(node, options) {
|
|
|
36573
36573
|
return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
|
|
36574
36574
|
}
|
|
36575
36575
|
|
|
36576
|
-
const binaryishNodeTypes = new Set(["BinaryExpression", "LogicalExpression", "NGPipeExpression"
|
|
36576
|
+
const binaryishNodeTypes = new Set(["BinaryExpression", "LogicalExpression", "NGPipeExpression"]);
|
|
36577
36577
|
|
|
36578
36578
|
function isBinaryish(node) {
|
|
36579
36579
|
return binaryishNodeTypes.has(node.type);
|
|
@@ -38389,12 +38389,7 @@ function printPathNoParens(path, options, print, args) {
|
|
|
38389
38389
|
case "BinaryExpression":
|
|
38390
38390
|
case "LogicalExpression":
|
|
38391
38391
|
case "NGPipeExpression":
|
|
38392
|
-
case "TSAsExpression":
|
|
38393
38392
|
{
|
|
38394
|
-
const {
|
|
38395
|
-
rightNodeName,
|
|
38396
|
-
operator
|
|
38397
|
-
} = getBinaryishNodeNames(n);
|
|
38398
38393
|
const parent = path.getParentNode();
|
|
38399
38394
|
const parentParent = path.getParentNode(1);
|
|
38400
38395
|
const isInsideParenthesis = n !== parent.body && (parent.type === "IfStatement" || parent.type === "WhileStatement" || parent.type === "SwitchStatement" || parent.type === "DoWhileStatement");
|
|
@@ -38429,19 +38424,11 @@ function printPathNoParens(path, options, print, args) {
|
|
|
38429
38424
|
// indented accordingly. We should indent sub-expressions where the first case isn't indented.
|
|
38430
38425
|
|
|
38431
38426
|
|
|
38432
|
-
|
|
38427
|
+
const shouldNotIndent = parent.type === "ReturnStatement" || parent.type === "ThrowStatement" || parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n.operator !== "|" && parent.type === "JsExpressionRoot" || n.type !== "NGPipeExpression" && (parent.type === "NGRoot" && options.parser === "__ng_binding" || parent.type === "NGMicrosyntaxExpression" && parentParent.type === "NGMicrosyntax" && parentParent.body.length === 1) || n === parent.body && parent.type === "ArrowFunctionExpression" || n !== parent.body && parent.type === "ForStatement" || parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement" && parentParent.type !== "ThrowStatement" && parentParent.type !== "CallExpression" && parentParent.type !== "OptionalCallExpression" || parent.type === "TemplateLiteral";
|
|
38428
|
+
const shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
|
|
38429
|
+
const samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(n.operator, n.left.operator);
|
|
38433
38430
|
|
|
38434
|
-
if (
|
|
38435
|
-
if (shouldInlineLogicalExpression(n)) {
|
|
38436
|
-
const samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(operator, n.left.operator);
|
|
38437
|
-
shouldNotIndent = !samePrecedenceSubExpression;
|
|
38438
|
-
} else {
|
|
38439
|
-
const shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
|
|
38440
|
-
shouldNotIndent = shouldIndentIfInlining;
|
|
38441
|
-
}
|
|
38442
|
-
}
|
|
38443
|
-
|
|
38444
|
-
if (shouldNotIndent) {
|
|
38431
|
+
if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
|
|
38445
38432
|
return group$2(concat$6(parts));
|
|
38446
38433
|
}
|
|
38447
38434
|
|
|
@@ -38457,7 +38444,7 @@ function printPathNoParens(path, options, print, args) {
|
|
|
38457
38444
|
// )
|
|
38458
38445
|
|
|
38459
38446
|
|
|
38460
|
-
const hasJSX = isJSXNode$1(n
|
|
38447
|
+
const hasJSX = isJSXNode$1(n.right);
|
|
38461
38448
|
const rest = concat$6(hasJSX ? parts.slice(1, -1) : parts.slice(1));
|
|
38462
38449
|
const groupId = Symbol("logicalChain-" + ++uid);
|
|
38463
38450
|
const chain = group$2(concat$6([// Don't include the initial expression in the indentation
|
|
@@ -39594,7 +39581,7 @@ function printPathNoParens(path, options, print, args) {
|
|
|
39594
39581
|
if (!isSimple) {
|
|
39595
39582
|
// Breaks at the template element boundaries (${ and }) are preferred to breaking
|
|
39596
39583
|
// in the middle of a MemberExpression
|
|
39597
|
-
if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression" || n.expressions[i].type === "SequenceExpression" || isBinaryish$1(n.expressions[i])) {
|
|
39584
|
+
if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression" || n.expressions[i].type === "SequenceExpression" || n.expressions[i].type === "TSAsExpression" || isBinaryish$1(n.expressions[i])) {
|
|
39598
39585
|
printed = concat$6([indent$3(concat$6([softline$2, printed])), softline$2]);
|
|
39599
39586
|
}
|
|
39600
39587
|
}
|
|
@@ -40160,6 +40147,9 @@ function printPathNoParens(path, options, print, args) {
|
|
|
40160
40147
|
case "TSVoidKeyword":
|
|
40161
40148
|
return "void";
|
|
40162
40149
|
|
|
40150
|
+
case "TSAsExpression":
|
|
40151
|
+
return concat$6([path.call(print, "expression"), " as ", path.call(print, "typeAnnotation")]);
|
|
40152
|
+
|
|
40163
40153
|
case "TSArrayType":
|
|
40164
40154
|
return concat$6([path.call(print, "elementType"), "[]"]);
|
|
40165
40155
|
|
|
@@ -41809,17 +41799,6 @@ function shouldInlineLogicalExpression(node) {
|
|
|
41809
41799
|
}
|
|
41810
41800
|
|
|
41811
41801
|
return false;
|
|
41812
|
-
}
|
|
41813
|
-
|
|
41814
|
-
function getBinaryishNodeNames(node) {
|
|
41815
|
-
const leftNodeName = node.type === "TSAsExpression" ? "expression" : "left";
|
|
41816
|
-
const rightNodeName = node.type === "TSAsExpression" ? "typeAnnotation" : "right";
|
|
41817
|
-
const operator = node.type === "NGPipeExpression" ? "|" : node.type === "TSAsExpression" ? "as" : node.operator;
|
|
41818
|
-
return {
|
|
41819
|
-
leftNodeName,
|
|
41820
|
-
rightNodeName,
|
|
41821
|
-
operator
|
|
41822
|
-
};
|
|
41823
41802
|
} // For binary expressions to be consistent, we need to group
|
|
41824
41803
|
// subsequent operators with the same precedence level under a single
|
|
41825
41804
|
// group. Otherwise they will be nested such that some of them break
|
|
@@ -41832,14 +41811,10 @@ function getBinaryishNodeNames(node) {
|
|
|
41832
41811
|
|
|
41833
41812
|
function printBinaryishExpressions(path, print, options, isNested, isInsideParenthesis) {
|
|
41834
41813
|
let parts = [];
|
|
41835
|
-
const node = path.getValue(); // We treat BinaryExpression
|
|
41814
|
+
const node = path.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
|
|
41836
41815
|
|
|
41837
41816
|
if (isBinaryish$1(node)) {
|
|
41838
|
-
|
|
41839
|
-
leftNodeName,
|
|
41840
|
-
rightNodeName,
|
|
41841
|
-
operator
|
|
41842
|
-
} = getBinaryishNodeNames(node); // Put all operators with the same precedence level in the same
|
|
41817
|
+
// Put all operators with the same precedence level in the same
|
|
41843
41818
|
// group. The reason we only need to do this with the `left`
|
|
41844
41819
|
// expression is because given an expression like `1 + 2 - 3`, it
|
|
41845
41820
|
// is always parsed like `((1 + 2) - 3)`, meaning the `left` side
|
|
@@ -41848,24 +41823,24 @@ function printBinaryishExpressions(path, print, options, isNested, isInsideParen
|
|
|
41848
41823
|
// precedence level and should be treated as a separate group, so
|
|
41849
41824
|
// print them normally. (This doesn't hold for the `**` operator,
|
|
41850
41825
|
// which is unique in that it is right-associative.)
|
|
41851
|
-
|
|
41852
|
-
if (node.type === "NGPipeExpression" || node.type !== "TSAsExpression" && shouldFlatten$1(operator, node[leftNodeName].operator)) {
|
|
41826
|
+
if (shouldFlatten$1(node.operator, node.left.operator)) {
|
|
41853
41827
|
// Flatten them out by recursively calling this function.
|
|
41854
41828
|
parts = parts.concat(path.call(left => printBinaryishExpressions(left, print, options,
|
|
41855
41829
|
/* isNested */
|
|
41856
|
-
true, isInsideParenthesis),
|
|
41830
|
+
true, isInsideParenthesis), "left"));
|
|
41857
41831
|
} else {
|
|
41858
|
-
parts.push(path.call(print,
|
|
41832
|
+
parts.push(path.call(print, "left"));
|
|
41859
41833
|
}
|
|
41860
41834
|
|
|
41861
41835
|
const shouldInline = shouldInlineLogicalExpression(node);
|
|
41862
|
-
const lineBeforeOperator = (operator === "|>" || node.type === "NGPipeExpression" || operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node
|
|
41836
|
+
const lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node.right, options);
|
|
41837
|
+
const operator = node.type === "NGPipeExpression" ? "|" : node.operator;
|
|
41863
41838
|
const rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$2(indent$3(concat$6([softline$2, ": ", join$4(concat$6([softline$2, ":", ifBreak$1(" ")]), path.map(print, "arguments").map(arg => align$1(2, group$2(arg))))]))) : "";
|
|
41864
|
-
const right = shouldInline ? concat$6([operator, " ", path.call(print,
|
|
41839
|
+
const right = shouldInline ? concat$6([operator, " ", path.call(print, "right"), rightSuffix]) : concat$6([lineBeforeOperator ? softline$2 : "", operator, lineBeforeOperator ? " " : line$4, path.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
|
|
41865
41840
|
// in order to avoid having a small right part like -1 be on its own line.
|
|
41866
41841
|
|
|
41867
41842
|
const parent = path.getParentNode();
|
|
41868
|
-
const shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node
|
|
41843
|
+
const shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
|
|
41869
41844
|
parts.push(" ", shouldGroup ? group$2(right) : right); // The root comments are already printed, but we need to manually print
|
|
41870
41845
|
// the other ones since we don't call the normal print on BinaryExpression,
|
|
41871
41846
|
// only for the left and right parts
|
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var stream$5 = _interopDefault(require('stream'));
|
|
|
12
12
|
var events = _interopDefault(require('events'));
|
|
13
13
|
|
|
14
14
|
var name = "prettier";
|
|
15
|
-
var version = "2.0.
|
|
15
|
+
var version = "2.0.4";
|
|
16
16
|
var description = "Prettier is an opinionated code formatter";
|
|
17
17
|
var bin = "./bin/prettier.js";
|
|
18
18
|
var repository = "prettier/prettier";
|
|
@@ -109,7 +109,7 @@ var devDependencies = {
|
|
|
109
109
|
"jest-snapshot-serializer-ansi": "1.0.0",
|
|
110
110
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
111
111
|
"jest-watch-typeahead": "0.5.0",
|
|
112
|
-
prettier: "2.0.
|
|
112
|
+
prettier: "2.0.3",
|
|
113
113
|
rimraf: "3.0.2",
|
|
114
114
|
rollup: "2.3.2",
|
|
115
115
|
"rollup-plugin-babel": "4.4.0",
|
|
@@ -36531,7 +36531,7 @@ function isTypeAnnotationAFunction(node, options) {
|
|
|
36531
36531
|
return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
|
|
36532
36532
|
}
|
|
36533
36533
|
|
|
36534
|
-
const binaryishNodeTypes = new Set(["BinaryExpression", "LogicalExpression", "NGPipeExpression"
|
|
36534
|
+
const binaryishNodeTypes = new Set(["BinaryExpression", "LogicalExpression", "NGPipeExpression"]);
|
|
36535
36535
|
|
|
36536
36536
|
function isBinaryish(node) {
|
|
36537
36537
|
return binaryishNodeTypes.has(node.type);
|
|
@@ -38347,12 +38347,7 @@ function printPathNoParens(path, options, print, args) {
|
|
|
38347
38347
|
case "BinaryExpression":
|
|
38348
38348
|
case "LogicalExpression":
|
|
38349
38349
|
case "NGPipeExpression":
|
|
38350
|
-
case "TSAsExpression":
|
|
38351
38350
|
{
|
|
38352
|
-
const {
|
|
38353
|
-
rightNodeName,
|
|
38354
|
-
operator
|
|
38355
|
-
} = getBinaryishNodeNames(n);
|
|
38356
38351
|
const parent = path.getParentNode();
|
|
38357
38352
|
const parentParent = path.getParentNode(1);
|
|
38358
38353
|
const isInsideParenthesis = n !== parent.body && (parent.type === "IfStatement" || parent.type === "WhileStatement" || parent.type === "SwitchStatement" || parent.type === "DoWhileStatement");
|
|
@@ -38387,19 +38382,11 @@ function printPathNoParens(path, options, print, args) {
|
|
|
38387
38382
|
// indented accordingly. We should indent sub-expressions where the first case isn't indented.
|
|
38388
38383
|
|
|
38389
38384
|
|
|
38390
|
-
|
|
38385
|
+
const shouldNotIndent = parent.type === "ReturnStatement" || parent.type === "ThrowStatement" || parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n.operator !== "|" && parent.type === "JsExpressionRoot" || n.type !== "NGPipeExpression" && (parent.type === "NGRoot" && options.parser === "__ng_binding" || parent.type === "NGMicrosyntaxExpression" && parentParent.type === "NGMicrosyntax" && parentParent.body.length === 1) || n === parent.body && parent.type === "ArrowFunctionExpression" || n !== parent.body && parent.type === "ForStatement" || parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement" && parentParent.type !== "ThrowStatement" && parentParent.type !== "CallExpression" && parentParent.type !== "OptionalCallExpression" || parent.type === "TemplateLiteral";
|
|
38386
|
+
const shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
|
|
38387
|
+
const samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(n.operator, n.left.operator);
|
|
38391
38388
|
|
|
38392
|
-
if (
|
|
38393
|
-
if (shouldInlineLogicalExpression(n)) {
|
|
38394
|
-
const samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(operator, n.left.operator);
|
|
38395
|
-
shouldNotIndent = !samePrecedenceSubExpression;
|
|
38396
|
-
} else {
|
|
38397
|
-
const shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
|
|
38398
|
-
shouldNotIndent = shouldIndentIfInlining;
|
|
38399
|
-
}
|
|
38400
|
-
}
|
|
38401
|
-
|
|
38402
|
-
if (shouldNotIndent) {
|
|
38389
|
+
if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
|
|
38403
38390
|
return group$2(concat$6(parts));
|
|
38404
38391
|
}
|
|
38405
38392
|
|
|
@@ -38415,7 +38402,7 @@ function printPathNoParens(path, options, print, args) {
|
|
|
38415
38402
|
// )
|
|
38416
38403
|
|
|
38417
38404
|
|
|
38418
|
-
const hasJSX = isJSXNode$1(n
|
|
38405
|
+
const hasJSX = isJSXNode$1(n.right);
|
|
38419
38406
|
const rest = concat$6(hasJSX ? parts.slice(1, -1) : parts.slice(1));
|
|
38420
38407
|
const groupId = Symbol("logicalChain-" + ++uid);
|
|
38421
38408
|
const chain = group$2(concat$6([// Don't include the initial expression in the indentation
|
|
@@ -39552,7 +39539,7 @@ function printPathNoParens(path, options, print, args) {
|
|
|
39552
39539
|
if (!isSimple) {
|
|
39553
39540
|
// Breaks at the template element boundaries (${ and }) are preferred to breaking
|
|
39554
39541
|
// in the middle of a MemberExpression
|
|
39555
|
-
if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression" || n.expressions[i].type === "SequenceExpression" || isBinaryish$1(n.expressions[i])) {
|
|
39542
|
+
if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression" || n.expressions[i].type === "SequenceExpression" || n.expressions[i].type === "TSAsExpression" || isBinaryish$1(n.expressions[i])) {
|
|
39556
39543
|
printed = concat$6([indent$3(concat$6([softline$2, printed])), softline$2]);
|
|
39557
39544
|
}
|
|
39558
39545
|
}
|
|
@@ -40118,6 +40105,9 @@ function printPathNoParens(path, options, print, args) {
|
|
|
40118
40105
|
case "TSVoidKeyword":
|
|
40119
40106
|
return "void";
|
|
40120
40107
|
|
|
40108
|
+
case "TSAsExpression":
|
|
40109
|
+
return concat$6([path.call(print, "expression"), " as ", path.call(print, "typeAnnotation")]);
|
|
40110
|
+
|
|
40121
40111
|
case "TSArrayType":
|
|
40122
40112
|
return concat$6([path.call(print, "elementType"), "[]"]);
|
|
40123
40113
|
|
|
@@ -41767,17 +41757,6 @@ function shouldInlineLogicalExpression(node) {
|
|
|
41767
41757
|
}
|
|
41768
41758
|
|
|
41769
41759
|
return false;
|
|
41770
|
-
}
|
|
41771
|
-
|
|
41772
|
-
function getBinaryishNodeNames(node) {
|
|
41773
|
-
const leftNodeName = node.type === "TSAsExpression" ? "expression" : "left";
|
|
41774
|
-
const rightNodeName = node.type === "TSAsExpression" ? "typeAnnotation" : "right";
|
|
41775
|
-
const operator = node.type === "NGPipeExpression" ? "|" : node.type === "TSAsExpression" ? "as" : node.operator;
|
|
41776
|
-
return {
|
|
41777
|
-
leftNodeName,
|
|
41778
|
-
rightNodeName,
|
|
41779
|
-
operator
|
|
41780
|
-
};
|
|
41781
41760
|
} // For binary expressions to be consistent, we need to group
|
|
41782
41761
|
// subsequent operators with the same precedence level under a single
|
|
41783
41762
|
// group. Otherwise they will be nested such that some of them break
|
|
@@ -41790,14 +41769,10 @@ function getBinaryishNodeNames(node) {
|
|
|
41790
41769
|
|
|
41791
41770
|
function printBinaryishExpressions(path, print, options, isNested, isInsideParenthesis) {
|
|
41792
41771
|
let parts = [];
|
|
41793
|
-
const node = path.getValue(); // We treat BinaryExpression
|
|
41772
|
+
const node = path.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
|
|
41794
41773
|
|
|
41795
41774
|
if (isBinaryish$1(node)) {
|
|
41796
|
-
|
|
41797
|
-
leftNodeName,
|
|
41798
|
-
rightNodeName,
|
|
41799
|
-
operator
|
|
41800
|
-
} = getBinaryishNodeNames(node); // Put all operators with the same precedence level in the same
|
|
41775
|
+
// Put all operators with the same precedence level in the same
|
|
41801
41776
|
// group. The reason we only need to do this with the `left`
|
|
41802
41777
|
// expression is because given an expression like `1 + 2 - 3`, it
|
|
41803
41778
|
// is always parsed like `((1 + 2) - 3)`, meaning the `left` side
|
|
@@ -41806,24 +41781,24 @@ function printBinaryishExpressions(path, print, options, isNested, isInsideParen
|
|
|
41806
41781
|
// precedence level and should be treated as a separate group, so
|
|
41807
41782
|
// print them normally. (This doesn't hold for the `**` operator,
|
|
41808
41783
|
// which is unique in that it is right-associative.)
|
|
41809
|
-
|
|
41810
|
-
if (node.type === "NGPipeExpression" || node.type !== "TSAsExpression" && shouldFlatten$1(operator, node[leftNodeName].operator)) {
|
|
41784
|
+
if (shouldFlatten$1(node.operator, node.left.operator)) {
|
|
41811
41785
|
// Flatten them out by recursively calling this function.
|
|
41812
41786
|
parts = parts.concat(path.call(left => printBinaryishExpressions(left, print, options,
|
|
41813
41787
|
/* isNested */
|
|
41814
|
-
true, isInsideParenthesis),
|
|
41788
|
+
true, isInsideParenthesis), "left"));
|
|
41815
41789
|
} else {
|
|
41816
|
-
parts.push(path.call(print,
|
|
41790
|
+
parts.push(path.call(print, "left"));
|
|
41817
41791
|
}
|
|
41818
41792
|
|
|
41819
41793
|
const shouldInline = shouldInlineLogicalExpression(node);
|
|
41820
|
-
const lineBeforeOperator = (operator === "|>" || node.type === "NGPipeExpression" || operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node
|
|
41794
|
+
const lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node.right, options);
|
|
41795
|
+
const operator = node.type === "NGPipeExpression" ? "|" : node.operator;
|
|
41821
41796
|
const rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$2(indent$3(concat$6([softline$2, ": ", join$4(concat$6([softline$2, ":", ifBreak$1(" ")]), path.map(print, "arguments").map(arg => align$1(2, group$2(arg))))]))) : "";
|
|
41822
|
-
const right = shouldInline ? concat$6([operator, " ", path.call(print,
|
|
41797
|
+
const right = shouldInline ? concat$6([operator, " ", path.call(print, "right"), rightSuffix]) : concat$6([lineBeforeOperator ? softline$2 : "", operator, lineBeforeOperator ? " " : line$4, path.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
|
|
41823
41798
|
// in order to avoid having a small right part like -1 be on its own line.
|
|
41824
41799
|
|
|
41825
41800
|
const parent = path.getParentNode();
|
|
41826
|
-
const shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node
|
|
41801
|
+
const shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
|
|
41827
41802
|
parts.push(" ", shouldGroup ? group$2(right) : right); // The root comments are already printed, but we need to manually print
|
|
41828
41803
|
// the other ones since we don't call the normal print on BinaryExpression,
|
|
41829
41804
|
// only for the left and right parts
|
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 = "2.0.
|
|
8
|
+
var version = "2.0.4";
|
|
9
9
|
var description = "Prettier is an opinionated code formatter";
|
|
10
10
|
var bin = "./bin/prettier.js";
|
|
11
11
|
var repository = "prettier/prettier";
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"jest-snapshot-serializer-ansi": "1.0.0",
|
|
103
103
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
104
104
|
"jest-watch-typeahead": "0.5.0",
|
|
105
|
-
prettier: "2.0.
|
|
105
|
+
prettier: "2.0.3",
|
|
106
106
|
rimraf: "3.0.2",
|
|
107
107
|
rollup: "2.3.2",
|
|
108
108
|
"rollup-plugin-babel": "4.4.0",
|
|
@@ -24640,7 +24640,7 @@
|
|
|
24640
24640
|
return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
|
|
24641
24641
|
}
|
|
24642
24642
|
|
|
24643
|
-
const binaryishNodeTypes = new Set(["BinaryExpression", "LogicalExpression", "NGPipeExpression"
|
|
24643
|
+
const binaryishNodeTypes = new Set(["BinaryExpression", "LogicalExpression", "NGPipeExpression"]);
|
|
24644
24644
|
|
|
24645
24645
|
function isBinaryish(node) {
|
|
24646
24646
|
return binaryishNodeTypes.has(node.type);
|
|
@@ -26456,12 +26456,7 @@
|
|
|
26456
26456
|
case "BinaryExpression":
|
|
26457
26457
|
case "LogicalExpression":
|
|
26458
26458
|
case "NGPipeExpression":
|
|
26459
|
-
case "TSAsExpression":
|
|
26460
26459
|
{
|
|
26461
|
-
const {
|
|
26462
|
-
rightNodeName,
|
|
26463
|
-
operator
|
|
26464
|
-
} = getBinaryishNodeNames(n);
|
|
26465
26460
|
const parent = path.getParentNode();
|
|
26466
26461
|
const parentParent = path.getParentNode(1);
|
|
26467
26462
|
const isInsideParenthesis = n !== parent.body && (parent.type === "IfStatement" || parent.type === "WhileStatement" || parent.type === "SwitchStatement" || parent.type === "DoWhileStatement");
|
|
@@ -26496,19 +26491,11 @@
|
|
|
26496
26491
|
// indented accordingly. We should indent sub-expressions where the first case isn't indented.
|
|
26497
26492
|
|
|
26498
26493
|
|
|
26499
|
-
|
|
26494
|
+
const shouldNotIndent = parent.type === "ReturnStatement" || parent.type === "ThrowStatement" || parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n.operator !== "|" && parent.type === "JsExpressionRoot" || n.type !== "NGPipeExpression" && (parent.type === "NGRoot" && options.parser === "__ng_binding" || parent.type === "NGMicrosyntaxExpression" && parentParent.type === "NGMicrosyntax" && parentParent.body.length === 1) || n === parent.body && parent.type === "ArrowFunctionExpression" || n !== parent.body && parent.type === "ForStatement" || parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement" && parentParent.type !== "ThrowStatement" && parentParent.type !== "CallExpression" && parentParent.type !== "OptionalCallExpression" || parent.type === "TemplateLiteral";
|
|
26495
|
+
const shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
|
|
26496
|
+
const samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(n.operator, n.left.operator);
|
|
26500
26497
|
|
|
26501
|
-
if (
|
|
26502
|
-
if (shouldInlineLogicalExpression(n)) {
|
|
26503
|
-
const samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(operator, n.left.operator);
|
|
26504
|
-
shouldNotIndent = !samePrecedenceSubExpression;
|
|
26505
|
-
} else {
|
|
26506
|
-
const shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
|
|
26507
|
-
shouldNotIndent = shouldIndentIfInlining;
|
|
26508
|
-
}
|
|
26509
|
-
}
|
|
26510
|
-
|
|
26511
|
-
if (shouldNotIndent) {
|
|
26498
|
+
if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
|
|
26512
26499
|
return group$b(concat$d(parts));
|
|
26513
26500
|
}
|
|
26514
26501
|
|
|
@@ -26524,7 +26511,7 @@
|
|
|
26524
26511
|
// )
|
|
26525
26512
|
|
|
26526
26513
|
|
|
26527
|
-
const hasJSX = isJSXNode$1(n
|
|
26514
|
+
const hasJSX = isJSXNode$1(n.right);
|
|
26528
26515
|
const rest = concat$d(hasJSX ? parts.slice(1, -1) : parts.slice(1));
|
|
26529
26516
|
const groupId = Symbol("logicalChain-" + ++uid);
|
|
26530
26517
|
const chain = group$b(concat$d([// Don't include the initial expression in the indentation
|
|
@@ -27661,7 +27648,7 @@
|
|
|
27661
27648
|
if (!isSimple) {
|
|
27662
27649
|
// Breaks at the template element boundaries (${ and }) are preferred to breaking
|
|
27663
27650
|
// in the middle of a MemberExpression
|
|
27664
|
-
if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression" || n.expressions[i].type === "SequenceExpression" || isBinaryish$1(n.expressions[i])) {
|
|
27651
|
+
if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression" || n.expressions[i].type === "SequenceExpression" || n.expressions[i].type === "TSAsExpression" || isBinaryish$1(n.expressions[i])) {
|
|
27665
27652
|
printed = concat$d([indent$7(concat$d([softline$6, printed])), softline$6]);
|
|
27666
27653
|
}
|
|
27667
27654
|
}
|
|
@@ -28227,6 +28214,9 @@
|
|
|
28227
28214
|
case "TSVoidKeyword":
|
|
28228
28215
|
return "void";
|
|
28229
28216
|
|
|
28217
|
+
case "TSAsExpression":
|
|
28218
|
+
return concat$d([path.call(print, "expression"), " as ", path.call(print, "typeAnnotation")]);
|
|
28219
|
+
|
|
28230
28220
|
case "TSArrayType":
|
|
28231
28221
|
return concat$d([path.call(print, "elementType"), "[]"]);
|
|
28232
28222
|
|
|
@@ -29876,17 +29866,6 @@
|
|
|
29876
29866
|
}
|
|
29877
29867
|
|
|
29878
29868
|
return false;
|
|
29879
|
-
}
|
|
29880
|
-
|
|
29881
|
-
function getBinaryishNodeNames(node) {
|
|
29882
|
-
const leftNodeName = node.type === "TSAsExpression" ? "expression" : "left";
|
|
29883
|
-
const rightNodeName = node.type === "TSAsExpression" ? "typeAnnotation" : "right";
|
|
29884
|
-
const operator = node.type === "NGPipeExpression" ? "|" : node.type === "TSAsExpression" ? "as" : node.operator;
|
|
29885
|
-
return {
|
|
29886
|
-
leftNodeName,
|
|
29887
|
-
rightNodeName,
|
|
29888
|
-
operator
|
|
29889
|
-
};
|
|
29890
29869
|
} // For binary expressions to be consistent, we need to group
|
|
29891
29870
|
// subsequent operators with the same precedence level under a single
|
|
29892
29871
|
// group. Otherwise they will be nested such that some of them break
|
|
@@ -29899,14 +29878,10 @@
|
|
|
29899
29878
|
|
|
29900
29879
|
function printBinaryishExpressions(path, print, options, isNested, isInsideParenthesis) {
|
|
29901
29880
|
let parts = [];
|
|
29902
|
-
const node = path.getValue(); // We treat BinaryExpression
|
|
29881
|
+
const node = path.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
|
|
29903
29882
|
|
|
29904
29883
|
if (isBinaryish$1(node)) {
|
|
29905
|
-
|
|
29906
|
-
leftNodeName,
|
|
29907
|
-
rightNodeName,
|
|
29908
|
-
operator
|
|
29909
|
-
} = getBinaryishNodeNames(node); // Put all operators with the same precedence level in the same
|
|
29884
|
+
// Put all operators with the same precedence level in the same
|
|
29910
29885
|
// group. The reason we only need to do this with the `left`
|
|
29911
29886
|
// expression is because given an expression like `1 + 2 - 3`, it
|
|
29912
29887
|
// is always parsed like `((1 + 2) - 3)`, meaning the `left` side
|
|
@@ -29915,24 +29890,24 @@
|
|
|
29915
29890
|
// precedence level and should be treated as a separate group, so
|
|
29916
29891
|
// print them normally. (This doesn't hold for the `**` operator,
|
|
29917
29892
|
// which is unique in that it is right-associative.)
|
|
29918
|
-
|
|
29919
|
-
if (node.type === "NGPipeExpression" || node.type !== "TSAsExpression" && shouldFlatten$1(operator, node[leftNodeName].operator)) {
|
|
29893
|
+
if (shouldFlatten$1(node.operator, node.left.operator)) {
|
|
29920
29894
|
// Flatten them out by recursively calling this function.
|
|
29921
29895
|
parts = parts.concat(path.call(left => printBinaryishExpressions(left, print, options,
|
|
29922
29896
|
/* isNested */
|
|
29923
|
-
true, isInsideParenthesis),
|
|
29897
|
+
true, isInsideParenthesis), "left"));
|
|
29924
29898
|
} else {
|
|
29925
|
-
parts.push(path.call(print,
|
|
29899
|
+
parts.push(path.call(print, "left"));
|
|
29926
29900
|
}
|
|
29927
29901
|
|
|
29928
29902
|
const shouldInline = shouldInlineLogicalExpression(node);
|
|
29929
|
-
const lineBeforeOperator = (operator === "|>" || node.type === "NGPipeExpression" || operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node
|
|
29903
|
+
const lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node.right, options);
|
|
29904
|
+
const operator = node.type === "NGPipeExpression" ? "|" : node.operator;
|
|
29930
29905
|
const rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$b(indent$7(concat$d([softline$6, ": ", join$9(concat$d([softline$6, ":", ifBreak$6(" ")]), path.map(print, "arguments").map(arg => align$1(2, group$b(arg))))]))) : "";
|
|
29931
|
-
const right = shouldInline ? concat$d([operator, " ", path.call(print,
|
|
29906
|
+
const right = shouldInline ? concat$d([operator, " ", path.call(print, "right"), rightSuffix]) : concat$d([lineBeforeOperator ? softline$6 : "", operator, lineBeforeOperator ? " " : line$9, path.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
|
|
29932
29907
|
// in order to avoid having a small right part like -1 be on its own line.
|
|
29933
29908
|
|
|
29934
29909
|
const parent = path.getParentNode();
|
|
29935
|
-
const shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node
|
|
29910
|
+
const shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
|
|
29936
29911
|
parts.push(" ", shouldGroup ? group$b(right) : right); // The root comments are already printed, but we need to manually print
|
|
29937
29912
|
// the other ones since we don't call the normal print on BinaryExpression,
|
|
29938
29913
|
// only for the left and right parts
|