typescript 4.7.0-dev.20220330 → 4.7.0-dev.20220331

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/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220330";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220331";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -9495,6 +9495,7 @@ var ts;
9495
9495
  An_expanded_version_of_this_information_showing_all_possible_compiler_options: diag(6928, ts.DiagnosticCategory.Message, "An_expanded_version_of_this_information_showing_all_possible_compiler_options_6928", "An expanded version of this information, showing all possible compiler options"),
9496
9496
  Compiles_the_current_project_with_additional_settings: diag(6929, ts.DiagnosticCategory.Message, "Compiles_the_current_project_with_additional_settings_6929", "Compiles the current project, with additional settings."),
9497
9497
  true_for_ES2022_and_above_including_ESNext: diag(6930, ts.DiagnosticCategory.Message, "true_for_ES2022_and_above_including_ESNext_6930", "`true` for ES2022 and above, including ESNext."),
9498
+ List_of_file_name_suffixes_to_search_when_resolving_a_module: diag(6931, ts.DiagnosticCategory.Error, "List_of_file_name_suffixes_to_search_when_resolving_a_module_6931", "List of file name suffixes to search when resolving a module."),
9498
9499
  Variable_0_implicitly_has_an_1_type: diag(7005, ts.DiagnosticCategory.Error, "Variable_0_implicitly_has_an_1_type_7005", "Variable '{0}' implicitly has an '{1}' type."),
9499
9500
  Parameter_0_implicitly_has_an_1_type: diag(7006, ts.DiagnosticCategory.Error, "Parameter_0_implicitly_has_an_1_type_7006", "Parameter '{0}' implicitly has an '{1}' type."),
9500
9501
  Member_0_implicitly_has_an_1_type: diag(7008, ts.DiagnosticCategory.Error, "Member_0_implicitly_has_an_1_type_7008", "Member '{0}' implicitly has an '{1}' type."),
@@ -39489,6 +39490,18 @@ var ts;
39489
39490
  description: ts.Diagnostics.Allow_accessing_UMD_globals_from_modules,
39490
39491
  defaultValueDescription: false,
39491
39492
  },
39493
+ {
39494
+ name: "moduleSuffixes",
39495
+ type: "list",
39496
+ element: {
39497
+ name: "suffix",
39498
+ type: "string",
39499
+ },
39500
+ listPreserveFalsyValues: true,
39501
+ affectsModuleResolution: true,
39502
+ category: ts.Diagnostics.Modules,
39503
+ description: ts.Diagnostics.List_of_file_name_suffixes_to_search_when_resolving_a_module,
39504
+ },
39492
39505
  // Source Maps
39493
39506
  {
39494
39507
  name: "sourceRoot",
@@ -41415,7 +41428,7 @@ var ts;
41415
41428
  if (option.type === "list") {
41416
41429
  var listOption_1 = option;
41417
41430
  if (listOption_1.element.isFilePath || !ts.isString(listOption_1.element.type)) {
41418
- return ts.filter(ts.map(value, function (v) { return normalizeOptionValue(listOption_1.element, basePath, v); }), function (v) { return !!v; });
41431
+ return ts.filter(ts.map(value, function (v) { return normalizeOptionValue(listOption_1.element, basePath, v); }), function (v) { return listOption_1.listPreserveFalsyValues ? true : !!v; });
41419
41432
  }
41420
41433
  return value;
41421
41434
  }
@@ -41456,7 +41469,7 @@ var ts;
41456
41469
  }
41457
41470
  }
41458
41471
  function convertJsonOptionOfListType(option, values, basePath, errors) {
41459
- return ts.filter(ts.map(values, function (v) { return convertJsonOption(option.element, v, basePath, errors); }), function (v) { return !!v; });
41472
+ return ts.filter(ts.map(values, function (v) { return convertJsonOption(option.element, v, basePath, errors); }), function (v) { return option.listPreserveFalsyValues ? true : !!v; });
41460
41473
  }
41461
41474
  /**
41462
41475
  * Tests for a path that ends in a recursive directory wildcard.
@@ -43082,6 +43095,15 @@ var ts;
43082
43095
  }
43083
43096
  /** Return the file if it exists. */
