typescript 4.8.0-dev.20220722 → 4.8.0-dev.20220723

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/lib/tsc.js CHANGED
@@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  var ts;
70
70
  (function (ts) {
71
71
  ts.versionMajorMinor = "4.8";
72
- ts.version = ts.versionMajorMinor + ".0-dev.20220722";
72
+ ts.version = ts.versionMajorMinor + ".0-dev.20220723";
73
73
  var NativeCollections;
74
74
  (function (NativeCollections) {
75
75
  var globals = typeof globalThis !== "undefined" ? globalThis :
@@ -4317,8 +4317,10 @@ var ts;
4317
4317
  watchPresentFileSystemEntry();
4318
4318
  return {
4319
4319
  close: function () {
4320
- watcher.close();
4321
- watcher = undefined;
4320
+ if (watcher) {
4321
+ watcher.close();
4322
+ watcher = undefined;
4323
+ }
4322
4324
  }
4323
4325
  };
4324
4326
  function updateWatcher(createWatcher) {
@@ -66741,7 +66743,11 @@ var ts;
66741
66743
  var operator = operatorToken.kind;
66742
66744
  if (operator === 55 || operator === 56 || operator === 60) {
66743
66745
  if (operator === 55) {
66744
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
66746
+ var parent = node.parent;
66747
+ while (parent.kind === 212
66748
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 || parent.operatorToken.kind === 56)) {
66749
+ parent = parent.parent;
66750
+ }
66745
66751
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
66746
66752
  }
66747
66753
  checkTruthinessOfType(leftType, node.left);
@@ -76304,13 +76310,13 @@ var ts;
76304
76310
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
76305
76311
  case 200:
76306
76312
  ts.Debug.type(node);
76307
- return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), visitNodes(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
76313
+ return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
76308
76314
  case 295:
76309
76315
  ts.Debug.type(node);
76310
76316
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
76311
76317
  case 197:
76312
76318
  ts.Debug.type(node);
76313
- return factory.updateNamedTupleMember(node, visitNode(node.dotDotDotToken, visitor, ts.isDotDotDotToken), visitNode(node.name, visitor, ts.isIdentifier), visitNode(node.questionToken, visitor, ts.isQuestionToken), visitNode(node.type, visitor, ts.isTypeNode));
76319
+ return factory.updateNamedTupleMember(node, nodeVisitor(node.dotDotDotToken, visitor, ts.isDotDotDotToken), nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.questionToken, visitor, ts.isQuestionToken), nodeVisitor(node.type, visitor, ts.isTypeNode));
76314
76320
  case 191:
76315
76321
  ts.Debug.type(node);
76316
76322
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -76373,7 +76379,7 @@ var ts;
76373
76379
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
76374
76380
  case 210:
76375
76381
  ts.Debug.type(node);
76376
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
76382
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
76377
76383
  case 211:
76378
76384
  ts.Debug.type(node);
76379
76385
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
package/lib/tsserver.js CHANGED
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220722";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220723";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -6857,8 +6857,10 @@ var ts;
6857
6857
  return {
6858
6858
  close: function () {
6859
6859
  // Close the watcher (either existing file system entry watcher or missing file system entry watcher)
6860
- watcher.close();
6861
- watcher = undefined;
6860
+ if (watcher) {
6861
+ watcher.close();
6862
+ watcher = undefined;
6863
+ }
6862
6864
  }
6863
6865
  };
6864
6866
  function updateWatcher(createWatcher) {
@@ -79638,7 +79640,11 @@ var ts;
79638
79640
  var operator = operatorToken.kind;
79639
79641
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79640
79642
  if (operator === 55 /* AmpersandAmpersandToken */) {
79641
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79643
+ var parent = node.parent;
79644
+ while (parent.kind === 212 /* ParenthesizedExpression */
79645
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79646
+ parent = parent.parent;
79647
+ }
79642
79648
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79643
79649
  }
79644
79650
  checkTruthinessOfType(leftType, node.left);
@@ -90560,13 +90566,13 @@ var ts;
90560
90566
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90561
90567
  case 200 /* ImportType */:
90562
90568
  ts.Debug.type(node);
90563
- return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), visitNodes(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90569
+ return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90564
90570
  case 295 /* ImportTypeAssertionContainer */:
90565
90571
  ts.Debug.type(node);
90566
90572
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90567
90573
  case 197 /* NamedTupleMember */:
90568
90574
  ts.Debug.type(node);
90569
- return factory.updateNamedTupleMember(node, visitNode(node.dotDotDotToken, visitor, ts.isDotDotDotToken), visitNode(node.name, visitor, ts.isIdentifier), visitNode(node.questionToken, visitor, ts.isQuestionToken), visitNode(node.type, visitor, ts.isTypeNode));
90575
+ return factory.updateNamedTupleMember(node, nodeVisitor(node.dotDotDotToken, visitor, ts.isDotDotDotToken), nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.questionToken, visitor, ts.isQuestionToken), nodeVisitor(node.type, visitor, ts.isTypeNode));
90570
90576
  case 191 /* ParenthesizedType */:
90571
90577
  ts.Debug.type(node);
90572
90578
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90631,7 +90637,7 @@ var ts;
90631
90637
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90632
90638
  case 210 /* TaggedTemplateExpression */:
90633
90639
  ts.Debug.type(node);
90634
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90640
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90635
90641
  case 211 /* TypeAssertionExpression */:
90636
90642
  ts.Debug.type(node);
90637
90643
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
@@ -148845,6 +148851,7 @@ var ts;
148845
148851
  consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
148846
148852
  }
148847
148853
  function processChildNode(child, inheritedIndentation, parent, parentDynamicIndentation, parentStartLine, undecoratedParentStartLine, isListItem, isFirstListItem) {
148854
+ ts.Debug.assert(!ts.nodeIsSynthesized(child));
148848
148855
  if (ts.nodeIsMissing(child)) {
148849
148856
  return inheritedIndentation;
148850
148857
  }
@@ -148911,6 +148918,7 @@ var ts;
148911
148918
  }
148912
148919
  function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) {
148913
148920
  ts.Debug.assert(ts.isNodeArray(nodes));
148921
+ ts.Debug.assert(!ts.nodeIsSynthesized(nodes));
148914
148922
  var listStartToken = getOpenTokenForList(parent, nodes);
148915
148923
  var listDynamicIndentation = parentDynamicIndentation;
148916
148924
  var startLine = parentStartLine;
@@ -155370,54 +155378,91 @@ var ts;
155370
155378
  codefix.registerCodeFix({
155371
155379
  errorCodes: errorCodes,
155372
155380
  getCodeActions: function (context) {
155373
- var sourceFile = context.sourceFile, span = context.span, program = context.program;
155374
- var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155375
- if (!related) {
155381
+ var sourceFile = context.sourceFile, span = context.span, program = context.program, preferences = context.preferences, host = context.host;
155382
+ var info = getInfo(program, sourceFile, span);
155383
+ if (info === undefined)
155376
155384
  return;
155377
- }
155378
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155385
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, program, preferences, host, sourceFile, info); });
155379
155386
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155380
155387
  },
155381
155388
  fixIds: [fixId],
155382
- getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155383
- var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155384
- if (!info)
155385
- return;
155386
- return addMissingConstraint(changes, info);
155387
- }); },
155389
+ getAllCodeActions: function (context) {
155390
+ var program = context.program, preferences = context.preferences, host = context.host;
155391
+ var seen = new ts.Map();
155392
+ return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
155393
+ codefix.eachDiagnostic(context, errorCodes, function (diag) {
155394
+ var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
155395
+ if (info) {
155396
+ var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
155397
+ if (ts.addToSeen(seen, id)) {
155398
+ return addMissingConstraint(changes, program, preferences, host, diag.file, info);
155399
+ }
155400
+ }
155401
+ return undefined;
155402
+ });
155403
+ }));
155404
+ }
155388
155405
  });
