@typescript-deploys/pr-build 4.8.0-pr-49981-17 → 4.8.0-pr-50021-12

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-insiders.20220721";
72
+ ts.version = ts.versionMajorMinor + ".0-insiders.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) {
@@ -56677,42 +56679,28 @@ var ts;
56677
56679
  var commonBaseType;
56678
56680
  for (var _i = 0, types_13 = types; _i < types_13.length; _i++) {
56679
56681
  var t = types_13[_i];
56680
- var baseType = getBaseTypeOfLiteralType(t);
56681
- if (!commonBaseType) {
56682
- commonBaseType = baseType;
56683
- }
56684
- if (baseType === t || baseType !== commonBaseType) {
56685
- return false;
56682
+ if (!(t.flags & 131072)) {
56683
+ var baseType = getBaseTypeOfLiteralType(t);
56684
+ commonBaseType !== null && commonBaseType !== void 0 ? commonBaseType : (commonBaseType = baseType);
56685
+ if (baseType === t || baseType !== commonBaseType) {
56686
+ return false;
56687
+ }
56686
56688
  }
56687
56689
  }
56688
56690
  return true;
56689
56691
  }
56690
- function getSupertypeOrUnion(types) {
56691
- if (types.length === 1) {
56692
- return types[0];
56693
- }
56694
- return literalTypesWithSameBaseType(types) ?
56695
- getUnionType(types) :
56696
- ts.reduceLeft(types, function (s, t) { return isTypeSubtypeOf(getNonNullableTypeIfNeeded(s), getNonNullableTypeIfNeeded(t)) ? t : s; });
56692
+ function getCombinedTypeFlags(types) {
56693
+ return ts.reduceLeft(types, function (flags, t) { return flags | (t.flags & 1048576 ? getCombinedTypeFlags(t.types) : t.flags); }, 0);
56697
56694
  }
56698
56695
  function getCommonSupertype(types) {
56699
- if (!strictNullChecks) {
56700
- return getSupertypeOrUnion(types);
56701
- }
56702
- var supertypeOrUnion = getSupertypeOrUnion(types);
56703
- var shouldHaveNull = ts.some(types, function (t) { return someHas(t, 65536); });
56704
- var shouldHaveUndefined = ts.some(types, function (t) { return someHas(t, 32768); });
56705
- var missingNullableFlags = 0;
56706
- if (shouldHaveNull && !someHas(supertypeOrUnion, 65536)) {
56707
- missingNullableFlags |= 65536;
56708
- }
56709
- if (shouldHaveUndefined && !someHas(supertypeOrUnion, 32768)) {
56710
- missingNullableFlags |= 32768;
56711
- }
56712
- return getNullableType(supertypeOrUnion, missingNullableFlags);
56713
- function someHas(type, flags) {
56714
- return someType(type, function (t) { return !!(t.flags & flags); });
56696
+ if (types.length === 1) {
56697
+ return types[0];
56715
56698
  }
56699
+ var primaryTypes = strictNullChecks ? ts.sameMap(types, function (t) { return filterType(t, function (u) { return !(u.flags & 98304); }); }) : types;
56700
+ var superTypeOrUnion = literalTypesWithSameBaseType(primaryTypes) ?
56701
+ getUnionType(primaryTypes) :
56702
+ ts.reduceLeft(primaryTypes, function (s, t) { return isTypeSubtypeOf(s, t) ? t : s; });
56703
+ return primaryTypes === types ? superTypeOrUnion : getNullableType(superTypeOrUnion, getCombinedTypeFlags(types) & 98304);
56716
56704
  }
56717
56705
  function getCommonSubtype(types) {
56718
56706
  return ts.reduceLeft(types, function (s, t) { return isTypeSubtypeOf(t, s) ? t : s; });
@@ -66749,7 +66737,11 @@ var ts;
66749
66737
  var operator = operatorToken.kind;
66750
66738
  if (operator === 55 || operator === 56 || operator === 60) {
66751
66739
  if (operator === 55) {
66752
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
66740
+ var parent = node.parent;
66741
+ while (parent.kind === 212
66742
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 || parent.operatorToken.kind === 56)) {
66743
+ parent = parent.parent;
66744
+ }
66753
66745
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
66754
66746
  }
66755
66747
  checkTruthinessOfType(leftType, node.left);
@@ -76312,13 +76304,13 @@ var ts;
76312
76304
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
76313
76305
  case 200:
76314
76306
  ts.Debug.type(node);
76315
- 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);
76307
+ 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);
76316
76308
  case 295:
76317
76309
  ts.Debug.type(node);
76318
76310
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
76319
76311
  case 197:
76320
76312
  ts.Debug.type(node);
76321
- 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));
76313
+ 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));
76322
76314
  case 191:
76323
76315
  ts.Debug.type(node);
