typescript 4.8.0-dev.20220722 → 4.8.0-dev.20220725

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.
@@ -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.20220725";
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) {
@@ -68140,37 +68142,33 @@ var ts;
68140
68142
  var commonBaseType;
68141
68143
  for (var _i = 0, types_13 = types; _i < types_13.length; _i++) {
68142
68144
  var t = types_13[_i];
68143
- var baseType = getBaseTypeOfLiteralType(t);
68144
- if (!commonBaseType) {
68145
- commonBaseType = baseType;
68146
- }
68147
- if (baseType === t || baseType !== commonBaseType) {
68148
- return false;
68145
+ if (!(t.flags & 131072 /* Never */)) {
68146
+ var baseType = getBaseTypeOfLiteralType(t);
68147
+ commonBaseType !== null && commonBaseType !== void 0 ? commonBaseType : (commonBaseType = baseType);
68148
+ if (baseType === t || baseType !== commonBaseType) {
68149
+ return false;
68150
+ }
68149
68151
  }
68150
68152
  }
68151
68153
  return true;
68152
68154
  }
68153
- // When the candidate types are all literal types with the same base type, return a union
68154
- // of those literal types. Otherwise, return the leftmost type for which no type to the
68155
- // right is a supertype.
68156
- function getSupertypeOrUnion(types) {
68157
- if (types.length === 1) {
68158
- return types[0];
68159
- }
68160
- return literalTypesWithSameBaseType(types) ?
68161
- getUnionType(types) :
68162
- ts.reduceLeft(types, function (s, t) { return isTypeSubtypeOf(s, t) ? t : s; });
68155
+ function getCombinedTypeFlags(types) {
68156
+ return ts.reduceLeft(types, function (flags, t) { return flags | (t.flags & 1048576 /* Union */ ? getCombinedTypeFlags(t.types) : t.flags); }, 0);
68163
68157
  }
68164
68158
  function getCommonSupertype(types) {
68165
- if (!strictNullChecks) {
68166
- return getSupertypeOrUnion(types);
68167
- }
68168
- var primaryTypes = ts.filter(types, function (t) { return !(t.flags & 98304 /* Nullable */); });
68169
- if (primaryTypes.length) {
68170
- var supertypeOrUnion = getSupertypeOrUnion(primaryTypes);
68171
- return primaryTypes === types ? supertypeOrUnion : getUnionType(__spreadArray([supertypeOrUnion], ts.filter(types, function (t) { return !!(t.flags & 98304 /* Nullable */); }), true));
68159
+ if (types.length === 1) {
68160
+ return types[0];
68172
68161
  }
68173
- return getUnionType(types, 2 /* Subtype */);
68162
+ // Remove nullable types from each of the candidates.
68163
+ var primaryTypes = strictNullChecks ? ts.sameMap(types, function (t) { return filterType(t, function (u) { return !(u.flags & 98304 /* Nullable */); }); }) : types;
68164
+ // When the candidate types are all literal types with the same base type, return a union
68165
+ // of those literal types. Otherwise, return the leftmost type for which no type to the
68166
+ // right is a supertype.
68167
+ var superTypeOrUnion = literalTypesWithSameBaseType(primaryTypes) ?
68168
+ getUnionType(primaryTypes) :
68169
+ ts.reduceLeft(primaryTypes, function (s, t) { return isTypeSubtypeOf(s, t) ? t : s; });
68170
+ // Add any nullable types that occurred in the candidates back to the result.
68171
+ return primaryTypes === types ? superTypeOrUnion : getNullableType(superTypeOrUnion, getCombinedTypeFlags(types) & 98304 /* Nullable */);
68174
68172
  }
68175
68173
  // Return the leftmost type for which no type to the right is a subtype.
68176
68174
  function getCommonSubtype(types) {
@@ -79832,7 +79830,11 @@ var ts;
79832
79830
  var operator = operatorToken.kind;
79833
79831
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79834
79832
  if (operator === 55 /* AmpersandAmpersandToken */) {
79835
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79833
+ var parent = node.parent;
79834
+ while (parent.kind === 212 /* ParenthesizedExpression */
79835
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79836
+ parent = parent.parent;
79837
+ }
79836
79838
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79837
79839
  }
79838
79840
  checkTruthinessOfType(leftType, node.left);
@@ -90754,13 +90756,13 @@ var ts;
90754
90756
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90755
90757
  case 200 /* ImportType */:
90756
90758
  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);
90759
+ 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
90760
  case 295 /* ImportTypeAssertionContainer */:
90759
90761
  ts.Debug.type(node);
90760
90762
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90761
90763
  case 197 /* NamedTupleMember */:
90762
90764
  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));
90765
+ 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
90766
  case 191 /* ParenthesizedType */:
90765
90767
  ts.Debug.type(node);
90766
90768
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90825,7 +90827,7 @@ var ts;
90825
90827
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90826
90828
  case 210 /* TaggedTemplateExpression */:
90827
90829
  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));