155389
- function getDiagnosticRelatedInfo(program, sourceFile, span) {
155406
+ function getInfo(program, sourceFile, span) {
155390
155407
  var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155391
- if (!diag || !diag.relatedInformation)
155408
+ if (diag === undefined || diag.relatedInformation === undefined)
155392
155409
  return;
155393
155410
  var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
155394
- if (!related)
155411
+ if (related === undefined || related.file === undefined || related.start === undefined || related.length === undefined)
155395
155412
  return;
155396
- return related;
155397
- }
155398
- function addMissingConstraint(changes, related) {
155399
- var decl = findAncestorMatchingSpan(related.file, related);
155400
- if (!decl)
155413
+ var declaration = findAncestorMatchingSpan(related.file, ts.createTextSpan(related.start, related.length));
155414
+ if (declaration === undefined)
155401
155415
  return;
155402
- if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
155403
- decl = decl.parent;
155416
+ if (ts.isIdentifier(declaration) && ts.isTypeParameterDeclaration(declaration.parent)) {
155417
+ declaration = declaration.parent;
155418
+ }
155419
+ if (ts.isTypeParameterDeclaration(declaration)) {
155420
+ // should only issue fix on type parameters written using `extends`
155421
+ if (ts.isMappedTypeNode(declaration.parent))
155422
+ return;
155423
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
155424
+ var checker = program.getTypeChecker();
155425
+ var constraint = tryGetConstraintType(checker, token) || tryGetConstraintFromDiagnosticMessage(related.messageText);
155426
+ return { constraint: constraint, declaration: declaration, token: token };
155427
+ }
155428
+ return undefined;
155429
+ }
155430
+ function addMissingConstraint(changes, program, preferences, host, sourceFile, info) {
155431
+ var declaration = info.declaration, constraint = info.constraint;
155432
+ var checker = program.getTypeChecker();
155433
+ if (ts.isString(constraint)) {
155434
+ changes.insertText(sourceFile, declaration.name.end, " extends " + constraint);
155435
+ }
155436
+ else {
155437
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
155438
+ var tracker = codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host });
155439
+ var importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
155440
+ var typeNode = codefix.typeToAutoImportableTypeNode(checker, importAdder, constraint, /*contextNode*/ undefined, scriptTarget, /*flags*/ undefined, tracker);
155441
+ if (typeNode) {
155442
+ changes.replaceNode(sourceFile, declaration, ts.factory.updateTypeParameterDeclaration(declaration, /*modifiers*/ undefined, declaration.name, typeNode, declaration.default));
155443
+ importAdder.writeFixes(changes);
155444
+ }
155404
155445
  }
