typescript 4.7.0-dev.20220330 → 4.7.0-dev.20220402

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.20220402";
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
  }
@@ -111123,6 +111158,7 @@ var ts;
111123
111158
  writeLine();
111124
111159
  decreaseIndent();
111125
111160
  }
111161
+ emitList(node, node.members, 2 /* PreserveLines */);
111126
111162
  writePunctuation("}");
111127
111163
  }
111128
111164
  function emitLiteralType(node) {
@@ -130919,6 +130955,7 @@ var ts;
130919
130955
  var source = getSourceFromOrigin(origin);
130920
130956
  var sourceDisplay;
130921
130957
  var hasAction;
130958
+ var labelDetails;
130922
130959
  var typeChecker = program.getTypeChecker();
130923
130960
  var insertQuestionDot = origin && originIsNullableMember(origin);
130924
130961
  var useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess;
@@ -130987,7 +131024,11 @@ var ts;
130987
131024
  }
130988
131025
  if (origin && originIsObjectLiteralMethod(origin)) {
130989
131026
  var importAdder = void 0;
130990
- (insertText = origin.insertText, isSnippet = origin.isSnippet, importAdder = origin.importAdder, sourceDisplay = origin.sourceDisplay);
131027
+ (insertText = origin.insertText, isSnippet = origin.isSnippet, importAdder = origin.importAdder, labelDetails = origin.labelDetails);
131028
+ if (!preferences.useLabelDetailsInCompletionEntries) {
131029
+ name = name + labelDetails.detail;
131030
+ labelDetails = undefined;
131031
+ }
130991
131032
  source = CompletionSource.ObjectLiteralMethodSnippet;
130992
131033
  sortText = Completions.SortText.SortBelow(sortText);
130993
131034
  if (importAdder.hasFixes()) {
@@ -131041,6 +131082,7 @@ var ts;
131041
131082
  insertText: insertText,
131042
131083
  replacementSpan: replacementSpan,
131043
131084
  sourceDisplay: sourceDisplay,
131085
+ labelDetails: labelDetails,
131044
131086
  isSnippet: isSnippet,
131045
131087
  isPackageJsonImport: originIsPackageJsonImport(origin) || undefined,
131046
131088
  isImportStatementCompletion: !!importCompletionNode || undefined,
@@ -131232,9 +131274,19 @@ var ts;
131232
131274
  else {
131233
131275
  insertText = printer.printSnippetList(16 /* CommaDelimited */ | 64 /* AllowTrailingComma */, ts.factory.createNodeArray([method], /*hasTrailingComma*/ true), sourceFile);
131234
131276
  }
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 };
131277
+ var signaturePrinter = ts.createPrinter({
131278
+ removeComments: true,
131279
+ module: options.module,
131280
+ target: options.target,
131281
+ omitTrailingSemicolon: true,
131282
+ });
131283
+ // The `labelDetails.detail` will be displayed right beside the method name,
131284
+ // so we drop the name (and modifiers) from the signature.
131285
+ var methodSignature = ts.factory.createMethodSignature(
131286
+ /*modifiers*/ undefined,
131287
+ /*name*/ "", method.questionToken, method.typeParameters, method.parameters, method.type);
131288
+ var labelDetails = { detail: signaturePrinter.printNode(4 /* Unspecified */, methodSignature, sourceFile) };
131289
+ return { isSnippet: isSnippet, insertText: insertText, importAdder: importAdder, labelDetails: labelDetails };
131238
131290
  }
131239
131291
  ;
131240
131292
  function createObjectLiteralMethod(symbol, enclosingDeclaration, sourceFile, program, host, preferences, importAdder) {
@@ -135404,9 +135456,10 @@ var ts;
135404
135456
  })(FindReferencesUse = FindAllReferences.FindReferencesUse || (FindAllReferences.FindReferencesUse = {}));
135405
135457
  function findReferencedSymbols(program, cancellationToken, sourceFiles, sourceFile, position) {
135406
135458
  var node = ts.getTouchingPropertyName(sourceFile, position);
135407
- var referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, { use: 1 /* References */ });
135459
+ var options = { use: 1 /* References */ };
135460
+ var referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options);
135408
135461
  var checker = program.getTypeChecker();