90830
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90829
90831
  case 211 /* TypeAssertionExpression */:
90830
90832
  ts.Debug.type(node);
90831
90833
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
@@ -149458,6 +149460,7 @@ var ts;
149458
149460
  consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
149459
149461
  }
149460
149462
  function processChildNode(child, inheritedIndentation, parent, parentDynamicIndentation, parentStartLine, undecoratedParentStartLine, isListItem, isFirstListItem) {
149463
+ ts.Debug.assert(!ts.nodeIsSynthesized(child));
149461
149464
  if (ts.nodeIsMissing(child)) {
149462
149465
  return inheritedIndentation;
149463
149466
  }
@@ -149524,6 +149527,7 @@ var ts;
149524
149527
  }
149525
149528
  function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) {
149526
149529
  ts.Debug.assert(ts.isNodeArray(nodes));
149530
+ ts.Debug.assert(!ts.nodeIsSynthesized(nodes));
149527
149531
  var listStartToken = getOpenTokenForList(parent, nodes);
149528
149532
  var listDynamicIndentation = parentDynamicIndentation;
149529
149533
  var startLine = parentStartLine;
@@ -155983,54 +155987,91 @@ var ts;
155983
155987
  codefix.registerCodeFix({
155984
155988
  errorCodes: errorCodes,
155985
155989
  getCodeActions: function (context) {
155986
- var sourceFile = context.sourceFile, span = context.span, program = context.program;
155987
- var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155988
- if (!related) {
155990
+ var sourceFile = context.sourceFile, span = context.span, program = context.program, preferences = context.preferences, host = context.host;
155991
+ var info = getInfo(program, sourceFile, span);
155992
+ if (info === undefined)
155989
155993
  return;
155990
- }
155991
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155994
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, program, preferences, host, sourceFile, info); });
155992
155995
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155993
155996
  },
155994
155997
  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
- }); },
155998
+ getAllCodeActions: function (context) {
155999
+ var program = context.program, preferences = context.preferences, host = context.host;
156000
+ var seen = new ts.Map();
156001
+ return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
156002
+ codefix.eachDiagnostic(context, errorCodes, function (diag) {
156003
+ var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
156004
+ if (info) {
156005
+ var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
156006
+ if (ts.addToSeen(seen, id)) {
156007
+ return addMissingConstraint(changes, program, preferences, host, diag.file, info);
156008
+ }
156009
+ }
156010
+ return undefined;
156011
+ });
156012
+ }));
156013
+ }
156001
156014
  });
