typescript 4.7.0-dev.20220329 → 4.7.0-dev.20220401

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.20220329";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220401";
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) {
@@ -47406,7 +47428,8 @@ var ts;
47406
47428
  CheckMode[CheckMode["SkipContextSensitive"] = 4] = "SkipContextSensitive";
47407
47429
  CheckMode[CheckMode["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
47408
47430
  CheckMode[CheckMode["IsForSignatureHelp"] = 16] = "IsForSignatureHelp";
47409
- CheckMode[CheckMode["RestBindingElement"] = 32] = "RestBindingElement";
47431
+ CheckMode[CheckMode["IsForStringLiteralArgumentCompletions"] = 32] = "IsForStringLiteralArgumentCompletions";
47432
+ CheckMode[CheckMode["RestBindingElement"] = 64] = "RestBindingElement";
47410
47433
  // e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
47411
47434
  // we need to preserve generic types instead of substituting them for constraints
47412
47435
  })(CheckMode || (CheckMode = {}));
@@ -47744,26 +47767,10 @@ var ts;
47744
47767
  if (!node) {
47745
47768
  return undefined;
47746
47769
  }
47747
- var containingCall = ts.findAncestor(node, ts.isCallLikeExpression);
47748
- var containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature;
47749
- if (contextFlags & 4 /* Completions */ && containingCall) {
47750
- var toMarkSkip = node;
47751
- do {
47752
- getNodeLinks(toMarkSkip).skipDirectInference = true;
47753
- toMarkSkip = toMarkSkip.parent;
47754
- } while (toMarkSkip && toMarkSkip !== containingCall);
47755
- getNodeLinks(containingCall).resolvedSignature = undefined;
47756
- }
47757
- var result = getContextualType(node, contextFlags);
47758
- if (contextFlags & 4 /* Completions */ && containingCall) {
47759
- var toMarkSkip = node;
47760
- do {
47761
- getNodeLinks(toMarkSkip).skipDirectInference = undefined;
47762
- toMarkSkip = toMarkSkip.parent;
47763
- } while (toMarkSkip && toMarkSkip !== containingCall);
47764
- getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature;
47770
+ if (contextFlags & 4 /* Completions */) {
47771
+ return runWithInferenceBlockedFromSourceNode(node, function () { return getContextualType(node, contextFlags); });
47765
47772
  }
47766
- return result;
47773
+ return getContextualType(node, contextFlags);
47767
47774
  },
47768
47775
  getContextualTypeForObjectLiteralElement: function (nodeIn) {
47769
47776
  var node = ts.getParseTreeNode(nodeIn, ts.isObjectLiteralElementLike);
@@ -47783,6 +47790,9 @@ var ts;
47783
47790
  getResolvedSignature: function (node, candidatesOutArray, argumentCount) {
47784
47791
  return getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, 0 /* Normal */);
47785
47792
  },
47793
+ getResolvedSignatureForStringLiteralCompletions: function (call, editingArgument, candidatesOutArray) {
47794
+ return getResolvedSignatureWorker(call, candidatesOutArray, /*argumentCount*/ undefined, 32 /* IsForStringLiteralArgumentCompletions */, editingArgument);
47795
+ },
47786
47796
  getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, argumentCount) {
47787
47797
  return getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, 16 /* IsForSignatureHelp */);
47788
47798
  },
@@ -47935,10 +47945,34 @@ var ts;
47935
47945
  getTypeOnlyAliasDeclaration: getTypeOnlyAliasDeclaration,
47936
47946
  getMemberOverrideModifierStatus: getMemberOverrideModifierStatus,
47937
47947
  };
47938
- function getResolvedSignatureWorker(nodeIn, candidatesOutArray, argumentCount, checkMode) {
47948
+ function runWithInferenceBlockedFromSourceNode(node, fn) {
47949
+ var containingCall = ts.findAncestor(node, ts.isCallLikeExpression);
47950
+ var containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature;
47951
+ if (containingCall) {
47952
+ var toMarkSkip = node;
47953
+ do {
47954
+ getNodeLinks(toMarkSkip).skipDirectInference = true;
47955
+ toMarkSkip = toMarkSkip.parent;
47956
+ } while (toMarkSkip && toMarkSkip !== containingCall);
47957
+ getNodeLinks(containingCall).resolvedSignature = undefined;
47958
+ }
47959
+ var result = fn();
47960
+ if (containingCall) {
47961
+ var toMarkSkip = node;
47962
+ do {
47963
+ getNodeLinks(toMarkSkip).skipDirectInference = undefined;
47964
+ toMarkSkip = toMarkSkip.parent;
47965
+ } while (toMarkSkip && toMarkSkip !== containingCall);
47966
+ getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature;
47967
+ }
47968
+ return result;
47969
+ }
47970
+ function getResolvedSignatureWorker(nodeIn, candidatesOutArray, argumentCount, checkMode, editingArgument) {
47939
47971
  var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
47940
47972
  apparentArgumentCount = argumentCount;
47941
- var res = node ? getResolvedSignature(node, candidatesOutArray, checkMode) : undefined;
47973
+ var res = !node ? undefined :
47974
+ editingArgument ? runWithInferenceBlockedFromSourceNode(editingArgument, function () { return getResolvedSignature(node, candidatesOutArray, checkMode); }) :
47975
+ getResolvedSignature(node, candidatesOutArray, checkMode);
47942
47976
  apparentArgumentCount = undefined;
47943
47977
  return res;
47944
47978
  }
@@ -52065,7 +52099,15 @@ var ts;
52065
52099
  if (!ts.nodeIsSynthesized(node) && ts.getParseTreeNode(node) === node) {
52066
52100
  return node;
52067
52101
  }
52068
- 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);
52069
52111
  }
52070
52112
  }
52071
52113
  function createTypeNodeFromObjectType(type) {
@@ -55072,7 +55114,7 @@ var ts;
55072
55114
  }
55073
55115
  /** Return the inferred type for a binding element */
55074
55116
  function getTypeForBindingElement(declaration) {
55075
- var checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
55117
+ var checkMode = declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */;
55076
55118
  var parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
55077
55119
  return parentType && getBindingElementTypeFromParentType(declaration, parentType);
55078
55120
  }
@@ -68200,7 +68242,7 @@ var ts;
68200
68242
  for (var _i = 0, properties_3 = properties; _i < properties_3.length; _i++) {
68201
68243
  var targetProp = properties_3[_i];
68202
68244
  var sourceProp = getPropertyOfType(source, targetProp.escapedName);
68203
- if (sourceProp) {
68245
+ if (sourceProp && !ts.some(sourceProp.declarations, hasSkipDirectInferenceFlag)) {
68204
68246
  inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
68205
68247
  }
68206
68248
  }
@@ -70674,7 +70716,7 @@ var ts;
70674
70716
  // as we want the type of a rest element to be generic when possible.
70675
70717
  var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
70676
70718
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
70677
- (checkMode && checkMode & 32 /* RestBindingElement */ ?
70719
+ (checkMode && checkMode & 64 /* RestBindingElement */ ?
70678
70720
  getContextualType(node, 8 /* SkipBindingPatterns */)
70679
70721
  : getContextualType(node));
70680
70722
  return contextualType && !isGenericType(contextualType);
@@ -70795,7 +70837,7 @@ var ts;
70795
70837
  if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
70796
70838
  var contextualSignature = getContextualSignature(func);
70797
70839
  if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
70798
- var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
70840
+ var restType = getReducedApparentType(getTypeOfSymbol(contextualSignature.parameters[0]));
70799
70841
  if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
70800
70842
  var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
70801
70843
  var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
@@ -71613,7 +71655,7 @@ var ts;
71613
71655
  var parent = declaration.parent.parent;
71614
71656
  var name = declaration.propertyName || declaration.name;
71615
71657
  var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
71616
- parent.kind !== 203 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
71658
+ parent.kind !== 203 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */);
71617
71659
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
71618
71660
  return undefined;
71619
71661
  if (parent.name.kind === 202 /* ArrayBindingPattern */) {
@@ -72100,9 +72142,14 @@ var ts;
72100
72142
  return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72101
72143
  }
72102
72144
  // For other purposes (e.g. determining whether to produce literal types) we only
72103
- // 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).
72104
72148
  if (inferenceContext.returnMapper) {
72105
- 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;
72106
72153
  }
72107
72154
  }
72108
72155
  }
@@ -74667,7 +74714,7 @@ var ts;
74667
74714
  }
74668
74715
  for (var i = 0; i < argCount; i++) {
74669
74716
  var arg = args[i];
74670
- if (arg.kind !== 227 /* OmittedExpression */) {
74717
+ if (arg.kind !== 227 /* OmittedExpression */ && !(checkMode & 32 /* IsForStringLiteralArgumentCompletions */ && hasSkipDirectInferenceFlag(arg))) {
74671
74718
  var paramType = getTypeAtPosition(signature, i);
74672
74719
  var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
74673
74720
  inferTypes(context.inferences, argType, paramType);
@@ -75352,7 +75399,7 @@ var ts;
75352
75399
  }
75353
75400
  }
75354
75401
  }
75355
- return getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);
75402
+ return getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
75356
75403
  function addImplementationSuccessElaboration(failed, diagnostic) {
75357
75404
  var _a, _b;
75358
75405
  var oldCandidatesForArgumentError = candidatesForArgumentError;
@@ -75453,14 +75500,14 @@ var ts;
75453
75500
  }
75454
75501
  }
75455
75502
  // No signature was applicable. We have already reported the errors for the invalid signature.
75456
- function getCandidateForOverloadFailure(node, candidates, args, hasCandidatesOutArray) {
75503
+ function getCandidateForOverloadFailure(node, candidates, args, hasCandidatesOutArray, checkMode) {
75457
75504
  ts.Debug.assert(candidates.length > 0); // Else should not have called this.
75458
75505
  checkNodeDeferred(node);
75459
75506
  // Normally we will combine overloads. Skip this if they have type parameters since that's hard to combine.
75460
75507
  // Don't do this if there is a `candidatesOutArray`,
75461
75508
  // because then we want the chosen best candidate to be one of the overloads, not a combination.
75462
75509
  return hasCandidatesOutArray || candidates.length === 1 || candidates.some(function (c) { return !!c.typeParameters; })
75463
- ? pickLongestCandidateSignature(node, candidates, args)
75510
+ ? pickLongestCandidateSignature(node, candidates, args, checkMode)
75464
75511
  : createUnionOfSignaturesForOverloadFailure(candidates);
75465
75512
  }
75466
75513
  function createUnionOfSignaturesForOverloadFailure(candidates) {
@@ -75508,7 +75555,7 @@ var ts;
75508
75555
  // This function is currently only used for erroneous overloads, so it's good enough to just use the first source.
75509
75556
  return createSymbolWithType(ts.first(sources), type);
75510
75557
  }
75511
- function pickLongestCandidateSignature(node, candidates, args) {
75558
+ function pickLongestCandidateSignature(node, candidates, args, checkMode) {
75512
75559
  // Pick the longest signature. This way we can get a contextual type for cases like:
75513
75560
  // declare function f(a: { xa: number; xb: number; }, b: number);
75514
75561
  // f({ |
@@ -75524,7 +75571,7 @@ var ts;
75524
75571
  var typeArgumentNodes = callLikeExpressionMayHaveTypeArguments(node) ? node.typeArguments : undefined;
75525
75572
  var instantiated = typeArgumentNodes
75526
75573
  ? createSignatureInstantiation(candidate, getTypeArgumentsFromNodes(typeArgumentNodes, typeParameters, ts.isInJSFile(node)))
75527
- : inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args);
75574
+ : inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args, checkMode);
75528
75575
  candidates[bestIndex] = instantiated;
75529
75576
  return instantiated;
75530
75577
  }