135409
- var symbol = checker.getSymbolAtLocation(node);
135462
+ var symbol = checker.getSymbolAtLocation(ts.getAdjustedReferenceLocation(Core.getAdjustedNode(node, options)));
135410
135463
  return !referencedSymbols || !referencedSymbols.length ? undefined : ts.mapDefined(referencedSymbols, function (_a) {
135411
135464
  var definition = _a.definition, references = _a.references;
135412
135465
  // Only include referenced symbols that have a valid definition.
@@ -135751,12 +135804,7 @@ var ts;
135751
135804
  var _a, _b;
135752
135805
  if (options === void 0) { options = {}; }
135753
135806
  if (sourceFilesSet === void 0) { sourceFilesSet = new ts.Set(sourceFiles.map(function (f) { return f.fileName; })); }
135754
- if (options.use === 1 /* References */) {
135755
- node = ts.getAdjustedReferenceLocation(node);
135756
- }
135757
- else if (options.use === 2 /* Rename */) {
135758
- node = ts.getAdjustedRenameLocation(node);
135759
- }
135807
+ node = getAdjustedNode(node, options);
135760
135808
  if (ts.isSourceFile(node)) {
135761
135809
  var resolvedRef = ts.GoToDefinition.getReferenceAtPosition(node, position, program);
135762
135810
  if (!(resolvedRef === null || resolvedRef === void 0 ? void 0 : resolvedRef.file)) {
@@ -135817,6 +135865,16 @@ var ts;
135817
135865
  return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
135818
135866
  }
135819
135867
  Core.getReferencedSymbolsForNode = getReferencedSymbolsForNode;
135868
+ function getAdjustedNode(node, options) {
135869
+ if (options.use === 1 /* References */) {
135870
+ node = ts.getAdjustedReferenceLocation(node);
135871
+ }
135872
+ else if (options.use === 2 /* Rename */) {
135873
+ node = ts.getAdjustedRenameLocation(node);
135874
+ }
135875
+ return node;
135876
+ }
135877
+ Core.getAdjustedNode = getAdjustedNode;
135820
135878
  function getReferencesForFileName(fileName, program, sourceFiles, sourceFilesSet) {
135821
135879
  var _a, _b;
135822
135880
  if (sourceFilesSet === void 0) { sourceFilesSet = new ts.Set(sourceFiles.map(function (f) { return f.fileName; })); }
@@ -138783,7 +138841,8 @@ var ts;
138783
138841
  return undefined;
138784
138842
  }
138785
138843
  var commentOwner = commentOwnerInfo.commentOwner, parameters = commentOwnerInfo.parameters, hasReturn = commentOwnerInfo.hasReturn;
138786
- if (commentOwner.getStart(sourceFile) < position) {
138844
+ var commentOwnerJSDoc = ts.hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? ts.lastOrUndefined(commentOwner.jsDoc) : undefined;
138845
+ if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) {
138787
138846
  return undefined;
138788
138847
  }
138789
138848
  var indentationStr = getIndentationStringAtPosition(sourceFile, position);
@@ -147477,25 +147536,25 @@ var ts;
147477
147536
  suffix: this.newLineCharacter
147478
147537
  });
147479
147538
  };
147480
- ChangeTracker.prototype.insertNodeAtClassStart = function (sourceFile, cls, newElement) {
147481
- this.insertNodeAtStartWorker(sourceFile, cls, newElement);
147539
+ ChangeTracker.prototype.insertMemberAtStart = function (sourceFile, node, newElement) {
147540
+ this.insertNodeAtStartWorker(sourceFile, node, newElement);
147482
147541
  };
147483
147542
  ChangeTracker.prototype.insertNodeAtObjectStart = function (sourceFile, obj, newElement) {
147484
147543
  this.insertNodeAtStartWorker(sourceFile, obj, newElement);
147485
147544
  };
147486
- ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile, cls, newElement) {
147545
+ ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile, node, newElement) {
147487
147546
  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));