156002
- function getDiagnosticRelatedInfo(program, sourceFile, span) {
156015
+ function getInfo(program, sourceFile, span) {
156003
156016
  var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
156004
- if (!diag || !diag.relatedInformation)
156017
+ if (diag === undefined || diag.relatedInformation === undefined)
156005
156018
  return;
156006
156019
  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)
156020
+ if (related === undefined || related.file === undefined || related.start === undefined || related.length === undefined)
156008
156021
  return;
156009
- return related;
156010
- }
156011
- function addMissingConstraint(changes, related) {
156012
- var decl = findAncestorMatchingSpan(related.file, related);
156013
- if (!decl)
156022
+ var declaration = findAncestorMatchingSpan(related.file, ts.createTextSpan(related.start, related.length));
156023
+ if (declaration === undefined)
156014
156024
  return;
156015
- if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
156016
- decl = decl.parent;
156025
+ if (ts.isIdentifier(declaration) && ts.isTypeParameterDeclaration(declaration.parent)) {
156026
+ declaration = declaration.parent;
156027
+ }
156028
+ if (ts.isTypeParameterDeclaration(declaration)) {
156029
+ // should only issue fix on type parameters written using `extends`
156030
+ if (ts.isMappedTypeNode(declaration.parent))
156031
+ return;
156032
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156033
+ var checker = program.getTypeChecker();
156034
+ var constraint = tryGetConstraintType(checker, token) || tryGetConstraintFromDiagnosticMessage(related.messageText);
156035
+ return { constraint: constraint, declaration: declaration, token: token };
156036
+ }
156037
+ return undefined;
156038
+ }
156039
+ function addMissingConstraint(changes, program, preferences, host, sourceFile, info) {
156040
+ var declaration = info.declaration, constraint = info.constraint;
156041
+ var checker = program.getTypeChecker();
156042
+ if (ts.isString(constraint)) {
156043
+ changes.insertText(sourceFile, declaration.name.end, " extends " + constraint);
156044
+ }
156045
+ else {
156046
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156047
+ var tracker = codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host });
156048
+ var importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
156049
+ var typeNode = codefix.typeToAutoImportableTypeNode(checker, importAdder, constraint, /*contextNode*/ undefined, scriptTarget, /*flags*/ undefined, tracker);
156050
+ if (typeNode) {
156051
+ changes.replaceNode(sourceFile, declaration, ts.factory.updateTypeParameterDeclaration(declaration, /*modifiers*/ undefined, declaration.name, typeNode, declaration.default));
156052
+ importAdder.writeFixes(changes);
156053
+ }
156017
156054
  }
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
156055
  }
156026
156056
  function findAncestorMatchingSpan(sourceFile, span) {
156027
- var token = ts.getTokenAtPosition(sourceFile, span.start);
156028
156057
  var end = ts.textSpanEnd(span);
156058
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156029
156059
  while (token.end < end) {
156030
156060
  token = token.parent;
156031
156061
  }
156032
156062
  return token;
156033
156063
  }
156064
+ function tryGetConstraintFromDiagnosticMessage(messageText) {
156065
+ var _a = ts.flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [], _ = _a[0], constraint = _a[1];
156066
+ return constraint;
156067
+ }
156068
+ function tryGetConstraintType(checker, node) {
156069
+ if (ts.isTypeNode(node.parent)) {
156070
+ return checker.getTypeArgumentConstraint(node.parent);
156071
+ }
156072
+ var contextualType = ts.isExpression(node) ? checker.getContextualType(node) : undefined;
156073
+ return contextualType || checker.getTypeAtLocation(node);
156074
+ }
156034
156075
  })(codefix = ts.codefix || (ts.codefix = {}));
156035
156076
  })(ts || (ts = {}));
156036
156077
  /* @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.20220725";
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) {
@@ -68131,37 +68133,33 @@ var ts;
68131
68133
  var commonBaseType;
68132
68134
  for (var _i = 0, types_13 = types; _i < types_13.length; _i++) {
68133
68135
  var t = types_13[_i];
68134
- var baseType = getBaseTypeOfLiteralType(t);
68135
- if (!commonBaseType) {
68136
- commonBaseType = baseType;
68137
- }
68138
- if (baseType === t || baseType !== commonBaseType) {
68139
- return false;
68136
+ if (!(t.flags & 131072 /* Never */)) {
68137
+ var baseType = getBaseTypeOfLiteralType(t);
68138
+ commonBaseType !== null && commonBaseType !== void 0 ? commonBaseType : (commonBaseType = baseType);
68139
+ if (baseType === t || baseType !== commonBaseType) {
68140
+ return false;
68141
+ }
68140
68142
  }