43084
43097
  function tryFile(fileName, onlyRecordFailures, state) {
43098
+ var _a, _b;
43099
+ if (!((_a = state.compilerOptions.moduleSuffixes) === null || _a === void 0 ? void 0 : _a.length)) {
43100
+ return tryFileLookup(fileName, onlyRecordFailures, state);
43101
+ }
43102
+ var ext = (_b = ts.tryGetExtensionFromPath(fileName)) !== null && _b !== void 0 ? _b : "";
43103
+ var fileNameNoExtension = ext ? ts.removeExtension(fileName, ext) : fileName;
43104
+ return ts.forEach(state.compilerOptions.moduleSuffixes, function (suffix) { return tryFileLookup(fileNameNoExtension + suffix + ext, onlyRecordFailures, state); });
43105
+ }
43106
+ function tryFileLookup(fileName, onlyRecordFailures, state) {
43085
43107
  if (!onlyRecordFailures) {
43086
43108
  if (state.host.fileExists(fileName)) {
43087
43109
  if (state.traceEnabled) {
@@ -52077,7 +52099,15 @@ var ts;
52077
52099
  if (!ts.nodeIsSynthesized(node) && ts.getParseTreeNode(node) === node) {
52078
52100
  return node;
52079
52101
  }
52080
- return ts.setTextRange(ts.factory.cloneNode(ts.visitEachChild(node, deepCloneOrReuseNode, ts.nullTransformationContext)), node);
52102
+ return ts.setTextRange(ts.factory.cloneNode(ts.visitEachChild(node, deepCloneOrReuseNode, ts.nullTransformationContext, deepCloneOrReuseNodes)), node);
52103
+ }
52104
+ function deepCloneOrReuseNodes(nodes, visitor, test, start, count) {
52105
+ if (nodes && nodes.length === 0) {
52106
+ // Ensure we explicitly make a copy of an empty array; visitNodes will not do this unless the array has elements,
52107
+ // which can lead to us reusing the same empty NodeArray more than once within the same AST during type noding.
52108
+ return ts.setTextRange(ts.factory.createNodeArray(/*nodes*/ undefined, nodes.hasTrailingComma), nodes);
52109
+ }
52110
+ return ts.visitNodes(nodes, visitor, test, start, count);
52081
52111
  }
52082
52112
  }
52083
52113
  function createTypeNodeFromObjectType(type) {
@@ -70807,7 +70837,7 @@ var ts;
70807
70837
  if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
70808
70838
  var contextualSignature = getContextualSignature(func);
70809
70839
  if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
70810
- var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
70840
+ var restType = getReducedApparentType(getTypeOfSymbol(contextualSignature.parameters[0]));
70811
70841
  if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
70812
70842
  var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
70813
70843
  var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
@@ -72112,9 +72142,14 @@ var ts;
72112
72142
  return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72113
72143
  }
72114
72144
  // For other purposes (e.g. determining whether to produce literal types) we only
72115
- // incorporate inferences made from the return type in a function call.
72145
+ // incorporate inferences made from the return type in a function call. We remove
72146
+ // the 'boolean' type from the contextual type such that contextually typed boolean
72147
+ // literals actually end up widening to 'boolean' (see #48363).
72116
72148
  if (inferenceContext.returnMapper) {
72117
- return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72149
+ var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72150
+ return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72151
+ filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72152
+ type;
72118
72153
  }
72119
72154
  }
72120
72155
  }
@@ -130919,6 +130954,7 @@ var ts;
130919
130954
  var source = getSourceFromOrigin(origin);
130920
130955
  var sourceDisplay;
130921
130956
  var hasAction;
130957
+ var labelDetails;
130922
130958
  var typeChecker = program.getTypeChecker();
130923
130959
  var insertQuestionDot = origin && originIsNullableMember(origin);
130924
130960
  var useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess;
@@ -130987,7 +131023,11 @@ var ts;
130987
131023
  }
130988
131024
  if (origin && originIsObjectLiteralMethod(origin)) {
130989
131025
  var importAdder = void 0;
130990
- (insertText = origin.insertText, isSnippet = origin.isSnippet, importAdder = origin.importAdder, sourceDisplay = origin.sourceDisplay);
131026
+ (insertText = origin.insertText, isSnippet = origin.isSnippet, importAdder = origin.importAdder, labelDetails = origin.labelDetails);
131027
+ if (!preferences.useLabelDetailsInCompletionEntries) {
131028
+ name = name + labelDetails.detail;
131029
+ labelDetails = undefined;
131030
+ }
130991
131031
  source = CompletionSource.ObjectLiteralMethodSnippet;
130992
131032
  sortText = Completions.SortText.SortBelow(sortText);
130993
131033
  if (importAdder.hasFixes()) {
@@ -131041,6 +131081,7 @@ var ts;
131041
131081
  insertText: insertText,
131042
131082
  replacementSpan: replacementSpan,
131043
131083
  sourceDisplay: sourceDisplay,
131084
+ labelDetails: labelDetails,
131044
131085
  isSnippet: isSnippet,
131045
131086
  isPackageJsonImport: originIsPackageJsonImport(origin) || undefined,
131046
131087
  isImportStatementCompletion: !!importCompletionNode || undefined,
@@ -131232,9 +131273,19 @@ var ts;
131232
131273
  else {
131233
131274
  insertText = printer.printSnippetList(16 /* CommaDelimited */ | 64 /* AllowTrailingComma */, ts.factory.createNodeArray([method], /*hasTrailingComma*/ true), sourceFile);
131234
131275
  }
131235
- var methodSignature = ts.factory.createMethodSignature(method.modifiers, method.name, method.questionToken, method.typeParameters, method.parameters, method.type);
131236
- var sourceDisplay = ts.nodeToDisplayParts(methodSignature, enclosingDeclaration);
131237
- return { isSnippet: isSnippet, insertText: insertText, importAdder: importAdder, sourceDisplay: sourceDisplay };
131276
+ var signaturePrinter = ts.createPrinter({
131277
+ removeComments: true,
131278
+ module: options.module,
131279
+ target: options.target,
131280
+ omitTrailingSemicolon: true,
131281
+ });
131282
+ // The `labelDetails.detail` will be displayed right beside the method name,
131283
+ // so we drop the name (and modifiers) from the signature.
131284
+ var methodSignature = ts.factory.createMethodSignature(
131285
+ /*modifiers*/ undefined,
131286
+ /*name*/ "", method.questionToken, method.typeParameters, method.parameters, method.type);
131287
+ var labelDetails = { detail: signaturePrinter.printNode(4 /* Unspecified */, methodSignature, sourceFile) };
131288
+ return { isSnippet: isSnippet, insertText: insertText, importAdder: importAdder, labelDetails: labelDetails };
131238
131289
  }
131239
131290
  ;
131240
131291
  function createObjectLiteralMethod(symbol, enclosingDeclaration, sourceFile, program, host, preferences, importAdder) {
@@ -138783,7 +138834,8 @@ var ts;
138783
138834
  return undefined;
138784
138835
  }
138785
138836
  var commentOwner = commentOwnerInfo.commentOwner, parameters = commentOwnerInfo.parameters, hasReturn = commentOwnerInfo.hasReturn;
138786
- if (commentOwner.getStart(sourceFile) < position) {
138837
+ var commentOwnerJSDoc = ts.hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? ts.lastOrUndefined(commentOwner.jsDoc) : undefined;
138838
+ if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) {
138787
138839
  return undefined;
138788
138840
  }
138789
138841
  var indentationStr = getIndentationStringAtPosition(sourceFile, position);
@@ -147477,25 +147529,25 @@ var ts;
147477
147529
  suffix: this.newLineCharacter
147478
147530
  });