155405
- if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
155406
- return; // should only issue fix on type parameters written using `extends`
155407
- var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
155408
- if (!newConstraint)
155409
- return;
155410
- var newConstraintText = newConstraint[1];
155411
- changes.insertText(related.file, decl.name.end, " extends " + newConstraintText);
155412
155446
  }
155413
155447
  function findAncestorMatchingSpan(sourceFile, span) {
155414
- var token = ts.getTokenAtPosition(sourceFile, span.start);
155415
155448
  var end = ts.textSpanEnd(span);
155449
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
155416
155450
  while (token.end < end) {
155417
155451
  token = token.parent;
155418
155452
  }
155419
155453
  return token;
155420
155454
  }
155455
+ function tryGetConstraintFromDiagnosticMessage(messageText) {
155456
+ var _a = ts.flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [], _ = _a[0], constraint = _a[1];
155457
+ return constraint;
155458
+ }
155459
+ function tryGetConstraintType(checker, node) {
155460
+ if (ts.isTypeNode(node.parent)) {
155461
+ return checker.getTypeArgumentConstraint(node.parent);
155462
+ }
155463
+ var contextualType = ts.isExpression(node) ? checker.getContextualType(node) : undefined;
155464
+ return contextualType || checker.getTypeAtLocation(node);
155465
+ }
155421
155466
  })(codefix = ts.codefix || (ts.codefix = {}));
155422
155467
  })(ts || (ts = {}));
155423
155468
  /* @internal */
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220722";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220723";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -7051,8 +7051,10 @@ var ts;
7051
7051
  return {
7052
7052
  close: function () {
7053
7053
  // Close the watcher (either existing file system entry watcher or missing file system entry watcher)
7054
- watcher.close();
7055
- watcher = undefined;
7054
+ if (watcher) {
7055
+ watcher.close();
7056
+ watcher = undefined;
7057
+ }
7056
7058
  }
7057
7059
  };
7058
7060
  function updateWatcher(createWatcher) {
@@ -79832,7 +79834,11 @@ var ts;
79832
79834
  var operator = operatorToken.kind;
79833
79835
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79834
79836
  if (operator === 55 /* AmpersandAmpersandToken */) {
79835
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79837
+ var parent = node.parent;
79838
+ while (parent.kind === 212 /* ParenthesizedExpression */
79839
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79840
+ parent = parent.parent;
79841
+ }
79836
79842
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79837
79843
  }
79838
79844
  checkTruthinessOfType(leftType, node.left);
@@ -90754,13 +90760,13 @@ var ts;
90754
90760
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90755
90761
  case 200 /* ImportType */:
90756
90762
  ts.Debug.type(node);
90757
- return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), visitNodes(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90763
+ return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90758
90764
  case 295 /* ImportTypeAssertionContainer */:
90759
90765
  ts.Debug.type(node);
90760
90766
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90761
90767
  case 197 /* NamedTupleMember */:
90762
90768
  ts.Debug.type(node);
90763
- return factory.updateNamedTupleMember(node, visitNode(node.dotDotDotToken, visitor, ts.isDotDotDotToken), visitNode(node.name, visitor, ts.isIdentifier), visitNode(node.questionToken, visitor, ts.isQuestionToken), visitNode(node.type, visitor, ts.isTypeNode));
90769
+ return factory.updateNamedTupleMember(node, nodeVisitor(node.dotDotDotToken, visitor, ts.isDotDotDotToken), nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.questionToken, visitor, ts.isQuestionToken), nodeVisitor(node.type, visitor, ts.isTypeNode));
90764
90770
  case 191 /* ParenthesizedType */:
90765
90771
  ts.Debug.type(node);
90766
90772
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90825,7 +90831,7 @@ var ts;
90825
90831
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90826
90832
  case 210 /* TaggedTemplateExpression */:
90827
90833
  ts.Debug.type(node);
90828
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90834
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90829
90835
  case 211 /* TypeAssertionExpression */:
90830
90836
  ts.Debug.type(node);
90831
90837
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
@@ -149458,6 +149464,7 @@ var ts;
149458
149464
  consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
149459
149465
  }
149460
149466
  function processChildNode(child, inheritedIndentation, parent, parentDynamicIndentation, parentStartLine, undecoratedParentStartLine, isListItem, isFirstListItem) {
149467
+ ts.Debug.assert(!ts.nodeIsSynthesized(child));
149461
149468
  if (ts.nodeIsMissing(child)) {
149462
149469
  return inheritedIndentation;
149463
149470
  }
@@ -149524,6 +149531,7 @@ var ts;
149524
149531
  }
149525
149532
  function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) {
149526
149533
  ts.Debug.assert(ts.isNodeArray(nodes));
149534
+ ts.Debug.assert(!ts.nodeIsSynthesized(nodes));
149527
149535
  var listStartToken = getOpenTokenForList(parent, nodes);
149528
149536
  var listDynamicIndentation = parentDynamicIndentation;
149529
149537
  var startLine = parentStartLine;
@@ -155983,54 +155991,91 @@ var ts;
155983
155991
  codefix.registerCodeFix({
155984
155992
  errorCodes: errorCodes,
155985
155993
  getCodeActions: function (context) {
155986
- var sourceFile = context.sourceFile, span = context.span, program = context.program;
155987
- var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155988
- if (!related) {
155994
+ var sourceFile = context.sourceFile, span = context.span, program = context.program, preferences = context.preferences, host = context.host;
155995
+ var info = getInfo(program, sourceFile, span);
155996
+ if (info === undefined)
155989
155997
  return;
155990
- }
155991
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155998
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, program, preferences, host, sourceFile, info); });
155992
155999
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155993
156000
  },