76324
76316
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -76381,7 +76373,7 @@ var ts;
76381
76373
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
76382
76374
  case 210:
76383
76375
  ts.Debug.type(node);
76384
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
76376
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
76385
76377
  case 211:
76386
76378
  ts.Debug.type(node);
76387
76379
  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-insiders.20220721";
112
+ ts.version = ts.versionMajorMinor + ".0-insiders.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) {
@@ -67946,45 +67948,33 @@ var ts;
67946
67948
  var commonBaseType;
67947
67949
  for (var _i = 0, types_13 = types; _i < types_13.length; _i++) {
67948
67950
  var t = types_13[_i];
67949
- var baseType = getBaseTypeOfLiteralType(t);
67950
- if (!commonBaseType) {
67951
- commonBaseType = baseType;
67952
- }
67953
- if (baseType === t || baseType !== commonBaseType) {
67954
- return false;
67951
+ if (!(t.flags & 131072 /* Never */)) {
67952
+ var baseType = getBaseTypeOfLiteralType(t);
67953
+ commonBaseType !== null && commonBaseType !== void 0 ? commonBaseType : (commonBaseType = baseType);
67954
+ if (baseType === t || baseType !== commonBaseType) {
67955
+ return false;
67956
+ }
67955
67957
  }
67956
67958
  }
67957
67959
  return true;
67958
67960
  }
67959
- // When the candidate types are all literal types with the same base type, return a union
67960
- // of those literal types. Otherwise, return the leftmost type for which no type to the
67961
- // right is a supertype.
67962
- function getSupertypeOrUnion(types) {
67963
- if (types.length === 1) {
67964
- return types[0];
67965
- }
67966
- return literalTypesWithSameBaseType(types) ?
67967
- getUnionType(types) :
67968
- ts.reduceLeft(types, function (s, t) { return isTypeSubtypeOf(getNonNullableTypeIfNeeded(s), getNonNullableTypeIfNeeded(t)) ? t : s; });
67961
+ function getCombinedTypeFlags(types) {
67962
+ return ts.reduceLeft(types, function (flags, t) { return flags | (t.flags & 1048576 /* Union */ ? getCombinedTypeFlags(t.types) : t.flags); }, 0);
67969
67963
  }
67970
67964
  function getCommonSupertype(types) {
67971
- if (!strictNullChecks) {
67972
- return getSupertypeOrUnion(types);
67973
- }
67974
- var supertypeOrUnion = getSupertypeOrUnion(types);
67975
- var shouldHaveNull = ts.some(types, function (t) { return someHas(t, 65536 /* Null */); });
67976
- var shouldHaveUndefined = ts.some(types, function (t) { return someHas(t, 32768 /* Undefined */); });
67977
- var missingNullableFlags = 0;
67978
- if (shouldHaveNull && !someHas(supertypeOrUnion, 65536 /* Null */)) {
67979
- missingNullableFlags |= 65536 /* Null */;
67980
- }
67981
- if (shouldHaveUndefined && !someHas(supertypeOrUnion, 32768 /* Undefined */)) {
67982
- missingNullableFlags |= 32768 /* Undefined */;
67983
- }
67984
- return getNullableType(supertypeOrUnion, missingNullableFlags);
67985
- function someHas(type, flags) {
67986
- return someType(type, function (t) { return !!(t.flags & flags); });
67965
+ if (types.length === 1) {
67966
+ return types[0];
67987
67967
  }
67968
+ // Remove nullable types from each of the candidates.
67969
+ var primaryTypes = strictNullChecks ? ts.sameMap(types, function (t) { return filterType(t, function (u) { return !(u.flags & 98304 /* Nullable */); }); }) : types;
67970
+ // When the candidate types are all literal types with the same base type, return a union
67971
+ // of those literal types. Otherwise, return the leftmost type for which no type to the
67972
+ // right is a supertype.
67973
+ var superTypeOrUnion = literalTypesWithSameBaseType(primaryTypes) ?
67974
+ getUnionType(primaryTypes) :
67975
+ ts.reduceLeft(primaryTypes, function (s, t) { return isTypeSubtypeOf(s, t) ? t : s; });
67976
+ // Add any nullable types that occurred in the candidates back to the result.
67977
+ return primaryTypes === types ? superTypeOrUnion : getNullableType(superTypeOrUnion, getCombinedTypeFlags(types) & 98304 /* Nullable */);
67988
67978
  }
67989
67979
  // Return the leftmost type for which no type to the right is a subtype.
67990
67980
  function getCommonSubtype(types) {
@@ -79646,7 +79636,11 @@ var ts;
79646
79636
  var operator = operatorToken.kind;
79647
79637
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79648
79638
  if (operator === 55 /* AmpersandAmpersandToken */) {
79649
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79639
+ var parent = node.parent;
79640
+ while (parent.kind === 212 /* ParenthesizedExpression */
79641
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79642
+ parent = parent.parent;
79643
+ }
79650
79644
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79651
79645
  }
79652
79646
  checkTruthinessOfType(leftType, node.left);
@@ -90568,13 +90562,13 @@ var ts;
90568
90562
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90569
90563
  case 200 /* ImportType */:
90570
90564
  ts.Debug.type(node);
90571
- 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);
90565
+ 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);
90572
90566
  case 295 /* ImportTypeAssertionContainer */:
90573
90567
  ts.Debug.type(node);
90574
90568
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90575
90569
  case 197 /* NamedTupleMember */:
90576
90570
  ts.Debug.type(node);
90577
- 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));
90571
+ 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));
90578
90572
  case 191 /* ParenthesizedType */:
90579
90573
  ts.Debug.type(node);
90580
90574
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90639,7 +90633,7 @@ var ts;
90639
90633
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90640
90634
  case 210 /* TaggedTemplateExpression */:
90641
90635
  ts.Debug.type(node);
90642
- return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), visitNodes(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90636
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90643
90637
  case 211 /* TypeAssertionExpression */:
90644
90638
  ts.Debug.type(node);
90645
90639
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
@@ -141767,8 +141761,12 @@ var ts;
141767
141761
  return undefined;
141768
141762
  }
141769
141763
  var commentOwner = commentOwnerInfo.commentOwner, parameters = commentOwnerInfo.parameters, hasReturn = commentOwnerInfo.hasReturn;
141770
- var commentOwnerJSDoc = ts.hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? ts.lastOrUndefined(commentOwner.jsDoc) : undefined;
141771
- if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) {
141764
+ var commentOwnerJsDoc = ts.hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? commentOwner.jsDoc : undefined;
141765
+ var lastJsDoc = ts.lastOrUndefined(commentOwnerJsDoc);
141766
+ if (commentOwner.getStart(sourceFile) < position
141767
+ || lastJsDoc
141768
+ && existingDocComment
141769
+ && lastJsDoc !== existingDocComment) {
141772
141770
  return undefined;
141773
141771
  }
141774
141772
  var indentationStr = getIndentationStringAtPosition(sourceFile, position);
@@ -141785,7 +141783,9 @@ var ts;
141785
141783
  // * if the caret was directly in front of the object, then we add an extra line and indentation.
141786
141784
  var openComment = "/**";
141787
141785
  var closeComment = " */";
141788
- if (tags) {
141786
+ // If any of the existing jsDoc has tags, ignore adding new ones.
141787
+ var hasTag = (commentOwnerJsDoc || []).some(function (jsDoc) { return !!jsDoc.tags; });
141788
+ if (tags && !hasTag) {
141789
141789
  var preamble = openComment + newLine + indentationStr + " * ";
141790
141790
  var endLine = tokenStart === position ? newLine + indentationStr : "";
141791
141791
  var result = preamble + newLine + tags + indentationStr + closeComment + endLine;
@@ -148847,6 +148847,7 @@ var ts;
148847
148847
  consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
148848
148848
  }
148849
148849
  function processChildNode(child, inheritedIndentation, parent, parentDynamicIndentation, parentStartLine, undecoratedParentStartLine, isListItem, isFirstListItem) {
148850
+ ts.Debug.assert(!ts.nodeIsSynthesized(child));
148850
148851
  if (ts.nodeIsMissing(child)) {
148851
148852
  return inheritedIndentation;
148852
148853
  }
@@ -148913,6 +148914,7 @@ var ts;
148913
148914
  }
148914
148915
  function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) {
148915
148916
  ts.Debug.assert(ts.isNodeArray(nodes));
148917
+ ts.Debug.assert(!ts.nodeIsSynthesized(nodes));
148916
148918
  var listStartToken = getOpenTokenForList(parent, nodes);
148917
148919
  var listDynamicIndentation = parentDynamicIndentation;
148918
148920
  var startLine = parentStartLine;
@@ -155372,54 +155374,91 @@ var ts;
155372
155374
  codefix.registerCodeFix({
155373
155375
  errorCodes: errorCodes,
155374
155376
  getCodeActions: function (context) {
155375
- var sourceFile = context.sourceFile, span = context.span, program = context.program;
155376
- var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155377
- if (!related) {
155377
+ var sourceFile = context.sourceFile, span = context.span, program = context.program, preferences = context.preferences, host = context.host;
155378
+ var info = getInfo(program, sourceFile, span);
155379
+ if (info === undefined)
155378
155380
  return;
155379
- }
155380
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155381
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, program, preferences, host, sourceFile, info); });
155381
155382
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155382
155383
  },
155383
155384
  fixIds: [fixId],
155384
- getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155385
- var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155386
- if (!info)
155387
- return;
155388
- return addMissingConstraint(changes, info);
155389
- }); },
155385
+ getAllCodeActions: function (context) {
155386
+ var program = context.program, preferences = context.preferences, host = context.host;
155387
+ var seen = new ts.Map();
155388
+ return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
155389
+ codefix.eachDiagnostic(context, errorCodes, function (diag) {
155390
+ var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
155391
+ if (info) {
155392
+ var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
155393
+ if (ts.addToSeen(seen, id)) {
155394
+ return addMissingConstraint(changes, program, preferences, host, diag.file, info);
155395
+ }
155396
+ }
155397
+ return undefined;
155398
+ });
155399
+ }));
155400
+ }
155390
155401
  });