147479
147531
  };
147480
- ChangeTracker.prototype.insertNodeAtClassStart = function (sourceFile, cls, newElement) {
147481
- this.insertNodeAtStartWorker(sourceFile, cls, newElement);
147532
+ ChangeTracker.prototype.insertMemberAtStart = function (sourceFile, node, newElement) {
147533
+ this.insertNodeAtStartWorker(sourceFile, node, newElement);
147482
147534
  };
147483
147535
  ChangeTracker.prototype.insertNodeAtObjectStart = function (sourceFile, obj, newElement) {
147484
147536
  this.insertNodeAtStartWorker(sourceFile, obj, newElement);
147485
147537
  };
147486
- ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile, cls, newElement) {
147538
+ ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile, node, newElement) {
147487
147539
  var _a;
147488
- var indentation = (_a = this.guessIndentationFromExistingMembers(sourceFile, cls)) !== null && _a !== void 0 ? _a : this.computeIndentationForNewMember(sourceFile, cls);
147489
- this.insertNodeAt(sourceFile, getMembersOrProperties(cls).pos, newElement, this.getInsertNodeAtStartInsertOptions(sourceFile, cls, indentation));
147540
+ var indentation = (_a = this.guessIndentationFromExistingMembers(sourceFile, node)) !== null && _a !== void 0 ? _a : this.computeIndentationForNewMember(sourceFile, node);
147541
+ this.insertNodeAt(sourceFile, getMembersOrProperties(node).pos, newElement, this.getInsertNodeAtStartInsertOptions(sourceFile, node, indentation));
147490
147542
  };
147491
147543
  /**
147492
147544
  * Tries to guess the indentation from the existing members of a class/interface/object. All members must be on
147493
147545
  * new lines and must share the same indentation.
147494
147546
  */