147547
+ var indentation = (_a = this.guessIndentationFromExistingMembers(sourceFile, node)) !== null && _a !== void 0 ? _a : this.computeIndentationForNewMember(sourceFile, node);
147548
+ this.insertNodeAt(sourceFile, getMembersOrProperties(node).pos, newElement, this.getInsertNodeAtStartInsertOptions(sourceFile, node, indentation));
147490
147549
  };
147491
147550
  /**
147492
147551
  * Tries to guess the indentation from the existing members of a class/interface/object. All members must be on
147493
147552
  * new lines and must share the same indentation.
147494
147553
  */
147495
- ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile, cls) {
147554
+ ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile, node) {
147496
147555
  var indentation;
147497
- var lastRange = cls;
147498
- for (var _i = 0, _a = getMembersOrProperties(cls); _i < _a.length; _i++) {
147556
+ var lastRange = node;
147557
+ for (var _i = 0, _a = getMembersOrProperties(node); _i < _a.length; _i++) {
147499
147558
  var member = _a[_i];
147500
147559
  if (ts.rangeStartPositionsAreOnSameLine(lastRange, member, sourceFile)) {
147501
147560
  // each indented member must be on a new line
@@ -147514,13 +147573,13 @@ var ts;
147514
147573
  }
147515
147574
  return indentation;
147516
147575
  };
147517
- ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile, cls) {
147576
+ ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile, node) {
147518
147577
  var _a;
147519
- var clsStart = cls.getStart(sourceFile);
147520
- return ts.formatting.SmartIndenter.findFirstNonWhitespaceColumn(ts.getLineStartPositionForPosition(clsStart, sourceFile), clsStart, sourceFile, this.formatContext.options)
147578
+ var nodeStart = node.getStart(sourceFile);
147579
+ return ts.formatting.SmartIndenter.findFirstNonWhitespaceColumn(ts.getLineStartPositionForPosition(nodeStart, sourceFile), nodeStart, sourceFile, this.formatContext.options)
147521
147580
  + ((_a = this.formatContext.options.indentSize) !== null && _a !== void 0 ? _a : 4);
147522
147581
  };
147523
- ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile, cls, indentation) {
147582
+ ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile, node, indentation) {
147524
147583
  // Rules:
147525
147584
  // - Always insert leading newline.
147526
147585
  // - For object literals:
@@ -147530,11 +147589,11 @@ var ts;
147530
147589
  // and the node is empty (because we didn't add a trailing comma per the previous rule).
147531
147590
  // - Only insert a trailing newline if body is single-line and there are no other insertions for the node.
147532
147591
  // NOTE: This is handled in `finishClassesWithNodesInsertedAtStart`.
147533
- var members = getMembersOrProperties(cls);
147592
+ var members = getMembersOrProperties(node);
147534
147593
  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;
147594
+ var isFirstInsertion = ts.addToSeen(this.classesWithNodesInsertedAtStart, ts.getNodeId(node), { node: node, sourceFile: sourceFile });
147595
+ var insertTrailingComma = ts.isObjectLiteralExpression(node) && (!ts.isJsonSourceFile(sourceFile) || !isEmpty);
147596
+ var insertLeadingComma = ts.isObjectLiteralExpression(node) && ts.isJsonSourceFile(sourceFile) && isEmpty && !isFirstInsertion;
147538
147597
  return {
147539
147598
  indentation: indentation,
147540
147599
  prefix: (insertLeadingComma ? "," : "") + this.newLineCharacter,
@@ -147828,8 +147887,8 @@ var ts;
147828
147887
  var close = ts.findChildOfKind(cls, 19 /* CloseBraceToken */, sourceFile);
147829
147888
  return [open === null || open === void 0 ? void 0 : open.end, close === null || close === void 0 ? void 0 : close.end];
147830
147889
  }
147831
- function getMembersOrProperties(cls) {
147832
- return ts.isObjectLiteralExpression(cls) ? cls.properties : cls.members;
147890
+ function getMembersOrProperties(node) {
147891
+ return ts.isObjectLiteralExpression(node) ? node.properties : node.members;
147833
147892
  }
147834
147893
  function getNewFileText(statements, scriptKind, newLineCharacter, formatContext) {
147835
147894
  return changesToText.newFileChangesWorker(/*oldFile*/ undefined, scriptKind, statements, newLineCharacter, formatContext);
@@ -151112,7 +151171,7 @@ var ts;
151112
151171
  changeTracker.insertNodeAfter(sourceFile, constructor, newElement);
151113
151172
  }
151114
151173
  else {
151115
- changeTracker.insertNodeAtClassStart(sourceFile, cls, newElement);
151174
+ changeTracker.insertMemberAtStart(sourceFile, cls, newElement);
151116
151175
  }
151117
151176
  }
151118
151177
  }