@@ -75538,9 +75585,9 @@ var ts;
75538
75585
  }
75539
75586
  return typeArguments;
75540
75587
  }
75541
- function inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args) {
75588
+ function inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args, checkMode) {
75542
75589
  var inferenceContext = createInferenceContext(typeParameters, candidate, /*flags*/ ts.isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */);
75543
- var typeArgumentTypes = inferTypeArguments(node, candidate, args, 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext);
75590
+ var typeArgumentTypes = inferTypeArguments(node, candidate, args, checkMode | 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext);
75544
75591
  return createSignatureInstantiation(candidate, typeArgumentTypes);
75545
75592
  }
75546
75593
  function getLongestCandidateIndex(candidates, argsCount) {
@@ -81606,7 +81653,7 @@ var ts;
81606
81653
  }
81607
81654
  // check private/protected variable access
81608
81655
  var parent = node.parent.parent;
81609
- var parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
81656
+ var parentCheckMode = node.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */;
81610
81657
  var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
81611
81658
  var name = node.propertyName || node.name;
81612
81659
  if (parentType && !ts.isBindingPattern(name)) {
@@ -111111,6 +111158,7 @@ var ts;
111111
111158
  writeLine();
111112
111159
  decreaseIndent();
111113
111160
  }
111161
+ emitList(node, node.members, 2 /* PreserveLines */);
111114
111162
  writePunctuation("}");
111115
111163
  }
111116
111164
  function emitLiteralType(node) {
@@ -116704,6 +116752,13 @@ var ts;
116704
116752
  return "skip";
116705
116753
  }
116706
116754
  break;
116755
+ case 270 /* ImportSpecifier */:
116756
+ case 275 /* ExportSpecifier */:
116757
+ if (node.isTypeOnly) {
116758
+ diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, ts.isImportSpecifier(node) ? "import...type" : "export...type"));
116759
+ return "skip";
116760
+ }
116761
+ break;
116707
116762
  case 265 /* ImportEqualsDeclaration */:
116708
116763
  diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.import_can_only_be_used_in_TypeScript_files));
116709
116764
  return "skip";
@@ -127148,6 +127203,14 @@ var ts;
127148
127203
  });
127149
127204
  }
127150
127205
  ts.signatureToDisplayParts = signatureToDisplayParts;
127206
+ function nodeToDisplayParts(node, enclosingDeclaration) {
127207
+ var file = enclosingDeclaration.getSourceFile();
127208
+ return mapToDisplayParts(function (writer) {
127209
+ var printer = ts.createPrinter({ removeComments: true, omitTrailingSemicolon: true });
127210
+ printer.writeNode(4 /* Unspecified */, node, file, writer);
127211
+ });
127212
+ }
127213
+ ts.nodeToDisplayParts = nodeToDisplayParts;
127151
127214
  function isImportOrExportSpecifierName(location) {
127152
127215
  return !!location.parent && ts.isImportOrExportSpecifier(location.parent) && location.parent.propertyName === location;
127153
127216
  }
@@ -129844,12 +129907,13 @@ var ts;
129844
129907
  }
129845
129908
  case 208 /* CallExpression */:
129846
129909
  case 209 /* NewExpression */:
129910
+ case 285 /* JsxAttribute */:
129847
129911
  if (!isRequireCallArgument(node) && !ts.isImportCall(parent)) {
129848
- var argumentInfo = ts.SignatureHelp.getArgumentInfoForCompletions(node, position, sourceFile);
129912
+ var argumentInfo = ts.SignatureHelp.getArgumentInfoForCompletions(parent.kind === 285 /* JsxAttribute */ ? parent.parent : node, position, sourceFile);
129849
129913
  // Get string literal completions from specialized signatures of the target
129850
129914
  // i.e. declare function f(a: 'A');
129851
129915
  // f("/*completion position*/")
129852
- return argumentInfo ? getStringLiteralCompletionsFromSignature(argumentInfo, typeChecker) : fromContextualType();
129916
+ return argumentInfo ? getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) : fromContextualType();
129853
129917
  }
129854
129918
  // falls through (is `require("")` or `require(""` or `import("")`)
129855
129919
  case 266 /* ImportDeclaration */:
@@ -129886,15 +129950,22 @@ var ts;
129886
129950
  return type !== current && ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal) ? type.literal.text : undefined;
129887
129951
  });
129888
129952
  }
129889
- function getStringLiteralCompletionsFromSignature(argumentInfo, checker) {
129953
+ function getStringLiteralCompletionsFromSignature(call, arg, argumentInfo, checker) {
129890
129954
  var isNewIdentifier = false;
129891
129955
  var uniques = new ts.Map();
129892
129956
  var candidates = [];
129893
- checker.getResolvedSignature(argumentInfo.invocation, candidates, argumentInfo.argumentCount);
129957
+ var editingArgument = ts.isJsxOpeningLikeElement(call) ? ts.Debug.checkDefined(ts.findAncestor(arg.parent, ts.isJsxAttribute)) : arg;
129958
+ checker.getResolvedSignatureForStringLiteralCompletions(call, editingArgument, candidates);
129894
129959
  var types = ts.flatMap(candidates, function (candidate) {
129895
129960
  if (!ts.signatureHasRestParameter(candidate) && argumentInfo.argumentCount > candidate.parameters.length)
129896
129961
  return;
129897
129962
  var type = candidate.getTypeParameterAtPosition(argumentInfo.argumentIndex);
129963
+ if (ts.isJsxOpeningLikeElement(call)) {
129964
+ var propType = checker.getTypeOfPropertyOfType(type, editingArgument.name.text);
129965
+ if (propType) {
129966
+ type = propType;
129967
+ }
129968
+ }
129898
129969
  isNewIdentifier = isNewIdentifier || !!(type.flags & 4 /* String */);
129899
129970
  return getStringLiteralTypes(type, uniques);
129900
129971
  });
@@ -130437,43 +130508,28 @@ var ts;
130437
130508
  // Exported only for tests
130438
130509
  Completions.moduleSpecifierResolutionLimit = 100;
130439
130510
  Completions.moduleSpecifierResolutionCacheAttemptLimit = 1000;
130440
- // NOTE: Make sure that each entry has the exact same number of digits
130441
- // since many implementations will sort by string contents,
130442
- // where "10" is considered less than "2".
130443
- var SortText;
130444
- (function (SortText) {
130445
- SortText["LocalDeclarationPriority"] = "10";
130446
- SortText["LocationPriority"] = "11";
130447
- SortText["OptionalMember"] = "12";
130448
- SortText["MemberDeclaredBySpreadAssignment"] = "13";
130449
- SortText["SuggestedClassMembers"] = "14";
130450
- SortText["GlobalsOrKeywords"] = "15";
130451
- SortText["AutoImportSuggestions"] = "16";
130452
- SortText["ClassMemberSnippets"] = "17";
130453
- SortText["JavascriptIdentifiers"] = "18";
130454
- SortText["DeprecatedLocalDeclarationPriority"] = "19";
130455
- SortText["DeprecatedLocationPriority"] = "20";
130456
- SortText["DeprecatedOptionalMember"] = "21";
130457
- SortText["DeprecatedMemberDeclaredBySpreadAssignment"] = "22";
130458
- SortText["DeprecatedSuggestedClassMembers"] = "23";
130459
- SortText["DeprecatedGlobalsOrKeywords"] = "24";
130460
- SortText["DeprecatedAutoImportSuggestions"] = "25";
130461
- })(SortText = Completions.SortText || (Completions.SortText = {}));
130462
- var SortTextId;
130463
- (function (SortTextId) {
130464
- SortTextId[SortTextId["LocalDeclarationPriority"] = 10] = "LocalDeclarationPriority";
130465
- SortTextId[SortTextId["LocationPriority"] = 11] = "LocationPriority";
130466
- SortTextId[SortTextId["OptionalMember"] = 12] = "OptionalMember";
130467
- SortTextId[SortTextId["MemberDeclaredBySpreadAssignment"] = 13] = "MemberDeclaredBySpreadAssignment";
130468
- SortTextId[SortTextId["SuggestedClassMembers"] = 14] = "SuggestedClassMembers";
130469
- SortTextId[SortTextId["GlobalsOrKeywords"] = 15] = "GlobalsOrKeywords";
130470
- SortTextId[SortTextId["AutoImportSuggestions"] = 16] = "AutoImportSuggestions";
130471
- // Don't use these directly.
130472
- SortTextId[SortTextId["_JavaScriptIdentifiers"] = 18] = "_JavaScriptIdentifiers";
130473
- SortTextId[SortTextId["_DeprecatedStart"] = 19] = "_DeprecatedStart";
130474
- SortTextId[SortTextId["_First"] = 10] = "_First";
130475
- SortTextId[SortTextId["DeprecatedOffset"] = 9] = "DeprecatedOffset";
130476
- })(SortTextId || (SortTextId = {}));
130511
+ Completions.SortText = {
130512
+ // Presets
130513
+ LocalDeclarationPriority: "10",
130514
+ LocationPriority: "11",
130515
+ OptionalMember: "12",
130516
+ MemberDeclaredBySpreadAssignment: "13",
130517
+ SuggestedClassMembers: "14",
130518
+ GlobalsOrKeywords: "15",
130519
+ AutoImportSuggestions: "16",
130520
+ ClassMemberSnippets: "17",
130521
+ JavascriptIdentifiers: "18",
130522
+ // Transformations
130523
+ Deprecated: function (sortText) {
130524
+ return "z" + sortText;
130525
+ },
130526
+ ObjectLiteralProperty: function (presetSortText, symbolDisplayName) {
130527
+ return presetSortText + "\0" + symbolDisplayName + "\0";
130528
+ },
130529
+ SortBelow: function (sortText) {
130530
+ return sortText + "1";
130531
+ },
130532
+ };
130477
130533
  /**
130478
130534
  * Special values for `CompletionInfo['source']` used to disambiguate
130479
130535
  * completion items with the same `name`. (Each completion item must
@@ -130493,6 +130549,8 @@ var ts;
130493
130549
  CompletionSource["ClassMemberSnippet"] = "ClassMemberSnippet/";
130494
130550
  /** A type-only import that needs to be promoted in order to be used at the completion location */
130495
130551
  CompletionSource["TypeOnlyAlias"] = "TypeOnlyAlias/";
130552
+ /** Auto-import that comes attached to an object literal method snippet */
130553
+ CompletionSource["ObjectLiteralMethodSnippet"] = "ObjectLiteralMethodSnippet/";
130496
130554
  })(CompletionSource = Completions.CompletionSource || (Completions.CompletionSource = {}));
