prettier 1.17.0 → 1.18.2

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.17.0";
8
+ var version$1 = "1.18.2";
9
9
  var description = "Prettier is an opinionated code formatter";
10
10
  var bin = {
11
11
  "prettier": "./bin/prettier.js"
@@ -22,8 +22,8 @@ var dependencies = {
22
22
  "@angular/compiler": "7.2.9",
23
23
  "@babel/code-frame": "7.0.0",
24
24
  "@babel/parser": "7.2.0",
25
- "@glimmer/syntax": "0.30.3",
26
- "@iarna/toml": "2.0.0",
25
+ "@glimmer/syntax": "0.38.4",
26
+ "@iarna/toml": "2.2.3",
27
27
  "@typescript-eslint/typescript-estree": "1.6.0",
28
28
  "angular-estree-parser": "1.1.5",
29
29
  "angular-html-parser": "1.2.0",
@@ -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.16.4",
104
+ "prettier": "1.18.0",
105
105
  "prettylint": "1.0.0",
106
106
  "rimraf": "2.6.2",
107
107
  "rollup": "0.47.6",
@@ -13888,7 +13888,7 @@ function printString(raw, options, isDirectiveLiteral) {
13888
13888
  // sure that we consistently output the minimum amount of escaped quotes.
13889
13889
 
13890
13890
 
13891
- return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.parentParser === "html" || options.parentParser === "vue" || options.parentParser === "angular" || options.parentParser === "lwc"));
13891
+ return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.embeddedInHtml));
13892
13892
  }
13893
13893
 
13894
13894
  function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
@@ -13944,6 +13944,53 @@ function getMaxContinuousCount(str, target) {
13944
13944
  }, 0);
13945
13945
  }
13946
13946
 