68141
68143
  }
68142
68144
  return true;
68143
68145
  }
68144
- // When the candidate types are all literal types with the same base type, return a union
68145
- // of those literal types. Otherwise, return the leftmost type for which no type to the
68146
- // right is a supertype.
68147
- function getSupertypeOrUnion(types) {
68148
- if (types.length === 1) {
68149
- return types[0];
68150
- }
68151
- return literalTypesWithSameBaseType(types) ?
68152
- getUnionType(types) :
68153
- ts.reduceLeft(types, function (s, t) { return isTypeSubtypeOf(s, t) ? t : s; });
68146
+ function getCombinedTypeFlags(types) {
68147
+ return ts.reduceLeft(types, function (flags, t) { return flags | (t.flags & 1048576 /* Union */ ? getCombinedTypeFlags(t.types) : t.flags); }, 0);
68154
68148
  }
68155
68149
  function getCommonSupertype(types) {
68156
- if (!strictNullChecks) {
68157
- return getSupertypeOrUnion(types);
68158
- }
68159
- var primaryTypes = ts.filter(types, function (t) { return !(t.flags & 98304 /* Nullable */); });
68160
- if (primaryTypes.length) {
68161
- var supertypeOrUnion = getSupertypeOrUnion(primaryTypes);
68162
- return primaryTypes === types ? supertypeOrUnion : getUnionType(__spreadArray([supertypeOrUnion], ts.filter(types, function (t) { return !!(t.flags & 98304 /* Nullable */); }), true));
68150
+ if (types.length === 1) {
68151
+ return types[0];
68163
68152
  }
68164
- return getUnionType(types, 2 /* Subtype */);
68153
+ // Remove nullable types from each of the candidates.
68154
+ var primaryTypes = strictNullChecks ? ts.sameMap(types, function (t) { return filterType(t, function (u) { return !(u.flags & 98304 /* Nullable */); }); }) : types;
68155
+ // When the candidate types are all literal types with the same base type, return a union
68156
+ // of those literal types. Otherwise, return the leftmost type for which no type to the
68157
+ // right is a supertype.
68158
+ var superTypeOrUnion = literalTypesWithSameBaseType(primaryTypes) ?
68159
+ getUnionType(primaryTypes) :
68160
+ ts.reduceLeft(primaryTypes, function (s, t) { return isTypeSubtypeOf(s, t) ? t : s; });
68161
+ // Add any nullable types that occurred in the candidates back to the result.
68162
+ return primaryTypes === types ? superTypeOrUnion : getNullableType(superTypeOrUnion, getCombinedTypeFlags(types) & 98304 /* Nullable */);
68165
68163
  }
68166
68164
  // Return the leftmost type for which no type to the right is a subtype.
68167
68165
  function getCommonSubtype(types) {
@@ -79823,7 +79821,11 @@ var ts;
79823
79821
  var operator = operatorToken.kind;
79824
79822
  if (operator === 55 /* AmpersandAmpersandToken */ || operator === 56 /* BarBarToken */ || operator === 60 /* QuestionQuestionToken */) {
79825
79823
  if (operator === 55 /* AmpersandAmpersandToken */) {
79826
- var parent = ts.walkUpParenthesizedExpressions(node.parent);
79824
+ var parent = node.parent;
79825
+ while (parent.kind === 212 /* ParenthesizedExpression */
79826
+ || ts.isBinaryExpression(parent) && (parent.operatorToken.kind === 55 /* AmpersandAmpersandToken */ || parent.operatorToken.kind === 56 /* BarBarToken */)) {
79827
+ parent = parent.parent;
79828
+ }
79827
79829
  checkTestingKnownTruthyCallableOrAwaitableType(node.left, ts.isIfStatement(parent) ? parent.thenStatement : undefined);
79828
79830
  }
79829
79831
  checkTruthinessOfType(leftType, node.left);
@@ -90745,13 +90747,13 @@ var ts;
90745
90747
  return factory.updateInferTypeNode(node, nodeVisitor(node.typeParameter, visitor, ts.isTypeParameterDeclaration));
90746
90748
  case 200 /* ImportType */:
90747
90749
  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);
90750
+ 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
90751
  case 295 /* ImportTypeAssertionContainer */:
90750
90752
  ts.Debug.type(node);
90751
90753
  return factory.updateImportTypeAssertionContainer(node, nodeVisitor(node.assertClause, visitor, ts.isNode), node.multiLine);
90752
90754
  case 197 /* NamedTupleMember */:
90753
90755
  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));
90756
+ 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
90757
  case 191 /* ParenthesizedType */:
90756
90758
  ts.Debug.type(node);
90757
90759
  return factory.updateParenthesizedType(node, nodeVisitor(node.type, visitor, ts.isTypeNode));
@@ -90816,7 +90818,7 @@ var ts;
90816
90818
  return factory.updateNewExpression(node, nodeVisitor(node.expression, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodesVisitor(node.arguments, visitor, ts.isExpression));
90817
90819
  case 210 /* TaggedTemplateExpression */:
90818
90820
  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));