130497
130555
  var SymbolOriginInfoKind;
130498
130556
  (function (SymbolOriginInfoKind) {
@@ -130503,6 +130561,7 @@ var ts;
130503
130561
  SymbolOriginInfoKind[SymbolOriginInfoKind["Nullable"] = 16] = "Nullable";
130504
130562
  SymbolOriginInfoKind[SymbolOriginInfoKind["ResolvedExport"] = 32] = "ResolvedExport";
130505
130563
  SymbolOriginInfoKind[SymbolOriginInfoKind["TypeOnlyAlias"] = 64] = "TypeOnlyAlias";
130564
+ SymbolOriginInfoKind[SymbolOriginInfoKind["ObjectLiteralMethod"] = 128] = "ObjectLiteralMethod";
130506
130565
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberNoExport"] = 2] = "SymbolMemberNoExport";
130507
130566
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberExport"] = 6] = "SymbolMemberExport";
130508
130567
  })(SymbolOriginInfoKind || (SymbolOriginInfoKind = {}));
@@ -130533,6 +130592,9 @@ var ts;
130533
130592
  function originIsTypeOnlyAlias(origin) {
130534
130593
  return !!(origin && origin.kind & 64 /* TypeOnlyAlias */);
130535
130594
  }
130595
+ function originIsObjectLiteralMethod(origin) {
130596
+ return !!(origin && origin.kind & 128 /* ObjectLiteralMethod */);
130597
+ }
130536
130598
  var KeywordCompletionFilters;
130537
130599
  (function (KeywordCompletionFilters) {
130538
130600
  KeywordCompletionFilters[KeywordCompletionFilters["None"] = 0] = "None";
@@ -130625,7 +130687,7 @@ var ts;
130625
130687
  && (previousToken.kind === 81 /* BreakKeyword */ || previousToken.kind === 86 /* ContinueKeyword */ || previousToken.kind === 79 /* Identifier */)) {
130626
130688
  return getLabelCompletionAtPosition(previousToken.parent);
130627
130689
  }
130628
- var completionData = getCompletionData(program, log, sourceFile, isUncheckedFile(sourceFile, compilerOptions), position, preferences, /*detailsEntryId*/ undefined, host, cancellationToken);
130690
+ var completionData = getCompletionData(program, log, sourceFile, compilerOptions, position, preferences, /*detailsEntryId*/ undefined, host, formatContext, cancellationToken);
130629
130691
  if (!completionData) {
130630
130692
  return undefined;
130631
130693
  }
@@ -130723,7 +130785,7 @@ var ts;
130723
130785
  name: ts.tokenToString(keyword),
130724
130786
  kind: "keyword" /* keyword */,
130725
130787
  kindModifiers: "" /* none */,
130726
- sortText: SortText.GlobalsOrKeywords,
130788
+ sortText: Completions.SortText.GlobalsOrKeywords,
130727
130789
  };
130728
130790
  }
130729
130791
  function specificKeywordCompletionInfo(entries, isNewIdentifierLocation) {
@@ -130752,7 +130814,7 @@ var ts;
130752
130814
  return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
130753
130815
  }
130754
130816
  function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position) {
130755
- var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
130817
+ var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextMap = completionData.symbolToSortTextMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
130756
130818
  // Verify if the file is JSX language variant
130757
130819
  if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
130758
130820
  var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
@@ -130763,7 +130825,7 @@ var ts;
130763
130825
  var entries = ts.createSortedArray();
130764
130826
  if (isUncheckedFile(sourceFile, compilerOptions)) {
130765
130827
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
130766
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
130828
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextMap, isJsxIdentifierExpected, isRightOfOpenTag);
130767
130829
  getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries);
130768
130830
  }
130769
130831
  else {
@@ -130771,7 +130833,7 @@ var ts;
130771
130833
  return undefined;
130772
130834
  }
130773
130835
  getCompletionEntriesFromSymbols(symbols, entries,
130774
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
130836
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextMap, isJsxIdentifierExpected, isRightOfOpenTag);
130775
130837
  }
130776
130838
  if (keywordFilters !== 0 /* None */) {
130777
130839
  var entryNames_1 = new ts.Set(entries.map(function (e) { return e.name; }));
@@ -130852,7 +130914,7 @@ var ts;
130852
130914
  name: fullClosingTag,
130853
130915
  kind: "class" /* classElement */,
130854
130916
  kindModifiers: undefined,
130855
- sortText: SortText.LocationPriority,
130917
+ sortText: Completions.SortText.LocationPriority,
130856
130918
  };
130857
130919
  return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, optionalReplacementSpan: replacementSpan, entries: [entry] };
130858
130920
  }
@@ -130871,7 +130933,7 @@ var ts;
130871
130933
  name: realName,
130872
130934
  kind: "warning" /* warning */,
130873
130935
  kindModifiers: "",
130874
- sortText: SortText.JavascriptIdentifiers,
130936
+ sortText: Completions.SortText.JavascriptIdentifiers,
130875
130937
  isFromUncheckedFile: true
130876
130938
  }, compareCompletionEntries);
130877
130939
  }
@@ -130882,7 +130944,7 @@ var ts;
130882
130944
  ts.isString(literal) ? ts.quote(sourceFile, preferences, literal) : JSON.stringify(literal);
130883
130945
  }
130884
130946
  function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
130885
- return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
130947
+ return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: Completions.SortText.LocationPriority };
130886
130948
  }
130887
130949
  function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag) {
130888
130950
  var _a, _b;
@@ -130893,6 +130955,7 @@ var ts;
130893
130955
  var source = getSourceFromOrigin(origin);
130894
130956
  var sourceDisplay;
130895
130957
  var hasAction;
130958
+ var labelDetails;
130896
130959
  var typeChecker = program.getTypeChecker();
130897
130960
  var insertQuestionDot = origin && originIsNullableMember(origin);
130898
130961
  var useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess;
@@ -130953,12 +131016,25 @@ var ts;
130953
131016
  isClassLikeMemberCompletion(symbol, location)) {
130954
131017
  var importAdder = void 0;
130955
131018
  (_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder, replacementSpan = _b.replacementSpan);
130956
- sortText = SortText.ClassMemberSnippets; // sortText has to be lower priority than the sortText for keywords. See #47852.
131019
+ sortText = Completions.SortText.ClassMemberSnippets; // sortText has to be lower priority than the sortText for keywords. See #47852.
130957
131020
  if (importAdder === null || importAdder === void 0 ? void 0 : importAdder.hasFixes()) {
130958
131021
  hasAction = true;
130959
131022
  source = CompletionSource.ClassMemberSnippet;
130960
131023
  }
130961
131024
  }
131025
+ if (origin && originIsObjectLiteralMethod(origin)) {
131026
+ var importAdder = void 0;
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
+ }
131032
+ source = CompletionSource.ObjectLiteralMethodSnippet;
131033
+ sortText = Completions.SortText.SortBelow(sortText);
131034
+ if (importAdder.hasFixes()) {
131035
+ hasAction = true;
131036
+ }
131037
+ }
130962
131038
  if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
130963
131039
  var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
130964
131040
  var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
@@ -131006,6 +131082,7 @@ var ts;
131006
131082
  insertText: insertText,
131007
131083
  replacementSpan: replacementSpan,
131008
131084
  sourceDisplay: sourceDisplay,
131085
+ labelDetails: labelDetails,
131009
131086
  isSnippet: isSnippet,
131010
131087
  isPackageJsonImport: originIsPackageJsonImport(origin) || undefined,
131011
131088
  isImportStatementCompletion: !!importCompletionNode || undefined,
@@ -131117,27 +131194,15 @@ var ts;
131117
131194
  completionNodes.push(node);
131118
131195
  }, body, 2 /* Property */, isAbstract);