13947
+ function getMinNotPresentContinuousCount(str, target) {
13948
+ var matches = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
13949
+
13950
+ if (matches === null) {
13951
+ return 0;
13952
+ }
13953
+
13954
+ var countPresent = new Map();
13955
+ var max = 0;
13956
+ var _iteratorNormalCompletion = true;
13957
+ var _didIteratorError = false;
13958
+ var _iteratorError = undefined;
13959
+
13960
+ try {
13961
+ for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
13962
+ var match = _step.value;
13963
+ var count = match.length / target.length;
13964
+ countPresent.set(count, true);
13965
+
13966
+ if (count > max) {
13967
+ max = count;
13968
+ }
13969
+ }
13970
+ } catch (err) {
13971
+ _didIteratorError = true;
13972
+ _iteratorError = err;
13973
+ } finally {
13974
+ try {
13975
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
13976
+ _iterator.return();
13977
+ }
13978
+ } finally {
13979
+ if (_didIteratorError) {
13980
+ throw _iteratorError;
13981
+ }
13982
+ }
13983
+ }
13984
+
13985
+ for (var i = 1; i < max; i++) {
13986
+ if (!countPresent.get(i)) {
13987
+ return i;
13988
+ }
13989
+ }
13990
+
13991
+ return max + 1;
13992
+ }
13993
+
13947
13994
  function getStringWidth$1(text) {
13948
13995
  if (!text) {
13949
13996
  return 0;
@@ -14034,13 +14081,13 @@ function isWithinParentArrayProperty(path, propertyName) {
14034
14081
 
14035
14082
  function replaceEndOfLineWith(text, replacement) {
14036
14083
  var parts = [];
14037
- var _iteratorNormalCompletion = true;
14038
- var _didIteratorError = false;
14039
- var _iteratorError = undefined;
14084
+ var _iteratorNormalCompletion2 = true;
14085
+ var _didIteratorError2 = false;
14086
+ var _iteratorError2 = undefined;
14040
14087
 
14041
14088
  try {
14042
- for (var _iterator = text.split("\n")[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
14043
- var part = _step.value;
14089
+ for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
14090
+ var part = _step2.value;
14044
14091
 
14045
14092
  if (parts.length !== 0) {
14046
14093
  parts.push(replacement);
@@ -14049,16 +14096,16 @@ function replaceEndOfLineWith(text, replacement) {
14049
14096
  parts.push(part);
14050
14097
  }
14051
14098
  } catch (err) {
14052
- _didIteratorError = true;
14053
- _iteratorError = err;
14099
+ _didIteratorError2 = true;
14100
+ _iteratorError2 = err;
14054
14101
  } finally {
14055
14102
  try {
14056
- if (!_iteratorNormalCompletion && _iterator.return != null) {
14057
- _iterator.return();
14103
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
14104
+ _iterator2.return();
14058
14105
  }
14059
14106
  } finally {
14060
- if (_didIteratorError) {
14061
- throw _iteratorError;
14107
+ if (_didIteratorError2) {
14108
+ throw _iteratorError2;
14062
14109
  }
14063
14110
  }
14064
14111
  }
@@ -14070,6 +14117,7 @@ var util = {
14070
14117
  replaceEndOfLineWith: replaceEndOfLineWith,
14071
14118
  getStringWidth: getStringWidth$1,
14072
14119
  getMaxContinuousCount: getMaxContinuousCount,
14120
+ getMinNotPresentContinuousCount: getMinNotPresentContinuousCount,
14073
14121
  getPrecedence: getPrecedence,
14074
14122
  shouldFlatten: shouldFlatten,
14075
14123
  isBitwiseOperator: isBitwiseOperator,
@@ -14960,6 +15008,7 @@ var docUtils = {
14960
15008
  willBreak: willBreak,
14961
15009
  isLineNext: isLineNext,
14962
15010
  traverseDoc: traverseDoc,
15011
+ findInDoc: findInDoc,
14963
15012
  mapDoc: mapDoc$1,
14964
15013
  propagateBreaks: propagateBreaks,
14965
15014
  removeLines: removeLines,
@@ -15773,6 +15822,7 @@ function printSubtree(path, print, options$$1, printAstToDoc) {
15773
15822
  function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) {
15774
15823
  var nextOptions = normalize$3(Object.assign({}, parentOptions, partialNextOptions, {
15775
15824
  parentParser: parentOptions.parser,
15825
+ embeddedInHtml: !!(parentOptions.embeddedInHtml || parentOptions.parser === "html" || parentOptions.parser === "vue" || parentOptions.parser === "angular" || parentOptions.parser === "lwc"),
15776
15826
  originalText: text
15777
15827
  }), {
15778
15828
  passThrough: true
@@ -15840,7 +15890,7 @@ function printAstToDoc(ast, options) {
15840
15890
 
15841
15891
  var res;
15842
15892
 
15843
- if (printer.willPrintOwnComments && printer.willPrintOwnComments(path)) {
15893
+ if (printer.willPrintOwnComments && printer.willPrintOwnComments(path, options)) {
15844
15894
  res = callPluginPrintFunction(path, options, printGenerically, args);
15845
15895
  } else {
15846
15896
  // printComments will call the plugin print function and check for
@@ -16289,7 +16339,6 @@ function formatRange(text, opts) {
16289
16339
  var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
16290
16340
  rangeStart: 0,
16291
16341
  rangeEnd: Infinity,
16292
- printWidth: opts.printWidth - alignmentSize,
16293
16342
  // track the cursor offset only if it's within our range
16294
16343
  cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
16295
16344
  }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
@@ -18518,33 +18567,21 @@ function print(path, options, print) {
18518
18567
  var isGlimmerComponent = tagFirstChar.toUpperCase() === tagFirstChar || isLocal;
18519
18568
  var hasChildren = n.children.length > 0;
18520
18569
  var isVoid = isGlimmerComponent && !hasChildren || voidTags.indexOf(n.tag) !== -1;
18521
- var closeTag = isVoid ? concat$7([" />", softline$3]) : ">";
18570
+ var closeTagForNoBreak = isVoid ? concat$7([" />", softline$3]) : ">";
18571
+ var closeTagForBreak = isVoid ? "/>" : ">";
18522
18572
 
18523
18573
  var _getParams = function _getParams(path, print) {
18524
18574
  return indent$4(concat$7([n.attributes.length ? line$5 : "", join$4(line$5, path.map(print, "attributes")), n.modifiers.length ? line$5 : "", join$4(line$5, path.map(print, "modifiers")), n.comments.length ? line$5 : "", join$4(line$5, path.map(print, "comments"))]));
18525
- }; // The problem here is that I want to not break at all if the children
18526
- // would not break but I need to force an indent, so I use a hardline.
18527
-
18528
- /**
18529
- * What happens now:
18530
- * <div>
18531
- * Hello
18532
- * </div>
18533
- * ==>
18534
- * <div>Hello</div>
18535
- * This is due to me using hasChildren to decide to put the hardline in.
18536
- * I would rather use a {DOES THE WHOLE THING NEED TO BREAK}
18537
- */
18538
-
18575
+ };
18539
18576
 
18540
- return concat$7([group$6(concat$7(["<", n.tag, _getParams(path, print), n.blockParams.length ? " as |".concat(n.blockParams.join(" "), "|") : "", ifBreak$3(softline$3, ""), closeTag])), group$6(concat$7([indent$4(join$4(softline$3, [""].concat(path.map(print, "children")))), ifBreak$3(hasChildren ? hardline$6 : "", ""), !isVoid ? concat$7(["</", n.tag, ">"]) : ""]))]);
18577
+ return concat$7([group$6(concat$7(["<", n.tag, _getParams(path, print), n.blockParams.length ? " as |".concat(n.blockParams.join(" "), "|") : "", ifBreak$3(softline$3, ""), ifBreak$3(closeTagForBreak, closeTagForNoBreak)])), group$6(concat$7([indent$4(join$4(softline$3, [""].concat(path.map(print, "children")))), ifBreak$3(hasChildren ? hardline$6 : "", ""), !isVoid ? concat$7(["</", n.tag, ">"]) : ""]))]);
18541
18578
  }
18542
18579
 
18543
18580
  case "BlockStatement":
18544
18581
  {
18545
18582
  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[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
18583
+ var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
18584
+ var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
18548
18585
  var indentElse = hasElseIf ? function (a) {
18549
18586
  return a;
18550
18587
  } : indent$4;
@@ -20658,7 +20695,7 @@ function embed$2(path, print, textToDoc, options) {
20658
20695
  } // lit-html: html`<my-element obj=${obj}></my-element>`
20659
20696
 
20660
20697
 
20661
- if (/^PRETTIER_HTML_PLACEHOLDER_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
20698
+ if (/^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
20662
20699
  return concat$8([node.rawName, "=", node.value]);
20663
20700
  } // lwc: html`<my-element data-for={value}></my-elememt>`
20664
20701
 
@@ -21756,7 +21793,7 @@ function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
21756
21793
  // i.e. a function without any argument.
21757
21794
 
21758
21795
 
21759
- if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" && (enclosingNode.body.type !== "CallExpression" || enclosingNode.body.arguments.length === 0) || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || (enclosingNode.type === "CallExpression" || enclosingNode.type === "NewExpression") && enclosingNode.arguments.length === 0)) {
21796
+ if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || (enclosingNode.type === "CallExpression" || enclosingNode.type === "NewExpression") && enclosingNode.arguments.length === 0)) {
21760
21797
  addDanglingComment$2(enclosingNode, comment);
21761
21798
  return true;
21762
21799
  }
@@ -21986,9 +22023,7 @@ var _require$$1$utils = doc.utils;
21986
22023
  var mapDoc$5 = _require$$1$utils.mapDoc;
21987
22024
  var stripTrailingHardline$2 = _require$$1$utils.stripTrailingHardline;
21988
22025
 
21989
- function embed$4(path, print, textToDoc
21990
- /*, options */
21991
- ) {
22026
+ function embed$4(path, print, textToDoc, options) {
21992
22027
  var node = path.getValue();
21993
22028
  var parent = path.getParentNode();
21994
22029
  var parentParent = path.getParentNode(1);
@@ -22094,12 +22129,10 @@ function embed$4(path, print, textToDoc
22094
22129
  return concat$12(["`", indent$7(concat$12([hardline$9, join$8(hardline$9, parts)])), hardline$9, "`"]);
22095
22130
  }
22096
22131
 
22097
- if (isHtml(path)) {
22098
- return printHtmlTemplateLiteral(path, print, textToDoc, "html");
22099
- }
22132
+ var htmlParser = isHtml(path) ? "html" : isAngularComponentTemplate(path) ? "angular" : undefined;
22100
22133
 
22101
- if (isAngularComponentTemplate(path)) {
22102
- return printHtmlTemplateLiteral(path, print, textToDoc, "angular");
22134
+ if (htmlParser) {
22135
+ return printHtmlTemplateLiteral(path, print, textToDoc, htmlParser, options.embeddedInHtml);
22103
22136
  }
22104
22137
 
22105
22138
  break;
@@ -22139,6 +22172,10 @@ function getIndentation(str) {
22139
22172
  return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
22140
22173
  }
22141
22174
 
22175
+ function uncook(cookedValue) {
22176
+ return cookedValue.replace(/([\\`]|\$\{)/g, "\\$1");
22177
+ }
22178
+
22142
22179
  function escapeTemplateCharacters(doc$$2, raw) {
22143
22180
  return mapDoc$5(doc$$2, function (currentDoc) {
22144
22181
  if (!currentDoc.parts) {
@@ -22148,7 +22185,7 @@ function escapeTemplateCharacters(doc$$2, raw) {
22148
22185
  var parts = [];
22149
22186
  currentDoc.parts.forEach(function (part) {
22150
22187
  if (typeof part === "string") {
22151
- parts.push(raw ? part.replace(/(\\*)`/g, "$1$1\\`") : part.replace(/([\\`]|\$\{)/g, "\\$1"));
22188
+ parts.push(raw ? part.replace(/(\\*)`/g, "$1$1\\`") : uncook(part));
22152
22189
  } else {
22153
22190
  parts.push(part);
22154
22191
  }
@@ -22259,8 +22296,11 @@ function printGraphqlComments(lines) {
22259
22296
  return parts.length === 0 ? null : join$8(hardline$9, parts);
22260
22297
  }
22261
22298
  /**
22262
- * Template literal in this context:
22299
+ * Template literal in these contexts:
22263
22300
  * <style jsx>{`div{color:red}`}</style>
22301
+ * css``
22302
+ * css.global``
22303
+ * css.resolve``
22264
22304
  */
22265
22305
 
22266
22306
 
@@ -22270,7 +22310,7 @@ function isStyledJsx(path) {
22270
22310
  var parentParent = path.getParentNode(1);
22271
22311
  return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(function (attribute) {
22272
22312
  return attribute.name.name === "jsx";
22273
- });
22313
+ }) || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "Identifier" && parent.tag.name === "css" || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "MemberExpression" && parent.tag.object.name === "css" && (parent.tag.property.name === "global" || parent.tag.property.name === "resolve");
22274
22314
  }
22275
22315
  /**
22276
22316
  * Angular Components can have:
@@ -22338,9 +22378,9 @@ function isStyledComponents(path) {
22338
22378
 
22339
22379
  case "CallExpression":
22340
22380
  return (// styled(Component)``
22341
- isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attr({})``
22342
- isStyledIdentifier(tag.callee.object.object) || // Component.extend.attr({)``
22343
- isStyledExtend(tag.callee.object)) || // styled(Component).attr({})``
22381
+ isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attrs({})``
22382
+ isStyledIdentifier(tag.callee.object.object) || // Component.extend.attrs({})``
22383
+ isStyledExtend(tag.callee.object)) || // styled(Component).attrs({})``
22344
22384
  tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
22345
22385
  );
22346
22386
 
@@ -22458,16 +22498,22 @@ function isHtml(path) {
22458
22498
  }, function (node, name) {
22459
22499
  return node.type === "TaggedTemplateExpression" && node.tag.type === "Identifier" && node.tag.name === "html" && name === "quasi";
22460
22500
  }]);
22461
- }
22501
+ } // The counter is needed to distinguish nested embeds.
22502
+
22462
22503
 
22463
- function printHtmlTemplateLiteral(path, print, textToDoc, parser) {
22504
+ var htmlTemplateLiteralCounter = 0;
22505
+
22506
+ function printHtmlTemplateLiteral(path, print, textToDoc, parser, escapeClosingScriptTag) {
22464
22507
  var node = path.getValue();
22465
- var placeholderPattern = "PRETTIER_HTML_PLACEHOLDER_(\\d+)_IN_JS";
22466
- var placeholders = node.expressions.map(function (_, i) {
22467
- return "PRETTIER_HTML_PLACEHOLDER_".concat(i, "_IN_JS");
22468
- });
22508
+ var counter = htmlTemplateLiteralCounter;
22509
+ htmlTemplateLiteralCounter = htmlTemplateLiteralCounter + 1 >>> 0;
22510
+
22511
+ var composePlaceholder = function composePlaceholder(index) {
22512
+ return "PRETTIER_HTML_PLACEHOLDER_".concat(index, "_").concat(counter, "_IN_JS");
22513
+ };
22514
+
22469
22515
  var text = node.quasis.map(function (quasi, index, quasis) {
22470
- return index === quasis.length - 1 ? quasi.value.raw : quasi.value.raw + placeholders[index];
22516
+ return index === quasis.length - 1 ? quasi.value.cooked : quasi.value.cooked + composePlaceholder(index);
22471
22517
  }).join("");
22472
22518
  var expressionDocs = path.map(print, "expressions");
22473
22519
 
@@ -22475,13 +22521,11 @@ function printHtmlTemplateLiteral(path, print, textToDoc, parser) {
22475
22521
  return "``";
22476
22522
  }
22477
22523
 
22524
+ var placeholderRegex = RegExp(composePlaceholder("(\\d+)"), "g");
22478
22525
  var contentDoc = mapDoc$5(stripTrailingHardline$2(textToDoc(text, {
22479
22526
  parser: parser
22480
22527
  })), function (doc$$2) {
22481
- var placeholderRegex = new RegExp(placeholderPattern, "g");
22482
- var hasPlaceholder = typeof doc$$2 === "string" && placeholderRegex.test(doc$$2);
22483
-
22484
- if (!hasPlaceholder) {
22528
+ if (typeof doc$$2 !== "string") {
22485
22529
  return doc$$2;
22486
22530
  }
22487
22531
 
@@ -22493,6 +22537,12 @@ function printHtmlTemplateLiteral(path, print, textToDoc, parser) {
22493
22537
 
22494
22538
  if (i % 2 === 0) {
22495
22539
  if (component) {
22540
+ component = uncook(component);
22541
+
22542
+ if (escapeClosingScriptTag) {
22543
+ component = component.replace(/<\/(script)\b/gi, "<\\/$1");
22544
+ }
22545
+
22496
22546
  parts.push(component);
22497
22547
  }
22498
22548
 
@@ -22699,35 +22749,97 @@ function hasNode$1(node, fn) {
22699
22749
  });
22700
22750
  }
22701
22751
 
22752
+ function hasNakedLeftSide$2(node) {
22753
+ return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression" || node.type === "ConditionalExpression" || node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || node.type === "UpdateExpression" && !node.prefix || node.type === "TSAsExpression" || node.type === "TSNonNullExpression";
22754
+ }
22755
+
22756
+ function getLeftSide$1(node) {
22757
+ if (node.expressions) {
22758
+ return node.expressions[0];
22759
+ }
22760
+
22761
+ return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
22762
+ }
22763
+
22764
+ function getLeftSidePathName$2(path, node) {
22765
+ if (node.expressions) {
22766
+ return ["expressions", 0];
22767
+ }
22768
+
22769
+ if (node.left) {
22770
+ return ["left"];
22771
+ }
22772
+
22773
+ if (node.test) {
22774
+ return ["test"];
22775
+ }
22776
+
22777
+ if (node.object) {
22778
+ return ["object"];
22779
+ }
22780
+
22781
+ if (node.callee) {
22782
+ return ["callee"];
22783
+ }
22784
+
22785
+ if (node.tag) {
22786
+ return ["tag"];
22787
+ }
22788
+
22789
+ if (node.argument) {
22790
+ return ["argument"];
22791
+ }
22792
+
22793
+ if (node.expression) {
22794
+ return ["expression"];
22795
+ }
22796
+
22797
+ throw new Error("Unexpected node has no left side", node);
22798
+ }
22799
+
22702
22800
  var utils$8 = {
22801
+ getLeftSide: getLeftSide$1,
22802
+ getLeftSidePathName: getLeftSidePathName$2,
22803
+ hasNakedLeftSide: hasNakedLeftSide$2,
22703
22804
  hasNode: hasNode$1,
22704
22805
  hasFlowShorthandAnnotationComment: hasFlowShorthandAnnotationComment$2,
22705
22806
  hasFlowAnnotationComment: hasFlowAnnotationComment$1
22706
22807
  };
22707
22808
 
22809
+ var getLeftSidePathName$1 = utils$8.getLeftSidePathName;
22810
+ var hasNakedLeftSide$1 = utils$8.hasNakedLeftSide;
22708
22811
  var hasFlowShorthandAnnotationComment$1 = utils$8.hasFlowShorthandAnnotationComment;
22709
22812
 
22710
- function hasClosureCompilerTypeCastComment(text, path, locStart, locEnd) {
22813
+ function hasClosureCompilerTypeCastComment(text, path) {
22711
22814
  // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
22712
22815
  // Syntax example: var x = /** @type {string} */ (fruit);
22713
22816
  var n = path.getValue();
22714
- return util.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
22817
+ return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
22715
22818
 
22716
22819
  function hasAncestorTypeCastComment(index) {
22717
22820
  var ancestor = path.getParentNode(index);
22718
- return ancestor && util.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
22821
+ return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
22719
22822
  }
22720
22823
 
22721
22824
  function hasTypeCastComment(node) {
22722
22825
  return node.comments && node.comments.some(function (comment) {
22723
- return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value) && util.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
22826
+ return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
22724
22827
  });
22725
22828
  }
22726
22829
 
22830
+ function isParenthesized(node) {
22831
+ // Closure typecast comments only really make sense when _not_ using
22832
+ // typescript or flow parsers, so we take advantage of the babel parser's
22833
+ // parenthesized expressions.
22834
+ return node.extra && node.extra.parenthesized;
22835
+ }
22836
+
22727
22837
  function isTypeCastComment(comment) {
22728
- var trimmed = comment.trim();
22838
+ var cleaned = comment.trim().split("\n").map(function (line) {
22839
+ return line.replace(/^[\s*]+/, "");
22840
+ }).join(" ").trim();
22729
22841
 
22730
- if (!/^\*\s*@type\s*\{[^]+\}$/.test(trimmed)) {
22842
+ if (!/^@type\s*\{[^]+\}$/.test(cleaned)) {
22731
22843
  return false;
22732
22844
  }
22733
22845
 
@@ -22738,7 +22850,7 @@ function hasClosureCompilerTypeCastComment(text, path, locStart, locEnd) {
22738
22850
  var _iteratorError = undefined;
22739
22851
 
22740
22852
  try {
22741
- for (var _iterator = trimmed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
22853
+ for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
22742
22854
  var char = _step.value;
22743
22855
 
22744
22856
  if (char === "{") {
@@ -22806,7 +22918,7 @@ function needsParens(path, options) {
22806
22918
  // parentheses.
22807
22919
 
22808
22920
 
22809
- if (hasClosureCompilerTypeCastComment(options.originalText, path, options.locStart, options.locEnd)) {
22921
+ if (hasClosureCompilerTypeCastComment(options.originalText, path)) {
22810
22922
  return true;
22811
22923
  }
22812
22924
 
@@ -22819,6 +22931,15 @@ function needsParens(path, options) {
22819
22931
 
22820
22932
 
22821
22933
  if (node.type === "Identifier") {
22934
+ // ...unless those identifiers are embed placeholders. They might be substituted by complex
22935
+ // expressions, so the parens around them should not be dropped. Example (JS-in-HTML-in-JS):
22936
+ // let tpl = html`<script> f((${expr}) / 2); </script>`;
22937
+ // If the inner JS formatter removes the parens, the expression might change its meaning:
22938
+ // f((a + b) / 2) vs f(a + b / 2)
22939
+ if (node.extra && node.extra.parenthesized && /^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(node.name)) {
22940
+ return true;
22941
+ }
22942
+
22822
22943
  return false;
22823
22944
  }
22824
22945
 
@@ -22830,6 +22951,13 @@ function needsParens(path, options) {
22830
22951
 
22831
22952
  if ((parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node && (node.type === "ArrowFunctionExpression" || node.type === "AssignmentExpression" || node.type === "AwaitExpression" || node.type === "BinaryExpression" || node.type === "ConditionalExpression" || node.type === "LogicalExpression" || node.type === "NewExpression" || node.type === "ObjectExpression" || node.type === "ParenthesizedExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "UnaryExpression" || node.type === "UpdateExpression" || node.type === "YieldExpression")) {
22832
22953
  return true;
22954
+ } // `export default function` or `export default class` can't be followed by
22955
+ // anything after. So an expression like `export default (function(){}).toString()`
22956
+ // needs to be followed by a parentheses
22957
+
22958
+
22959
+ if (parent.type === "ExportDefaultDeclaration") {
22960
+ return shouldWrapFunctionForExportDefault(path, options);
22833
22961
  }
22834
22962
 
22835
22963
  if (parent.type === "Decorator" && parent.expression === node) {
@@ -22881,9 +23009,11 @@ function needsParens(path, options) {
22881
23009
  case "CallExpression":
22882
23010
  {
22883
23011
  var firstParentNotMemberExpression = parent;
22884
- var i = 0;
23012
+ var i = 0; // tagged templates are basically member expressions from a grammar perspective
23013
+ // see https://tc39.github.io/ecma262/#prod-MemberExpression
23014
+ // so are typescript's non-null assertions, though there's no grammar to point to
22885
23015
 
22886
- while (firstParentNotMemberExpression && firstParentNotMemberExpression.type === "MemberExpression") {
23016
+ while (firstParentNotMemberExpression && (firstParentNotMemberExpression.type === "MemberExpression" && firstParentNotMemberExpression.object === path.getParentNode(i - 1) || firstParentNotMemberExpression.type === "TaggedTemplateExpression" || firstParentNotMemberExpression.type === "TSNonNullExpression")) {
22887
23017
  firstParentNotMemberExpression = path.getParentNode(++i);
22888
23018
  }
22889
23019
 
@@ -22987,6 +23117,7 @@ function needsParens(path, options) {
22987
23117
  case "TSTypeAssertion":
22988
23118
  case "TaggedTemplateExpression":
22989
23119
  case "UnaryExpression":
23120
+ case "JSXSpreadAttribute":
22990
23121
  case "SpreadElement":
22991
23122
  case "SpreadProperty":
22992
23123
  case "BindExpression":
@@ -23066,7 +23197,7 @@ function needsParens(path, options) {
23066
23197
  } // Delegate to inner TSParenthesizedType
23067
23198
 
23068
23199
 
23069
- if (node.typeAnnotation.type === "TSParenthesizedType") {
23200
+ if (node.typeAnnotation.type === "TSParenthesizedType" && parent.type !== "TSArrayType") {
23070
23201
  return false;
23071
23202
  }
23072
23203
 
@@ -23117,6 +23248,7 @@ function needsParens(path, options) {
23117
23248
  case "TSAsExpression":
23118
23249
  case "TSNonNullExpression":
23119
23250
  case "BindExpression":
23251
+ case "OptionalMemberExpression":
23120
23252
  return true;
23121
23253
 
23122
23254
  case "MemberExpression":
@@ -23239,9 +23371,6 @@ function needsParens(path, options) {
23239
23371
  return true;
23240
23372
  // This is basically a kind of IIFE.
23241
23373
 
23242
- case "ExportDefaultDeclaration":
23243
- return true;
23244
-
23245
23374
  default:
23246
23375
  return false;
23247
23376
  }
@@ -23276,9 +23405,6 @@ function needsParens(path, options) {
23276
23405
 
23277
23406
  case "ClassExpression":
23278
23407
  switch (parent.type) {
23279
- case "ExportDefaultDeclaration":
23280
- return true;
23281
-
23282
23408
  case "NewExpression":
23283
23409
  return name === "callee" && parent.callee === node;
23284
23410
 
@@ -23309,7 +23435,7 @@ function needsParens(path, options) {
23309
23435
  return false;
23310
23436
 
23311
23437
  case "BindExpression":
23312
- if (parent.type === "BindExpression" && name === "callee" && parent.callee === node || parent.type === "MemberExpression") {
23438
+ if (parent.type === "BindExpression" && name === "callee" && parent.callee === node || parent.type === "MemberExpression" && name === "object" && parent.object === node || parent.type === "NewExpression" && name === "callee" && parent.callee === node) {
23313
23439
  return true;
23314
23440
  }
23315
23441
 
@@ -23391,6 +23517,26 @@ function isFollowedByRightBracket(path) {
23391
23517
  return false;
23392
23518
  }
23393
23519
 
23520
+ function shouldWrapFunctionForExportDefault(path, options) {
23521
+ var node = path.getValue();
23522
+ var parent = path.getParentNode();
23523
+
23524
+ if (node.type === "FunctionExpression" || node.type === "ClassExpression") {
23525
+ return parent.type === "ExportDefaultDeclaration" || // in some cases the function is already wrapped
23526
+ // (e.g. `export default (function() {})();`)
23527
+ // in this case we don't need to add extra parens
23528
+ !needsParens(path, options);
23529
+ }
23530
+
23531
+ if (!hasNakedLeftSide$1(node) || parent.type !== "ExportDefaultDeclaration" && needsParens(path, options)) {
23532
+ return false;
23533
+ }
23534
+
23535
+ return path.call.apply(path, [function (childPath) {
23536
+ return shouldWrapFunctionForExportDefault(childPath, options);
23537
+ }].concat(getLeftSidePathName$1(path, node)));
23538
+ }
23539
+
23394
23540
  var needsParens_1 = needsParens;
23395
23541
 
23396
23542
  var _require$$0$builders$6 = doc.builders;
@@ -23496,6 +23642,9 @@ var isIdentifierName = utils$2.keyword.isIdentifierNameES5;
23496
23642
  var insertPragma$7 = pragma$2.insertPragma;
23497
23643
  var printHtmlBinding = htmlBinding.printHtmlBinding;
23498
23644
  var isVueEventBindingExpression$2 = htmlBinding.isVueEventBindingExpression;
23645
+ var getLeftSide = utils$8.getLeftSide;
23646
+ var getLeftSidePathName = utils$8.getLeftSidePathName;
23647
+ var hasNakedLeftSide = utils$8.hasNakedLeftSide;
23499
23648
  var hasNode = utils$8.hasNode;
23500
23649
  var hasFlowAnnotationComment = utils$8.hasFlowAnnotationComment;
23501
23650
  var hasFlowShorthandAnnotationComment = utils$8.hasFlowShorthandAnnotationComment;
@@ -25070,85 +25219,23 @@ function printPathNoParens(path, options, print, args) {
25070
25219
  var expressions = path.map(print, "expressions");
25071
25220
 
25072
25221
  var _parentNode = path.getParentNode();
25073
- /**
25074
- * describe.each`table`(name, fn)
25075
- * describe.only.each`table`(name, fn)
25076
- * describe.skip.each`table`(name, fn)
25077
- * test.each`table`(name, fn)
25078
- * test.only.each`table`(name, fn)
25079
- * test.skip.each`table`(name, fn)
25080
- *
25081
- * Ref: https://github.com/facebook/jest/pull/6102
25082
- */
25083
25222
 
25223
+ if (isJestEachTemplateLiteral(n, _parentNode)) {
25224
+ var _printed2 = printJestEachTemplateLiteral(n, expressions, options);
25084
25225
 
25085
- var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
25226
+ if (_printed2) {
25227
+ return _printed2;
25228
+ }
25229
+ }
25086
25230
 
25087
- if (_parentNode.type === "TaggedTemplateExpression" && _parentNode.quasi === n && _parentNode.tag.type === "MemberExpression" && _parentNode.tag.property.type === "Identifier" && _parentNode.tag.property.name === "each" && (_parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.name) || _parentNode.tag.object.type === "MemberExpression" && _parentNode.tag.object.property.type === "Identifier" && (_parentNode.tag.object.property.name === "only" || _parentNode.tag.object.property.name === "skip") && _parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.object.name))) {
25088
- /**
25089
- * a | b | expected
25090
- * ${1} | ${1} | ${2}
25091
- * ${1} | ${2} | ${3}
25092
- * ${2} | ${1} | ${3}
25093
- */
25094
- var headerNames = n.quasis[0].value.raw.trim().split(/\s*\|\s*/);
25231
+ var isSimple = isSimpleTemplateLiteral(n);
25095
25232
 
25096
- if (headerNames.length > 1 || headerNames.some(function (headerName) {
25097
- return headerName.length !== 0;
25098
- })) {
25099
- var stringifiedExpressions = expressions.map(function (doc$$2) {
25100
- return "${" + printDocToString$1(doc$$2, Object.assign({}, options, {
25101
- printWidth: Infinity,
25102
- endOfLine: "lf"
25103
- })).formatted + "}";
25104
- });
25105
- var tableBody = [{
25106
- hasLineBreak: false,
25107
- cells: []
25108
- }];
25109
-
25110
- for (var _i = 1; _i < n.quasis.length; _i++) {
25111
- var row = tableBody[tableBody.length - 1];
25112
- var correspondingExpression = stringifiedExpressions[_i - 1];
25113
- row.cells.push(correspondingExpression);
25114
-
25115
- if (correspondingExpression.indexOf("\n") !== -1) {
25116
- row.hasLineBreak = true;
25117
- }
25118
-
25119
- if (n.quasis[_i].value.raw.indexOf("\n") !== -1) {
25120
- tableBody.push({
25121
- hasLineBreak: false,
25122
- cells: []
25123
- });
25124
- }
25125
- }
25126
-
25127
- var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
25128
- return Math.max(maxColumnCount, row.cells.length);
25129
- }, headerNames.length);
25130
- var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
25131
- return 0;
25132
- });
25133
- var table = [{
25134
- cells: headerNames
25135
- }].concat(tableBody.filter(function (row) {
25136
- return row.cells.length !== 0;
25137
- }));
25138
- table.filter(function (row) {
25139
- return !row.hasLineBreak;
25140
- }).forEach(function (row) {
25141
- row.cells.forEach(function (cell, index) {
25142
- maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$2(cell));
25143
- });
25144
- });
25145
- parts.push("`", indent$6(concat$11([hardline$8, join$7(hardline$8, table.map(function (row) {
25146
- return join$7(" | ", row.cells.map(function (cell, index) {
25147
- return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$2(cell));
25148
- }));
25149
- }))])), hardline$8, "`");
25150
- return concat$11(parts);
25151
- }
25233
+ if (isSimple) {
25234
+ expressions = expressions.map(function (doc$$2) {
25235
+ return printDocToString$1(doc$$2, Object.assign({}, options, {
25236
+ printWidth: Infinity
25237
+ })).formatted;
25238
+ });
25152
25239
  }
25153
25240
 
25154
25241
  parts.push("`");
@@ -25171,13 +25258,17 @@ function printPathNoParens(path, options, print, args) {
25171
25258
  var tabWidth = options.tabWidth;
25172
25259
  var quasi = childPath.getValue();
25173
25260
  var indentSize = getIndentSize$1(quasi.value.raw, tabWidth);
25174
- var _printed2 = expressions[i];
25261
+ var _printed3 = expressions[i];
25175
25262
 
25176
- 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") {
25177
- _printed2 = concat$11([indent$6(concat$11([softline$5, _printed2])), softline$5]);
25263
+ if (!isSimple) {
25264
+ // Breaks at the template element boundaries (${ and }) are preferred to breaking
25265
+ // in the middle of a MemberExpression
25266
+ 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") {
25267
+ _printed3 = concat$11([indent$6(concat$11([softline$5, _printed3])), softline$5]);
25268
+ }
25178
25269
  }
25179
25270
 
25180
- var aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$1(-Infinity, _printed2) : addAlignmentToDoc$2(_printed2, indentSize, tabWidth);
25271
+ var aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$1(-Infinity, _printed3) : addAlignmentToDoc$2(_printed3, indentSize, tabWidth);
25181
25272
  parts.push(group$10(concat$11(["${", aligned, lineSuffixBoundary$1, "}"])));
25182
25273
  }
25183
25274
  }, "quasis");
@@ -25224,8 +25315,7 @@ function printPathNoParens(path, options, print, args) {
25224
25315
  case "TupleTypeAnnotation":
25225
25316
  {
25226
25317
  var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
25227
- return group$10(concat$11(["[", indent$6(concat$11([softline$5, printArrayItems(path, options, typesField, print)])), // TypeScript doesn't support trailing commas in tuple types
25228
- n.type === "TSTupleType" ? "" : ifBreak$6(shouldPrintComma$1(options) ? "," : ""), comments.printDanglingComments(path, options,
25318
+ return group$10(concat$11(["[", indent$6(concat$11([softline$5, printArrayItems(path, options, typesField, print)])), ifBreak$6(shouldPrintComma$1(options, "all") ? "," : ""), comments.printDanglingComments(path, options,
25229
25319
  /* sameIndent */
25230
25320
  true), softline$5, "]"]));
25231
25321
  }
@@ -25393,22 +25483,22 @@ function printPathNoParens(path, options, print, args) {
25393
25483
  var result = [];
25394
25484
  var wasIndented = false;
25395
25485
 
25396
- for (var _i2 = 0; _i2 < types.length; ++_i2) {
25397
- if (_i2 === 0) {
25398
- result.push(types[_i2]);
25399
- } else if (isObjectType(n.types[_i2 - 1]) && isObjectType(n.types[_i2])) {
25486
+ for (var _i = 0; _i < types.length; ++_i) {
25487
+ if (_i === 0) {
25488
+ result.push(types[_i]);
25489
+ } else if (isObjectType(n.types[_i - 1]) && isObjectType(n.types[_i])) {
25400
25490
  // If both are objects, don't indent
25401
- result.push(concat$11([" & ", wasIndented ? indent$6(types[_i2]) : types[_i2]]));
25402
- } else if (!isObjectType(n.types[_i2 - 1]) && !isObjectType(n.types[_i2])) {
25491
+ result.push(concat$11([" & ", wasIndented ? indent$6(types[_i]) : types[_i]]));
25492
+ } else if (!isObjectType(n.types[_i - 1]) && !isObjectType(n.types[_i])) {
25403
25493
  // If no object is involved, go to the next line if it breaks
25404
- result.push(indent$6(concat$11([" &", line$8, types[_i2]])));
25494
+ result.push(indent$6(concat$11([" &", line$8, types[_i]])));
25405
25495
  } else {
25406
25496
  // If you go from object to non-object or vis-versa, then inline it
25407
- if (_i2 > 1) {
25497
+ if (_i > 1) {
25408
25498
  wasIndented = true;
25409
25499
  }
25410
25500
 
25411
- result.push(" & ", _i2 > 1 ? indent$6(types[_i2]) : types[_i2]);
25501
+ result.push(" & ", _i > 1 ? indent$6(types[_i]) : types[_i]);
25412
25502
  }
25413
25503
  }
25414
25504
 
@@ -25437,7 +25527,7 @@ function printPathNoParens(path, options, print, args) {
25437
25527
  // // comment
25438
25528
  // | child2
25439
25529
 
25440
- var _printed3 = path.map(function (typePath) {
25530
+ var _printed4 = path.map(function (typePath) {
25441
25531
  var printedType = typePath.call(print);
25442
25532
 
25443
25533
  if (!shouldHug) {
@@ -25450,11 +25540,11 @@ function printPathNoParens(path, options, print, args) {
25450
25540
  }, "types");
25451
25541
 
25452
25542
  if (shouldHug) {
25453
- return join$7(" | ", _printed3);
25543
+ return join$7(" | ", _printed4);
25454
25544
  }
25455
25545
 
25456
25546
  var shouldAddStartLine = shouldIndent && !hasLeadingOwnLineComment(options.originalText, n, options);
25457
- var code = concat$11([ifBreak$6(concat$11([shouldAddStartLine ? line$8 : "", "| "])), join$7(concat$11([line$8, "| "]), _printed3)]);
25547
+ var code = concat$11([ifBreak$6(concat$11([shouldAddStartLine ? line$8 : "", "| "])), join$7(concat$11([line$8, "| "]), _printed4)]);
25458
25548
  var hasParens;
25459
25549
 
25460
25550
  if (n.type === "TSUnionType") {
@@ -25540,9 +25630,9 @@ function printPathNoParens(path, options, print, args) {
25540
25630
  parts.push("declare ");
25541
25631
  }
25542
25632
 
25543
- var _printed4 = printAssignmentRight(n.id, n.right, path.call(print, "right"), options);
25633
+ var _printed5 = printAssignmentRight(n.id, n.right, path.call(print, "right"), options);
25544
25634
 
25545
- parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", _printed4, semi);
25635
+ parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", _printed5, semi);
25546
25636
  return group$10(concat$11(parts));
25547
25637
  }
25548
25638
 
@@ -25619,6 +25709,15 @@ function printPathNoParens(path, options, print, args) {
25619
25709
 
25620
25710
  if (n["default"]) {
25621
25711
  parts.push(" = ", path.call(print, "default"));
25712
+ } // Keep comma if the file extension is .tsx and
25713
+ // has one type parameter that isn't extend with any types.
25714
+ // Because, otherwise formatted result will be invalid as tsx.
25715
+
25716
+
25717
+ var _grandParent = path.getNode(2);
25718
+
25719
+ if (_parent9.params && _parent9.params.length === 1 && options.filepath && /\.tsx$/i.test(options.filepath) && !n.constraint && _grandParent.type === "ArrowFunctionExpression") {
25720
+ parts.push(",");
25622
25721
  }
25623
25722
 
25624
25723
  return concat$11(parts);
@@ -25833,9 +25932,15 @@ function printPathNoParens(path, options, print, args) {
25833
25932
  return concat$11([n.operator, " ", path.call(print, "typeAnnotation")]);
25834
25933
 
25835
25934
  case "TSMappedType":
25836
- return group$10(concat$11(["{", indent$6(concat$11([options.bracketSpacing ? line$8 : softline$5, n.readonly ? concat$11([getTypeScriptMappedTypeModifier(n.readonly, "readonly"), " "]) : "", printTypeScriptModifiers(path, options, print), path.call(print, "typeParameter"), n.optional ? getTypeScriptMappedTypeModifier(n.optional, "?") : "", ": ", path.call(print, "typeAnnotation")])), comments.printDanglingComments(path, options,
25837
- /* sameIndent */
25838
- true), options.bracketSpacing ? line$8 : softline$5, "}"]));
25935
+ {
25936
+ var _shouldBreak2 = hasNewlineInRange$1(options.originalText, options.locStart(n), options.locEnd(n));
25937
+
25938
+ return group$10(concat$11(["{", indent$6(concat$11([options.bracketSpacing ? line$8 : softline$5, n.readonly ? concat$11([getTypeScriptMappedTypeModifier(n.readonly, "readonly"), " "]) : "", printTypeScriptModifiers(path, options, print), path.call(print, "typeParameter"), n.optional ? getTypeScriptMappedTypeModifier(n.optional, "?") : "", ": ", path.call(print, "typeAnnotation"), _shouldBreak2 && options.semi ? ";" : ""])), comments.printDanglingComments(path, options,
25939
+ /* sameIndent */
25940
+ true), options.bracketSpacing ? line$8 : softline$5, "}"]), {
25941
+ shouldBreak: _shouldBreak2
25942
+ });
25943
+ }
25839
25944
 
25840
25945
  case "TSMethodSignature":
25841
25946
  parts.push(n.accessibility ? concat$11([n.accessibility, " "]) : "", n.export ? "export " : "", n.static ? "static " : "", n.readonly ? "readonly " : "", n.computed ? "[" : "", path.call(print, "key"), n.computed ? "]" : "", printOptionalToken(path), printFunctionParams(path, print, options,
@@ -26113,7 +26218,7 @@ function printPropertyKey(path, options, print) {
26113
26218
 
26114
26219
  if (options.quoteProps === "consistent" && !needsQuoteProps.has(parent)) {
26115
26220
  var objectHasStringProp = (parent.properties || parent.body || parent.members).some(function (prop) {
26116
- return prop.key && prop.key.type !== "Identifier" && !isStringPropSafeToCoerceToIdentifier(prop, options);
26221
+ return !prop.computed && prop.key && isStringLiteral(prop.key) && !isStringPropSafeToCoerceToIdentifier(prop, options);
26117
26222
  });
26118
26223
  needsQuoteProps.set(parent, objectHasStringProp);
26119
26224
  }
@@ -26128,7 +26233,7 @@ function printPropertyKey(path, options, print) {
26128
26233
  }, "key");
26129
26234
  }
26130
26235
 
26131
- if (isStringPropSafeToCoerceToIdentifier(node, options) && (options.quoteProps === "as-needed" || options.quoteProps === "consistent" && !needsQuoteProps.get(parent))) {
26236
+ if (!node.computed && isStringPropSafeToCoerceToIdentifier(node, options) && (options.quoteProps === "as-needed" || options.quoteProps === "consistent" && !needsQuoteProps.get(parent))) {
26132
26237
  // 'a' -> a
26133
26238
  return path.call(function (keyPath) {
26134
26239
  return comments.printComments(keyPath, function () {
@@ -26183,7 +26288,18 @@ function printMethod(path, options, print) {
26183
26288
  }
26184
26289
 
26185
26290
  function couldGroupArg(arg) {
26186
- return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertion" || arg.type === "TSAsExpression" || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && !arg.returnType && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode(arg.body));
26291
+ return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertion" || arg.type === "TSAsExpression" || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && ( // we want to avoid breaking inside composite return types but not simple keywords
26292
+ // https://github.com/prettier/prettier/issues/4070
26293
+ // export class Thing implements OtherThing {
26294
+ // do: (type: Type) => Provider<Prop> = memoize(
26295
+ // (type: ObjectType): Provider<Opts> => {}
26296
+ // );
26297
+ // }
26298
+ // https://github.com/prettier/prettier/issues/6099
26299
+ // app.get("/", (req, res): void => {
26300
+ // res.send("Hello World!");
26301
+ // });
26302
+ !arg.returnType || !arg.returnType.typeAnnotation || arg.returnType.typeAnnotation.type !== "TSTypeReference") && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode(arg.body));
26187
26303
  }
26188
26304
 
26189
26305
  function shouldGroupLastArg(args) {
@@ -26209,6 +26325,130 @@ function isSimpleFlowType(node) {
26209
26325
  return node && flowTypeAnnotations.indexOf(node.type) !== -1 && !(node.type === "GenericTypeAnnotation" && node.typeParameters);
26210
26326
  }
26211
26327
 
26328
+ function isJestEachTemplateLiteral(node, parentNode) {
26329
+ /**
26330
+ * describe.each`table`(name, fn)
26331
+ * describe.only.each`table`(name, fn)
26332
+ * describe.skip.each`table`(name, fn)
26333
+ * test.each`table`(name, fn)
26334
+ * test.only.each`table`(name, fn)
26335
+ * test.skip.each`table`(name, fn)
26336
+ *
26337
+ * Ref: https://github.com/facebook/jest/pull/6102
26338
+ */
26339
+ var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
26340
+ return parentNode.type === "TaggedTemplateExpression" && parentNode.quasi === node && parentNode.tag.type === "MemberExpression" && parentNode.tag.property.type === "Identifier" && parentNode.tag.property.name === "each" && (parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.name) || parentNode.tag.object.type === "MemberExpression" && parentNode.tag.object.property.type === "Identifier" && (parentNode.tag.object.property.name === "only" || parentNode.tag.object.property.name === "skip") && parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.object.name));
26341
+ }
26342
+
26343
+ function printJestEachTemplateLiteral(node, expressions, options) {
26344
+ /**
26345
+ * a | b | expected
26346
+ * ${1} | ${1} | ${2}
26347
+ * ${1} | ${2} | ${3}
26348
+ * ${2} | ${1} | ${3}
26349
+ */
26350
+ var headerNames = node.quasis[0].value.raw.trim().split(/\s*\|\s*/);
26351
+
26352
+ if (headerNames.length > 1 || headerNames.some(function (headerName) {
26353
+ return headerName.length !== 0;
26354
+ })) {
26355
+ var parts = [];
26356
+ var stringifiedExpressions = expressions.map(function (doc$$2) {
26357
+ return "${" + printDocToString$1(doc$$2, Object.assign({}, options, {
26358
+ printWidth: Infinity,
26359
+ endOfLine: "lf"
26360
+ })).formatted + "}";
26361
+ });
26362
+ var tableBody = [{
26363
+ hasLineBreak: false,
26364
+ cells: []
26365
+ }];
26366
+
26367
+ for (var i = 1; i < node.quasis.length; i++) {
26368
+ var row = tableBody[tableBody.length - 1];
26369
+ var correspondingExpression = stringifiedExpressions[i - 1];
26370
+ row.cells.push(correspondingExpression);
26371
+
26372
+ if (correspondingExpression.indexOf("\n") !== -1) {
26373
+ row.hasLineBreak = true;
26374
+ }
26375
+
26376
+ if (node.quasis[i].value.raw.indexOf("\n") !== -1) {
26377
+ tableBody.push({
26378
+ hasLineBreak: false,
26379
+ cells: []
26380
+ });
26381
+ }
26382
+ }
26383
+
26384
+ var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
26385
+ return Math.max(maxColumnCount, row.cells.length);
26386
+ }, headerNames.length);
26387
+ var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
26388
+ return 0;
26389
+ });
26390
+ var table = [{
26391
+ cells: headerNames
26392
+ }].concat(tableBody.filter(function (row) {
26393
+ return row.cells.length !== 0;
26394
+ }));
26395
+ table.filter(function (row) {
26396
+ return !row.hasLineBreak;
26397
+ }).forEach(function (row) {
26398
+ row.cells.forEach(function (cell, index) {
26399
+ maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$2(cell));
26400
+ });
26401
+ });
26402
+ parts.push("`", indent$6(concat$11([hardline$8, join$7(hardline$8, table.map(function (row) {
26403
+ return join$7(" | ", row.cells.map(function (cell, index) {
26404
+ return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$2(cell));
26405
+ }));
26406
+ }))])), hardline$8, "`");
26407
+ return concat$11(parts);
26408
+ }
26409
+ }
26410
+ /** @param node {import("estree").TemplateLiteral} */
26411
+
26412
+
26413
+ function isSimpleTemplateLiteral(node) {
26414
+ if (node.expressions.length === 0) {
26415
+ return false;
26416
+ }
26417
+
26418
+ return node.expressions.every(function (expr) {
26419
+ // Disallow comments since printDocToString can't print them here
26420
+ if (expr.comments) {
26421
+ return false;
26422
+ } // Allow `x` and `this`
26423
+
26424
+
26425
+ if (expr.type === "Identifier" || expr.type === "ThisExpression") {
26426
+ return true;
26427
+ } // Allow `a.b.c`, `a.b[c]`, and `this.x.y`
26428
+
26429
+
26430
+ if ((expr.type === "MemberExpression" || expr.type === "OptionalMemberExpression") && (expr.property.type === "Identifier" || expr.property.type === "Literal")) {
26431
+ var ancestor = expr;
26432
+
26433
+ while (ancestor.type === "MemberExpression" || ancestor.type === "OptionalMemberExpression") {
26434
+ ancestor = ancestor.object;
26435
+
26436
+ if (ancestor.comments) {
26437
+ return false;
26438
+ }
26439
+ }
26440
+
26441
+ if (ancestor.type === "Identifier" || ancestor.type === "ThisExpression") {
26442
+ return true;
26443
+ }
26444
+
26445
+ return false;
26446
+ }
26447
+
26448
+ return false;
26449
+ });
26450
+ }
26451
+
26212
26452
  var functionCompositionFunctionNames = new Set(["pipe", // RxJS, Ramda
26213
26453
  "pipeP", // Ramda
26214
26454
  "pipeK", // Ramda
@@ -27344,11 +27584,10 @@ function printJSXChildren(path, options, print, jsxWhitespace, isFacebookTransla
27344
27584
 
27345
27585
 
27346
27586
  function printJSXElement(path, options, print) {
27347
- var n = path.getValue(); // Turn <div></div> into <div />
27587
+ var n = path.getValue();
27348
27588
 
27349
27589
  if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
27350
- n.openingElement.selfClosing = true;
27351
- return path.call(print, "openingElement");
27590
+ return concat$11([path.call(print, "openingElement"), path.call(print, "closingElement")]);
27352
27591
  }
27353
27592
 
27354
27593
  var openingLines = n.type === "JSXElement" ? path.call(print, "openingElement") : path.call(print, "openingFragment");
@@ -27590,7 +27829,7 @@ function printAssignmentRight(leftNode, rightNode, printedRight, options) {
27590
27829
  }
27591
27830
 
27592
27831
  var canBreak = isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode) || rightNode.type === "ConditionalExpression" && isBinaryish(rightNode.test) && !shouldInlineLogicalExpression(rightNode.test) || rightNode.type === "StringLiteralTypeAnnotation" || rightNode.type === "ClassExpression" && rightNode.decorators && rightNode.decorators.length || (leftNode.type === "Identifier" || isStringLiteral(leftNode) || leftNode.type === "MemberExpression") && (isStringLiteral(rightNode) || isMemberExpressionChain(rightNode)) && // do not put values on a separate line from the key in json
27593
- options.parser !== "json" && options.parser !== "json5";
27832
+ options.parser !== "json" && options.parser !== "json5" || rightNode.type === "SequenceExpression";
27594
27833
 
27595
27834
  if (canBreak) {
27596
27835
  return group$10(indent$6(concat$11([line$8, printedRight])));
@@ -27668,60 +27907,12 @@ function hasLeadingOwnLineComment(text, node, options) {
27668
27907
  return res;
27669
27908
  }
27670
27909
 
27671
- function hasNakedLeftSide(node) {
27672
- return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression" || node.type === "ConditionalExpression" || node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || node.type === "UpdateExpression" && !node.prefix || node.type === "TSNonNullExpression";
27673
- }
27674
-
27675
27910
  function isFlowAnnotationComment(text, typeAnnotation, options) {
27676
27911
  var start = options.locStart(typeAnnotation);
27677
27912
  var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
27678
27913
  return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
27679
27914
  }
27680
27915
 
27681
- function getLeftSide(node) {
27682
- if (node.expressions) {
27683
- return node.expressions[0];
27684
- }
27685
-
27686
- return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
27687
- }
27688
-
27689
- function getLeftSidePathName(path, node) {
27690
- if (node.expressions) {
27691
- return ["expressions", 0];
27692
- }
27693
-
27694
- if (node.left) {
27695
- return ["left"];
27696
- }
27697
-
27698
- if (node.test) {
27699
- return ["test"];
27700
- }
27701
-
27702
- if (node.object) {
27703
- return ["object"];
27704
- }
27705
-
27706
- if (node.callee) {
27707
- return ["callee"];
27708
- }
27709
-
27710
- if (node.tag) {
27711
- return ["tag"];
27712
- }
27713
-
27714
- if (node.argument) {
27715
- return ["argument"];
27716
- }
27717
-
27718
- if (node.expression) {
27719
- return ["expression"];
27720
- }
27721
-
27722
- throw new Error("Unexpected node has no left side", node);
27723
- }
27724
-
27725
27916
  function exprNeedsASIProtection(path, options) {
27726
27917
  var node = path.getValue();
27727
27918
  var maybeASIProblem = needsParens_1(path, options) || node.type === "ParenthesizedExpression" || node.type === "TypeCastExpression" || node.type === "ArrowFunctionExpression" && !shouldPrintParamsWithoutParens(path, options) || node.type === "ArrayExpression" || node.type === "ArrayPattern" || node.type === "UnaryExpression" && node.prefix && (node.operator === "+" || node.operator === "-") || node.type === "TemplateLiteral" || node.type === "TemplateElement" || isJSXNode(node) || node.type === "BindExpression" && !node.object || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
@@ -27964,7 +28155,7 @@ function isLiteral(node) {
27964
28155
  }
27965
28156
 
27966
28157
  function isStringPropSafeToCoerceToIdentifier(node, options) {
27967
- return isStringLiteral(node.key) && isIdentifierName(node.key.value) && !node.computed && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty");
28158
+ return isStringLiteral(node.key) && isIdentifierName(node.key.value) && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty");
27968
28159
  }
27969
28160
 
27970
28161
  function isNumericLiteral(node) {
@@ -28050,7 +28241,9 @@ function isTheOnlyJSXElementInMarkdown(options, path) {
28050
28241
  return parent.type === "Program" && parent.body.length == 1;
28051
28242
  }
28052
28243
 
28053
- function willPrintOwnComments(path) {
28244
+ function willPrintOwnComments(path
28245
+ /*, options */
28246
+ ) {
28054
28247
  var node = path.getValue();
28055
28248
  var parent = path.getParentNode();
28056
28249
  return (node && (isJSXNode(node) || hasFlowShorthandAnnotationComment(node) || parent && parent.type === "CallExpression" && (hasFlowAnnotationComment(node.leadingComments) || hasFlowAnnotationComment(node.trailingComments))) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && !hasIgnoreComment$3(path);
@@ -29248,9 +29441,9 @@ function genericPrint$5(path, options, print) {
29248
29441
 
29249
29442
  case "inlineCode":
29250
29443
  {
29251
- var backtickCount = util.getMaxContinuousCount(node.value, "`");
29444
+ var backtickCount = util.getMinNotPresentContinuousCount(node.value, "`");
29252
29445
 
29253
- var _style = backtickCount === 1 ? "``" : "`";
29446
+ var _style = "`".repeat(backtickCount || 1);
29254
29447
 
29255
29448
  var gap = backtickCount ? " " : "";
29256
29449
  return concat$15([_style, gap, node.value, gap, _style]);