90821
+ return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, ts.isExpression), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode), nodeVisitor(node.template, visitor, ts.isTemplateLiteral));
90820
90822
  case 211 /* TypeAssertionExpression */:
90821
90823
  ts.Debug.type(node);
90822
90824
  return factory.updateTypeAssertion(node, nodeVisitor(node.type, visitor, ts.isTypeNode), nodeVisitor(node.expression, visitor, ts.isExpression));
@@ -149449,6 +149451,7 @@ var ts;
149449
149451
  consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
149450
149452
  }
149451
149453
  function processChildNode(child, inheritedIndentation, parent, parentDynamicIndentation, parentStartLine, undecoratedParentStartLine, isListItem, isFirstListItem) {
149454
+ ts.Debug.assert(!ts.nodeIsSynthesized(child));
149452
149455
  if (ts.nodeIsMissing(child)) {
149453
149456
  return inheritedIndentation;
149454
149457
  }
@@ -149515,6 +149518,7 @@ var ts;
149515
149518
  }
149516
149519
  function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) {
149517
149520
  ts.Debug.assert(ts.isNodeArray(nodes));
149521
+ ts.Debug.assert(!ts.nodeIsSynthesized(nodes));
149518
149522
  var listStartToken = getOpenTokenForList(parent, nodes);
149519
149523
  var listDynamicIndentation = parentDynamicIndentation;
149520
149524
  var startLine = parentStartLine;
@@ -155974,54 +155978,91 @@ var ts;
155974
155978
  codefix.registerCodeFix({
155975
155979
  errorCodes: errorCodes,
155976
155980
  getCodeActions: function (context) {
155977
- var sourceFile = context.sourceFile, span = context.span, program = context.program;
155978
- var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155979
- if (!related) {
155981
+ var sourceFile = context.sourceFile, span = context.span, program = context.program, preferences = context.preferences, host = context.host;
155982
+ var info = getInfo(program, sourceFile, span);
155983
+ if (info === undefined)
155980
155984
  return;
155981
- }
155982
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155985
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, program, preferences, host, sourceFile, info); });
155983
155986
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155984
155987
  },
155985
155988
  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
- }); },
155989
+ getAllCodeActions: function (context) {
155990
+ var program = context.program, preferences = context.preferences, host = context.host;
155991
+ var seen = new ts.Map();
155992
+ return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
155993
+ codefix.eachDiagnostic(context, errorCodes, function (diag) {
155994
+ var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
155995
+ if (info) {
155996
+ var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
155997
+ if (ts.addToSeen(seen, id)) {
155998
+ return addMissingConstraint(changes, program, preferences, host, diag.file, info);
155999
+ }
156000
+ }
156001
+ return undefined;
156002
+ });
156003
+ }));
156004
+ }
155992
156005
  });
