@typescript-deploys/pr-build 5.0.0-pr-52899-2 → 5.0.0-pr-52944-9

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
@@ -11289,8 +11289,7 @@ var Diagnostics = {
11289
11289
  _0_is_possibly_undefined: diag(18048, 1 /* Error */, "_0_is_possibly_undefined_18048", "'{0}' is possibly 'undefined'."),
11290
11290
  _0_is_possibly_null_or_undefined: diag(18049, 1 /* Error */, "_0_is_possibly_null_or_undefined_18049", "'{0}' is possibly 'null' or 'undefined'."),
11291
11291
  The_value_0_cannot_be_used_here: diag(18050, 1 /* Error */, "The_value_0_cannot_be_used_here_18050", "The value '{0}' cannot be used here."),
11292
- Compiler_option_0_cannot_be_given_an_empty_string: diag(18051, 1 /* Error */, "Compiler_option_0_cannot_be_given_an_empty_string_18051", "Compiler option '{0}' cannot be given an empty string."),
11293
- Add_missing_comma_for_an_object_member_completion_0: diag(18052, 3 /* Message */, "Add_missing_comma_for_an_object_member_completion_0_18052", "Add missing comma for an object member completion '{0}'.")
11292
+ Compiler_option_0_cannot_be_given_an_empty_string: diag(18051, 1 /* Error */, "Compiler_option_0_cannot_be_given_an_empty_string_18051", "Compiler option '{0}' cannot be given an empty string.")
11294
11293
  };
11295
11294
 
11296
11295
  // src/compiler/scanner.ts
@@ -59029,27 +59028,15 @@ function createTypeChecker(host) {
59029
59028
  isInJSFile(signature.declaration)
59030
59029
  );
59031
59030
  }