@@ -152896,7 +152955,7 @@ var ts;
152896
152955
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addFunctionDeclaration(t, context, info); });
152897
152956
  return [codefix.createCodeFixAction(fixMissingFunctionDeclaration, changes, [ts.Diagnostics.Add_missing_function_declaration_0, info.token.text], fixMissingFunctionDeclaration, ts.Diagnostics.Add_all_missing_function_declarations)];
152898
152957
  }
152899
- if (info.kind === 0 /* Enum */) {
152958
+ if (info.kind === 1 /* Enum */) {
152900
152959
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addEnumMemberDeclaration(t, context.program.getTypeChecker(), info); });
152901
152960
  return [codefix.createCodeFixAction(fixMissingMember, changes, [ts.Diagnostics.Add_missing_enum_member_0, info.token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members)];
152902
152961
  }
@@ -152924,10 +152983,10 @@ var ts;
152924
152983
  addJsxAttributes(changes, context, info);
152925
152984
  }
152926
152985
  else {
152927
- if (info.kind === 0 /* Enum */) {
152986
+ if (info.kind === 1 /* Enum */) {
152928
152987
  addEnumMemberDeclaration(changes, checker, info);
152929
152988
  }
152930
- if (info.kind === 1 /* ClassOrInterface */) {
152989
+ if (info.kind === 0 /* TypeLikeDeclaration */) {
152931
152990
  var parentDeclaration = info.parentDeclaration, token_1 = info.token;
152932
152991
  var infos = ts.getOrUpdate(typeDeclToMembers, parentDeclaration, function () { return []; });
152933
152992
  if (!infos.some(function (i) { return i.token.text === token_1.text; })) {
@@ -152936,11 +152995,11 @@ var ts;
152936
152995
  }
152937
152996
  }
152938
152997
  });
152939
- typeDeclToMembers.forEach(function (infos, classDeclaration) {
152940
- var supers = codefix.getAllSupers(classDeclaration, checker);
152998
+ typeDeclToMembers.forEach(function (infos, declaration) {
152999
+ var supers = ts.isTypeLiteralNode(declaration) ? undefined : codefix.getAllSupers(declaration, checker);
152941
153000
  var _loop_15 = function (info) {
152942
153001
  // If some superclass added this property, don't add it again.
152943
- if (supers.some(function (superClassOrInterface) {
153002
+ if (supers === null || supers === void 0 ? void 0 : supers.some(function (superClassOrInterface) {
152944
153003
  var superInfos = typeDeclToMembers.get(superClassOrInterface);
152945
153004
  return !!superInfos && superInfos.some(function (_a) {
152946
153005
  var token = _a.token;
@@ -152954,11 +153013,11 @@ var ts;
152954
153013
  addMethodDeclaration(context, changes, call, token, modifierFlags & 32 /* Static */, parentDeclaration, declSourceFile);
152955
153014
  }
152956
153015
  else {
152957
- if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration)) {
153016
+ if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration) && !ts.isTypeLiteralNode(parentDeclaration)) {
152958
153017
  addMissingMemberInJs(changes, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */));
152959
153018
  }
152960
153019
  else {
152961
- var typeNode = getTypeNode(program.getTypeChecker(), parentDeclaration, token);
153020
+ var typeNode = getTypeNode(checker, parentDeclaration, token);
152962
153021
  addPropertyDeclaration(changes, declSourceFile, parentDeclaration, token.text, typeNode, modifierFlags & 32 /* Static */);
152963
153022
  }
152964
153023
  }
@@ -152973,8 +153032,8 @@ var ts;
152973
153032
  });
152974
153033
  var InfoKind;
152975
153034
  (function (InfoKind) {
152976
- InfoKind[InfoKind["Enum"] = 0] = "Enum";
152977
- InfoKind[InfoKind["ClassOrInterface"] = 1] = "ClassOrInterface";
153035
+ InfoKind[InfoKind["TypeLikeDeclaration"] = 0] = "TypeLikeDeclaration";
153036
+ InfoKind[InfoKind["Enum"] = 1] = "Enum";
152978
153037
  InfoKind[InfoKind["Function"] = 2] = "Function";
152979
153038
  InfoKind[InfoKind["ObjectLiteral"] = 3] = "ObjectLiteral";
152980
153039
  InfoKind[InfoKind["JsxAttributes"] = 4] = "JsxAttributes";
@@ -153044,20 +153103,21 @@ var ts;
153044
153103
  if (!classDeclaration && ts.isPrivateIdentifier(token))
153045
153104
  return undefined;
153046
153105
  // 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)))
153106
+ var declaration = classDeclaration || ts.find(symbol.declarations, function (d) { return ts.isInterfaceDeclaration(d) || ts.isTypeLiteralNode(d); });
153107
+ if (declaration && !isSourceFileFromLibrary(program, declaration.getSourceFile())) {
153108
+ var makeStatic = !ts.isTypeLiteralNode(declaration) && (leftExpressionType.target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
153109
+ if (makeStatic && (ts.isPrivateIdentifier(token) || ts.isInterfaceDeclaration(declaration)))
153051
153110
  return undefined;
153052
- var declSourceFile = classOrInterface.getSourceFile();
153053
- var modifierFlags = (makeStatic ? 32 /* Static */ : 0) | (ts.startsWithUnderscore(token.text) ? 8 /* Private */ : 0);
153111
+ var declSourceFile = declaration.getSourceFile();
153112
+ var modifierFlags = ts.isTypeLiteralNode(declaration) ? 0 /* None */ :
153113
+ (makeStatic ? 32 /* Static */ : 0 /* None */) | (ts.startsWithUnderscore(token.text) ? 8 /* Private */ : 0 /* None */);
153054
153114
  var isJSFile = ts.isSourceFileJS(declSourceFile);
153055
153115
  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 };
153116
+ return { kind: 0 /* TypeLikeDeclaration */, token: token, call: call, modifierFlags: modifierFlags, parentDeclaration: declaration, declSourceFile: declSourceFile, isJSFile: isJSFile };
153057
153117
  }
153058
153118
  var enumDeclaration = ts.find(symbol.declarations, ts.isEnumDeclaration);
153059
153119
  if (enumDeclaration && !ts.isPrivateIdentifier(token) && !isSourceFileFromLibrary(program, enumDeclaration.getSourceFile())) {
153060
- return { kind: 0 /* Enum */, token: token, parentDeclaration: enumDeclaration };
153120
+ return { kind: 1 /* Enum */, token: token, parentDeclaration: enumDeclaration };
153061
153121
  }
153062
153122
  return undefined;
153063
153123
  }
@@ -153070,7 +153130,7 @@ var ts;
153070
153130
  }
153071
153131
  function createActionForAddMissingMemberInJavascriptFile(context, _a) {
153072
153132
  var parentDeclaration = _a.parentDeclaration, declSourceFile = _a.declSourceFile, modifierFlags = _a.modifierFlags, token = _a.token;
153073
- if (ts.isInterfaceDeclaration(parentDeclaration)) {
153133
+ if (ts.isInterfaceDeclaration(parentDeclaration) || ts.isTypeLiteralNode(parentDeclaration)) {
153074
153134
  return undefined;
153075
153135
  }
153076
153136
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingMemberInJs(t, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */)); });
@@ -153081,7 +153141,7 @@ var ts;
153081
153141
  ts.isPrivateIdentifier(token) ? ts.Diagnostics.Declare_a_private_field_named_0 : ts.Diagnostics.Initialize_property_0_in_the_constructor;
153082
153142
  return codefix.createCodeFixAction(fixMissingMember, changes, [diagnostic, token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members);
153083
153143
  }
153084
- function addMissingMemberInJs(changeTracker, declSourceFile, classDeclaration, token, makeStatic) {
153144
+ function addMissingMemberInJs(changeTracker, sourceFile, classDeclaration, token, makeStatic) {
153085
153145
  var tokenName = token.text;
153086
153146
  if (makeStatic) {
153087
153147
  if (classDeclaration.kind === 226 /* ClassExpression */) {
@@ -153089,7 +153149,7 @@ var ts;
153089
153149
  }
153090
153150
  var className = classDeclaration.name.getText();
153091
153151
  var staticInitialization = initializePropertyToUndefined(ts.factory.createIdentifier(className), tokenName);
153092
- changeTracker.insertNodeAfter(declSourceFile, classDeclaration, staticInitialization);
153152
+ changeTracker.insertNodeAfter(sourceFile, classDeclaration, staticInitialization);
153093
153153
  }
153094
153154
  else if (ts.isPrivateIdentifier(token)) {
153095
153155
  var property = ts.factory.createPropertyDeclaration(
@@ -153100,10 +153160,10 @@ var ts;
153100
153160
  /*initializer*/ undefined);
153101
153161
  var lastProp = getNodeToInsertPropertyAfter(classDeclaration);
153102
153162
  if (lastProp) {
153103
- changeTracker.insertNodeAfter(declSourceFile, lastProp, property);
153163
+ changeTracker.insertNodeAfter(sourceFile, lastProp, property);
153104
153164
  }
153105
153165
  else {
153106
- changeTracker.insertNodeAtClassStart(declSourceFile, classDeclaration, property);
153166
+ changeTracker.insertMemberAtStart(sourceFile, classDeclaration, property);
153107
153167
  }
153108
153168
  }
153109
153169
  else {
@@ -153112,7 +153172,7 @@ var ts;
153112
153172
  return;
153113
153173
  }
153114
153174
  var propertyInitialization = initializePropertyToUndefined(ts.factory.createThis(), tokenName);
153115
- changeTracker.insertNodeAtConstructorEnd(declSourceFile, classConstructor, propertyInitialization);
153175
+ changeTracker.insertNodeAtConstructorEnd(sourceFile, classConstructor, propertyInitialization);
153116
153176
  }
153117
153177
  }
153118
153178
  function initializePropertyToUndefined(obj, propertyName) {
@@ -153134,13 +153194,13 @@ var ts;
153134
153194
  actions.push(createAddIndexSignatureAction(context, declSourceFile, parentDeclaration, token.text, typeNode));
153135
153195
  return actions;
153136
153196
  }
153137
- function getTypeNode(checker, classDeclaration, token) {
153197
+ function getTypeNode(checker, node, token) {
153138
153198
  var typeNode;
153139
153199
  if (token.parent.parent.kind === 221 /* BinaryExpression */) {
153140
153200
  var binaryExpression = token.parent.parent;
153141
153201
  var otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left;
153142
153202
  var widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
153143
- typeNode = checker.typeToTypeNode(widenedType, classDeclaration, 1 /* NoTruncation */);
153203
+ typeNode = checker.typeToTypeNode(widenedType, node, 1 /* NoTruncation */);
153144
153204
  }
153145
153205
  else {
153146
153206
  var contextualType = checker.getContextualType(token.parent);
@@ -153148,24 +153208,23 @@ var ts;
153148
153208
  }
153149
153209
  return typeNode || ts.factory.createKeywordTypeNode(130 /* AnyKeyword */);
153150
153210
  }
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);
153211
+ function addPropertyDeclaration(changeTracker, sourceFile, node, tokenName, typeNode, modifierFlags) {
153212
+ var modifiers = modifierFlags ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags)) : undefined;
153213
+ var property = ts.isClassLike(node)
153214
+ ? ts.factory.createPropertyDeclaration(/*decorators*/ undefined, modifiers, tokenName, /*questionToken*/ undefined, typeNode, /*initializer*/ undefined)
153215
+ : ts.factory.createPropertySignature(/*modifiers*/ undefined, tokenName, /*questionToken*/ undefined, typeNode);
153216
+ var lastProp = getNodeToInsertPropertyAfter(node);
153158
153217
  if (lastProp) {
153159
- changeTracker.insertNodeAfter(declSourceFile, lastProp, property);
153218
+ changeTracker.insertNodeAfter(sourceFile, lastProp, property);
153160
153219
  }
153161
153220
  else {
153162
- changeTracker.insertNodeAtClassStart(declSourceFile, classDeclaration, property);
153221
+ changeTracker.insertMemberAtStart(sourceFile, node, property);
153163
153222
  }
153164
153223
  }
153165
153224
  // Gets the last of the first run of PropertyDeclarations, or undefined if the class does not start with a PropertyDeclaration.
153166
- function getNodeToInsertPropertyAfter(cls) {
153225
+ function getNodeToInsertPropertyAfter(node) {
153167
153226
  var res;
153168
- for (var _i = 0, _a = cls.members; _i < _a.length; _i++) {
153227
+ for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
153169
153228
  var member = _a[_i];
153170
153229
  if (!ts.isPropertyDeclaration(member))
153171
153230
  break;
@@ -153173,7 +153232,7 @@ var ts;
153173
153232
  }
153174
153233
  return res;
153175
153234
  }
153176
- function createAddIndexSignatureAction(context, declSourceFile, classDeclaration, tokenName, typeNode) {
153235
+ function createAddIndexSignatureAction(context, sourceFile, node, tokenName, typeNode) {
153177
153236
  // Index signatures cannot have the static modifier.
153178
153237
  var stringTypeNode = ts.factory.createKeywordTypeNode(150 /* StringKeyword */);
153179
153238
  var indexingParameter = ts.factory.createParameterDeclaration(
@@ -153185,7 +153244,7 @@ var ts;
153185
153244
  var indexSignature = ts.factory.createIndexSignature(
153186
153245
  /*decorators*/ undefined,
153187
153246
  /*modifiers*/ undefined, [indexingParameter], typeNode);
153188
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return t.insertNodeAtClassStart(declSourceFile, classDeclaration, indexSignature); });
153247
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return t.insertMemberAtStart(sourceFile, node, indexSignature); });
153189
153248
  // No fixId here because code-fix-all currently only works on adding individual named properties.
153190
153249
  return codefix.createCodeFixActionWithoutFixAll(fixMissingMember, changes, [ts.Diagnostics.Add_index_signature_for_property_0, tokenName]);
153191
153250
  }
@@ -153208,13 +153267,14 @@ var ts;
153208
153267
  }
153209
153268
  function addMethodDeclaration(context, changes, callExpression, name, modifierFlags, parentDeclaration, sourceFile) {
153210
153269
  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);
153270
+ var kind = ts.isClassLike(parentDeclaration) ? 169 /* MethodDeclaration */ : 168 /* MethodSignature */;
153271
+ var signatureDeclaration = codefix.createSignatureDeclarationFromCallExpression(kind, context, importAdder, callExpression, name, modifierFlags, parentDeclaration);
153272
+ var containingMethodDeclaration = tryGetContainingMethodDeclaration(parentDeclaration, callExpression);
153273
+ if (containingMethodDeclaration) {
153274
+ changes.insertNodeAfter(sourceFile, containingMethodDeclaration, signatureDeclaration);
153215
153275
  }
153216
153276
  else {
153217
- changes.insertNodeAtClassStart(sourceFile, parentDeclaration, methodDeclaration);
153277
+ changes.insertMemberAtStart(sourceFile, parentDeclaration, signatureDeclaration);
153218
153278
  }
153219
153279
  importAdder.writeFixes(changes);
153220
153280
  }
@@ -153377,6 +153437,13 @@ var ts;
153377
153437
  return ts.isIdentifierText(targetProp.name, target, 1 /* JSX */) && !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
153378
153438
  });