155993
- function getDiagnosticRelatedInfo(program, sourceFile, span) {
156006
+ function getInfo(program, sourceFile, span) {
155994
156007
  var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155995
- if (!diag || !diag.relatedInformation)
156008
+ if (diag === undefined || diag.relatedInformation === undefined)
155996
156009
  return;
155997
156010
  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)
156011
+ if (related === undefined || related.file === undefined || related.start === undefined || related.length === undefined)
155999
156012
  return;
156000
- return related;
156001
- }
156002
- function addMissingConstraint(changes, related) {
156003
- var decl = findAncestorMatchingSpan(related.file, related);
156004
- if (!decl)
156013
+ var declaration = findAncestorMatchingSpan(related.file, ts.createTextSpan(related.start, related.length));
156014
+ if (declaration === undefined)
156005
156015
  return;
156006
- if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
156007
- decl = decl.parent;
156016
+ if (ts.isIdentifier(declaration) && ts.isTypeParameterDeclaration(declaration.parent)) {
156017
+ declaration = declaration.parent;
156018
+ }
156019
+ if (ts.isTypeParameterDeclaration(declaration)) {
156020
+ // should only issue fix on type parameters written using `extends`
156021
+ if (ts.isMappedTypeNode(declaration.parent))
156022
+ return;
156023
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156024
+ var checker = program.getTypeChecker();
156025
+ var constraint = tryGetConstraintType(checker, token) || tryGetConstraintFromDiagnosticMessage(related.messageText);
156026
+ return { constraint: constraint, declaration: declaration, token: token };
156027
+ }
156028
+ return undefined;
156029
+ }
156030
+ function addMissingConstraint(changes, program, preferences, host, sourceFile, info) {
156031
+ var declaration = info.declaration, constraint = info.constraint;
156032
+ var checker = program.getTypeChecker();
156033
+ if (ts.isString(constraint)) {
156034
+ changes.insertText(sourceFile, declaration.name.end, " extends " + constraint);
156035
+ }
156036
+ else {
156037
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156038
+ var tracker = codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host });
156039
+ var importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
156040
+ var typeNode = codefix.typeToAutoImportableTypeNode(checker, importAdder, constraint, /*contextNode*/ undefined, scriptTarget, /*flags*/ undefined, tracker);
156041
+ if (typeNode) {
156042
+ changes.replaceNode(sourceFile, declaration, ts.factory.updateTypeParameterDeclaration(declaration, /*modifiers*/ undefined, declaration.name, typeNode, declaration.default));
156043
+ importAdder.writeFixes(changes);
156044
+ }
156008
156045
  }
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
156046
  }
156017
156047
  function findAncestorMatchingSpan(sourceFile, span) {
156018
- var token = ts.getTokenAtPosition(sourceFile, span.start);
156019
156048
  var end = ts.textSpanEnd(span);
156049
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
156020
156050
  while (token.end < end) {
156021
156051
  token = token.parent;
156022
156052
  }
156023
156053
  return token;
156024
156054
  }
156055
+ function tryGetConstraintFromDiagnosticMessage(messageText) {
156056
+ var _a = ts.flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [], _ = _a[0], constraint = _a[1];
156057
+ return constraint;
156058
+ }
156059
+ function tryGetConstraintType(checker, node) {
156060
+ if (ts.isTypeNode(node.parent)) {
156061
+ return checker.getTypeArgumentConstraint(node.parent);
156062
+ }
156063
+ var contextualType = ts.isExpression(node) ? checker.getContextualType(node) : undefined;
156064
+ return contextualType || checker.getTypeAtLocation(node);
156065
+ }
156025
156066
  })(codefix = ts.codefix || (ts.codefix = {}));
156026
156067
  })(ts || (ts = {}));
156027
156068
  /* @internal */