155994
156001
  fixIds: [fixId],
155995
- getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155996
- var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155997
- if (!info)
155998
- return;
155999
- return addMissingConstraint(changes, info);
156000
- }); },
156002
+ getAllCodeActions: function (context) {
156003
+ var program = context.program, preferences = context.preferences, host = context.host;
156004
+ var seen = new ts.Map();
156005
+ return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
156006
+ codefix.eachDiagnostic(context, errorCodes, function (diag) {
156007
+ var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
156008
+ if (info) {
156009
+ var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
156010
+ if (ts.addToSeen(seen, id)) {
156011
+ return addMissingConstraint(changes, program, preferences, host, diag.file, info);
156012
+ }
156013
+ }
156014
+ return undefined;
156015
+ });
156016
+ }));
156017
+ }
156001
156018
  });
156002
- function getDiagnosticRelatedInfo(program, sourceFile, span) {
156019
+ function getInfo(program, sourceFile, span) {
156003
156020
  var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
156004
- if (!diag || !diag.relatedInformation)
156021
+ if (diag === undefined || diag.relatedInformation === undefined)
156005
156022
  return;
156006
156023
  var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
156007
- if (!related)
156024
+ if (related === undefined || related.file === undefined || related.start === undefined || related.length === undefined)
156008
156025
  return;
156009
- return related;
156010
- }
156011
- function addMissingConstraint(changes, related) {
156012
- var decl = findAncestorMatchingSpan(related.file, related);
156013
- if (!decl)
156026
+ var declaration = findAncestorMatchingSpan(related.file, ts.createTextSpan(related.start, related.length));
156027
+ if (declaration === undefined)
156014
156028
  return;
156015
- if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
156016
- decl = decl.parent;
156029
+ if (ts.isIdentifier(declaration) && ts.isTypeParameterDeclaration(declaration.parent)) {
156030
+ declaration = declaration.parent;
156031
+ }
156032
+ if (ts.isTypeParameterDeclaration(declaration)) {
156033
+ // should only issue fix on type parameters written using `extends`
156034
+ if (ts.isMappedTypeNode(declaration.parent))
156035
+ return;
156036
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156037
+ var checker = program.getTypeChecker();
156038
+ var constraint = tryGetConstraintType(checker, token) || tryGetConstraintFromDiagnosticMessage(related.messageText);
156039
+ return { constraint: constraint, declaration: declaration, token: token };
156040
+ }
156041
+ return undefined;
156042
+ }
156043
+ function addMissingConstraint(changes, program, preferences, host, sourceFile, info) {
156044
+ var declaration = info.declaration, constraint = info.constraint;
156045
+ var checker = program.getTypeChecker();
156046
+ if (ts.isString(constraint)) {
156047
+ changes.insertText(sourceFile, declaration.name.end, " extends " + constraint);
156048
+ }
156049
+ else {
156050
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156051
+ var tracker = codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host });
156052
+ var importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
156053
+ var typeNode = codefix.typeToAutoImportableTypeNode(checker, importAdder, constraint, /*contextNode*/ undefined, scriptTarget, /*flags*/ undefined, tracker);
156054
+ if (typeNode) {
156055
+ changes.replaceNode(sourceFile, declaration, ts.factory.updateTypeParameterDeclaration(declaration, /*modifiers*/ undefined, declaration.name, typeNode, declaration.default));
156056
+ importAdder.writeFixes(changes);
156057
+ }
156017
156058
  }
156018
- if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
156019
- return; // should only issue fix on type parameters written using `extends`
156020
- var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
156021
- if (!newConstraint)
156022
- return;
156023
- var newConstraintText = newConstraint[1];
156024
- changes.insertText(related.file, decl.name.end, " extends " + newConstraintText);
156025
156059
  }
156026
156060
  function findAncestorMatchingSpan(sourceFile, span) {
156027
- var token = ts.getTokenAtPosition(sourceFile, span.start);
156028
156061
  var end = ts.textSpanEnd(span);
156062
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156029
156063
  while (token.end < end) {
156030
156064
  token = token.parent;
156031
156065
  }
156032
156066
  return token;
156033
156067
  }
156068
+ function tryGetConstraintFromDiagnosticMessage(messageText) {
156069
+ var _a = ts.flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [], _ = _a[0], constraint = _a[1];
156070
+ return constraint;
156071
+ }
156072
+ function tryGetConstraintType(checker, node) {
156073
+ if (ts.isTypeNode(node.parent)) {
156074
+ return checker.getTypeArgumentConstraint(node.parent);
156075
+ }
156076
+ var contextualType = ts.isExpression(node) ? checker.getContextualType(node) : undefined;
156077
+ return contextualType || checker.getTypeAtLocation(node);
156078
+ }
156034
156079
  })(codefix = ts.codefix || (ts.codefix = {}));