147495
- ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile, cls) {
147547
+ ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile, node) {
147496
147548
  var indentation;
147497
- var lastRange = cls;
147498
- for (var _i = 0, _a = getMembersOrProperties(cls); _i < _a.length; _i++) {
147549
+ var lastRange = node;
147550
+ for (var _i = 0, _a = getMembersOrProperties(node); _i < _a.length; _i++) {
147499
147551
  var member = _a[_i];
147500
147552
  if (ts.rangeStartPositionsAreOnSameLine(lastRange, member, sourceFile)) {
147501
147553
  // each indented member must be on a new line
@@ -147514,13 +147566,13 @@ var ts;
147514
147566
  }
147515
147567
  return indentation;
147516
147568
  };
147517
- ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile, cls) {
147569
+ ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile, node) {
147518
147570
  var _a;
147519
- var clsStart = cls.getStart(sourceFile);
147520
- return ts.formatting.SmartIndenter.findFirstNonWhitespaceColumn(ts.getLineStartPositionForPosition(clsStart, sourceFile), clsStart, sourceFile, this.formatContext.options)
147571
+ var nodeStart = node.getStart(sourceFile);
147572
+ return ts.formatting.SmartIndenter.findFirstNonWhitespaceColumn(ts.getLineStartPositionForPosition(nodeStart, sourceFile), nodeStart, sourceFile, this.formatContext.options)
147521
147573
  + ((_a = this.formatContext.options.indentSize) !== null && _a !== void 0 ? _a : 4);
147522
147574
  };
147523
- ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile, cls, indentation) {
147575
+ ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile, node, indentation) {
147524
147576
  // Rules:
147525
147577
  // - Always insert leading newline.
147526
147578
  // - For object literals:
@@ -147530,11 +147582,11 @@ var ts;
147530
147582
  // and the node is empty (because we didn't add a trailing comma per the previous rule).
147531
147583
  // - Only insert a trailing newline if body is single-line and there are no other insertions for the node.
147532
147584
  // NOTE: This is handled in `finishClassesWithNodesInsertedAtStart`.
147533
- var members = getMembersOrProperties(cls);
147585
+ var members = getMembersOrProperties(node);
147534
147586
  var isEmpty = members.length === 0;
147535
- var isFirstInsertion = ts.addToSeen(this.classesWithNodesInsertedAtStart, ts.getNodeId(cls), { node: cls, sourceFile: sourceFile });
147536
- var insertTrailingComma = ts.isObjectLiteralExpression(cls) && (!ts.isJsonSourceFile(sourceFile) || !isEmpty);
147537
- var insertLeadingComma = ts.isObjectLiteralExpression(cls) && ts.isJsonSourceFile(sourceFile) && isEmpty && !isFirstInsertion;
147587
+ var isFirstInsertion = ts.addToSeen(this.classesWithNodesInsertedAtStart, ts.getNodeId(node), { node: node, sourceFile: sourceFile });
147588
+ var insertTrailingComma = ts.isObjectLiteralExpression(node) && (!ts.isJsonSourceFile(sourceFile) || !isEmpty);
147589
+ var insertLeadingComma = ts.isObjectLiteralExpression(node) && ts.isJsonSourceFile(sourceFile) && isEmpty && !isFirstInsertion;
147538
147590
  return {
147539
147591
  indentation: indentation,
147540
147592
  prefix: (insertLeadingComma ? "," : "") + this.newLineCharacter,
@@ -147828,8 +147880,8 @@ var ts;
147828
147880
  var close = ts.findChildOfKind(cls, 19 /* CloseBraceToken */, sourceFile);
147829
147881
  return [open === null || open === void 0 ? void 0 : open.end, close === null || close === void 0 ? void 0 : close.end];
147830
147882
  }
147831
- function getMembersOrProperties(cls) {
147832
- return ts.isObjectLiteralExpression(cls) ? cls.properties : cls.members;
147883
+ function getMembersOrProperties(node) {
147884
+ return ts.isObjectLiteralExpression(node) ? node.properties : node.members;
147833
147885
  }
147834
147886
  function getNewFileText(statements, scriptKind, newLineCharacter, formatContext) {
147835
147887
  return changesToText.newFileChangesWorker(/*oldFile*/ undefined, scriptKind, statements, newLineCharacter, formatContext);
@@ -151112,7 +151164,7 @@ var ts;
151112
151164
  changeTracker.insertNodeAfter(sourceFile, constructor, newElement);
151113
151165
  }
151114
151166
  else {
151115
- changeTracker.insertNodeAtClassStart(sourceFile, cls, newElement);
151167
+ changeTracker.insertMemberAtStart(sourceFile, cls, newElement);
151116
151168
  }
151117
151169
  }
151118
151170
  }
@@ -152896,7 +152948,7 @@ var ts;
152896
152948
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addFunctionDeclaration(t, context, info); });
152897
152949
  return [codefix.createCodeFixAction(fixMissingFunctionDeclaration, changes, [ts.Diagnostics.Add_missing_function_declaration_0, info.token.text], fixMissingFunctionDeclaration, ts.Diagnostics.Add_all_missing_function_declarations)];
152898
152950
  }
152899
- if (info.kind === 0 /* Enum */) {
152951
+ if (info.kind === 1 /* Enum */) {
152900
152952
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addEnumMemberDeclaration(t, context.program.getTypeChecker(), info); });
152901
152953
  return [codefix.createCodeFixAction(fixMissingMember, changes, [ts.Diagnostics.Add_missing_enum_member_0, info.token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members)];
152902
152954
  }
@@ -152924,10 +152976,10 @@ var ts;
152924
152976
  addJsxAttributes(changes, context, info);
152925
152977
  }