131119
131196
  if (completionNodes.length) {
131197
+ var format = 1 /* MultiLine */ | 131072 /* NoTrailingNewLine */;
131120
131198
  replacementSpan = modifiersSpan;
131121
131199
  // If we have access to formatting settings, we print the nodes using the emitter,
131122
131200
  // and then format the printed text.
131123
131201
  if (formatContext) {
131124
- var syntheticFile_1 = {
131125
- text: printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile),
131126
- getLineAndCharacterOfPosition: function (pos) {
131127
- return ts.getLineAndCharacterOfPosition(this, pos);
131128
- },
131129
- };
131130
- var formatOptions_1 = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
131131
- var changes = ts.flatMap(completionNodes, function (node) {
131132
- var nodeWithPos = ts.textChanges.assignPositionsToNode(node);
131133
- return ts.formatting.formatNodeGivenIndentation(nodeWithPos, syntheticFile_1, sourceFile.languageVariant,
131134
- /* indentation */ 0,
131135
- /* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions_1 }));
131136
- });
131137
- insertText = ts.textChanges.applyChanges(syntheticFile_1.text, changes);
131202
+ insertText = printer.printAndFormatSnippetList(format, ts.factory.createNodeArray(completionNodes), sourceFile, formatContext);
131138
131203
  }
131139
131204
  else { // Otherwise, just use emitter to print the new nodes.
131140
- insertText = printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile);
131205
+ insertText = printer.printSnippetList(format, ts.factory.createNodeArray(completionNodes), sourceFile);
131141
131206
  }
131142
131207
  }
131143
131208
  return { insertText: insertText, isSnippet: isSnippet, importAdder: importAdder, replacementSpan: replacementSpan };
@@ -131187,12 +131252,113 @@ var ts;
131187
131252
  }
131188
131253
  return undefined;
131189
131254
  }
131255
+ function getEntryForObjectLiteralMethodCompletion(symbol, name, enclosingDeclaration, program, host, options, preferences, formatContext) {
131256
+ var isSnippet = preferences.includeCompletionsWithSnippetText || undefined;
131257
+ var insertText = name;
131258
+ var sourceFile = enclosingDeclaration.getSourceFile();
131259
+ var importAdder = ts.codefix.createImportAdder(sourceFile, program, preferences, host);
131260
+ var method = createObjectLiteralMethod(symbol, enclosingDeclaration, sourceFile, program, host, preferences, importAdder);
131261
+ if (!method) {
131262
+ return undefined;
131263
+ }
131264
+ var printer = createSnippetPrinter({
131265
+ removeComments: true,
131266
+ module: options.module,
131267
+ target: options.target,
131268
+ omitTrailingSemicolon: false,
131269
+ newLine: ts.getNewLineKind(ts.getNewLineCharacter(options, ts.maybeBind(host, host.getNewLine))),
131270
+ });
131271
+ if (formatContext) {
131272
+ insertText = printer.printAndFormatSnippetList(16 /* CommaDelimited */ | 64 /* AllowTrailingComma */, ts.factory.createNodeArray([method], /*hasTrailingComma*/ true), sourceFile, formatContext);
131273
+ }
131274
+ else {
131275
+ insertText = printer.printSnippetList(16 /* CommaDelimited */ | 64 /* AllowTrailingComma */, ts.factory.createNodeArray([method], /*hasTrailingComma*/ true), sourceFile);
131276
+ }
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 };
131290
+ }
131291
+ ;
131292
+ function createObjectLiteralMethod(symbol, enclosingDeclaration, sourceFile, program, host, preferences, importAdder) {
131293
+ var declarations = symbol.getDeclarations();
131294
+ if (!(declarations && declarations.length)) {
131295
+ return undefined;
131296
+ }
131297
+ var checker = program.getTypeChecker();
131298
+ var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
131299
+ var declaration = declarations[0];
131300
+ var name = ts.getSynthesizedDeepClone(ts.getNameOfDeclaration(declaration), /*includeTrivia*/ false);
131301
+ var type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
131302
+ var quotePreference = ts.getQuotePreference(sourceFile, preferences);
131303
+ var builderFlags = quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : undefined;
131304
+ switch (declaration.kind) {
131305
+ case 166 /* PropertySignature */:
131306
+ case 167 /* PropertyDeclaration */:
131307
+ case 168 /* MethodSignature */:
131308
+ case 169 /* MethodDeclaration */: {
131309
+ var effectiveType = type.flags & 1048576 /* Union */ && type.types.length < 10
131310
+ ? checker.getUnionType(type.types, 2 /* Subtype */)
131311
+ : type;
131312
+ if (effectiveType.flags & 1048576 /* Union */) {
131313
+ // Only offer the completion if there's a single function type component.
131314
+ var functionTypes = ts.filter(effectiveType.types, function (type) { return checker.getSignaturesOfType(type, 0 /* Call */).length > 0; });
131315
+ if (functionTypes.length === 1) {
131316
+ effectiveType = functionTypes[0];
131317
+ }
131318
+ else {
131319
+ return undefined;
131320
+ }
131321
+ }
131322
+ var signatures = checker.getSignaturesOfType(effectiveType, 0 /* Call */);
131323
+ if (signatures.length !== 1) {
131324
+ // We don't support overloads in object literals.
131325
+ return undefined;
131326
+ }
131327
+ var typeNode = checker.typeToTypeNode(effectiveType, enclosingDeclaration, builderFlags, ts.codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host }));
131328
+ if (!typeNode || !ts.isFunctionTypeNode(typeNode)) {
131329
+ return undefined;
131330
+ }
131331
+ var importableReference = ts.codefix.tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
131332
+ if (importableReference) {
131333
+ typeNode = importableReference.typeNode;
131334
+ ts.codefix.importSymbols(importAdder, importableReference.symbols);
131335
+ }
131336
+ var body = void 0;
131337
+ if (preferences.includeCompletionsWithSnippetText) {
131338
+ var emptyStmt = ts.factory.createEmptyStatement();
131339
+ body = ts.factory.createBlock([emptyStmt], /* multiline */ true);
131340
+ ts.setSnippetElement(emptyStmt, { kind: 0 /* TabStop */, order: 0 });
131341
+ }
131342
+ else {
131343
+ body = ts.factory.createBlock([], /* multiline */ true);
131344
+ }
131345
+ return ts.factory.createMethodDeclaration(
131346
+ /*decorators*/ undefined,
131347
+ /*modifiers*/ undefined,
131348
+ /*asteriskToken*/ undefined, name,
131349
+ /*questionToken*/ undefined, typeNode.typeParameters, typeNode.parameters, typeNode.type, body);
131350
+ }
131351
+ default:
131352
+ return undefined;
131353
+ }
131354
+ }
131190
131355
  function createSnippetPrinter(printerOptions) {
131191
131356
  var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
131192
131357
  var printer = ts.createPrinter(printerOptions, baseWriter);
131193
131358
  var writer = __assign(__assign({}, baseWriter), { write: function (s) { return baseWriter.write(ts.escapeSnippetText(s)); }, nonEscapingWrite: baseWriter.write, writeLiteral: function (s) { return baseWriter.writeLiteral(ts.escapeSnippetText(s)); }, writeStringLiteral: function (s) { return baseWriter.writeStringLiteral(ts.escapeSnippetText(s)); }, writeSymbol: function (s, symbol) { return baseWriter.writeSymbol(ts.escapeSnippetText(s), symbol); }, writeParameter: function (s) { return baseWriter.writeParameter(ts.escapeSnippetText(s)); }, writeComment: function (s) { return baseWriter.writeComment(ts.escapeSnippetText(s)); }, writeProperty: function (s) { return baseWriter.writeProperty(ts.escapeSnippetText(s)); } });
131194
131359
  return {
131195
131360
  printSnippetList: printSnippetList,
131361
+ printAndFormatSnippetList: printAndFormatSnippetList,
131196
131362
  };
131197
131363
  /* Snippet-escaping version of `printer.printList`. */
131198
131364
  function printSnippetList(format, list, sourceFile) {
@@ -131200,6 +131366,22 @@ var ts;
131200
131366
  printer.writeList(format, list, sourceFile, writer);
131201
131367
  return writer.getText();
131202
131368
  }
131369
+ function printAndFormatSnippetList(format, list, sourceFile, formatContext) {
131370
+ var syntheticFile = {
131371
+ text: printSnippetList(format, list, sourceFile),
131372
+ getLineAndCharacterOfPosition: function (pos) {
131373
+ return ts.getLineAndCharacterOfPosition(this, pos);
131374
+ },
131375
+ };
131376
+ var formatOptions = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
131377
+ var changes = ts.flatMap(list, function (node) {
131378
+ var nodeWithPos = ts.textChanges.assignPositionsToNode(node);
131379
+ return ts.formatting.formatNodeGivenIndentation(nodeWithPos, syntheticFile, sourceFile.languageVariant,
131380
+ /* indentation */ 0,
131381
+ /* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions }));
131382
+ });
131383
+ return ts.textChanges.applyChanges(syntheticFile.text, changes);
131384
+ }
131203
131385
  }
131204
131386
  function originToCompletionEntryData(origin) {
131205
131387
  var ambientModuleName = origin.fileName ? undefined : ts.stripQuotes(origin.moduleSymbol.name);
@@ -131297,7 +131479,7 @@ var ts;
131297
131479
  return CompletionSource.TypeOnlyAlias;
131298
131480
  }
131299
131481
  }
131300
- function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
131482
+ function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextMap, isJsxIdentifierExpected, isRightOfOpenTag) {
131301
131483
  var _a;
131302
131484
  var start = ts.timestamp();
131303
131485
  var variableDeclaration = getVariableDeclaration(location);
@@ -131312,12 +131494,12 @@ var ts;
131312
131494
  var symbol = symbols[i];
131313
131495
  var origin = symbolToOriginInfoMap === null || symbolToOriginInfoMap === void 0 ? void 0 : symbolToOriginInfoMap[i];
131314
131496
  var info = getCompletionEntryDisplayNameForSymbol(symbol, target, origin, kind, !!jsxIdentifierExpected);
131315
- if (!info || uniques.get(info.name) || kind === 1 /* Global */ && symbolToSortTextIdMap && !shouldIncludeSymbol(symbol, symbolToSortTextIdMap)) {
131497
+ if (!info || (uniques.get(info.name) && (!origin || !originIsObjectLiteralMethod(origin))) || kind === 1 /* Global */ && symbolToSortTextMap && !shouldIncludeSymbol(symbol, symbolToSortTextMap)) {
131316
131498
  continue;
131317
131499
  }
131318
131500
  var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
131319
- var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
131320
- var sortText = (isDeprecated(symbol, typeChecker) ? 9 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
131501
+ var originalSortText = (_a = symbolToSortTextMap === null || symbolToSortTextMap === void 0 ? void 0 : symbolToSortTextMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : Completions.SortText.LocationPriority;
131502
+ var sortText = (isDeprecated(symbol, typeChecker) ? Completions.SortText.Deprecated(originalSortText) : originalSortText);
131321
131503
  var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag);
131322
131504
  if (!entry) {
131323
131505
  continue;
@@ -131335,7 +131517,7 @@ var ts;
131335
131517
  has: function (name) { return uniques.has(name); },
131336
131518
  add: function (name) { return uniques.set(name, true); },
131337
131519
  };
131338
- function shouldIncludeSymbol(symbol, symbolToSortTextIdMap) {
131520
+ function shouldIncludeSymbol(symbol, symbolToSortTextMap) {
131339
131521
  var allFlags = symbol.flags;
131340
131522
  if (!ts.isSourceFile(location)) {
131341
131523
  // export = /**/ here we want to get all meanings, so any symbol is ok
@@ -131357,9 +131539,9 @@ var ts;
131357
131539
  // Auto Imports are not available for scripts so this conditional is always false
131358
131540
  if (!!sourceFile.externalModuleIndicator
131359
131541
  && !compilerOptions.allowUmdGlobalAccess
131360
- && symbolToSortTextIdMap[ts.getSymbolId(symbol)] === 15 /* GlobalsOrKeywords */
131361
- && (symbolToSortTextIdMap[ts.getSymbolId(symbolOrigin)] === 16 /* AutoImportSuggestions */
131362
- || symbolToSortTextIdMap[ts.getSymbolId(symbolOrigin)] === 11 /* LocationPriority */)) {
131542
+ && symbolToSortTextMap[ts.getSymbolId(symbol)] === Completions.SortText.GlobalsOrKeywords
131543
+ && (symbolToSortTextMap[ts.getSymbolId(symbolOrigin)] === Completions.SortText.AutoImportSuggestions
131544
+ || symbolToSortTextMap[ts.getSymbolId(symbolOrigin)] === Completions.SortText.LocationPriority)) {
131363
131545
  return false;
131364
131546
  }
131365
131547
  allFlags |= ts.getCombinedLocalAndExportSymbolFlags(symbolOrigin);
@@ -131399,7 +131581,7 @@ var ts;
131399
131581
  name: name,
131400
131582
  kindModifiers: "" /* none */,
131401
131583
  kind: "label" /* label */,
131402
- sortText: SortText.LocationPriority
131584
+ sortText: Completions.SortText.LocationPriority
131403
131585
  });
131404
131586
  }
131405
131587
  }
@@ -131425,7 +131607,7 @@ var ts;
131425
131607
  }
131426
131608
  }
131427
131609
  var compilerOptions = program.getCompilerOptions();
131428
- var completionData = getCompletionData(program, log, sourceFile, isUncheckedFile(sourceFile, compilerOptions), position, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true }, entryId, host);
131610
+ var completionData = getCompletionData(program, log, sourceFile, compilerOptions, position, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true }, entryId, host, /*formatContext*/ undefined);
131429
131611
  if (!completionData) {
131430
131612
  return { type: "none" };
131431
131613
  }
@@ -131443,7 +131625,9 @@ var ts;
131443
131625
  return ts.firstDefined(symbols, function (symbol, index) {
131444
131626
  var origin = symbolToOriginInfoMap[index];
131445
131627
  var info = getCompletionEntryDisplayNameForSymbol(symbol, ts.getEmitScriptTarget(compilerOptions), origin, completionKind, completionData.isJsxIdentifierExpected);
131446
- return info && info.name === entryId.name && (entryId.source === CompletionSource.ClassMemberSnippet && symbol.flags & 106500 /* ClassMember */ || getSourceFromOrigin(origin) === entryId.source)
131628
+ return info && info.name === entryId.name && (entryId.source === CompletionSource.ClassMemberSnippet && symbol.flags & 106500 /* ClassMember */
131629
+ || entryId.source === CompletionSource.ObjectLiteralMethodSnippet && symbol.flags & (4 /* Property */ | 8192 /* Method */)
131630
+ || getSourceFromOrigin(origin) === entryId.source)
131447
131631
  ? { type: "symbol", symbol: symbol, location: location, origin: origin, contextToken: contextToken, previousToken: previousToken, isJsxInitializer: isJsxInitializer, isTypeOnlyLocation: isTypeOnlyLocation }
131448
131632
  : undefined;
131449
131633
  }) || { type: "none" };
@@ -131525,6 +131709,20 @@ var ts;
131525
131709
  };