156035
156080
  })(ts || (ts = {}));
156036
156081
  /* @internal */
package/lib/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220722";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220723";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -7042,8 +7042,10 @@ var ts;
7042
7042
  return {
7043
7043
  close: function () {
7044
7044
  // Close the watcher (either existing file system entry watcher or missing file system entry watcher)
7045
- watcher.close();
7046
- watcher = undefined;
7045
+ if (watcher) {
7046
+ watcher.close();
7047
+ watcher = undefined;
7048
+ }
7047
7049
  }
7048
7050
  };
7049
7051
  function updateWatcher(createWatcher) {
@@ -79823,7 +79825,11 @@ var ts;
79823
79825
  var operator = operatorToken.kind;
79824
79826
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79825
79827
  if (operator === 55 /* AmpersandAmpersandToken */) {
79826
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79828
+ var parent = node.parent;
79829
+ while (parent.kind === 212 /* ParenthesizedExpression */
79830
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79831
+ parent = parent.parent;
79832
+ }
79827
79833
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79828
79834
  }
79829
79835
  checkTruthinessOfType(leftType, node.left);
@@ -90745,13 +90751,13 @@ var ts;
90745
90751
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90746
90752
  case 200 /* ImportType */:
90747
90753
  ts.Debug.type(node);
90748
- return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), visitNodes(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90754
+ return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90749
90755
  case 295 /* ImportTypeAssertionContainer */:
90750
90756
  ts.Debug.type(node);
90751
90757
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90752
90758
  case 197 /* NamedTupleMember */:
90753
90759
  ts.Debug.type(node);
90754
- return factory.updateNamedTupleMember(node, visitNode(node.dotDotDotToken, visitor, ts.isDotDotDotToken), visitNode(node.name, visitor, ts.isIdentifier), visitNode(node.questionToken, visitor, ts.isQuestionToken), visitNode(node.type, visitor, ts.isTypeNode));
90760
+ return factory.updateNamedTupleMember(node, nodeVisitor(node.dotDotDotToken, visitor, ts.isDotDotDotToken), nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.questionToken, visitor, ts.isQuestionToken), nodeVisitor(node.type, visitor, ts.isTypeNode));
90755
90761
  case 191 /* ParenthesizedType */:
90756
90762
  ts.Debug.type(node);
90757
90763
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90816,7 +90822,7 @@ var ts;
90816
90822
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90817
90823
  case 210 /* TaggedTemplateExpression */:
90818
90824
  ts.Debug.type(node);
90819
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90825
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90820
90826
  case 211 /* TypeAssertionExpression */:
90821
90827
  ts.Debug.type(node);
90822
90828
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
@@ -149449,6 +149455,7 @@ var ts;
149449
149455
  consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
149450
149456
  }
149451
149457
  function processChildNode(child, inheritedIndentation, parent, parentDynamicIndentation, parentStartLine, undecoratedParentStartLine, isListItem, isFirstListItem) {
149458
+ ts.Debug.assert(!ts.nodeIsSynthesized(child));
149452
149459
  if (ts.nodeIsMissing(child)) {
149453
149460
  return inheritedIndentation;
149454
149461
  }
@@ -149515,6 +149522,7 @@ var ts;
149515
149522
  }
149516
149523
  function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) {
149517
149524
  ts.Debug.assert(ts.isNodeArray(nodes));
149525
+ ts.Debug.assert(!ts.nodeIsSynthesized(nodes));
149518
149526
  var listStartToken = getOpenTokenForList(parent, nodes);
149519
149527
  var listDynamicIndentation = parentDynamicIndentation;
149520
149528
  var startLine = parentStartLine;
@@ -155974,54 +155982,91 @@ var ts;
155974
155982
  codefix.registerCodeFix({
155975
155983
  errorCodes: errorCodes,
155976
155984
  getCodeActions: function (context) {
155977
- var sourceFile = context.sourceFile, span = context.span, program = context.program;
155978
- var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155979
- if (!related) {
155985
+ var sourceFile = context.sourceFile, span = context.span, program = context.program, preferences = context.preferences, host = context.host;
155986
+ var info = getInfo(program, sourceFile, span);
155987
+ if (info === undefined)
155980
155988
  return;
155981
- }
155982
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155989
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, program, preferences, host, sourceFile, info); });
155983
155990
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155984
155991
  },
155985
155992
  fixIds: [fixId],
155986
- getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155987
- var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155988
- if (!info)
155989
- return;
155990
- return addMissingConstraint(changes, info);
155991
- }); },
155993
+ getAllCodeActions: function (context) {
155994
+ var program = context.program, preferences = context.preferences, host = context.host;
155995
+ var seen = new ts.Map();
155996
+ return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
155997
+ codefix.eachDiagnostic(context, errorCodes, function (diag) {
155998
+ var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
155999
+ if (info) {
156000
+ var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
156001
+ if (ts.addToSeen(seen, id)) {
156002
+ return addMissingConstraint(changes, program, preferences, host, diag.file, info);
156003
+ }
156004
+ }
156005
+ return undefined;
156006
+ });
156007
+ }));
156008
+ }
155992
156009
  });