152926
152978
  else {
152927
- if (info.kind === 0 /* Enum */) {
152979
+ if (info.kind === 1 /* Enum */) {
152928
152980
  addEnumMemberDeclaration(changes, checker, info);
152929
152981
  }
152930
- if (info.kind === 1 /* ClassOrInterface */) {
152982
+ if (info.kind === 0 /* TypeLikeDeclaration */) {
152931
152983
  var parentDeclaration = info.parentDeclaration, token_1 = info.token;
152932
152984
  var infos = ts.getOrUpdate(typeDeclToMembers, parentDeclaration, function () { return []; });
152933
152985
  if (!infos.some(function (i) { return i.token.text === token_1.text; })) {
@@ -152936,11 +152988,11 @@ var ts;
152936
152988
  }
152937
152989
  }
152938
152990
  });
152939
- typeDeclToMembers.forEach(function (infos, classDeclaration) {
152940
- var supers = codefix.getAllSupers(classDeclaration, checker);
152991
+ typeDeclToMembers.forEach(function (infos, declaration) {
152992
+ var supers = ts.isTypeLiteralNode(declaration) ? undefined : codefix.getAllSupers(declaration, checker);
152941
152993
  var _loop_15 = function (info) {
152942
152994
  // If some superclass added this property, don't add it again.
152943
- if (supers.some(function (superClassOrInterface) {
152995
+ if (supers === null || supers === void 0 ? void 0 : supers.some(function (superClassOrInterface) {
152944
152996
  var superInfos = typeDeclToMembers.get(superClassOrInterface);
152945
152997
  return !!superInfos && superInfos.some(function (_a) {
152946
152998
  var token = _a.token;
@@ -152954,11 +153006,11 @@ var ts;
152954
153006
  addMethodDeclaration(context, changes, call, token, modifierFlags & 32 /* Static */, parentDeclaration, declSourceFile);
152955
153007
  }
152956
153008
  else {
152957
- if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration)) {
153009
+ if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration) && !ts.isTypeLiteralNode(parentDeclaration)) {
152958
153010
  addMissingMemberInJs(changes, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */));
152959
153011
  }
152960
153012
  else {
152961
- var typeNode = getTypeNode(program.getTypeChecker(), parentDeclaration, token);
153013
+ var typeNode = getTypeNode(checker, parentDeclaration, token);
152962
153014
  addPropertyDeclaration(changes, declSourceFile, parentDeclaration, token.text, typeNode, modifierFlags & 32 /* Static */);
152963
153015
  }
152964
153016
  }
@@ -152973,8 +153025,8 @@ var ts;
152973
153025
  });
152974
153026
  var InfoKind;
152975
153027
  (function (InfoKind) {
152976
- InfoKind[InfoKind["Enum"] = 0] = "Enum";
152977
- InfoKind[InfoKind["ClassOrInterface"] = 1] = "ClassOrInterface";
153028
+ InfoKind[InfoKind["TypeLikeDeclaration"] = 0] = "TypeLikeDeclaration";
153029
+ InfoKind[InfoKind["Enum"] = 1] = "Enum";
152978
153030
  InfoKind[InfoKind["Function"] = 2] = "Function";
152979
153031
  InfoKind[InfoKind["ObjectLiteral"] = 3] = "ObjectLiteral";
152980
153032
  InfoKind[InfoKind["JsxAttributes"] = 4] = "JsxAttributes";
@@ -153044,20 +153096,21 @@ var ts;
153044
153096
  if (!classDeclaration && ts.isPrivateIdentifier(token))
153045
153097
  return undefined;
153046
153098
  // Prefer to change the class instead of the interface if they are merged
153047
- var classOrInterface = classDeclaration || ts.find(symbol.declarations, ts.isInterfaceDeclaration);
153048
- if (classOrInterface && !isSourceFileFromLibrary(program, classOrInterface.getSourceFile())) {
153049
- var makeStatic = (leftExpressionType.target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
153050
- if (makeStatic && (ts.isPrivateIdentifier(token) || ts.isInterfaceDeclaration(classOrInterface)))
153099
+ var declaration = classDeclaration || ts.find(symbol.declarations, function (d) { return ts.isInterfaceDeclaration(d) || ts.isTypeLiteralNode(d); });
153100
+ if (declaration && !isSourceFileFromLibrary(program, declaration.getSourceFile())) {
153101
+ var makeStatic = !ts.isTypeLiteralNode(declaration) && (leftExpressionType.target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
153102
+ if (makeStatic && (ts.isPrivateIdentifier(token) || ts.isInterfaceDeclaration(declaration)))
153051
153103
  return undefined;
153052
- var declSourceFile = classOrInterface.getSourceFile();
153053
- var modifierFlags = (makeStatic ? 32 /* Static */ : 0) | (ts.startsWithUnderscore(token.text) ? 8 /* Private */ : 0);
153104
+ var declSourceFile = declaration.getSourceFile();
153105
+ var modifierFlags = ts.isTypeLiteralNode(declaration) ? 0 /* None */ :
153106
+ (makeStatic ? 32 /* Static */ : 0 /* None */) | (ts.startsWithUnderscore(token.text) ? 8 /* Private */ : 0 /* None */);
153054
153107
  var isJSFile = ts.isSourceFileJS(declSourceFile);
153055
153108
  var call = ts.tryCast(parent.parent, ts.isCallExpression);
153056
- return { kind: 1 /* ClassOrInterface */, token: token, call: call, modifierFlags: modifierFlags, parentDeclaration: classOrInterface, declSourceFile: declSourceFile, isJSFile: isJSFile };
153109
+ return { kind: 0 /* TypeLikeDeclaration */, token: token, call: call, modifierFlags: modifierFlags, parentDeclaration: declaration, declSourceFile: declSourceFile, isJSFile: isJSFile };
153057
153110
  }
153058
153111
  var enumDeclaration = ts.find(symbol.declarations, ts.isEnumDeclaration);
153059
153112
  if (enumDeclaration && !ts.isPrivateIdentifier(token) && !isSourceFileFromLibrary(program, enumDeclaration.getSourceFile())) {
153060
- return { kind: 0 /* Enum */, token: token, parentDeclaration: enumDeclaration };
153113
+ return { kind: 1 /* Enum */, token: token, parentDeclaration: enumDeclaration };
153061
153114
  }
153062
153115
  return undefined;
153063
153116
  }
@@ -153070,7 +153123,7 @@ var ts;
153070
153123
  }
153071
153124
  function createActionForAddMissingMemberInJavascriptFile(context, _a) {
153072
153125
  var parentDeclaration = _a.parentDeclaration, declSourceFile = _a.declSourceFile, modifierFlags = _a.modifierFlags, token = _a.token;
153073
- if (ts.isInterfaceDeclaration(parentDeclaration)) {
153126
+ if (ts.isInterfaceDeclaration(parentDeclaration) || ts.isTypeLiteralNode(parentDeclaration)) {
153074
153127
  return undefined;
153075
153128
  }
153076
153129
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingMemberInJs(t, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */)); });
@@ -153081,7 +153134,7 @@ var ts;
153081
153134
  ts.isPrivateIdentifier(token) ? ts.Diagnostics.Declare_a_private_field_named_0 : ts.Diagnostics.Initialize_property_0_in_the_constructor;
153082
153135
  return codefix.createCodeFixAction(fixMissingMember, changes, [diagnostic, token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members);
153083
153136
  }
153084
- function addMissingMemberInJs(changeTracker, declSourceFile, classDeclaration, token, makeStatic) {
153137
+ function addMissingMemberInJs(changeTracker, sourceFile, classDeclaration, token, makeStatic) {
153085
153138
  var tokenName = token.text;
153086
153139
  if (makeStatic) {
153087
153140
  if (classDeclaration.kind === 226 /* ClassExpression */) {
@@ -153089,7 +153142,7 @@ var ts;
153089
153142
  }
153090
153143
  var className = classDeclaration.name.getText();
153091
153144
  var staticInitialization = initializePropertyToUndefined(ts.factory.createIdentifier(className), tokenName);
153092
- changeTracker.insertNodeAfter(declSourceFile, classDeclaration, staticInitialization);
153145
+ changeTracker.insertNodeAfter(sourceFile, classDeclaration, staticInitialization);
153093
153146
  }
153094
153147
  else if (ts.isPrivateIdentifier(token)) {
153095
153148
  var property = ts.factory.createPropertyDeclaration(
@@ -153100,10 +153153,10 @@ var ts;
153100
153153
  /*initializer*/ undefined);
153101
153154
  var lastProp = getNodeToInsertPropertyAfter(classDeclaration);
153102
153155
  if (lastProp) {
153103
- changeTracker.insertNodeAfter(declSourceFile, lastProp, property);
153156
+ changeTracker.insertNodeAfter(sourceFile, lastProp, property);
153104
153157
  }
153105
153158
  else {
153106
- changeTracker.insertNodeAtClassStart(declSourceFile, classDeclaration, property);
153159
+ changeTracker.insertMemberAtStart(sourceFile, classDeclaration, property);
153107
153160
  }
153108
153161
  }
153109
153162
  else {
@@ -153112,7 +153165,7 @@ var ts;
153112
153165
  return;
153113
153166
  }
153114
153167
  var propertyInitialization = initializePropertyToUndefined(ts.factory.createThis(), tokenName);
153115
- changeTracker.insertNodeAtConstructorEnd(declSourceFile, classConstructor, propertyInitialization);
153168
+ changeTracker.insertNodeAtConstructorEnd(sourceFile, classConstructor, propertyInitialization);
153116
153169
  }
153117
153170
  }
153118
153171
  function initializePropertyToUndefined(obj, propertyName) {
@@ -153134,13 +153187,13 @@ var ts;
153134
153187
  actions.push(createAddIndexSignatureAction(context, declSourceFile, parentDeclaration, token.text, typeNode));
153135
153188
  return actions;
153136
153189
  }
153137
- function getTypeNode(checker, classDeclaration, token) {
153190
+ function getTypeNode(checker, node, token) {
153138
153191
  var typeNode;
153139
153192
  if (token.parent.parent.kind === 221 /* BinaryExpression */) {
153140
153193
  var binaryExpression = token.parent.parent;
153141
153194
  var otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left;
153142
153195
  var widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
153143
- typeNode = checker.typeToTypeNode(widenedType, classDeclaration, 1 /* NoTruncation */);
153196
+ typeNode = checker.typeToTypeNode(widenedType, node, 1 /* NoTruncation */);
153144
153197
  }
153145
153198
  else {
153146
153199
  var contextualType = checker.getContextualType(token.parent);
@@ -153148,24 +153201,23 @@ var ts;
153148
153201
  }
153149
153202
  return typeNode || ts.factory.createKeywordTypeNode(130 /* AnyKeyword */);
153150
153203
  }
153151
- function addPropertyDeclaration(changeTracker, declSourceFile, classDeclaration, tokenName, typeNode, modifierFlags) {
153152
- var property = ts.factory.createPropertyDeclaration(
153153
- /*decorators*/ undefined,
153154
- /*modifiers*/ modifierFlags ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags)) : undefined, tokenName,
153155
- /*questionToken*/ undefined, typeNode,
153156
- /*initializer*/ undefined);
153157
- var lastProp = getNodeToInsertPropertyAfter(classDeclaration);
153204
+ function addPropertyDeclaration(changeTracker, sourceFile, node, tokenName, typeNode, modifierFlags) {
153205
+ var modifiers = modifierFlags ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags)) : undefined;
153206
+ var property = ts.isClassLike(node)
153207
+ ? ts.factory.createPropertyDeclaration(/*decorators*/ undefined, modifiers, tokenName, /*questionToken*/ undefined, typeNode, /*initializer*/ undefined)
153208
+ : ts.factory.createPropertySignature(/*modifiers*/ undefined, tokenName, /*questionToken*/ undefined, typeNode);
153209
+ var lastProp = getNodeToInsertPropertyAfter(node);
153158
153210
  if (lastProp) {
153159
- changeTracker.insertNodeAfter(declSourceFile, lastProp, property);
153211
+ changeTracker.insertNodeAfter(sourceFile, lastProp, property);
153160
153212
  }
153161
153213
  else {
153162
- changeTracker.insertNodeAtClassStart(declSourceFile, classDeclaration, property);
153214
+ changeTracker.insertMemberAtStart(sourceFile, node, property);
153163
153215
  }
153164
153216
  }
153165
153217
  // Gets the last of the first run of PropertyDeclarations, or undefined if the class does not start with a PropertyDeclaration.
153166
- function getNodeToInsertPropertyAfter(cls) {
153218
+ function getNodeToInsertPropertyAfter(node) {
153167
153219
  var res;
153168
- for (var _i = 0, _a = cls.members; _i < _a.length; _i++) {
153220
+ for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
153169
153221
  var member = _a[_i];
153170
153222
  if (!ts.isPropertyDeclaration(member))
153171
153223
  break;
@@ -153173,7 +153225,7 @@ var ts;
153173
153225
  }
153174
153226
  return res;
153175
153227
  }
153176
- function createAddIndexSignatureAction(context, declSourceFile, classDeclaration, tokenName, typeNode) {
153228
+ function createAddIndexSignatureAction(context, sourceFile, node, tokenName, typeNode) {
153177
153229
  // Index signatures cannot have the static modifier.
153178
153230
  var stringTypeNode = ts.factory.createKeywordTypeNode(150 /* StringKeyword */);
153179
153231
  var indexingParameter = ts.factory.createParameterDeclaration(
@@ -153185,7 +153237,7 @@ var ts;
153185
153237
  var indexSignature = ts.factory.createIndexSignature(
153186
153238
  /*decorators*/ undefined,
153187
153239
  /*modifiers*/ undefined, [indexingParameter], typeNode);
153188
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return t.insertNodeAtClassStart(declSourceFile, classDeclaration, indexSignature); });
153240
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return t.insertMemberAtStart(sourceFile, node, indexSignature); });
153189
153241
  // No fixId here because code-fix-all currently only works on adding individual named properties.
153190
153242
  return codefix.createCodeFixActionWithoutFixAll(fixMissingMember, changes, [ts.Diagnostics.Add_index_signature_for_property_0, tokenName]);
153191
153243
  }
@@ -153208,13 +153260,14 @@ var ts;
153208
153260
  }
153209
153261
  function addMethodDeclaration(context, changes, callExpression, name, modifierFlags, parentDeclaration, sourceFile) {
153210
153262
  var importAdder = codefix.createImportAdder(sourceFile, context.program, context.preferences, context.host);
153211
- var methodDeclaration = codefix.createSignatureDeclarationFromCallExpression(169 /* MethodDeclaration */, context, importAdder, callExpression, name, modifierFlags, parentDeclaration);
153212
- var containingMethodDeclaration = ts.findAncestor(callExpression, function (n) { return ts.isMethodDeclaration(n) || ts.isConstructorDeclaration(n); });
153213
- if (containingMethodDeclaration && containingMethodDeclaration.parent === parentDeclaration) {
153214
- changes.insertNodeAfter(sourceFile, containingMethodDeclaration, methodDeclaration);
153263
+ var kind = ts.isClassLike(parentDeclaration) ? 169 /* MethodDeclaration */ : 168 /* MethodSignature */;
153264
+ var signatureDeclaration = codefix.createSignatureDeclarationFromCallExpression(kind, context, importAdder, callExpression, name, modifierFlags, parentDeclaration);
153265
+ var containingMethodDeclaration = tryGetContainingMethodDeclaration(parentDeclaration, callExpression);
153266
+ if (containingMethodDeclaration) {
153267
+ changes.insertNodeAfter(sourceFile, containingMethodDeclaration, signatureDeclaration);
153215
153268
  }
153216
153269
  else {
153217
- changes.insertNodeAtClassStart(sourceFile, parentDeclaration, methodDeclaration);
153270
+ changes.insertMemberAtStart(sourceFile, parentDeclaration, signatureDeclaration);
153218
153271
  }
153219
153272
  importAdder.writeFixes(changes);
153220
153273
  }
@@ -153377,6 +153430,13 @@ var ts;
153377
153430
  return ts.isIdentifierText(targetProp.name, target, 1 /* JSX */) && !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
153378
153431
  });
153379
153432
  }
153433
+ function tryGetContainingMethodDeclaration(node, callExpression) {
153434
+ if (ts.isTypeLiteralNode(node)) {
153435
+ return undefined;
153436
+ }
153437
+ var declaration = ts.findAncestor(callExpression, function (n) { return ts.isMethodDeclaration(n) || ts.isConstructorDeclaration(n); });
153438
+ return declaration && declaration.parent === node ? declaration : undefined;
153439
+ }
153380
153440
  })(codefix = ts.codefix || (ts.codefix = {}));
153381
153441
  })(ts || (ts = {}));