153379
153439
  }
153440
+ function tryGetContainingMethodDeclaration(node, callExpression) {
153441
+ if (ts.isTypeLiteralNode(node)) {
153442
+ return undefined;
153443
+ }
153444
+ var declaration = ts.findAncestor(callExpression, function (n) { return ts.isMethodDeclaration(n) || ts.isConstructorDeclaration(n); });
153445
+ return declaration && declaration.parent === node ? declaration : undefined;
153446
+ }
153380
153447
  })(codefix = ts.codefix || (ts.codefix = {}));
153381
153448
  })(ts || (ts = {}));
153382
153449
  /* @internal */
@@ -153520,7 +153587,7 @@ var ts;
153520
153587
  // so duplicates cannot occur.
153521
153588
  var abstractAndNonPrivateExtendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType).filter(symbolPointsToNonPrivateAndAbstractMember);
153522
153589
  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); });
153590
+ codefix.createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, sourceFile, context, preferences, importAdder, function (member) { return changeTracker.insertMemberAtStart(sourceFile, classDeclaration, member); });
153524
153591
  importAdder.writeFixes(changeTracker);
153525
153592
  }
153526
153593
  function symbolPointsToNonPrivateAndAbstractMember(symbol) {
@@ -156093,13 +156160,20 @@ var ts;
156093
156160
  var type = isJs || contextualType === undefined
156094
156161
  ? undefined
156095
156162
  : 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));