131526
131710
  }
131527
131711
  }
131712
+ if (source === CompletionSource.ObjectLiteralMethodSnippet) {
131713
+ var enclosingDeclaration = tryGetObjectLikeCompletionContainer(contextToken);
131714
+ var importAdder = getEntryForObjectLiteralMethodCompletion(symbol, name, enclosingDeclaration, program, host, compilerOptions, preferences, formatContext).importAdder;
131715
+ if (importAdder.hasFixes()) {
131716
+ var changes = ts.textChanges.ChangeTracker.with({ host: host, formatContext: formatContext, preferences: preferences }, importAdder.writeFixes);
131717
+ return {
131718
+ sourceDisplay: undefined,
131719
+ codeActions: [{
131720
+ changes: changes,
131721
+ description: ts.diagnosticToString([ts.Diagnostics.Includes_imports_of_types_referenced_by_0, name]),
131722
+ }],
131723
+ };
131724
+ }
131725
+ }
131528
131726
  if (originIsTypeOnlyAlias(origin)) {
131529
131727
  var codeAction_1 = ts.codefix.getPromoteTypeOnlyCompletionAction(sourceFile, origin.declaration.name, program, host, formatContext, preferences);
131530
131728
  ts.Debug.assertIsDefined(codeAction_1, "Expected to have a code action for promoting type-only alias");
@@ -131617,8 +131815,9 @@ var ts;
131617
131815
  var _a;
131618
131816
  return !!((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d.kind === 305 /* SourceFile */; }));
131619
131817
  }
131620
- function getCompletionData(program, log, sourceFile, isUncheckedFile, position, preferences, detailsEntryId, host, cancellationToken) {
131818
+ function getCompletionData(program, log, sourceFile, compilerOptions, position, preferences, detailsEntryId, host, formatContext, cancellationToken) {
131621
131819
  var typeChecker = program.getTypeChecker();
131820
+ var inUncheckedFile = isUncheckedFile(sourceFile, compilerOptions);
131622
131821
  var start = ts.timestamp();
131623
131822
  var currentToken = ts.getTokenAtPosition(sourceFile, position); // TODO: GH#15853
131624
131823
  // We will check for jsdoc comments with insideComment and getJsDocTagAtPosition. (TODO: that seems rather inefficient to check the same thing so many times.)
@@ -131861,7 +132060,7 @@ var ts;
131861
132060
  // This also gets mutated in nested-functions after the return
131862
132061
  var symbols = [];
131863
132062
  var symbolToOriginInfoMap = [];
131864
- var symbolToSortTextIdMap = [];
132063
+ var symbolToSortTextMap = [];
131865
132064
  var seenPropertySymbols = new ts.Map();
131866
132065
  var isTypeOnlyLocation = isTypeOnlyCompletion();
131867
132066
  var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
@@ -131916,7 +132115,7 @@ var ts;
131916
132115
  contextToken: contextToken,
131917
132116
  isJsxInitializer: isJsxInitializer,
131918
132117
  insideJsDocTagTypeExpression: insideJsDocTagTypeExpression,
131919
- symbolToSortTextIdMap: symbolToSortTextIdMap,
132118
+ symbolToSortTextMap: symbolToSortTextMap,
131920
132119
  isTypeOnlyLocation: isTypeOnlyLocation,
131921
132120
  isJsxIdentifierExpected: isJsxIdentifierExpected,
131922
132121
  isRightOfOpenTag: isRightOfOpenTag,
@@ -132030,7 +132229,7 @@ var ts;
132030
132229
  isNewIdentifierLocation = true;
132031
132230
  }
132032
132231
  var propertyAccess = node.kind === 200 /* ImportType */ ? node : node.parent;
132033
- if (isUncheckedFile) {
132232
+ if (inUncheckedFile) {
132034
132233
  // In javascript files, for union types, we don't just get the members that
132035
132234
  // the individual types have in common, we also include all the members that
132036
132235
  // each individual type has. This is because we're going to add all identifiers
@@ -132115,7 +132314,7 @@ var ts;
132115
132314
  }
132116
132315
  function addSymbolSortInfo(symbol) {
132117
132316
  if (isStaticProperty(symbol)) {
132118
- symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 10 /* LocalDeclarationPriority */;
132317
+ symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.LocalDeclarationPriority;
132119
132318
  }
132120
132319
  }
132121
132320
  function addSymbolOriginInfo(symbol) {
@@ -132225,7 +132424,7 @@ var ts;
132225
132424
  var symbol = symbols[i];
132226
132425
  if (!typeChecker.isArgumentsSymbol(symbol) &&
132227
132426
  !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === sourceFile; })) {
132228
- symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 15 /* GlobalsOrKeywords */;
132427
+ symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.GlobalsOrKeywords;
132229
132428
  }
132230
132429
  if (typeOnlyAliasNeedsPromotion && !(symbol.flags & 111551 /* Value */)) {
132231
132430
  var typeOnlyAliasDeclaration = symbol.declarations && ts.find(symbol.declarations, ts.isTypeOnlyImportOrExportDeclaration);
@@ -132243,7 +132442,7 @@ var ts;
132243
132442
  var symbol = _a[_i];
132244
132443
  symbolToOriginInfoMap[symbols.length] = { kind: 1 /* ThisType */ };
132245
132444
  symbols.push(symbol);
132246
- symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 14 /* SuggestedClassMembers */;
132445
+ symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.SuggestedClassMembers;
132247
132446
  }
132248
132447
  }
132249
132448
  }
@@ -132321,7 +132520,7 @@ var ts;
132321
132520
  }
132322
132521
  return false;
132323
132522
  }
132324
- /** Mutates `symbols`, `symbolToOriginInfoMap`, and `symbolToSortTextIdMap` */
132523
+ /** Mutates `symbols`, `symbolToOriginInfoMap`, and `symbolToSortTextMap` */
132325
132524
  function collectAutoImports() {
132326
132525
  var _a, _b;
132327
132526
  if (!shouldOfferImportCompletions())
@@ -132403,14 +132602,55 @@ var ts;
132403
132602
  }
132404
132603
  function pushAutoImportSymbol(symbol, origin) {
132405
132604
  var symbolId = ts.getSymbolId(symbol);
132406
- if (symbolToSortTextIdMap[symbolId] === 15 /* GlobalsOrKeywords */) {
132605
+ if (symbolToSortTextMap[symbolId] === Completions.SortText.GlobalsOrKeywords) {
132407
132606
  // If an auto-importable symbol is available as a global, don't add the auto import
132408
132607
  return;
132409
132608
  }
132410
132609
  symbolToOriginInfoMap[symbols.length] = origin;
132411
- symbolToSortTextIdMap[symbolId] = importCompletionNode ? 11 /* LocationPriority */ : 16 /* AutoImportSuggestions */;
132610
+ symbolToSortTextMap[symbolId] = importCompletionNode ? Completions.SortText.LocationPriority : Completions.SortText.AutoImportSuggestions;
132412
132611
  symbols.push(symbol);
132413
132612
  }
132613
+ /* Mutates `symbols` and `symbolToOriginInfoMap`. */
132614
+ function collectObjectLiteralMethodSymbols(members, enclosingDeclaration) {
132615
+ // TODO: support JS files.
132616
+ if (ts.isInJSFile(location)) {
132617
+ return;
132618
+ }
132619
+ members.forEach(function (member) {
132620
+ if (!isObjectLiteralMethodSymbol(member)) {
132621
+ return;
132622
+ }
132623
+ var displayName = getCompletionEntryDisplayNameForSymbol(member, ts.getEmitScriptTarget(compilerOptions),
132624
+ /*origin*/ undefined, 0 /* ObjectPropertyDeclaration */,
132625
+ /*jsxIdentifierExpected*/ false);
132626
+ if (!displayName) {
132627
+ return;
132628
+ }
132629
+ var name = displayName.name;
132630
+ var entryProps = getEntryForObjectLiteralMethodCompletion(member, name, enclosingDeclaration, program, host, compilerOptions, preferences, formatContext);
132631
+ if (!entryProps) {
132632
+ return;
132633
+ }
132634
+ var origin = __assign({ kind: 128 /* ObjectLiteralMethod */ }, entryProps);
132635
+ symbolToOriginInfoMap[symbols.length] = origin;
132636
+ symbols.push(member);
132637
+ });
132638
+ }
132639
+ function isObjectLiteralMethodSymbol(symbol) {
132640
+ /*
132641
+ For an object type
132642
+ `type Foo = {
132643
+ bar(x: number): void;
132644
+ foo: (x: string) => string;
132645
+ }`,
132646
+ `bar` will have symbol flag `Method`,
132647
+ `foo` will have symbol flag `Property`.
132648
+ */
132649
+ if (!(symbol.flags & (4 /* Property */ | 8192 /* Method */))) {
132650
+ return false;
132651
+ }
132652
+ return true;
132653
+ }
132414
132654
  /**
132415
132655
  * Finds the first node that "embraces" the position, so that one may
132416
132656
  * accurately aggregate locals from the closest containing scope.
@@ -132544,6 +132784,7 @@ var ts;
132544
132784
  * @returns true if 'symbols' was successfully populated; false otherwise.
132545
132785
  */
132546
132786
  function tryGetObjectLikeCompletionSymbols() {
132787
+ var symbolsStartIndex = symbols.length;
132547
132788
  var objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken);
132548
132789
  if (!objectLikeContainer)
132549
132790
  return 0 /* Continue */;
@@ -132608,9 +132849,16 @@ var ts;
132608
132849
  }