153382
153442
  /* @internal */
@@ -153520,7 +153580,7 @@ var ts;
153520
153580
  // so duplicates cannot occur.
153521
153581
  var abstractAndNonPrivateExtendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType).filter(symbolPointsToNonPrivateAndAbstractMember);
153522
153582
  var importAdder = codefix.createImportAdder(sourceFile, context.program, preferences, context.host);
153523
- codefix.createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, sourceFile, context, preferences, importAdder, function (member) { return changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member); });
153583
+ codefix.createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, sourceFile, context, preferences, importAdder, function (member) { return changeTracker.insertMemberAtStart(sourceFile, classDeclaration, member); });
153524
153584
  importAdder.writeFixes(changeTracker);
153525
153585
  }
153526
153586
  function symbolPointsToNonPrivateAndAbstractMember(symbol) {
@@ -156093,13 +156153,20 @@ var ts;
156093
156153
  var type = isJs || contextualType === undefined
156094
156154
  ? undefined
156095
156155
  : checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
156096
- if (kind === 169 /* MethodDeclaration */) {
156097
- return ts.factory.createMethodDeclaration(
156098
- /*decorators*/ undefined, modifiers, asteriskToken, name,
156099
- /*questionToken*/ undefined, typeParameters, parameters, type, ts.isInterfaceDeclaration(contextNode) ? undefined : createStubbedMethodBody(quotePreference));
156156
+ switch (kind) {
156157
+ case 169 /* MethodDeclaration */:
156158
+ return ts.factory.createMethodDeclaration(
156159
+ /*decorators*/ undefined, modifiers, asteriskToken, name,
156160
+ /*questionToken*/ undefined, typeParameters, parameters, type, createStubbedMethodBody(quotePreference));
156161
+ case 168 /* MethodSignature */:
156162
+ return ts.factory.createMethodSignature(modifiers, name,
156163
+ /*questionToken*/ undefined, typeParameters, parameters, type);
156164
+ case 256 /* FunctionDeclaration */:
156165
+ return ts.factory.createFunctionDeclaration(
156166
+ /*decorators*/ undefined, modifiers, asteriskToken, name, typeParameters, parameters, type, createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference));
156167
+ default:
156168
+ ts.Debug.fail("Unexpected kind");
156100
156169
  }
156101
- return ts.factory.createFunctionDeclaration(
156102
- /*decorators*/ undefined, modifiers, asteriskToken, name, typeParameters, parameters, type, createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference));
156103
156170
  }