155391
- function getDiagnosticRelatedInfo(program, sourceFile, span) {
155402
+ function getInfo(program, sourceFile, span) {
155392
155403
  var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155393
- if (!diag || !diag.relatedInformation)
155404
+ if (diag === undefined || diag.relatedInformation === undefined)
155394
155405
  return;
155395
155406
  var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
155396
- if (!related)
155407
+ if (related === undefined || related.file === undefined || related.start === undefined || related.length === undefined)
155397
155408
  return;
155398
- return related;
155399
- }
155400
- function addMissingConstraint(changes, related) {
155401
- var decl = findAncestorMatchingSpan(related.file, related);
155402
- if (!decl)
155409
+ var declaration = findAncestorMatchingSpan(related.file, ts.createTextSpan(related.start, related.length));
155410
+ if (declaration === undefined)
155403
155411
  return;
155404
- if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
155405
- decl = decl.parent;
155412
+ if (ts.isIdentifier(declaration) && ts.isTypeParameterDeclaration(declaration.parent)) {
155413
+ declaration = declaration.parent;
155414
+ }
155415
+ if (ts.isTypeParameterDeclaration(declaration)) {
155416
+ // should only issue fix on type parameters written using `extends`
155417
+ if (ts.isMappedTypeNode(declaration.parent))
155418
+ return;
155419
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
155420
+ var checker = program.getTypeChecker();
155421
+ var constraint = tryGetConstraintType(checker, token) || tryGetConstraintFromDiagnosticMessage(related.messageText);
155422
+ return { constraint: constraint, declaration: declaration, token: token };
155423
+ }
155424
+ return undefined;
155425
+ }
155426
+ function addMissingConstraint(changes, program, preferences, host, sourceFile, info) {
155427
+ var declaration = info.declaration, constraint = info.constraint;
155428
+ var checker = program.getTypeChecker();
155429
+ if (ts.isString(constraint)) {
155430
+ changes.insertText(sourceFile, declaration.name.end, " extends " + constraint);
155431
+ }
155432
+ else {
155433
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
155434
+ var tracker = codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host });
155435
+ var importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
155436
+ var typeNode = codefix.typeToAutoImportableTypeNode(checker, importAdder, constraint, /*contextNode*/ undefined, scriptTarget, /*flags*/ undefined, tracker);
155437
+ if (typeNode) {
155438
+ changes.replaceNode(sourceFile, declaration, ts.factory.updateTypeParameterDeclaration(declaration, /*modifiers*/ undefined, declaration.name, typeNode, declaration.default));
155439
+ importAdder.writeFixes(changes);
155440
+ }
155406
155441
  }
155407
- if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
155408
- return; // should only issue fix on type parameters written using `extends`
155409
- var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
155410
- if (!newConstraint)
155411
- return;
155412
- var newConstraintText = newConstraint[1];
155413
- changes.insertText(related.file, decl.name.end, " extends " + newConstraintText);
155414
155442
  }
155415
155443
  function findAncestorMatchingSpan(sourceFile, span) {
155416
- var token = ts.getTokenAtPosition(sourceFile, span.start);
155417
155444
  var end = ts.textSpanEnd(span);
155445
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
155418
155446
  while (token.end < end) {
155419
155447
  token = token.parent;
155420
155448
  }
155421
155449
  return token;
155422
155450
  }
155451
+ function tryGetConstraintFromDiagnosticMessage(messageText) {
155452
+ var _a = ts.flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [], _ = _a[0], constraint = _a[1];
155453
+ return constraint;
155454
+ }
155455
+ function tryGetConstraintType(checker, node) {
155456
+ if (ts.isTypeNode(node.parent)) {
155457
+ return checker.getTypeArgumentConstraint(node.parent);
155458
+ }
155459
+ var contextualType = ts.isExpression(node) ? checker.getContextualType(node) : undefined;
155460
+ return contextualType || checker.getTypeAtLocation(node);
155461
+ }
155423
155462
  })(codefix = ts.codefix || (ts.codefix = {}));
155424
155463
  })(ts || (ts = {}));
155425
155464
  /* @internal */