132609
132850
  if (typeMembers && typeMembers.length > 0) {
132610
132851
  // Add filtered items to the completion list
132611
- symbols = ts.concatenate(symbols, filterObjectMembersList(typeMembers, ts.Debug.checkDefined(existingMembers)));
132852
+ var filteredMembers = filterObjectMembersList(typeMembers, ts.Debug.checkDefined(existingMembers));
132853
+ symbols = ts.concatenate(symbols, filteredMembers);
132854
+ setSortTextToOptionalMember();
132855
+ if (objectLikeContainer.kind === 205 /* ObjectLiteralExpression */
132856
+ && preferences.includeCompletionsWithObjectLiteralMethodSnippets
132857
+ && preferences.includeCompletionsWithInsertText) {
132858
+ transformObjectLiteralMembersSortText(symbolsStartIndex);
132859
+ collectObjectLiteralMethodSymbols(filteredMembers, objectLikeContainer);
132860
+ }
132612
132861
  }
132613
- setSortTextToOptionalMember();
132614
132862
  return 1 /* Success */;
132615
132863
  }
132616
132864
  /**
@@ -132685,7 +132933,7 @@ var ts;
132685
132933
  var _a, _b;
132686
132934
  symbols.push(symbol);
132687
132935
  if ((_b = (_a = localsContainer.symbol) === null || _a === void 0 ? void 0 : _a.exports) === null || _b === void 0 ? void 0 : _b.has(name)) {
132688
- symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 12 /* OptionalMember */;
132936
+ symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.OptionalMember;
132689
132937
  }
132690
132938
  });
132691
132939
  return 1 /* Success */;
@@ -132740,29 +132988,6 @@ var ts;
132740
132988
  }
132741
132989
  return 1 /* Success */;
132742
132990
  }
132743
- /**
132744
- * Returns the immediate owning object literal or binding pattern of a context token,
132745
- * on the condition that one exists and that the context implies completion should be given.
132746
- */
132747
- function tryGetObjectLikeCompletionContainer(contextToken) {
132748
- if (contextToken) {
132749
- var parent = contextToken.parent;
132750
- switch (contextToken.kind) {
132751
- case 18 /* OpenBraceToken */: // const x = { |
132752
- case 27 /* CommaToken */: // const x = { a: 0, |
132753
- if (ts.isObjectLiteralExpression(parent) || ts.isObjectBindingPattern(parent)) {
132754
- return parent;
132755
- }
132756
- break;
132757
- case 41 /* AsteriskToken */:
132758
- return ts.isMethodDeclaration(parent) ? ts.tryCast(parent.parent, ts.isObjectLiteralExpression) : undefined;
132759
- case 79 /* Identifier */:
132760
- return contextToken.text === "async" && ts.isShorthandPropertyAssignment(contextToken.parent)
132761
- ? contextToken.parent.parent : undefined;
132762
- }
132763
- }
132764
- return undefined;
132765
- }
132766
132991
  function isConstructorParameterCompletion(node) {
132767
132992
  return !!node.parent && ts.isParameter(node.parent) && ts.isConstructorDeclaration(node.parent.parent)
132768
132993
  && (ts.isParameterPropertyModifier(node.kind) || ts.isDeclarationName(node));
@@ -133099,7 +133324,7 @@ var ts;
133099
133324
  var _a;
133100
133325
  if (m.flags & 16777216 /* Optional */) {
133101
133326
  var symbolId = ts.getSymbolId(m);
133102
- symbolToSortTextIdMap[symbolId] = (_a = symbolToSortTextIdMap[symbolId]) !== null && _a !== void 0 ? _a : 12 /* OptionalMember */;
133327
+ symbolToSortTextMap[symbolId] = (_a = symbolToSortTextMap[symbolId]) !== null && _a !== void 0 ? _a : Completions.SortText.OptionalMember;
133103
133328
  }
133104
133329
  });
133105
133330
  }
@@ -133111,7 +133336,23 @@ var ts;
133111
133336
  for (var _i = 0, contextualMemberSymbols_1 = contextualMemberSymbols; _i < contextualMemberSymbols_1.length; _i++) {
133112
133337
  var contextualMemberSymbol = contextualMemberSymbols_1[_i];
133113
133338
  if (membersDeclaredBySpreadAssignment.has(contextualMemberSymbol.name)) {
133114
- symbolToSortTextIdMap[ts.getSymbolId(contextualMemberSymbol)] = 13 /* MemberDeclaredBySpreadAssignment */;
133339
+ symbolToSortTextMap[ts.getSymbolId(contextualMemberSymbol)] = Completions.SortText.MemberDeclaredBySpreadAssignment;
133340
+ }
133341
+ }
133342
+ }
133343
+ function transformObjectLiteralMembersSortText(start) {
133344
+ var _a;
133345
+ for (var i = start; i < symbols.length; i++) {
133346
+ var symbol = symbols[i];
133347
+ var symbolId = ts.getSymbolId(symbol);
133348
+ var origin = symbolToOriginInfoMap === null || symbolToOriginInfoMap === void 0 ? void 0 : symbolToOriginInfoMap[i];
133349
+ var target = ts.getEmitScriptTarget(compilerOptions);
133350
+ var displayName = getCompletionEntryDisplayNameForSymbol(symbol, target, origin, 0 /* ObjectPropertyDeclaration */,
133351
+ /*jsxIdentifierExpected*/ false);
133352
+ if (displayName) {
133353
+ var originalSortText = (_a = symbolToSortTextMap[symbolId]) !== null && _a !== void 0 ? _a : Completions.SortText.LocationPriority;
133354
+ var name = displayName.name;
133355
+ symbolToSortTextMap[symbolId] = Completions.SortText.ObjectLiteralProperty(originalSortText, name);
133115
133356
  }
133116
133357
  }
133117
133358
  }
@@ -133185,6 +133426,29 @@ var ts;
133185
133426
  return node.getStart(sourceFile) <= position && position <= node.getEnd();
133186
133427
  }
133187
133428
  }
133429
+ /**
133430
+ * Returns the immediate owning object literal or binding pattern of a context token,
133431
+ * on the condition that one exists and that the context implies completion should be given.
133432
+ */
133433
+ function tryGetObjectLikeCompletionContainer(contextToken) {
133434
+ if (contextToken) {
133435
+ var parent = contextToken.parent;
133436
+ switch (contextToken.kind) {
133437
+ case 18 /* OpenBraceToken */: // const x = { |
133438
+ case 27 /* CommaToken */: // const x = { a: 0, |
133439
+ if (ts.isObjectLiteralExpression(parent) || ts.isObjectBindingPattern(parent)) {
133440
+ return parent;
133441
+ }
133442
+ break;
133443
+ case 41 /* AsteriskToken */:
133444
+ return ts.isMethodDeclaration(parent) ? ts.tryCast(parent.parent, ts.isObjectLiteralExpression) : undefined;
133445
+ case 79 /* Identifier */:
133446
+ return contextToken.text === "async" && ts.isShorthandPropertyAssignment(contextToken.parent)
133447
+ ? contextToken.parent.parent : undefined;
133448
+ }
133449
+ }
133450
+ return undefined;
133451
+ }
133188
133452
  function getRelevantTokens(position, sourceFile) {
133189
133453
  var previousToken = ts.findPrecedingToken(position, sourceFile);
133190
133454
  if (previousToken && position <= previousToken.end && (ts.isMemberName(previousToken) || ts.isKeyword(previousToken.kind))) {
@@ -133250,7 +133514,7 @@ var ts;
133250
133514
  name: ts.tokenToString(i),
133251
133515
  kind: "keyword" /* keyword */,
133252
133516
  kindModifiers: "" /* none */,
133253
- sortText: SortText.GlobalsOrKeywords
133517
+ sortText: Completions.SortText.GlobalsOrKeywords
133254
133518
  });
133255
133519
  }
133256
133520
  return res;
@@ -133378,7 +133642,7 @@ var ts;
133378
133642
  name: ts.tokenToString(129 /* AssertKeyword */),
133379
133643
  kind: "keyword" /* keyword */,
133380
133644
  kindModifiers: "" /* none */,
133381
- sortText: SortText.GlobalsOrKeywords,
133645
+ sortText: Completions.SortText.GlobalsOrKeywords,
133382
133646
  });
133383
133647
  }
133384
133648
  }
@@ -135192,9 +135456,10 @@ var ts;
135192
135456
  })(FindReferencesUse = FindAllReferences.FindReferencesUse || (FindAllReferences.FindReferencesUse = {}));
135193
135457
  function findReferencedSymbols(program, cancellationToken, sourceFiles, sourceFile, position) {
135194
135458
  var node = ts.getTouchingPropertyName(sourceFile, position);
135195
- 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);
135196
135461
  var checker = program.getTypeChecker();
135197
- var symbol = checker.getSymbolAtLocation(node);
135462
+ var symbol = checker.getSymbolAtLocation(ts.getAdjustedReferenceLocation(Core.getAdjustedNode(node, options)));
135198
135463
  return !referencedSymbols || !referencedSymbols.length ? undefined : ts.mapDefined(referencedSymbols, function (_a) {
135199
135464
  var definition = _a.definition, references = _a.references;
135200
135465
  // Only include referenced symbols that have a valid definition.
@@ -135539,12 +135804,7 @@ var ts;
135539
135804
  var _a, _b;
135540
135805
  if (options === void 0) { options = {}; }
135541
135806
  if (sourceFilesSet === void 0) { sourceFilesSet = new ts.Set(sourceFiles.map(function (f) { return f.fileName; })); }
135542
- if (options.use === 1 /* References */) {
135543
- node = ts.getAdjustedReferenceLocation(node);
135544
- }
135545
- else if (options.use === 2 /* Rename */) {
135546
- node = ts.getAdjustedRenameLocation(node);
135547
- }
135807
+ node = getAdjustedNode(node, options);
135548
135808
  if (ts.isSourceFile(node)) {
135549
135809
  var resolvedRef = ts.GoToDefinition.getReferenceAtPosition(node, position, program);
135550
135810
  if (!(resolvedRef === null || resolvedRef === void 0 ? void 0 : resolvedRef.file)) {
@@ -135605,6 +135865,16 @@ var ts;
135605
135865
  return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
135606
135866
  }
135607
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;
135608
135878
  function getReferencesForFileName(fileName, program, sourceFiles, sourceFilesSet) {
135609
135879
  var _a, _b;
135610
135880
  if (sourceFilesSet === void 0) { sourceFilesSet = new ts.Set(sourceFiles.map(function (f) { return f.fileName; })); }
@@ -138571,7 +138841,8 @@ var ts;
138571
138841
  return undefined;
138572
138842
  }
138573
138843
  var commentOwner = commentOwnerInfo.commentOwner, parameters = commentOwnerInfo.parameters, hasReturn = commentOwnerInfo.hasReturn;
138574
- 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) {
138575
138846
  return undefined;
138576
138847
  }
138577
138848
  var indentationStr = getIndentationStringAtPosition(sourceFile, position);
@@ -147265,25 +147536,25 @@ var ts;
147265
147536
  suffix: this.newLineCharacter
147266
147537
  });