156104
156171
  codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
156105
156172
  function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
@@ -156425,7 +156492,7 @@ var ts;
156425
156492
  }
156426
156493
  }
156427
156494
  function insertAccessor(changeTracker, file, accessor, declaration, container) {
156428
- ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.insertNodeAtClassStart(file, container, accessor) :
156495
+ ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.insertMemberAtStart(file, container, accessor) :
156429
156496
  ts.isPropertyAssignment(declaration) ? changeTracker.insertNodeAfterComma(file, declaration, accessor) :
156430
156497
  changeTracker.insertNodeAfter(file, declaration, accessor);
156431
156498
  }
@@ -175035,10 +175102,26 @@ var ts;
175035
175102
  var prefix = args.prefix || "";
175036
175103
  var entries = ts.mapDefined(completions.entries, function (entry) {
175037
175104
  if (completions.isMemberCompletion || ts.startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) {
175038
- var name = entry.name, kind_1 = entry.kind, kindModifiers = entry.kindModifiers, sortText = entry.sortText, insertText = entry.insertText, replacementSpan = entry.replacementSpan, hasAction = entry.hasAction, source = entry.source, sourceDisplay = entry.sourceDisplay, isSnippet = entry.isSnippet, isRecommended = entry.isRecommended, isPackageJsonImport = entry.isPackageJsonImport, isImportStatementCompletion = entry.isImportStatementCompletion, data = entry.data;
175105
+ var name = entry.name, kind_1 = entry.kind, kindModifiers = entry.kindModifiers, sortText = entry.sortText, insertText = entry.insertText, replacementSpan = entry.replacementSpan, hasAction = entry.hasAction, source = entry.source, sourceDisplay = entry.sourceDisplay, labelDetails = entry.labelDetails, isSnippet = entry.isSnippet, isRecommended = entry.isRecommended, isPackageJsonImport = entry.isPackageJsonImport, isImportStatementCompletion = entry.isImportStatementCompletion, data = entry.data;
175039
175106
  var convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined;
175040
175107
  // Use `hasAction || undefined` to avoid serializing `false`.
175041
- return { name: name, kind: kind_1, kindModifiers: kindModifiers, sortText: sortText, insertText: insertText, replacementSpan: convertedSpan, isSnippet: isSnippet, hasAction: hasAction || undefined, source: source, sourceDisplay: sourceDisplay, isRecommended: isRecommended, isPackageJsonImport: isPackageJsonImport, isImportStatementCompletion: isImportStatementCompletion, data: data };
175108
+ return {
175109
+ name: name,
175110
+ kind: kind_1,
175111
+ kindModifiers: kindModifiers,
175112
+ sortText: sortText,
175113
+ insertText: insertText,
175114
+ replacementSpan: convertedSpan,
175115
+ isSnippet: isSnippet,
175116
+ hasAction: hasAction || undefined,
175117
+ source: source,
175118
+ sourceDisplay: sourceDisplay,
175119
+ labelDetails: labelDetails,
175120
+ isRecommended: isRecommended,
175121
+ isPackageJsonImport: isPackageJsonImport,
175122
+ isImportStatementCompletion: isImportStatementCompletion,
175123
+ data: data
175124
+ };
175042
175125
  }
175043
175126
  });
175044
175127
  if (kind === "completions" /* Completions */) {