156163
+ switch (kind) {
156164
+ case 169 /* MethodDeclaration */:
156165
+ return ts.factory.createMethodDeclaration(
156166
+ /*decorators*/ undefined, modifiers, asteriskToken, name,
156167
+ /*questionToken*/ undefined, typeParameters, parameters, type, createStubbedMethodBody(quotePreference));
156168
+ case 168 /* MethodSignature */:
156169
+ return ts.factory.createMethodSignature(modifiers, name,
156170
+ /*questionToken*/ undefined, typeParameters, parameters, type);
156171
+ case 256 /* FunctionDeclaration */:
156172
+ return ts.factory.createFunctionDeclaration(
156173
+ /*decorators*/ undefined, modifiers, asteriskToken, name, typeParameters, parameters, type, createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference));
156174
+ default:
156175
+ ts.Debug.fail("Unexpected kind");
156100
156176
  }
156101
- return ts.factory.createFunctionDeclaration(
156102
- /*decorators*/ undefined, modifiers, asteriskToken, name, typeParameters, parameters, type, createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference));
156103
156177
  }
156104
156178
  codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
156105
156179
  function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
@@ -156425,7 +156499,7 @@ var ts;
156425
156499
  }
156426
156500
  }
156427
156501
  function insertAccessor(changeTracker, file, accessor, declaration, container) {
156428
- ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.insertNodeAtClassStart(file, container, accessor) :
156502
+ ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.insertMemberAtStart(file, container, accessor) :
156429
156503
  ts.isPropertyAssignment(declaration) ? changeTracker.insertNodeAfterComma(file, declaration, accessor) :
156430
156504
  changeTracker.insertNodeAfter(file, declaration, accessor);
156431
156505
  }
@@ -175035,10 +175109,26 @@ var ts;
175035
175109
  var prefix = args.prefix || "";
175036
175110
  var entries = ts.mapDefined(completions.entries, function (entry) {
175037
175111
  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;
175112
+ 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
175113
  var convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined;
175040
175114
  // 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 };
175115
+ return {
175116
+ name: name,
175117
+ kind: kind_1,
175118
+ kindModifiers: kindModifiers,
175119
+ sortText: sortText,
175120
+ insertText: insertText,
175121
+ replacementSpan: convertedSpan,
175122
+ isSnippet: isSnippet,
175123
+ hasAction: hasAction || undefined,
175124
+ source: source,
175125
+ sourceDisplay: sourceDisplay,
175126
+ labelDetails: labelDetails,
175127
+ isRecommended: isRecommended,
175128
+ isPackageJsonImport: isPackageJsonImport,
175129
+ isImportStatementCompletion: isImportStatementCompletion,
175130
+ data: data
175131
+ };
175042
175132
  }
175043
175133
  });
175044
175134
  if (kind === "completions" /* Completions */) {