147267
147538
  };
147268
- ChangeTracker.prototype.insertNodeAtClassStart = function (sourceFile, cls, newElement) {
147269
- this.insertNodeAtStartWorker(sourceFile, cls, newElement);
147539
+ ChangeTracker.prototype.insertMemberAtStart = function (sourceFile, node, newElement) {
147540
+ this.insertNodeAtStartWorker(sourceFile, node, newElement);
147270
147541
  };
147271
147542
  ChangeTracker.prototype.insertNodeAtObjectStart = function (sourceFile, obj, newElement) {
147272
147543
  this.insertNodeAtStartWorker(sourceFile, obj, newElement);
147273
147544
  };
147274
- ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile, cls, newElement) {
147545
+ ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile, node, newElement) {
147275
147546
  var _a;
147276
- var indentation = (_a = this.guessIndentationFromExistingMembers(sourceFile, cls)) !== null && _a !== void 0 ? _a : this.computeIndentationForNewMember(sourceFile, cls);
147277
- 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));
147278
147549
  };
147279
147550
  /**
147280
147551
  * Tries to guess the indentation from the existing members of a class/interface/object. All members must be on
147281
147552
  * new lines and must share the same indentation.
147282
147553
  */
147283
- ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile, cls) {
147554
+ ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile, node) {
147284
147555
  var indentation;
147285
- var lastRange = cls;
147286
- 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++) {
147287
147558
  var member = _a[_i];
147288
147559
  if (ts.rangeStartPositionsAreOnSameLine(lastRange, member, sourceFile)) {
147289
147560
  // each indented member must be on a new line
@@ -147302,13 +147573,13 @@ var ts;
147302
147573
  }
147303
147574
  return indentation;
147304
147575
  };
147305
- ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile, cls) {
147576
+ ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile, node) {
147306
147577
  var _a;
147307
- var clsStart = cls.getStart(sourceFile);
147308
- 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)
147309
147580
  + ((_a = this.formatContext.options.indentSize) !== null && _a !== void 0 ? _a : 4);
147310
147581
  };
147311
- ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile, cls, indentation) {
147582
+ ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile, node, indentation) {
147312
147583
  // Rules:
147313
147584
  // - Always insert leading newline.
147314
147585
  // - For object literals:
@@ -147318,11 +147589,11 @@ var ts;
147318
147589
  // and the node is empty (because we didn't add a trailing comma per the previous rule).
147319
147590
  // - Only insert a trailing newline if body is single-line and there are no other insertions for the node.
147320
147591
  // NOTE: This is handled in `finishClassesWithNodesInsertedAtStart`.
147321
- var members = getMembersOrProperties(cls);
147592
+ var members = getMembersOrProperties(node);
147322
147593
  var isEmpty = members.length === 0;
147323
- var isFirstInsertion = ts.addToSeen(this.classesWithNodesInsertedAtStart, ts.getNodeId(cls), { node: cls, sourceFile: sourceFile });
147324
- var insertTrailingComma = ts.isObjectLiteralExpression(cls) && (!ts.isJsonSourceFile(sourceFile) || !isEmpty);
147325
- 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;
147326
147597
  return {
147327
147598
  indentation: indentation,
147328
147599
  prefix: (insertLeadingComma ? "," : "") + this.newLineCharacter,
@@ -147616,8 +147887,8 @@ var ts;
147616
147887
  var close = ts.findChildOfKind(cls, 19 /* CloseBraceToken */, sourceFile);
147617
147888
  return [open === null || open === void 0 ? void 0 : open.end, close === null || close === void 0 ? void 0 : close.end];
147618
147889
  }
147619
- function getMembersOrProperties(cls) {
147620
- return ts.isObjectLiteralExpression(cls) ? cls.properties : cls.members;
147890
+ function getMembersOrProperties(node) {
147891
+ return ts.isObjectLiteralExpression(node) ? node.properties : node.members;
147621
147892
  }
147622
147893
  function getNewFileText(statements, scriptKind, newLineCharacter, formatContext) {
147623
147894
  return changesToText.newFileChangesWorker(/*oldFile*/ undefined, scriptKind, statements, newLineCharacter, formatContext);
@@ -150900,7 +151171,7 @@ var ts;
150900
151171
  changeTracker.insertNodeAfter(sourceFile, constructor, newElement);
150901
151172
  }
150902
151173
  else {
150903
- changeTracker.insertNodeAtClassStart(sourceFile, cls, newElement);
151174
+ changeTracker.insertMemberAtStart(sourceFile, cls, newElement);
150904
151175
  }
150905
151176
  }
150906
151177
  }
@@ -152684,7 +152955,7 @@ var ts;
152684
152955
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addFunctionDeclaration(t, context, info); });
152685
152956
  return [codefix.createCodeFixAction(fixMissingFunctionDeclaration, changes, [ts.Diagnostics.Add_missing_function_declaration_0, info.token.text], fixMissingFunctionDeclaration, ts.Diagnostics.Add_all_missing_function_declarations)];
152686
152957
  }
152687
- if (info.kind === 0 /* Enum */) {
152958
+ if (info.kind === 1 /* Enum */) {
152688
152959
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addEnumMemberDeclaration(t, context.program.getTypeChecker(), info); });
152689
152960
  return [codefix.createCodeFixAction(fixMissingMember, changes, [ts.Diagnostics.Add_missing_enum_member_0, info.token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members)];
152690
152961
  }
@@ -152712,10 +152983,10 @@ var ts;
152712
152983
  addJsxAttributes(changes, context, info);
152713
152984
  }