155993
- function getDiagnosticRelatedInfo(program, sourceFile, span) {
156010
+ function getInfo(program, sourceFile, span) {
155994
156011
  var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155995
- if (!diag || !diag.relatedInformation)
156012
+ if (diag === undefined || diag.relatedInformation === undefined)
155996
156013
  return;
155997
156014
  var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
155998
- if (!related)
156015
+ if (related === undefined || related.file === undefined || related.start === undefined || related.length === undefined)
155999
156016
  return;
156000
- return related;
156001
- }
156002
- function addMissingConstraint(changes, related) {
156003
- var decl = findAncestorMatchingSpan(related.file, related);
156004
- if (!decl)
156017
+ var declaration = findAncestorMatchingSpan(related.file, ts.createTextSpan(related.start, related.length));
156018
+ if (declaration === undefined)
156005
156019
  return;
156006
- if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
156007
- decl = decl.parent;
156020
+ if (ts.isIdentifier(declaration) && ts.isTypeParameterDeclaration(declaration.parent)) {
156021
+ declaration = declaration.parent;
156022
+ }
156023
+ if (ts.isTypeParameterDeclaration(declaration)) {
156024
+ // should only issue fix on type parameters written using `extends`
156025
+ if (ts.isMappedTypeNode(declaration.parent))
156026
+ return;
156027
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156028
+ var checker = program.getTypeChecker();
156029
+ var constraint = tryGetConstraintType(checker, token) || tryGetConstraintFromDiagnosticMessage(related.messageText);
156030
+ return { constraint: constraint, declaration: declaration, token: token };
156031
+ }
156032
+ return undefined;
156033
+ }
156034
+ function addMissingConstraint(changes, program, preferences, host, sourceFile, info) {
156035
+ var declaration = info.declaration, constraint = info.constraint;
156036
+ var checker = program.getTypeChecker();
156037
+ if (ts.isString(constraint)) {
156038
+ changes.insertText(sourceFile, declaration.name.end, " extends " + constraint);
156039
+ }
156040
+ else {
156041
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156042
+ var tracker = codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host });
156043
+ var importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
156044
+ var typeNode = codefix.typeToAutoImportableTypeNode(checker, importAdder, constraint, /*contextNode*/ undefined, scriptTarget, /*flags*/ undefined, tracker);
156045
+ if (typeNode) {
156046
+ changes.replaceNode(sourceFile, declaration, ts.factory.updateTypeParameterDeclaration(declaration, /*modifiers*/ undefined, declaration.name, typeNode, declaration.default));
156047
+ importAdder.writeFixes(changes);
156048
+ }
156008
156049
  }
156009
- if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
156010
- return; // should only issue fix on type parameters written using `extends`
156011
- var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
156012
- if (!newConstraint)
156013
- return;
156014
- var newConstraintText = newConstraint[1];
156015
- changes.insertText(related.file, decl.name.end, " extends " + newConstraintText);
156016
156050
  }
156017
156051
  function findAncestorMatchingSpan(sourceFile, span) {
156018
- var token = ts.getTokenAtPosition(sourceFile, span.start);
156019
156052
  var end = ts.textSpanEnd(span);
156053
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156020
156054
  while (token.end < end) {
156021
156055
  token = token.parent;
156022
156056
  }
156023
156057
  return token;
156024
156058
  }
156059
+ function tryGetConstraintFromDiagnosticMessage(messageText) {
156060
+ var _a = ts.flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [], _ = _a[0], constraint = _a[1];
156061
+ return constraint;
156062
+ }
156063
+ function tryGetConstraintType(checker, node) {
156064
+ if (ts.isTypeNode(node.parent)) {
156065
+ return checker.getTypeArgumentConstraint(node.parent);
156066
+ }
156067
+ var contextualType = ts.isExpression(node) ? checker.getContextualType(node) : undefined;
156068
+ return contextualType || checker.getTypeAtLocation(node);
156069
+ }
156025
156070
  })(codefix = ts.codefix || (ts.codefix = {}));
156026
156071
  })(ts || (ts = {}));
156027
156072
  /* @internal */
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220722";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220723";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -7042,8 +7042,10 @@ var ts;
7042
7042
  return {
7043
7043
  close: function () {
7044
7044
  // Close the watcher (either existing file system entry watcher or missing file system entry watcher)
7045
- watcher.close();
7046
- watcher = undefined;
7045
+ if (watcher) {
7046
+ watcher.close();
7047
+ watcher = undefined;
7048
+ }
7047
7049
  }
7048
7050
  };
7049
7051
  function updateWatcher(createWatcher) {
@@ -79823,7 +79825,11 @@ var ts;
79823
79825
  var operator = operatorToken.kind;
79824
79826
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79825
79827
  if (operator === 55 /* AmpersandAmpersandToken */) {
79826
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79828
+ var parent = node.parent;
79829
+ while (parent.kind === 212 /* ParenthesizedExpression */
79830
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79831
+ parent = parent.parent;
79832
+ }
79827
79833
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79828
79834
  }
79829
79835
  checkTruthinessOfType(leftType, node.left);
@@ -90745,13 +90751,13 @@ var ts;
90745
90751
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90746
90752
  case 200 /* ImportType */:
90747
90753
  ts.Debug.type(node);
90748
- return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), visitNodes(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90754
+ return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90749
90755
  case 295 /* ImportTypeAssertionContainer */:
90750
90756
  ts.Debug.type(node);
90751
90757
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90752
90758
  case 197 /* NamedTupleMember */:
90753
90759
  ts.Debug.type(node);
90754
- return factory.updateNamedTupleMember(node, visitNode(node.dotDotDotToken, visitor, ts.isDotDotDotToken), visitNode(node.name, visitor, ts.isIdentifier), visitNode(node.questionToken, visitor, ts.isQuestionToken), visitNode(node.type, visitor, ts.isTypeNode));
90760
+ return factory.updateNamedTupleMember(node, nodeVisitor(node.dotDotDotToken, visitor, ts.isDotDotDotToken), nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.questionToken, visitor, ts.isQuestionToken), nodeVisitor(node.type, visitor, ts.isTypeNode));
90755
90761
  case 191 /* ParenthesizedType */:
90756
90762
  ts.Debug.type(node);
90757
90763
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90816,7 +90822,7 @@ var ts;
90816
90822
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90817
90823
  case 210 /* TaggedTemplateExpression */:
90818
90824
  ts.Debug.type(node);
90819
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90825
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90820
90826
  case 211 /* TypeAssertionExpression */:
90821
90827
  ts.Debug.type(node);
90822
90828
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
@@ -149449,6 +149455,7 @@ var ts;
149449
149455
  consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
149450
149456
  }
149451
149457
  function processChildNode(child, inheritedIndentation, parent, parentDynamicIndentation, parentStartLine, undecoratedParentStartLine, isListItem, isFirstListItem) {
149458
+ ts.Debug.assert(!ts.nodeIsSynthesized(child));
149452
149459
  if (ts.nodeIsMissing(child)) {
149453
149460
  return inheritedIndentation;
149454
149461
  }
@@ -149515,6 +149522,7 @@ var ts;
149515
149522
  }
149516
149523
  function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) {
149517
149524
  ts.Debug.assert(ts.isNodeArray(nodes));
149525
+ ts.Debug.assert(!ts.nodeIsSynthesized(nodes));
149518
149526
  var listStartToken = getOpenTokenForList(parent, nodes);
149519
149527
  var listDynamicIndentation = parentDynamicIndentation;
149520
149528
  var startLine = parentStartLine;
@@ -155974,54 +155982,91 @@ var ts;
155974
155982
  codefix.registerCodeFix({
155975
155983
  errorCodes: errorCodes,
155976
155984
  getCodeActions: function (context) {
155977
- var sourceFile = context.sourceFile, span = context.span, program = context.program;
155978
- var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155979
- if (!related) {
155985
+ var sourceFile = context.sourceFile, span = context.span, program = context.program, preferences = context.preferences, host = context.host;
155986
+ var info = getInfo(program, sourceFile, span);
155987
+ if (info === undefined)
155980
155988
  return;
155981
- }
155982
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155989
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, program, preferences, host, sourceFile, info); });
155983
155990
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155984
155991
  },
155985
155992
  fixIds: [fixId],
155986
- getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155987
- var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155988
- if (!info)
155989
- return;
155990
- return addMissingConstraint(changes, info);
155991
- }); },
155993
+ getAllCodeActions: function (context) {
155994
+ var program = context.program, preferences = context.preferences, host = context.host;
155995
+ var seen = new ts.Map();
155996
+ return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
155997
+ codefix.eachDiagnostic(context, errorCodes, function (diag) {
155998
+ var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
155999
+ if (info) {
156000
+ var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
156001
+ if (ts.addToSeen(seen, id)) {
156002
+ return addMissingConstraint(changes, program, preferences, host, diag.file, info);
156003
+ }
156004
+ }
156005
+ return undefined;
156006
+ });
156007
+ }));
156008
+ }
155992
156009
  });
155993
- function getDiagnosticRelatedInfo(program, sourceFile, span) {
156010
+ function getInfo(program, sourceFile, span) {
155994
156011
  var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155995
- if (!diag || !diag.relatedInformation)
156012
+ if (diag === undefined || diag.relatedInformation === undefined)
155996
156013
  return;
155997
156014
  var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
155998
- if (!related)
156015
+ if (related === undefined || related.file === undefined || related.start === undefined || related.length === undefined)
155999
156016
  return;
156000
- return related;
156001
- }
156002
- function addMissingConstraint(changes, related) {
156003
- var decl = findAncestorMatchingSpan(related.file, related);
156004
- if (!decl)
156017
+ var declaration = findAncestorMatchingSpan(related.file, ts.createTextSpan(related.start, related.length));
156018
+ if (declaration === undefined)
156005
156019
  return;
156006
- if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
156007
- decl = decl.parent;
156020
+ if (ts.isIdentifier(declaration) && ts.isTypeParameterDeclaration(declaration.parent)) {
156021
+ declaration = declaration.parent;
156022
+ }
156023
+ if (ts.isTypeParameterDeclaration(declaration)) {
156024
+ // should only issue fix on type parameters written using `extends`
156025
+ if (ts.isMappedTypeNode(declaration.parent))
156026
+ return;
156027
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156028
+ var checker = program.getTypeChecker();
156029
+ var constraint = tryGetConstraintType(checker, token) || tryGetConstraintFromDiagnosticMessage(related.messageText);
156030
+ return { constraint: constraint, declaration: declaration, token: token };
156031
+ }
156032
+ return undefined;
156033
+ }
156034
+ function addMissingConstraint(changes, program, preferences, host, sourceFile, info) {
156035
+ var declaration = info.declaration, constraint = info.constraint;
156036
+ var checker = program.getTypeChecker();
156037
+ if (ts.isString(constraint)) {
156038
+ changes.insertText(sourceFile, declaration.name.end, " extends " + constraint);
156039
+ }
156040
+ else {
156041
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156042
+ var tracker = codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host });
156043
+ var importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
156044
+ var typeNode = codefix.typeToAutoImportableTypeNode(checker, importAdder, constraint, /*contextNode*/ undefined, scriptTarget, /*flags*/ undefined, tracker);
156045
+ if (typeNode) {
156046
+ changes.replaceNode(sourceFile, declaration, ts.factory.updateTypeParameterDeclaration(declaration, /*modifiers*/ undefined, declaration.name, typeNode, declaration.default));
156047
+ importAdder.writeFixes(changes);
156048
+ }
156008
156049
  }