59032
- function getBaseSignature(signature) {
59033
- const typeParameters = signature.typeParameters;
59034
- if (typeParameters) {
59035
- if (signature.baseSignatureCache) {
59036
- return signature.baseSignatureCache;
59037
- }
59038
- const typeEraser = createTypeEraser(typeParameters);
59039
- const baseConstraintMapper = createTypeMapper(typeParameters, map(typeParameters, (tp) => getConstraintOfTypeParameter(tp) || unknownType));
59040
- let baseConstraints = map(typeParameters, (tp) => instantiateType(tp, baseConstraintMapper) || unknownType);
59041
- for (let i = 0; i < typeParameters.length - 1; i++) {
59042
- baseConstraints = instantiateTypes(baseConstraints, baseConstraintMapper);
59043
- }
59044
- baseConstraints = instantiateTypes(baseConstraints, typeEraser);
59045
- return signature.baseSignatureCache = instantiateSignature(
59046
- signature,
59047
- createTypeMapper(typeParameters, baseConstraints),
59048
- /*eraseTypeParameters*/
59049
- true
59050
- );
59031
+ function getTypeParameterConstraintMapper(typeParameters) {
59032
+ const typeEraser = createTypeEraser(typeParameters);
59033
+ const baseConstraintMapper = createTypeMapper(typeParameters, map(typeParameters, (tp) => getConstraintOfTypeParameter(tp) || unknownType));
59034
+ let baseConstraints = map(typeParameters, (tp) => instantiateType(tp, baseConstraintMapper) || unknownType);
59035
+ for (let i = 0; i < typeParameters.length - 1; i++) {
59036
+ baseConstraints = instantiateTypes(baseConstraints, baseConstraintMapper);
59051
59037
  }
59052
- return signature;
59038
+ baseConstraints = instantiateTypes(baseConstraints, typeEraser);
59039
+ return createTypeMapper(typeParameters, baseConstraints);
59053
59040
  }
59054
59041
  function getOrCreateTypeFromSignature(signature) {
59055
59042
  var _a2;
@@ -61574,9 +61561,9 @@ function createTypeChecker(host) {
61574
61561
  }
61575
61562
  }
61576
61563
  if (!checkTypeDeferred) {
61577
- inferTypes(context.inferences, checkType, instantiateType(extendsType, freshMapper), 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
61564
+ inferTypes(context, checkType, instantiateType(extendsType, freshMapper), 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
61578
61565
  }
61579
- const innerMapper = combineTypeMappers(freshMapper, context.mapper);
61566
+ const innerMapper = combineTypeMappers(freshMapper, getMapperFromContext(context));
61580
61567
  combinedMapper = mapper ? combineTypeMappers(innerMapper, mapper) : innerMapper;
61581
61568
  }
61582
61569
  const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
@@ -62263,8 +62250,11 @@ function createTypeChecker(host) {
62263
62250
  void 0
62264
62251
  );
62265
62252
  }
62266
- function createBackreferenceMapper(context, index) {
62267
- const forwardInferences = context.inferences.slice(index);
62253
+ function createBackreferenceMapper(context, inference) {
62254
+ const inferences = context.inferences.indexOf(inference) >= 0 ? context.inferences : context.freeTypeVariables;
62255
+ Debug.assert(inferences, "Inference for backreference mapper must exist within provided context");
62256
+ const index = inferences.indexOf(inference);
62257
+ const forwardInferences = inferences.slice(index);
62268
62258
  return createTypeMapper(map(forwardInferences, (i) => i.typeParameter), map(forwardInferences, () => unknownType));
62269
62259
  }
62270
62260
  function combineTypeMappers(mapper1, mapper2) {
@@ -65078,9 +65068,10 @@ function createTypeChecker(host) {
65078
65068
  0 /* None */,
65079
65069
  isRelatedToWorker
65080
65070
  );
65081
- inferTypes(ctx.inferences, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
65082
- sourceExtends = instantiateType(sourceExtends, ctx.mapper);
65083
- mapper = ctx.mapper;
65071
+ inferTypes(ctx, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
65072
+ const newMapper = getMapperFromContext(ctx);
65073
+ sourceExtends = instantiateType(sourceExtends, newMapper);
65074
+ mapper = newMapper;
65084
65075
  }
65085
65076
  if (isTypeIdenticalTo(sourceExtends, target2.extendsType) && (isRelatedTo(source2.checkType, target2.checkType, 3 /* Both */) || isRelatedTo(target2.checkType, source2.checkType, 3 /* Both */))) {
65086
65077
  if (result2 = isRelatedTo(instantiateType(getTrueTypeFromConditionalType(source2), mapper), getTrueTypeFromConditionalType(target2), 3 /* Both */, reportErrors2)) {
@@ -66918,7 +66909,12 @@ function createTypeChecker(host) {
66918
66909
  return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
66919
66910
  }
66920
66911
  function cloneInferenceContext(context, extraFlags = 0) {
66921
- return context && createInferenceContextWorker(map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
66912
+ const newContext = context && createInferenceContextWorker(map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
66913
+ if (context && context.freeTypeVariables) {
66914
+ newContext.freeTypeVariables = map(context.freeTypeVariables, cloneInferenceInfo);
66915
+ newContext.freeTypeVariableSourceSignatures = new Map(mapIterator(context.freeTypeVariableSourceSignatures.entries(), ([k, v]) => [k, new Map(v.entries())]));
66916
+ }
66917
+ return newContext;
66922
66918
  }
66923
66919
  function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
66924
66920
  const context = {
@@ -66935,20 +66931,29 @@ function createTypeChecker(host) {
66935
66931
  return context;
66936
66932
  }
66937
66933
  function makeFixingMapperForContext(context) {
66938
- return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (inference, i) => () => {
66934
+ return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (inference) => () => {
66939
66935
  if (!inference.isFixed) {
66940
66936
  inferFromIntraExpressionSites(context);
66941
66937
  clearCachedInferences(context.inferences);
66942
66938
  inference.isFixed = true;
66943
66939
  }
66944
- return getInferredType(context, i);
66940
+ return getInferredType(context, inference);
66945
66941
  }));
66946
66942
  }
66947
66943
  function makeNonFixingMapperForContext(context) {
66948
- return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (_, i) => () => {
66949
- return getInferredType(context, i);
66944
+ return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (inference) => () => {
66945
+ return getInferredType(context, inference);
66950
66946
  }));
66951
66947
  }
66948
+ function makeFreeTypeVariableMapperForContext(context) {
66949
+ if (!context.freeTypeVariables)
66950
+ return void 0;
66951
+ const baseMapper = getTypeParameterConstraintMapper(map(context.freeTypeVariables, (i) => i.typeParameter));
66952
+ return context.freeTypeVariables.reduceRight(
66953
+ (previous, i) => combineTypeMappers(makeDeferredTypeMapper([i.typeParameter], [() => hasInferenceCandidatesOrDefault(i) ? getInferredType(context, i) : instantiateType(i.typeParameter, baseMapper)]), previous),
66954
+ baseMapper
66955
+ );
66956
+ }
66952
66957
  function clearCachedInferences(inferences) {
66953
66958
  for (const inference of inferences) {
66954
66959
  if (!inference.isFixed) {
@@ -66965,7 +66970,7 @@ function createTypeChecker(host) {
66965
66970
  for (const { node, type } of context.intraExpressionInferenceSites) {
66966
66971
  const contextualType = node.kind === 171 /* MethodDeclaration */ ? getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) : getContextualType2(node, 2 /* NoConstraints */);
66967
66972
  if (contextualType) {
66968
- inferTypes(context.inferences, type, contextualType);
66973
+ inferTypes(context, type, contextualType);
66969
66974
  }
66970
66975
  }
66971
66976
  context.intraExpressionInferenceSites = void 0;
@@ -67000,7 +67005,8 @@ function createTypeChecker(host) {
67000
67005
  return inferences.length ? createInferenceContextWorker(map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) : void 0;
67001
67006
  }
67002
67007
  function getMapperFromContext(context) {
67003
- return context && context.mapper;
67008
+ const innerContext = context && last(flattenInferenceContextAlternatives(context));
67009
+ return innerContext && innerContext.mapper && (innerContext.freeTypeVariables ? combineTypeMappers(innerContext.mapper, makeFreeTypeVariableMapperForContext(innerContext)) : innerContext.mapper);
67004
67010
  }
67005
67011
  function couldContainTypeVariables(type) {
67006
67012
  const objectFlags = getObjectFlags(type);
@@ -67100,8 +67106,15 @@ function createTypeChecker(host) {
67100
67106
  const typeParameter = getIndexedAccessType(constraint.type, getTypeParameterFromMappedType(target));
67101
67107
  const templateType = getTemplateTypeFromMappedType(target);
67102
67108
  const inference = createInferenceInfo(typeParameter);
67103
- inferTypes([inference], sourceType, templateType);
67104
- return getTypeFromInference(inference) || unknownType;
67109
+ const context = createInferenceContextWorker(
67110
+ [inference],
67111
+ /*signature*/
67112
+ void 0,
67113
+ 0 /* None */,
67114
+ compareTypesAssignable
67115
+ );
67116
+ inferTypes(context, sourceType, templateType);
67117
+ return getInferredTypes(context, returnFalse)[0] || unknownType;
67105
67118
  }
67106
67119
  function* getUnmatchedProperties(source, target, requireOptionalProperties, matchDiscriminantProperties) {
67107
67120
  const properties = getPropertiesOfType(target);
@@ -67278,7 +67291,15 @@ function createTypeChecker(host) {
67278
67291
  pos = p;
67279
67292
  }
67280
67293
  }
67281
- function inferTypes(inferences, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
67294
+ function flattenInferenceContextAlternatives(context) {
67295
+ return context.alternatives ? (context.alternatives.forEach((a) => mergeInferenceContexts(
67296
+ a,
67297
+ context,
67298
+ /*clone*/
67299
+ true
67300
+ )), context.alternatives) : [context];
67301
+ }
67302
+ function inferTypes(context, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
67282
67303
  let bivariant = false;
67283
67304
  let propagationType;
67284
67305
  let inferencePriority = 2048 /* MaxValue */;
@@ -67287,7 +67308,21 @@ function createTypeChecker(host) {
67287
67308
  let sourceStack;
67288
67309
  let targetStack;
67289
67310
  let expandingFlags = 0 /* None */;
67311
+ let useOnlyCachedAlternativeRoutes = false;
67290
67312
  inferFromTypes(originalSource, originalTarget);
67313
+ useOnlyCachedAlternativeRoutes = true;
67314
+ const group2 = forkInferenceContext();
67315
+ spawnAlternativeInferenceContext(
67316
+ group2,
67317
+ () => {
67318
+ if (length(context.freeTypeVariables)) {
67319
+ inferFromTypes(originalSource, instantiateType(originalTarget, context.nonFixingMapper));
67320
+ }
67321
+ },
67322
+ /*fork*/
67323
+ false
67324
+ );
67325
+ joinInferenceContext(group2);
67291
67326
  function inferFromTypes(source, target) {
67292
67327
  if (!couldContainTypeVariables(target)) {
67293
67328
  return;
@@ -67348,6 +67383,9 @@ function createTypeChecker(host) {
67348
67383
  if (getObjectFlags(source) & 262144 /* NonInferrableType */ || source === nonInferrableAnyType) {
67349
67384
  return;
67350
67385
  }
67386
+ if (useOnlyCachedAlternativeRoutes && source === target) {
67387
+ return;
67388
+ }
67351
67389
  if (!inference.isFixed) {
67352
67390
  if (inference.priority === void 0 || priority < inference.priority) {
67353
67391
  inference.candidates = void 0;
@@ -67360,16 +67398,16 @@ function createTypeChecker(host) {
67360
67398
  if (contravariant && !bivariant) {
67361
67399
  if (!contains(inference.contraCandidates, candidate)) {
67362
67400
  inference.contraCandidates = append(inference.contraCandidates, candidate);
67363
- clearCachedInferences(inferences);
67401
+ clearCachedInferences(context.inferences);
67364
67402
  }
67365
67403
  } else if (!contains(inference.candidates, candidate)) {
67366
67404
  inference.candidates = append(inference.candidates, candidate);
67367
- clearCachedInferences(inferences);
67405
+ clearCachedInferences(context.inferences);
67368
67406
  }
67369
67407
  }
67370
67408
  if (!(priority & 128 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
67371
67409
  inference.topLevel = false;
67372
- clearCachedInferences(inferences);
67410
+ clearCachedInferences(context.inferences);
67373
67411
  }
67374
67412
  }
67375
67413
  inferencePriority = Math.min(inferencePriority, priority);
@@ -67537,7 +67575,12 @@ function createTypeChecker(host) {
67537
67575
  }
67538
67576
  function getInferenceInfoForType(type) {
67539
67577
  if (type.flags & 8650752 /* TypeVariable */) {
67540
- for (const inference of inferences) {
67578
+ for (const inference of context.inferences) {
67579
+ if (type === inference.typeParameter) {
67580
+ return inference;
67581
+ }
67582
+ }
67583
+ for (const inference of context.freeTypeVariables || []) {
67541
67584
  if (type === inference.typeParameter) {
67542
67585
  return inference;
67543
67586
  }
@@ -67818,17 +67861,88 @@ function createTypeChecker(host) {
67818
67861
  }
67819
67862
  }
67820
67863
  }
67864
+ function forkInferenceContext() {
67865
+ return [];
67866
+ }
67867
+ function spawnAlternativeInferenceContext(group3, action, fork = true) {
67868
+ const oldContext = context;
67869
+ flattenInferenceContextAlternatives(context).forEach((alternative) => {
67870
+ const newContext = fork ? cloneInferenceContext(alternative) : alternative;
67871
+ context = newContext;
67872
+ action();
67873
+ context = oldContext;
67874
+ group3.push(...flattenInferenceContextAlternatives(newContext));
67875
+ });
67876
+ }
67877
+ function joinInferenceContext(group3) {
67878
+ group3 = group3.length < 10 ? deduplicate(group3, compareInferenceContext) : group3;
67879
+ if (group3.length === 1) {
67880
+ mergeInferenceContexts(context, group3[0]);
67881
+ context.freeTypeVariables = group3[0].freeTypeVariables;
67882
+ context.freeTypeVariableSourceSignatures = group3[0].freeTypeVariableSourceSignatures;
67883
+ context.inferredTypeParameters = group3[0].inferredTypeParameters;
67884
+ context.flags = group3[0].flags;
67885
+ context.alternatives = void 0;
67886
+ return;
67887
+ }
67888
+ context.alternatives = group3;
67889
+ }
67890
+ function compareInferenceContext(a, b) {
67891
+ return a.compareTypes === b.compareTypes && a.flags === b.flags && a.inferredTypeParameters === b.inferredTypeParameters && a.intraExpressionInferenceSites === b.intraExpressionInferenceSites && a.signature === b.signature && compareInferencesIdentical(a, a.inferences, b, b.inferences) && compareInferencesIdentical(a, a.freeTypeVariables, b, b.freeTypeVariables);
67892
+ }
67893
+ function compareInferencesIdentical(ctxA, a, ctxB, b) {
67894
+ if (length(a) !== length(b))
67895
+ return false;
67896
+ if (length(a) === 0)
67897
+ return true;
67898
+ for (let i = 0; i < length(a); i++) {
67899
+ if (a[i].typeParameter !== b[i].typeParameter || a[i].impliedArity !== b[i].impliedArity || a[i].isFixed !== b[i].isFixed || a[i].priority !== b[i].priority || a[i].topLevel !== b[i].topLevel || forEach(a, (_, i2) => getInferredType(ctxA, a[i2]) !== getInferredType(ctxB, b[i2])))
67900
+ return false;
67901
+ }
67902
+ return true;
67903
+ }
67821
67904
  function inferFromSignatures(source, target, kind) {
67905
+ var _a2, _b;
67822
67906
  const sourceSignatures = getSignaturesOfType(source, kind);
67823
67907
  const targetSignatures = getSignaturesOfType(target, kind);
67824
67908
  const sourceLen = sourceSignatures.length;
67825
67909
  const targetLen = targetSignatures.length;
67826
- const len = sourceLen < targetLen ? sourceLen : targetLen;
67827
- for (let i = 0; i < len; i++) {
67828
- inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
67910
+ if (targetLen === 1 && sourceLen > 1) {
67911
+ const group3 = forkInferenceContext();
67912
+ for (let i = 0; i < sourceLen; i++) {
67913
+ if (useOnlyCachedAlternativeRoutes && !((_b = (_a2 = context.freeTypeVariableSourceSignatures) == null ? void 0 : _a2.get(last(sourceStack))) == null ? void 0 : _b.get(sourceSignatures[i]))) {
67914
+ continue;
67915
+ }
67916
+ spawnAlternativeInferenceContext(
67917
+ group3,
67918
+ () => inferFromSignature(sourceSignatures[i], targetSignatures[0])
67919
+ );
67920
+ }
67921
+ joinInferenceContext(group3);
67922
+ } else {
67923
+ const len = sourceLen < targetLen ? sourceLen : targetLen;
67924
+ for (let i = 0; i < len; i++) {
67925
+ inferFromSignature(sourceSignatures[sourceLen - len + i], targetSignatures[targetLen - len + i]);
67926
+ }
67829
67927
  }
67830
67928
  }
67831
67929
  function inferFromSignature(source, target) {
67930
+ target = getErasedSignature(target);
67931
+ if (source.typeParameters) {
67932
+ let cache = (context.freeTypeVariableSourceSignatures || (context.freeTypeVariableSourceSignatures = /* @__PURE__ */ new Map())).get(last(sourceStack));
67933
+ if (!cache) {
67934
+ context.freeTypeVariableSourceSignatures.set(last(sourceStack), cache = /* @__PURE__ */ new Map());
67935
+ }
67936
+ const cached = cache.get(source);
67937
+ if (cached) {
67938
+ source = cached;
67939
+ } else {
67940
+ const originalSignature = source;
67941
+ source = instantiateSignature(source, makeUnaryTypeMapper(unknownType, unknownType));
67942
+ cache.set(originalSignature, source);
67943
+ (context.freeTypeVariables || (context.freeTypeVariables = [])).push(...map(source.typeParameters, createInferenceInfo));
67944
+ }
67945
+ }
67832
67946
  const saveBivariant = bivariant;
67833
67947
  const kind = target.declaration ? target.declaration.kind : 0 /* Unknown */;
67834
67948
  bivariant = bivariant || kind === 171 /* MethodDeclaration */ || kind === 170 /* MethodSignature */ || kind === 173 /* Constructor */;
@@ -67903,8 +68017,7 @@ function createTypeChecker(host) {
67903
68017
  const unwidenedType = inference.priority & 416 /* PriorityImpliesCombination */ ? getUnionType(baseCandidates, 2 /* Subtype */) : getCommonSupertype(baseCandidates);
67904
68018
  return getWidenedType(unwidenedType);
67905
68019
  }
67906
- function getInferredType(context, index) {
67907
- const inference = context.inferences[index];
68020
+ function getInferredType(context, inference) {
67908
68021
  if (!inference.inferredType) {
67909
68022
  let inferredType;
67910
68023
  const signature = context.signature;
@@ -67920,7 +68033,7 @@ function createTypeChecker(host) {
67920
68033
  } else {
67921
68034
  const defaultType = getDefaultFromTypeParameter(inference.typeParameter);
67922
68035
  if (defaultType) {
67923
- inferredType = instantiateType(defaultType, mergeTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
68036
+ inferredType = instantiateType(defaultType, mergeTypeMappers(createBackreferenceMapper(context, inference), context.nonFixingMapper));
67924
68037
  }
67925
68038
  }
67926
68039
  } else {
@@ -67940,12 +68053,24 @@ function createTypeChecker(host) {
67940
68053
  function getDefaultTypeArgumentType(isInJavaScriptFile) {
67941
68054
  return isInJavaScriptFile ? anyType : unknownType;
67942
68055
  }
67943
- function getInferredTypes(context) {
67944
- const result = [];
67945
- for (let i = 0; i < context.inferences.length; i++) {
67946
- result.push(getInferredType(context, i));
68056
+ function getInferredTypes(context, accept) {
68057
+ const alternatives = flattenInferenceContextAlternatives(context);
68058
+ let finalAlternative;
68059
+ for (let a = alternatives.length - 1; a >= 0; a--) {
68060
+ const context2 = alternatives[a];
68061
+ const freeTypeVariableMapper = makeFreeTypeVariableMapperForContext(context2);
68062
+ const result = [];
68063
+ for (const inference of context2.inferences) {
68064
+ result.push(instantiateType(getInferredType(context2, inference), freeTypeVariableMapper));
68065
+ }
68066
+ if (alternatives.length === 1 || accept(result)) {
68067
+ return result;
68068
+ }
68069
+ if (!finalAlternative) {
68070
+ finalAlternative = result;
68071
+ }
67947
68072
  }
67948
- return result;
68073
+ return finalAlternative;
67949
68074
  }
67950
68075
  function getCannotFindNameDiagnosticForName(node) {
67951
68076
  switch (node.escapedText) {
@@ -71323,8 +71448,11 @@ function createTypeChecker(host) {
71323
71448
  function instantiateContextualType(contextualType, node, contextFlags) {
71324
71449
  if (contextualType && maybeTypeOfKind(contextualType, 465829888 /* Instantiable */)) {
71325
71450
  const inferenceContext = getInferenceContext(node);
71326
- if (inferenceContext && contextFlags & 1 /* Signature */ && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault)) {
71327
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
71451
+ if (inferenceContext && contextFlags & 1 /* Signature */ && some(flatMap(flattenInferenceContextAlternatives(inferenceContext), (c) => c.inferences), hasInferenceCandidatesOrDefault)) {
71452
+ return getUnionType(map(
71453
+ flattenInferenceContextAlternatives(inferenceContext),
71454
+ (c) => instantiateInstantiableTypes(contextualType, c.nonFixingMapper)
71455
+ ));
71328
71456
  }
71329
71457
  if (inferenceContext == null ? void 0 : inferenceContext.returnMapper) {
71330
71458
  const type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
@@ -73683,23 +73811,23 @@ function createTypeChecker(host) {
73683
73811
  function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
73684
73812
  const context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
73685
73813
  const restType = getEffectiveRestType(contextualSignature);
73686
- const mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
73814
+ const mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : getMapperFromContext(inferenceContext));
73687
73815
  const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
73688
73816
  applyToParameterTypes(sourceSignature, signature, (source, target) => {
73689
- inferTypes(context.inferences, source, target);
73817
+ inferTypes(context, source, target);
73690
73818
  });
73691
73819
  if (!inferenceContext) {
73692
73820
  applyToReturnTypes(contextualSignature, signature, (source, target) => {
73693
- inferTypes(context.inferences, source, target, 128 /* ReturnType */);
73821
+ inferTypes(context, source, target, 128 /* ReturnType */);
73694
73822
  });
73695
73823
  }
73696
- return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
73824
+ return getSignatureInstantiation(signature, getInferredTypes(context, returnFalse), isInJSFile(contextualSignature.declaration));
73697
73825
  }
73698
- function inferJsxTypeArguments(node, signature, checkMode, context) {
73826
+ function inferJsxTypeArguments(node, signature, checkMode, context, accept) {
73699
73827
  const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
73700
73828
  const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode);
73701
- inferTypes(context.inferences, checkAttrType, paramType);
73702
- return getInferredTypes(context);
73829
+ inferTypes(context, checkAttrType, paramType);
73830
+ return getInferredTypes(context, accept);
73703
73831
  }
73704
73832
  function getThisArgumentType(thisArgumentNode) {
73705
73833
  if (!thisArgumentNode) {
@@ -73708,9 +73836,9 @@ function createTypeChecker(host) {
73708
73836
  const thisArgumentType = checkExpression(thisArgumentNode);
73709
73837
  return isOptionalChainRoot(thisArgumentNode.parent) ? getNonNullableType(thisArgumentType) : isOptionalChain(thisArgumentNode.parent) ? removeOptionalTypeMarker(thisArgumentType) : thisArgumentType;
73710
73838
  }
73711
- function inferTypeArguments(node, signature, args, checkMode, context) {
73839
+ function inferTypeArguments(node, signature, args, checkMode, context, accept) {
73712
73840
  if (isJsxOpeningLikeElement(node)) {
73713
- return inferJsxTypeArguments(node, signature, checkMode, context);
73841
+ return inferJsxTypeArguments(node, signature, checkMode, context, accept);
73714
73842
  }
73715
73843
  if (node.kind !== 167 /* Decorator */) {
73716
73844
  const skipBindingPatterns = every(signature.typeParameters, (p) => !!getDefaultFromTypeParameter(p));
@@ -73725,11 +73853,11 @@ function createTypeChecker(host) {
73725
73853
  const instantiatedType = instantiateType(contextualType, outerMapper);
73726
73854
  const contextualSignature = getSingleCallSignature(instantiatedType);
73727
73855
  const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : instantiatedType;
73728
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
73856
+ inferTypes(context, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
73729
73857
  }
73730
73858
  const returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
73731
73859
  const returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
73732
- inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
73860
+ inferTypes(returnContext, returnSourceType, inferenceTargetType);
73733
73861
  context.returnMapper = some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : void 0;
73734
73862
  }
73735
73863
  }
@@ -73745,7 +73873,7 @@ function createTypeChecker(host) {
73745
73873
  const thisType = getThisTypeOfSignature(signature);
73746
73874
  if (thisType && couldContainTypeVariables(thisType)) {
73747
73875
  const thisArgumentNode = getThisArgumentOfCall(node);
73748
- inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
73876
+ inferTypes(context, getThisArgumentType(thisArgumentNode), thisType);
73749
73877
  }
73750
73878
  for (let i = 0; i < argCount; i++) {
73751
73879
  const arg = args[i];
@@ -73753,15 +73881,15 @@ function createTypeChecker(host) {
73753
73881
  const paramType = getTypeAtPosition(signature, i);
73754
73882
  if (couldContainTypeVariables(paramType)) {
73755
73883
  const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
73756
- inferTypes(context.inferences, argType, paramType);
73884
+ inferTypes(context, argType, paramType);
73757
73885
  }
73758
73886
  }
73759
73887
  }
73760
73888
  if (restType && couldContainTypeVariables(restType)) {
73761
73889
  const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
73762
- inferTypes(context.inferences, spreadType, restType);
73890
+ inferTypes(context, spreadType, restType);
73763
73891
  }
73764
- return getInferredTypes(context);
73892
+ return getInferredTypes(context, accept);
73765
73893
  }
73766
73894
  function getMutableArrayOrTupleType(type) {
73767
73895
  return type.flags & 1048576 /* Union */ ? mapType(type, getMutableArrayOrTupleType) : type.flags & 1 /* Any */ || isMutableArrayOrTuple(getBaseConstraintOfType(type) || type) ? type : isTupleType(type) ? createTupleType(
@@ -74528,6 +74656,26 @@ function createTypeChecker(host) {
74528
74656
  }
74529
74657
  let checkCandidate;
74530
74658
  let inferenceContext;
74659
+ const acceptor = (types) => {
74660
+ const checkCandidate2 = getSignatureInstantiation(candidate, types, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
74661
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate2, signatureHelpTrailingComma2)) {
74662
+ return false;
74663
+ }
74664
+ if (getSignatureApplicabilityError(
74665
+ node,
74666
+ args,
74667
+ checkCandidate2,
74668
+ relation,
74669
+ argCheckMode,
74670
+ /*reportErrors*/
74671
+ false,
74672
+ /*containingMessageChain*/
74673
+ void 0
74674
+ )) {
74675
+ return false;
74676
+ }
74677
+ return true;
74678
+ };
74531
74679
  if (candidate.typeParameters) {
74532
74680
  let typeArgumentTypes;
74533
74681
  if (some(typeArguments)) {
@@ -74548,7 +74696,7 @@ function createTypeChecker(host) {
74548
74696
  /*flags*/
74549
74697
  isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */
74550
74698
  );
74551
- typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
74699
+ typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext, acceptor);
74552
74700
  argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
74553
74701
  }
74554
74702
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
@@ -74576,7 +74724,7 @@ function createTypeChecker(host) {
74576
74724
  if (argCheckMode) {
74577
74725
  argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
74578
74726
  if (inferenceContext) {
74579
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
74727
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext, acceptor);
74580
74728
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext.inferredTypeParameters);
74581
74729
  if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma2)) {
74582
74730
  candidateForArgumentArityError = checkCandidate;
@@ -74686,7 +74834,7 @@ function createTypeChecker(host) {
74686
74834
  /*flags*/
74687
74835
  isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */
74688
74836
  );
74689
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, checkMode | 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext);
74837
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, checkMode | 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext, returnFalse);
74690
74838
  return createSignatureInstantiation(candidate, typeArgumentTypes);
74691
74839
  }
74692
74840
  function getLongestCandidateIndex(candidates, argsCount) {
@@ -75954,7 +76102,7 @@ function createTypeChecker(host) {
75954
76102
  if (declaration.type) {
75955
76103
  const typeNode = getEffectiveTypeAnnotationNode(declaration);
75956
76104
  if (typeNode) {
75957
- inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
76105
+ inferTypes(inferenceContext, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
75958
76106
  }
75959
76107
  }
75960
76108
  }
@@ -76666,7 +76814,7 @@ function createTypeChecker(host) {
76666
76814
  instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext.nonFixingMapper);
76667
76815
  }
76668
76816
  }
76669
- instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ? instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature);
76817
+ instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ? instantiateSignature(contextualSignature, getMapperFromContext(inferenceContext)) : contextualSignature);
76670
76818
  assignContextualParameterTypes(signature, instantiatedContextualSignature);
76671
76819
  } else {
76672
76820
  assignNonContextualParameterTypes(signature);
@@ -78047,7 +78195,7 @@ function createTypeChecker(host) {
78047
78195
  return isAssertionExpression(parent2) && isConstTypeReference(parent2.type) || isJSDocTypeAssertion(parent2) && isConstTypeReference(getJSDocTypeAssertionType(parent2)) || isValidConstAssertionArgument(node) && isConstTypeParameterContext(node) || (isParenthesizedExpression(parent2) || isArrayLiteralExpression(parent2) || isSpreadElement(parent2)) && isConstContext(parent2) || (isPropertyAssignment(parent2) || isShorthandPropertyAssignment(parent2) || isTemplateSpan(parent2)) && isConstContext(parent2.parent);
78048
78196
  }
78049
78197
  function isConstTypeParameterContext(node) {
78050
- const contextualType = getContextualType2(node, 0 /* None */);
78198
+ const contextualType = getContextualType2(node, 1 /* Signature */);
78051
78199
  return !!contextualType && someType(contextualType, isConstTypeVariable);
78052
78200
  }
78053
78201
  function checkExpressionForMutableLocation(node, checkMode, forceTuple) {
@@ -78112,10 +78260,11 @@ function createTypeChecker(host) {
78112
78260
  if (returnSignature && !returnSignature.typeParameters && !every(context.inferences, hasInferenceCandidates)) {
78113
78261
  const uniqueTypeParameters = getUniqueTypeParameters(context, signature.typeParameters);
78114
78262
  const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters);
78115
- const inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
78263
+ const subcontext = cloneInferenceContext(context);
78264
+ subcontext.inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
78116
78265
  applyToParameterTypes(instantiatedSignature, contextualSignature, (source, target) => {
78117
78266
  inferTypes(
78118
- inferences,
78267
+ subcontext,
78119
78268
  source,
78120
78269
  target,
78121
78270
  /*priority*/
@@ -78124,12 +78273,12 @@ function createTypeChecker(host) {
78124
78273
  true
78125
78274
  );
78126
78275
  });
78127
- if (some(inferences, hasInferenceCandidates)) {
78276
+ if (some(subcontext.inferences, hasInferenceCandidates)) {
78128
78277
  applyToReturnTypes(instantiatedSignature, contextualSignature, (source, target) => {
78129
- inferTypes(inferences, source, target);
78278
+ inferTypes(subcontext, source, target);
78130
78279
  });
78131
- if (!hasOverlappingInferences(context.inferences, inferences)) {
78132
- mergeInferences(context.inferences, inferences);
78280
+ if (!hasOverlappingInferences(context.inferences, subcontext.inferences)) {
78281
+ mergeInferenceContexts(context, subcontext);
78133
78282
  context.inferredTypeParameters = concatenate(context.inferredTypeParameters, uniqueTypeParameters);
78134
78283
  return getOrCreateTypeFromSignature(instantiatedSignature);
78135
78284
  }
@@ -78162,13 +78311,22 @@ function createTypeChecker(host) {
78162
78311
  }
78163
78312
  return false;
78164
78313
  }
78165
- function mergeInferences(target, source) {
78314
+ function mergeInferences(target, source, clone2 = false) {
78166
78315
  for (let i = 0; i < target.length; i++) {
78167
78316
  if (!hasInferenceCandidates(target[i]) && hasInferenceCandidates(source[i])) {
78168
- target[i] = source[i];
78317
+ target[i] = clone2 ? {
78318
+ ...source[i],
78319
+ candidates: source[i].candidates && [...source[i].candidates],
78320
+ contraCandidates: source[i].contraCandidates && [...source[i].contraCandidates]
78321
+ } : source[i];
78169
78322
  }
78170
78323
  }
78171
78324
  }
78325
+ function mergeInferenceContexts(target, source, cloneInferences = false) {
78326
+ mergeInferences(target.inferences, source.inferences, cloneInferences);
78327
+ target.mapper = makeFixingMapperForContext(target);
78328
+ target.nonFixingMapper = makeNonFixingMapperForContext(target);
78329
+ }
78172
78330
  function getUniqueTypeParameters(context, typeParameters) {
78173
78331
  const result = [];
78174
78332
  let oldTypeParameters;
@@ -148295,7 +148453,6 @@ var CompletionSource = /* @__PURE__ */ ((CompletionSource2) => {
148295
148453
  CompletionSource2["TypeOnlyAlias"] = "TypeOnlyAlias/";
148296
148454
  CompletionSource2["ObjectLiteralMethodSnippet"] = "ObjectLiteralMethodSnippet/";
148297
148455
  CompletionSource2["SwitchCases"] = "SwitchCases/";
148298
- CompletionSource2["ObjectLiteralExpression"] = "ObjectLiteralExpression/";
148299
148456
  return CompletionSource2;
148300
148457
  })(CompletionSource || {});
148301
148458
  var SymbolOriginInfoKind = /* @__PURE__ */ ((SymbolOriginInfoKind2) => {
@@ -148893,7 +149050,6 @@ function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
148893
149050
  return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
148894
149051
  }
148895
149052
  function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, position, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importStatementCompletion, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag, includeSymbol) {
148896
- var _a2;
148897
149053
  let insertText;
148898
149054
  let replacementSpan = getReplacementSpanForContextToken(replacementToken);
148899
149055
  let data;
@@ -148951,10 +149107,6 @@ function createCompletionEntry(symbol, sortText, replacementToken, contextToken,
148951
149107
  if ((origin == null ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
148952
149108
  hasAction = true;
148953
149109
  }
148954
- if (contextToken && isPropertyAssignment(contextToken.parent) && ((_a2 = findNextToken(contextToken, contextToken == null ? void 0 : contextToken.parent, sourceFile)) == null ? void 0 : _a2.kind) !== 27 /* CommaToken */ && completionKind === 0 /* ObjectPropertyDeclaration */) {
148955
- source = "ObjectLiteralExpression/" /* ObjectLiteralExpression */;
148956
- hasAction = true;
148957
- }
148958
149110
  if (preferences.includeCompletionsWithClassMemberSnippets && preferences.includeCompletionsWithInsertText && completionKind === 3 /* MemberLike */ && isClassLikeMemberCompletion(symbol, location, sourceFile)) {
148959
149111
  let importAdder;
148960
149112
  ({ insertText, isSnippet, importAdder, replacementSpan } = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, position, contextToken, formatContext));
@@ -149643,7 +149795,7 @@ function getSymbolCompletionFromEntryId(program, log, sourceFile, position, entr
149643
149795
  return firstDefined(symbols, (symbol, index) => {
149644
149796
  const origin = symbolToOriginInfoMap[index];
149645
149797
  const info = getCompletionEntryDisplayNameForSymbol(symbol, getEmitScriptTarget(compilerOptions), origin, completionKind, completionData.isJsxIdentifierExpected);
149646
- return info && info.name === entryId.name && (entryId.source === "ClassMemberSnippet/" /* ClassMemberSnippet */ && symbol.flags & 106500 /* ClassMember */ || entryId.source === "ObjectLiteralMethodSnippet/" /* ObjectLiteralMethodSnippet */ && symbol.flags & (4 /* Property */ | 8192 /* Method */) || getSourceFromOrigin(origin) === entryId.source || entryId.source === "ObjectLiteralExpression/" /* ObjectLiteralExpression */) ? { type: "symbol", symbol, location, origin, contextToken, previousToken, isJsxInitializer, isTypeOnlyLocation } : void 0;
149798
+ return info && info.name === entryId.name && (entryId.source === "ClassMemberSnippet/" /* ClassMemberSnippet */ && symbol.flags & 106500 /* ClassMember */ || entryId.source === "ObjectLiteralMethodSnippet/" /* ObjectLiteralMethodSnippet */ && symbol.flags & (4 /* Property */ | 8192 /* Method */) || getSourceFromOrigin(origin) === entryId.source) ? { type: "symbol", symbol, location, origin, contextToken, previousToken, isJsxInitializer, isTypeOnlyLocation } : void 0;
149647
149799
  }) || { type: "none" };
149648
149800
  }
149649
149801
  function getCompletionEntryDetails(program, log, sourceFile, position, entryId, host, formatContext, preferences, cancellationToken) {
@@ -149781,21 +149933,6 @@ function getCompletionEntryCodeActionsAndSourceDisplay(name, location, contextTo
149781
149933
  Debug.assertIsDefined(codeAction2, "Expected to have a code action for promoting type-only alias");
149782
149934
  return { codeActions: [codeAction2], sourceDisplay: void 0 };
149783
149935
  }
149784
- if (source === "ObjectLiteralExpression/" /* ObjectLiteralExpression */ && contextToken) {
149785
- const changes = ts_textChanges_exports.ChangeTracker.with(
149786
- { host, formatContext, preferences },
149787
- (tracker) => tracker.insertText(sourceFile, contextToken.end, ",")
149788
- );
149789
- if (changes) {
149790
- return {
149791
- sourceDisplay: void 0,
149792
- codeActions: [{
149793
- changes,
149794
- description: diagnosticToString([Diagnostics.Add_missing_comma_for_an_object_member_completion_0, name])
149795
- }]
149796
- };
149797
- }
149798
- }
149799
149936
  if (!origin || !(originIsExport(origin) || originIsResolvedExport(origin))) {
149800
149937
  return { codeActions: void 0, sourceDisplay: void 0 };
149801
149938
  }
@@ -151203,10 +151340,6 @@ function tryGetObjectLikeCompletionContainer(contextToken) {
151203
151340
  return isMethodDeclaration(parent2) ? tryCast(parent2.parent, isObjectLiteralExpression) : void 0;
151204
151341
  case 79 /* Identifier */:
151205
151342
  return contextToken.text === "async" && isShorthandPropertyAssignment(contextToken.parent) ? contextToken.parent.parent : void 0;
151206
- default:
151207
- if (parent2.parent && isObjectLiteralExpression(parent2.parent) && contextToken.kind !== 58 /* ColonToken */) {
151208
- return parent2.parent;
151209
- }
151210
151343
  }
151211
151344
  }
151212
151345
  return void 0;
@@ -163900,10 +164033,6 @@ var ChangeTracker = class {
163900
164033
  const suffix = this.nextCommaToken(sourceFile, oldNode) ? "" : "," + this.newLineCharacter;
163901
164034
  this.replaceNode(sourceFile, oldNode, newNode, { suffix });
163902
164035
  }
163903
- replacePropertyAssignmentOnSameLine(sourceFile, oldNode, newNode) {
163904
- const suffix = this.nextCommaToken(sourceFile, oldNode) ? "" : ",";
163905
- this.replaceNode(sourceFile, oldNode, newNode, { suffix });
163906
- }
163907
164036
  insertNodeAt(sourceFile, pos, newNode, options = {}) {
163908
164037
  this.replaceRange(sourceFile, createRange(pos), newNode, options);
163909
164038
  }