152714
152985
  else {
152715
- if (info.kind === 0 /* Enum */) {
152986
+ if (info.kind === 1 /* Enum */) {
152716
152987
  addEnumMemberDeclaration(changes, checker, info);
152717
152988
  }
152718
- if (info.kind === 1 /* ClassOrInterface */) {
152989
+ if (info.kind === 0 /* TypeLikeDeclaration */) {
152719
152990
  var parentDeclaration = info.parentDeclaration, token_1 = info.token;
152720
152991
  var infos = ts.getOrUpdate(typeDeclToMembers, parentDeclaration, function () { return []; });
152721
152992
  if (!infos.some(function (i) { return i.token.text === token_1.text; })) {
@@ -152724,11 +152995,11 @@ var ts;
152724
152995
  }
152725
152996
  }
152726
152997
  });
152727
- typeDeclToMembers.forEach(function (infos, classDeclaration) {
152728
- var supers = codefix.getAllSupers(classDeclaration, checker);
152998
+ typeDeclToMembers.forEach(function (infos, declaration) {
152999
+ var supers = ts.isTypeLiteralNode(declaration) ? undefined : codefix.getAllSupers(declaration, checker);
152729
153000
  var _loop_15 = function (info) {
152730
153001
  // If some superclass added this property, don't add it again.
152731
- if (supers.some(function (superClassOrInterface) {
153002
+ if (supers === null || supers === void 0 ? void 0 : supers.some(function (superClassOrInterface) {
152732
153003
  var superInfos = typeDeclToMembers.get(superClassOrInterface);
152733
153004
  return !!superInfos && superInfos.some(function (_a) {
152734
153005
  var token = _a.token;
@@ -152742,11 +153013,11 @@ var ts;
152742
153013
  addMethodDeclaration(context, changes, call, token, modifierFlags & 32 /* Static */, parentDeclaration, declSourceFile);
152743
153014
  }
152744
153015
  else {
152745
- if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration)) {
153016
+ if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration) && !ts.isTypeLiteralNode(parentDeclaration)) {
152746
153017
  addMissingMemberInJs(changes, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */));
152747
153018
  }
152748
153019
  else {
152749
- var typeNode = getTypeNode(program.getTypeChecker(), parentDeclaration, token);
153020
+ var typeNode = getTypeNode(checker, parentDeclaration, token);
152750
153021
  addPropertyDeclaration(changes, declSourceFile, parentDeclaration, token.text, typeNode, modifierFlags & 32 /* Static */);
152751
153022
  }
152752
153023
  }
@@ -152761,8 +153032,8 @@ var ts;
152761
153032
  });
152762
153033
  var InfoKind;
152763
153034
  (function (InfoKind) {
152764
- InfoKind[InfoKind["Enum"] = 0] = "Enum";
152765
- InfoKind[InfoKind["ClassOrInterface"] = 1] = "ClassOrInterface";
153035
+ InfoKind[InfoKind["TypeLikeDeclaration"] = 0] = "TypeLikeDeclaration";
153036
+ InfoKind[InfoKind["Enum"] = 1] = "Enum";
152766
153037
  InfoKind[InfoKind["Function"] = 2] = "Function";
152767
153038
  InfoKind[InfoKind["ObjectLiteral"] = 3] = "ObjectLiteral";
152768
153039
  InfoKind[InfoKind["JsxAttributes"] = 4] = "JsxAttributes";
@@ -152832,20 +153103,21 @@ var ts;
152832
153103
  if (!classDeclaration && ts.isPrivateIdentifier(token))
152833
153104
  return undefined;
152834
153105
  // Prefer to change the class instead of the interface if they are merged
152835
- var classOrInterface = classDeclaration || ts.find(symbol.declarations, ts.isInterfaceDeclaration);
152836
- if (classOrInterface && !isSourceFileFromLibrary(program, classOrInterface.getSourceFile())) {
152837
- var makeStatic = (leftExpressionType.target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
152838
- 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)))
152839
153110
  return undefined;
152840
- var declSourceFile = classOrInterface.getSourceFile();
152841
- 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 */);
152842
153114
  var isJSFile = ts.isSourceFileJS(declSourceFile);
152843
153115
  var call = ts.tryCast(parent.parent, ts.isCallExpression);
152844
- 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 };
152845
153117
  }
152846
153118
  var enumDeclaration = ts.find(symbol.declarations, ts.isEnumDeclaration);
152847
153119
  if (enumDeclaration && !ts.isPrivateIdentifier(token) && !isSourceFileFromLibrary(program, enumDeclaration.getSourceFile())) {
152848
- return { kind: 0 /* Enum */, token: token, parentDeclaration: enumDeclaration };
153120
+ return { kind: 1 /* Enum */, token: token, parentDeclaration: enumDeclaration };
152849
153121
  }
152850
153122
  return undefined;
152851
153123
  }
@@ -152858,7 +153130,7 @@ var ts;
152858
153130
  }
152859
153131
  function createActionForAddMissingMemberInJavascriptFile(context, _a) {
152860
153132
  var parentDeclaration = _a.parentDeclaration, declSourceFile = _a.declSourceFile, modifierFlags = _a.modifierFlags, token = _a.token;
152861
- if (ts.isInterfaceDeclaration(parentDeclaration)) {
153133
+ if (ts.isInterfaceDeclaration(parentDeclaration) || ts.isTypeLiteralNode(parentDeclaration)) {
152862
153134
  return undefined;
152863
153135
  }
152864
153136
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingMemberInJs(t, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */)); });
@@ -152869,7 +153141,7 @@ var ts;
152869
153141
  ts.isPrivateIdentifier(token) ? ts.Diagnostics.Declare_a_private_field_named_0 : ts.Diagnostics.Initialize_property_0_in_the_constructor;
152870
153142
  return codefix.createCodeFixAction(fixMissingMember, changes, [diagnostic, token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members);
152871
153143
  }
152872
- function addMissingMemberInJs(changeTracker, declSourceFile, classDeclaration, token, makeStatic) {
153144
+ function addMissingMemberInJs(changeTracker, sourceFile, classDeclaration, token, makeStatic) {
152873
153145
  var tokenName = token.text;
152874
153146
  if (makeStatic) {
152875
153147
  if (classDeclaration.kind === 226 /* ClassExpression */) {
@@ -152877,7 +153149,7 @@ var ts;
152877
153149
  }
152878
153150
  var className = classDeclaration.name.getText();
152879
153151
  var staticInitialization = initializePropertyToUndefined(ts.factory.createIdentifier(className), tokenName);
152880
- changeTracker.insertNodeAfter(declSourceFile, classDeclaration, staticInitialization);
153152
+ changeTracker.insertNodeAfter(sourceFile, classDeclaration, staticInitialization);
152881
153153
  }
152882
153154
  else if (ts.isPrivateIdentifier(token)) {
152883
153155
  var property = ts.factory.createPropertyDeclaration(
@@ -152888,10 +153160,10 @@ var ts;
152888
153160
  /*initializer*/ undefined);
152889
153161
  var lastProp = getNodeToInsertPropertyAfter(classDeclaration);
152890
153162
  if (lastProp) {
152891
- changeTracker.insertNodeAfter(declSourceFile, lastProp, property);
153163
+ changeTracker.insertNodeAfter(sourceFile, lastProp, property);
152892
153164
  }
152893
153165
  else {
152894
- changeTracker.insertNodeAtClassStart(declSourceFile, classDeclaration, property);
153166
+ changeTracker.insertMemberAtStart(sourceFile, classDeclaration, property);
152895
153167
  }
152896
153168
  }
152897
153169
  else {
@@ -152900,7 +153172,7 @@ var ts;
152900
153172
  return;
152901
153173
  }
152902
153174
  var propertyInitialization = initializePropertyToUndefined(ts.factory.createThis(), tokenName);
152903
- changeTracker.insertNodeAtConstructorEnd(declSourceFile, classConstructor, propertyInitialization);
153175
+ changeTracker.insertNodeAtConstructorEnd(sourceFile, classConstructor, propertyInitialization);
152904
153176
  }
152905
153177
  }
152906
153178
  function initializePropertyToUndefined(obj, propertyName) {
@@ -152922,13 +153194,13 @@ var ts;
152922
153194
  actions.push(createAddIndexSignatureAction(context, declSourceFile, parentDeclaration, token.text, typeNode));
152923
153195
  return actions;
152924
153196
  }
152925
- function getTypeNode(checker, classDeclaration, token) {
153197
+ function getTypeNode(checker, node, token) {
152926
153198
  var typeNode;
152927
153199
  if (token.parent.parent.kind === 221 /* BinaryExpression */) {
152928
153200
  var binaryExpression = token.parent.parent;
152929
153201
  var otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left;
152930
153202
  var widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
152931
- typeNode = checker.typeToTypeNode(widenedType, classDeclaration, 1 /* NoTruncation */);
153203
+ typeNode = checker.typeToTypeNode(widenedType, node, 1 /* NoTruncation */);
152932
153204
  }
152933
153205
  else {
152934
153206
  var contextualType = checker.getContextualType(token.parent);
@@ -152936,24 +153208,23 @@ var ts;
152936
153208
  }
152937
153209
  return typeNode || ts.factory.createKeywordTypeNode(130 /* AnyKeyword */);
152938
153210
  }
152939
- function addPropertyDeclaration(changeTracker, declSourceFile, classDeclaration, tokenName, typeNode, modifierFlags) {
152940
- var property = ts.factory.createPropertyDeclaration(
152941
- /*decorators*/ undefined,
152942
- /*modifiers*/ modifierFlags ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags)) : undefined, tokenName,
152943
- /*questionToken*/ undefined, typeNode,
152944
- /*initializer*/ undefined);
152945
- 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);
152946
153217
  if (lastProp) {
152947
- changeTracker.insertNodeAfter(declSourceFile, lastProp, property);
153218
+ changeTracker.insertNodeAfter(sourceFile, lastProp, property);
152948
153219
  }
152949
153220
  else {
152950
- changeTracker.insertNodeAtClassStart(declSourceFile, classDeclaration, property);
153221
+ changeTracker.insertMemberAtStart(sourceFile, node, property);
152951
153222
  }
152952
153223
  }
152953
153224
  // Gets the last of the first run of PropertyDeclarations, or undefined if the class does not start with a PropertyDeclaration.
152954
- function getNodeToInsertPropertyAfter(cls) {
153225
+ function getNodeToInsertPropertyAfter(node) {
152955
153226
  var res;
152956
- for (var _i = 0, _a = cls.members; _i < _a.length; _i++) {
153227
+ for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
152957
153228
  var member = _a[_i];
152958
153229
  if (!ts.isPropertyDeclaration(member))
152959
153230
  break;
@@ -152961,7 +153232,7 @@ var ts;
152961
153232
  }
152962
153233
  return res;
152963
153234
  }
152964
- function createAddIndexSignatureAction(context, declSourceFile, classDeclaration, tokenName, typeNode) {
153235
+ function createAddIndexSignatureAction(context, sourceFile, node, tokenName, typeNode) {
152965
153236
  // Index signatures cannot have the static modifier.
152966
153237
  var stringTypeNode = ts.factory.createKeywordTypeNode(150 /* StringKeyword */);
152967
153238
  var indexingParameter = ts.factory.createParameterDeclaration(
@@ -152973,7 +153244,7 @@ var ts;
152973
153244
  var indexSignature = ts.factory.createIndexSignature(
152974
153245
  /*decorators*/ undefined,
152975
153246
  /*modifiers*/ undefined, [indexingParameter], typeNode);
152976
- 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); });
152977
153248
  // No fixId here because code-fix-all currently only works on adding individual named properties.
152978
153249
  return codefix.createCodeFixActionWithoutFixAll(fixMissingMember, changes, [ts.Diagnostics.Add_index_signature_for_property_0, tokenName]);
152979
153250
  }
@@ -152996,13 +153267,14 @@ var ts;
152996
153267
  }
152997
153268
  function addMethodDeclaration(context, changes, callExpression, name, modifierFlags, parentDeclaration, sourceFile) {
152998
153269
  var importAdder = codefix.createImportAdder(sourceFile, context.program, context.preferences, context.host);
152999
- var methodDeclaration = codefix.createSignatureDeclarationFromCallExpression(169 /* MethodDeclaration */, context, importAdder, callExpression, name, modifierFlags, parentDeclaration);
153000
- var containingMethodDeclaration = ts.findAncestor(callExpression, function (n) { return ts.isMethodDeclaration(n) || ts.isConstructorDeclaration(n); });
153001
- if (containingMethodDeclaration && containingMethodDeclaration.parent === parentDeclaration) {
153002
- 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);
153003
153275
  }
153004
153276
  else {
153005
- changes.insertNodeAtClassStart(sourceFile, parentDeclaration, methodDeclaration);
153277
+ changes.insertMemberAtStart(sourceFile, parentDeclaration, signatureDeclaration);
153006
153278
  }
153007
153279
  importAdder.writeFixes(changes);
153008
153280
  }
@@ -153165,6 +153437,13 @@ var ts;
153165
153437
  return ts.isIdentifierText(targetProp.name, target, 1 /* JSX */) && !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
153166
153438
  });
153167
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
+ }
153168
153447
  })(codefix = ts.codefix || (ts.codefix = {}));
153169
153448
  })(ts || (ts = {}));
153170
153449
  /* @internal */
@@ -153308,7 +153587,7 @@ var ts;
153308
153587
  // so duplicates cannot occur.
153309
153588
  var abstractAndNonPrivateExtendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType).filter(symbolPointsToNonPrivateAndAbstractMember);
153310
153589
  var importAdder = codefix.createImportAdder(sourceFile, context.program, preferences, context.host);
153311
- 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); });
153312
153591
  importAdder.writeFixes(changeTracker);
153313
153592
  }
153314
153593
  function symbolPointsToNonPrivateAndAbstractMember(symbol) {
@@ -155881,13 +156160,20 @@ var ts;
155881
156160
  var type = isJs || contextualType === undefined
155882
156161
  ? undefined
155883
156162
  : checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
155884
- if (kind === 169 /* MethodDeclaration */) {
155885
- return ts.factory.createMethodDeclaration(
155886
- /*decorators*/ undefined, modifiers, asteriskToken, name,
155887
- /*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");
155888
156176
  }
155889
- return ts.factory.createFunctionDeclaration(
155890
- /*decorators*/ undefined, modifiers, asteriskToken, name, typeParameters, parameters, type, createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference));
155891
156177
  }
155892
156178
  codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
155893
156179
  function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
@@ -156213,7 +156499,7 @@ var ts;
156213
156499
  }
156214
156500
  }
156215
156501
  function insertAccessor(changeTracker, file, accessor, declaration, container) {
156216
- ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.insertNodeAtClassStart(file, container, accessor) :
156502
+ ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.insertMemberAtStart(file, container, accessor) :
156217
156503
  ts.isPropertyAssignment(declaration) ? changeTracker.insertNodeAfterComma(file, declaration, accessor) :
156218
156504
  changeTracker.insertNodeAfter(file, declaration, accessor);
156219
156505
  }
@@ -174823,10 +175109,26 @@ var ts;
174823
175109
  var prefix = args.prefix || "";
174824
175110
  var entries = ts.mapDefined(completions.entries, function (entry) {
174825
175111
  if (completions.isMemberCompletion || ts.startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) {
174826
- 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;
174827
175113
  var convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined;
174828
175114
  // Use `hasAction || undefined` to avoid serializing `false`.
174829
- 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
+ };
174830
175132
  }
174831
175133
  });
174832
175134
  if (kind === "completions" /* Completions */) {