156009
- if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
156010
- return; // should only issue fix on type parameters written using `extends`
156011
- var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
156012
- if (!newConstraint)
156013
- return;
156014
- var newConstraintText = newConstraint[1];
156015
- changes.insertText(related.file, decl.name.end, " extends " + newConstraintText);
156016
156050
  }
156017
156051
  function findAncestorMatchingSpan(sourceFile, span) {
156018
- var token = ts.getTokenAtPosition(sourceFile, span.start);
156019
156052
  var end = ts.textSpanEnd(span);
156053
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156020
156054
  while (token.end < end) {
156021
156055
  token = token.parent;
156022
156056
  }
156023
156057
  return token;
156024
156058
  }
156059
+ function tryGetConstraintFromDiagnosticMessage(messageText) {
156060
+ var _a = ts.flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [], _ = _a[0], constraint = _a[1];
156061
+ return constraint;
156062
+ }
156063
+ function tryGetConstraintType(checker, node) {
156064
+ if (ts.isTypeNode(node.parent)) {
156065
+ return checker.getTypeArgumentConstraint(node.parent);
156066
+ }
156067
+ var contextualType = ts.isExpression(node) ? checker.getContextualType(node) : undefined;
156068
+ return contextualType || checker.getTypeAtLocation(node);
156069
+ }
156025
156070
  })(codefix = ts.codefix || (ts.codefix = {}));
156026
156071
  })(ts || (ts = {}));
156027
156072
  /* @internal */
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220722";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220723";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -6837,8 +6837,10 @@ var ts;
6837
6837
  return {
6838
6838
  close: function () {
6839
6839
  // Close the watcher (either existing file system entry watcher or missing file system entry watcher)
6840
- watcher.close();
6841
- watcher = undefined;
6840
+ if (watcher) {
6841
+ watcher.close();
6842
+ watcher = undefined;
6843
+ }
6842
6844
  }
6843
6845
  };
6844
6846
  function updateWatcher(createWatcher) {
@@ -79618,7 +79620,11 @@ var ts;
79618
79620
  var operator = operatorToken.kind;
79619
79621
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79620
79622
  if (operator === 55 /* AmpersandAmpersandToken */) {
79621
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79623
+ var parent = node.parent;
79624
+ while (parent.kind === 212 /* ParenthesizedExpression */
79625
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79626
+ parent = parent.parent;
79627
+ }
79622
79628
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79623
79629
  }
79624
79630
  checkTruthinessOfType(leftType, node.left);
@@ -90540,13 +90546,13 @@ var ts;
90540
90546
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90541
90547
  case 200 /* ImportType */:
90542
90548
  ts.Debug.type(node);
90543
- return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), visitNodes(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90549
+ return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, ts.isTypeNode), nodeVisitor(node.assertions, visitor, ts.isNode), nodeVisitor(node.qualifier, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), node.isTypeOf);
90544
90550
  case 295 /* ImportTypeAssertionContainer */:
90545
90551
  ts.Debug.type(node);
90546
90552
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90547
90553
  case 197 /* NamedTupleMember */:
90548
90554
  ts.Debug.type(node);
90549
- return factory.updateNamedTupleMember(node, visitNode(node.dotDotDotToken, visitor, ts.isDotDotDotToken), visitNode(node.name, visitor, ts.isIdentifier), visitNode(node.questionToken, visitor, ts.isQuestionToken), visitNode(node.type, visitor, ts.isTypeNode));
90555
+ return factory.updateNamedTupleMember(node, nodeVisitor(node.dotDotDotToken, visitor, ts.isDotDotDotToken), nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.questionToken, visitor, ts.isQuestionToken), nodeVisitor(node.type, visitor, ts.isTypeNode));
90550
90556
  case 191 /* ParenthesizedType */:
90551
90557
  ts.Debug.type(node);
90552
90558
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90611,7 +90617,7 @@ var ts;
90611
90617
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90612
90618
  case 210 /* TaggedTemplateExpression */:
90613
90619
  ts.Debug.type(node);
90614
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90620
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90615
90621
  case 211 /* TypeAssertionExpression */:
90616
90622
  ts.Debug.type(node);
90617
90623
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "typescript",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "4.8.0-dev.20220722",
5
+ "version": "4.8.0-dev.20220723",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [