@typescript-deploys/pr-build 5.9.0-pr-61359-4 → 5.9.0-pr-61535-10

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/_tsc.js CHANGED
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.9";
21
- var version = `${versionMajorMinor}.0-insiders.20250320`;
21
+ var version = `${versionMajorMinor}.0-insiders.20250416`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -3680,7 +3680,6 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
3680
3680
  ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
3681
3681
  ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
3682
3682
  ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
3683
- ObjectFlags3[ObjectFlags3["IsNarrowingType"] = 16777216] = "IsNarrowingType";
3684
3683
  ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
3685
3684
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
3686
3685
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
@@ -20014,6 +20013,82 @@ function getOptionsSyntaxByValue(optionsObject, name, value) {
20014
20013
  function forEachOptionsSyntaxByName(optionsObject, name, callback) {
20015
20014
  return forEachPropertyAssignment(optionsObject, name, callback);
20016
20015
  }
20016
+ function getSynthesizedDeepClone(node, includeTrivia = true) {
20017
+ const clone = node && getSynthesizedDeepCloneWorker(node);
20018
+ if (clone && !includeTrivia) suppressLeadingAndTrailingTrivia(clone);
20019
+ return setParentRecursive(
20020
+ clone,
20021
+ /*incremental*/
20022
+ false
20023
+ );
20024
+ }
20025
+ function getSynthesizedDeepCloneWithReplacements(node, includeTrivia, replaceNode) {
20026
+ let clone = replaceNode(node);
20027
+ if (clone) {
20028
+ setOriginalNode(clone, node);
20029
+ } else {
20030
+ clone = getSynthesizedDeepCloneWorker(node, replaceNode);
20031
+ }
20032
+ if (clone && !includeTrivia) suppressLeadingAndTrailingTrivia(clone);
20033
+ return clone;
20034
+ }
20035
+ function getSynthesizedDeepCloneWorker(node, replaceNode) {
20036
+ const nodeClone = replaceNode ? (n) => getSynthesizedDeepCloneWithReplacements(
20037
+ n,
20038
+ /*includeTrivia*/
20039
+ true,
20040
+ replaceNode
20041
+ ) : getSynthesizedDeepClone;
20042
+ const nodesClone = replaceNode ? (ns) => ns && getSynthesizedDeepClonesWithReplacements(
20043
+ ns,
20044
+ /*includeTrivia*/
20045
+ true,
20046
+ replaceNode
20047
+ ) : (ns) => ns && getSynthesizedDeepClones(ns);
20048
+ const visited = visitEachChild(
20049
+ node,
20050
+ nodeClone,
20051
+ /*context*/
20052
+ void 0,
20053
+ nodesClone,
20054
+ nodeClone
20055
+ );
20056
+ if (visited === node) {
20057
+ const clone = isStringLiteral(node) ? setOriginalNode(factory.createStringLiteralFromNode(node), node) : isNumericLiteral(node) ? setOriginalNode(factory.createNumericLiteral(node.text, node.numericLiteralFlags), node) : factory.cloneNode(node);
20058
+ return setTextRange(clone, node);
20059
+ }
20060
+ visited.parent = void 0;
20061
+ return visited;
20062
+ }
20063
+ function getSynthesizedDeepClones(nodes, includeTrivia = true) {
20064
+ if (nodes) {
20065
+ const cloned = factory.createNodeArray(nodes.map((n) => getSynthesizedDeepClone(n, includeTrivia)), nodes.hasTrailingComma);
20066
+ setTextRange(cloned, nodes);
20067
+ return cloned;
20068
+ }
20069
+ return nodes;
20070
+ }
20071
+ function getSynthesizedDeepClonesWithReplacements(nodes, includeTrivia, replaceNode) {
20072
+ return factory.createNodeArray(nodes.map((n) => getSynthesizedDeepCloneWithReplacements(n, includeTrivia, replaceNode)), nodes.hasTrailingComma);
20073
+ }
20074
+ function suppressLeadingAndTrailingTrivia(node) {
20075
+ suppressLeadingTrivia(node);
20076
+ suppressTrailingTrivia(node);
20077
+ }
20078
+ function suppressLeadingTrivia(node) {
20079
+ addEmitFlagsRecursively(node, 1024 /* NoLeadingComments */, getFirstChild);
20080
+ }
20081
+ function suppressTrailingTrivia(node) {
20082
+ addEmitFlagsRecursively(node, 2048 /* NoTrailingComments */, getLastChild);
20083
+ }
20084
+ function addEmitFlagsRecursively(node, flag, getChild) {
20085
+ addEmitFlags(node, flag);
20086
+ const child = getChild(node);
20087
+ if (child) addEmitFlagsRecursively(child, flag, getChild);
20088
+ }
20089
+ function getFirstChild(node) {
20090
+ return forEachChild(node, (child) => child);
20091
+ }
20017
20092
 
20018
20093
  // src/compiler/factory/baseNodeFactory.ts
20019
20094
  function createBaseNodeFactory() {
@@ -46377,11 +46452,11 @@ function createTypeChecker(host) {
46377
46452
  typePredicateToString: (predicate, enclosingDeclaration, flags) => {
46378
46453
  return typePredicateToString(predicate, getParseTreeNode(enclosingDeclaration), flags);
46379
46454
  },
46380
- writeSignature: (signature, enclosingDeclaration, flags, kind, writer) => {
46381
- return signatureToString(signature, getParseTreeNode(enclosingDeclaration), flags, kind, writer);
46455
+ writeSignature: (signature, enclosingDeclaration, flags, kind, writer, verbosityLevel, out) => {
46456
+ return signatureToString(signature, getParseTreeNode(enclosingDeclaration), flags, kind, writer, verbosityLevel, out);
46382
46457
  },
46383
- writeType: (type, enclosingDeclaration, flags, writer) => {
46384
- return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer);
46458
+ writeType: (type, enclosingDeclaration, flags, writer, verbosityLevel, out) => {
46459
+ return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer, verbosityLevel, out);
46385
46460
  },
46386
46461
  writeSymbol: (symbol, enclosingDeclaration, meaning, flags, writer) => {
46387
46462
  return symbolToString(symbol, getParseTreeNode(enclosingDeclaration), meaning, flags, writer);
@@ -46615,7 +46690,8 @@ function createTypeChecker(host) {
46615
46690
  isTypeParameterPossiblyReferenced,
46616
46691
  typeHasCallOrConstructSignatures,
46617
46692
  getSymbolFlags,
46618
- getTypeArgumentsForResolvedSignature
46693
+ getTypeArgumentsForResolvedSignature,
46694
+ isLibType
46619
46695
  };
46620
46696
  function getTypeArgumentsForResolvedSignature(signature) {
46621
46697
  if (signature.mapper === void 0) return void 0;
@@ -47127,6 +47203,9 @@ function createTypeChecker(host) {
47127
47203
  var inferenceContextNodes = [];
47128
47204
  var inferenceContexts = [];
47129
47205
  var inferenceContextCount = 0;
47206
+ var activeTypeMappers = [];
47207
+ var activeTypeMappersCaches = [];
47208
+ var activeTypeMappersCount = 0;
47130
47209
  var emptyStringType = getStringLiteralType("");
47131
47210
  var zeroType = getNumberLiteralType(0);
47132
47211
  var zeroBigIntType = getBigIntLiteralType({ negative: false, base10Value: "0" });
@@ -47179,7 +47258,6 @@ function createTypeChecker(host) {
47179
47258
  [".jsx", ".jsx"],
47180
47259
  [".json", ".json"]
47181
47260
  ];
47182
- var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
47183
47261
  initializeTypeChecker();
47184
47262
  return checker;
47185
47263
  function isDefinitelyReferenceToGlobalSymbolObject(node) {
@@ -50293,7 +50371,7 @@ function createTypeChecker(host) {
50293
50371
  return writer2;
50294
50372
  }
50295
50373
  }
50296
- function signatureToString(signature, enclosingDeclaration, flags = 0 /* None */, kind, writer) {
50374
+ function signatureToString(signature, enclosingDeclaration, flags = 0 /* None */, kind, writer, verbosityLevel, out) {
50297
50375
  return writer ? signatureToStringWorker(writer).getText() : usingSingleLineStringWriter(signatureToStringWorker);
50298
50376
  function signatureToStringWorker(writer2) {
50299
50377
  let sigOutput;
@@ -50302,7 +50380,18 @@ function createTypeChecker(host) {
50302
50380
  } else {
50303
50381
  sigOutput = kind === 1 /* Construct */ ? 180 /* ConstructSignature */ : 179 /* CallSignature */;
50304
50382
  }
50305
- const sig = nodeBuilder.signatureToSignatureDeclaration(signature, sigOutput, enclosingDeclaration, toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | 512 /* WriteTypeParametersInQualifiedName */);
50383
+ const sig = nodeBuilder.signatureToSignatureDeclaration(
50384
+ signature,
50385
+ sigOutput,
50386
+ enclosingDeclaration,
50387
+ toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | 512 /* WriteTypeParametersInQualifiedName */,
50388
+ /*internalFlags*/
50389
+ void 0,
50390
+ /*tracker*/
50391
+ void 0,
50392
+ verbosityLevel,
50393
+ out
50394
+ );
50306
50395
  const printer = createPrinterWithRemoveCommentsOmitTrailingSemicolon();
50307
50396
  const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
50308
50397
  printer.writeNode(
@@ -50315,14 +50404,18 @@ function createTypeChecker(host) {
50315
50404
  return writer2;
50316
50405
  }
50317
50406
  }
50318
- function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter("")) {
50407
+ function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter(""), verbosityLevel, out) {
50319
50408
  const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */;
50320
50409
  const typeNode = nodeBuilder.typeToTypeNode(
50321
50410
  type,
50322
50411
  enclosingDeclaration,
50323
- toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0 /* None */),
50412
+ toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0),
50324
50413
  /*internalFlags*/
50325
- void 0
50414
+ void 0,
50415
+ /*tracker*/
50416
+ void 0,
50417
+ verbosityLevel,
50418
+ out
50326
50419
  );
50327
50420
  if (typeNode === void 0) return Debug.fail("should always get typenode");
50328
50421
  const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
@@ -50401,7 +50494,6 @@ function createTypeChecker(host) {
50401
50494
  },
50402
50495
  isOptionalParameter,
50403
50496
  isUndefinedIdentifierExpression(node) {
50404
- Debug.assert(isExpressionNode(node));
50405
50497
  return getSymbolAtLocation(node) === undefinedSymbol;
50406
50498
  },
50407
50499
  isEntityNameVisible(context, entityName, shouldComputeAliasToMakeVisible) {
@@ -50553,31 +50645,120 @@ function createTypeChecker(host) {
50553
50645
  };
50554
50646
  return {
50555
50647
  syntacticBuilderResolver,
50556
- typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
50557
- typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
50558
- serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)),
50559
- serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)),
50560
- serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)),
50561
- indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
50562
- indexInfo,
50563
- context,
50564
- /*typeNode*/
50565
- void 0
50566
- )),
50567
- signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => signatureToSignatureDeclarationHelper(signature, kind, context)),
50568
- symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToName(
50569
- symbol,
50570
- context,
50571
- meaning,
50572
- /*expectsIdentifier*/
50573
- false
50574
- )),
50575
- symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToExpression(symbol, context, meaning)),
50576
- symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParametersToTypeParameterDeclarations(symbol, context)),
50577
- symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToParameterDeclaration(symbol, context)),
50578
- typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParameterToDeclaration(parameter, context)),
50579
- symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolTableToDeclarationStatements(symbolTable, context)),
50580
- symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToNode(symbol, context, meaning))
50648
+ typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeToTypeNodeHelper(type, context), out),
50649
+ typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50650
+ enclosingDeclaration,
50651
+ flags,
50652
+ internalFlags,
50653
+ tracker,
50654
+ /*verbosityLevel*/
50655
+ void 0,
50656
+ (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)
50657
+ ),
50658
+ serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50659
+ enclosingDeclaration,
50660
+ flags,
50661
+ internalFlags,
50662
+ tracker,
50663
+ /*verbosityLevel*/
50664
+ void 0,
50665
+ (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)
50666
+ ),
50667
+ serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50668
+ enclosingDeclaration,
50669
+ flags,
50670
+ internalFlags,
50671
+ tracker,
50672
+ /*verbosityLevel*/
50673
+ void 0,
50674
+ (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)
50675
+ ),
50676
+ serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50677
+ enclosingDeclaration,
50678
+ flags,
50679
+ internalFlags,
50680
+ tracker,
50681
+ /*verbosityLevel*/
50682
+ void 0,
50683
+ (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)
50684
+ ),
50685
+ indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50686
+ enclosingDeclaration,
50687
+ flags,
50688
+ internalFlags,
50689
+ tracker,
50690
+ /*verbosityLevel*/
50691
+ void 0,
50692
+ (context) => indexInfoToIndexSignatureDeclarationHelper(
50693
+ indexInfo,
50694
+ context,
50695
+ /*typeNode*/
50696
+ void 0
50697
+ )
50698
+ ),
50699
+ signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => signatureToSignatureDeclarationHelper(signature, kind, context), out),
50700
+ symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50701
+ enclosingDeclaration,
50702
+ flags,
50703
+ internalFlags,
50704
+ tracker,
50705
+ /*verbosityLevel*/
50706
+ void 0,
50707
+ (context) => symbolToName(
50708
+ symbol,
50709
+ context,
50710
+ meaning,
50711
+ /*expectsIdentifier*/
50712
+ false
50713
+ )
50714
+ ),
50715
+ symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50716
+ enclosingDeclaration,
50717
+ flags,
50718
+ internalFlags,
50719
+ tracker,
50720
+ /*verbosityLevel*/
50721
+ void 0,
50722
+ (context) => symbolToExpression(symbol, context, meaning)
50723
+ ),
50724
+ symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50725
+ enclosingDeclaration,
50726
+ flags,
50727
+ internalFlags,
50728
+ tracker,
50729
+ /*verbosityLevel*/
50730
+ void 0,
50731
+ (context) => typeParametersToTypeParameterDeclarations(symbol, context)
50732
+ ),
50733
+ symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50734
+ enclosingDeclaration,
50735
+ flags,
50736
+ internalFlags,
50737
+ tracker,
50738
+ /*verbosityLevel*/
50739
+ void 0,
50740
+ (context) => symbolToParameterDeclaration(symbol, context)
50741
+ ),
50742
+ typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeParameterToDeclaration(parameter, context), out),
50743
+ symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50744
+ enclosingDeclaration,
50745
+ flags,
50746
+ internalFlags,
50747
+ tracker,
50748
+ /*verbosityLevel*/
50749
+ void 0,
50750
+ (context) => symbolTableToDeclarationStatements(symbolTable, context)
50751
+ ),
50752
+ symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50753
+ enclosingDeclaration,
50754
+ flags,
50755
+ internalFlags,
50756
+ tracker,
50757
+ /*verbosityLevel*/
50758
+ void 0,
50759
+ (context) => symbolToNode(symbol, context, meaning)
50760
+ ),
50761
+ symbolToDeclarations
50581
50762
  };
50582
50763
  function getTypeFromTypeNode2(context, node, noMappedTypes) {
50583
50764
  const type = getTypeFromTypeNodeWithoutContext(node);
@@ -50619,7 +50800,75 @@ function createTypeChecker(host) {
50619
50800
  }
50620
50801
  return symbolToExpression(symbol, context, meaning);
50621
50802
  }
50622
- function withContext(enclosingDeclaration, flags, internalFlags, tracker, cb) {
50803
+ function symbolToDeclarations(symbol, meaning, flags, verbosityLevel, out) {
50804
+ const nodes = withContext(
50805
+ /*enclosingDeclaration*/
50806
+ void 0,
50807
+ flags,
50808
+ /*internalFlags*/
50809
+ void 0,
50810
+ /*tracker*/
50811
+ void 0,
50812
+ verbosityLevel,
50813
+ (context) => symbolToDeclarationsWorker(symbol, context),
50814
+ out
50815
+ );
50816
+ return mapDefined(nodes, (node) => {
50817
+ switch (node.kind) {
50818
+ case 263 /* ClassDeclaration */:
50819
+ return simplifyClassDeclaration(node, symbol);
50820
+ case 266 /* EnumDeclaration */:
50821
+ return simplifyModifiers(node, isEnumDeclaration, symbol);
50822
+ case 264 /* InterfaceDeclaration */:
50823
+ return simplifyInterfaceDeclaration(node, symbol, meaning);
50824
+ case 267 /* ModuleDeclaration */:
50825
+ return simplifyModifiers(node, isModuleDeclaration, symbol);
50826
+ default:
50827
+ return void 0;
50828
+ }
50829
+ });
50830
+ }
50831
+ function simplifyClassDeclaration(classDecl, symbol) {
50832
+ const classDeclarations = filter(symbol.declarations, isClassLike);
50833
+ const originalClassDecl = classDeclarations && classDeclarations.length > 0 ? classDeclarations[0] : classDecl;
50834
+ const modifiers = getEffectiveModifierFlags(originalClassDecl) & ~(32 /* Export */ | 128 /* Ambient */);
50835
+ const isAnonymous = isClassExpression(originalClassDecl);
50836
+ if (isAnonymous) {
50837
+ classDecl = factory.updateClassDeclaration(
50838
+ classDecl,
50839
+ classDecl.modifiers,
50840
+ /*name*/
50841
+ void 0,
50842
+ classDecl.typeParameters,
50843
+ classDecl.heritageClauses,
50844
+ classDecl.members
50845
+ );
50846
+ }
50847
+ return factory.replaceModifiers(classDecl, modifiers);
50848
+ }
50849
+ function simplifyModifiers(newDecl, isDeclKind, symbol) {
50850
+ const decls = filter(symbol.declarations, isDeclKind);
50851
+ const declWithModifiers = decls && decls.length > 0 ? decls[0] : newDecl;
50852
+ const modifiers = getEffectiveModifierFlags(declWithModifiers) & ~(32 /* Export */ | 128 /* Ambient */);
50853
+ return factory.replaceModifiers(newDecl, modifiers);
50854
+ }
50855
+ function simplifyInterfaceDeclaration(interfaceDecl, symbol, meaning) {
50856
+ if (!(meaning & 64 /* Interface */)) {
50857
+ return void 0;
50858
+ }
50859
+ return simplifyModifiers(interfaceDecl, isInterfaceDeclaration, symbol);
50860
+ }
50861
+ function symbolToDeclarationsWorker(symbol, context) {
50862
+ const type = getDeclaredTypeOfSymbol(symbol);
50863
+ context.typeStack.push(type.id);
50864
+ context.typeStack.push(-1);
50865
+ const table = createSymbolTable([symbol]);
50866
+ const statements = symbolTableToDeclarationStatements(table, context);
50867
+ context.typeStack.pop();
50868
+ context.typeStack.pop();
50869
+ return statements;
50870
+ }
50871
+ function withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, cb, out) {
50623
50872
  const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : (internalFlags || 0 /* None */) & 4 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
50624
50873
  const context = {
50625
50874
  enclosingDeclaration,
@@ -50627,6 +50876,7 @@ function createTypeChecker(host) {
50627
50876
  flags: flags || 0 /* None */,
50628
50877
  internalFlags: internalFlags || 0 /* None */,
50629
50878
  tracker: void 0,
50879
+ maxExpansionDepth: verbosityLevel ?? -1,
50630
50880
  encounteredError: false,
50631
50881
  suppressReportInferenceFallback: false,
50632
50882
  reportedDiagnostic: false,
@@ -50648,13 +50898,23 @@ function createTypeChecker(host) {
50648
50898
  typeParameterNamesByText: void 0,
50649
50899
  typeParameterNamesByTextNextNameCount: void 0,
50650
50900
  enclosingSymbolTypes: /* @__PURE__ */ new Map(),
50651
- mapper: void 0
50901
+ mapper: void 0,
50902
+ depth: 0,
50903
+ typeStack: [],
50904
+ out: {
50905
+ canIncreaseExpansionDepth: false,
50906
+ truncated: false
50907
+ }
50652
50908
  };
50653
50909
  context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
50654
50910
  const resultingNode = cb(context);
50655
50911
  if (context.truncating && context.flags & 1 /* NoTruncation */) {
50656
50912
  context.tracker.reportTruncationError();
50657
50913
  }
50914
+ if (out) {
50915
+ out.canIncreaseExpansionDepth = context.out.canIncreaseExpansionDepth;
50916
+ out.truncated = context.out.truncated;
50917
+ }
50658
50918
  return context.encounteredError ? void 0 : resultingNode;
50659
50919
  }
50660
50920
  function addSymbolTypeToContext(context, symbol, type) {
@@ -50673,19 +50933,49 @@ function createTypeChecker(host) {
50673
50933
  function saveRestoreFlags(context) {
50674
50934
  const flags = context.flags;
50675
50935
  const internalFlags = context.internalFlags;
50936
+ const depth = context.depth;
50676
50937
  return restore;
50677
50938
  function restore() {
50678
50939
  context.flags = flags;
50679
50940
  context.internalFlags = internalFlags;
50941
+ context.depth = depth;
50680
50942
  }
50681
50943
  }
50944
+ function checkTruncationLengthIfExpanding(context) {
50945
+ return context.maxExpansionDepth >= 0 && checkTruncationLength(context);
50946
+ }
50682
50947
  function checkTruncationLength(context) {
50683
50948
  if (context.truncating) return context.truncating;
50684
50949
  return context.truncating = context.approximateLength > (context.flags & 1 /* NoTruncation */ ? noTruncationMaximumTruncationLength : defaultMaximumTruncationLength);
50685
50950
  }
50951
+ function canPossiblyExpandType(type, context) {
50952
+ for (let i = 0; i < context.typeStack.length - 1; i++) {
50953
+ if (context.typeStack[i] === type.id) {
50954
+ return false;
50955
+ }
50956
+ }
50957
+ return context.depth < context.maxExpansionDepth || context.depth === context.maxExpansionDepth && !context.out.canIncreaseExpansionDepth;
50958
+ }
50959
+ function shouldExpandType(type, context, isAlias = false) {
50960
+ if (!isAlias && isLibType(type)) {
50961
+ return false;
50962
+ }
50963
+ for (let i = 0; i < context.typeStack.length - 1; i++) {
50964
+ if (context.typeStack[i] === type.id) {
50965
+ return false;
50966
+ }
50967
+ }
50968
+ const result = context.depth < context.maxExpansionDepth;
50969
+ if (!result) {
50970
+ context.out.canIncreaseExpansionDepth = true;
50971
+ }
50972
+ return result;
50973
+ }
50686
50974
  function typeToTypeNodeHelper(type, context) {
50687
50975
  const restoreFlags = saveRestoreFlags(context);
50976
+ if (type) context.typeStack.push(type.id);
50688
50977
  const typeNode = typeToTypeNodeWorker(type, context);
50978
+ if (type) context.typeStack.pop();
50689
50979
  restoreFlags();
50690
50980
  return typeNode;
50691
50981
  }
@@ -50696,6 +50986,7 @@ function createTypeChecker(host) {
50696
50986
  }
50697
50987
  const inTypeAlias = context.flags & 8388608 /* InTypeAlias */;
50698
50988
  context.flags &= ~8388608 /* InTypeAlias */;
50989
+ let expandingEnum = false;
50699
50990
  if (!type) {
50700
50991
  if (!(context.flags & 262144 /* AllowEmptyUnionOrIntersection */)) {
50701
50992
  context.encounteredError = true;
@@ -50763,7 +51054,11 @@ function createTypeChecker(host) {
50763
51054
  return Debug.fail("Unhandled type node kind returned from `symbolToTypeNode`.");
50764
51055
  }
50765
51056
  }
50766
- return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
51057
+ if (!shouldExpandType(type, context)) {
51058
+ return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
51059
+ } else {
51060
+ expandingEnum = true;
51061
+ }
50767
51062
  }
50768
51063
  if (type.flags & 128 /* StringLiteral */) {
50769
51064
  context.approximateLength += type.value.length + 2;
@@ -50830,16 +51125,34 @@ function createTypeChecker(host) {
50830
51125
  return factory.createThisTypeNode();
50831
51126
  }
50832
51127
  if (!inTypeAlias && type.aliasSymbol && (context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */ || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) {
50833
- const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
50834
- if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
50835
- if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
50836
- return factory.createArrayTypeNode(typeArgumentNodes[0]);
51128
+ if (!shouldExpandType(
51129
+ type,
51130
+ context,
51131
+ /*isAlias*/
51132
+ true
51133
+ )) {
51134
+ const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
51135
+ if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
51136
+ if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
51137
+ return factory.createArrayTypeNode(typeArgumentNodes[0]);
51138
+ }
51139
+ return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
50837
51140
  }
50838
- return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
51141
+ context.depth += 1;
50839
51142
  }
50840
51143
  const objectFlags = getObjectFlags(type);
50841
51144
  if (objectFlags & 4 /* Reference */) {
50842
51145
  Debug.assert(!!(type.flags & 524288 /* Object */));
51146
+ if (shouldExpandType(type, context)) {
51147
+ context.depth += 1;
51148
+ return createAnonymousTypeNode(
51149
+ type,
51150
+ /*forceClassExpansion*/
51151
+ true,
51152
+ /*forceExpansion*/
51153
+ true
51154
+ );
51155
+ }
50843
51156
  return type.node ? visitAndTransformType(type, typeReferenceToTypeNode) : typeReferenceToTypeNode(type);
50844
51157
  }
50845
51158
  if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
@@ -50869,6 +51182,16 @@ function createTypeChecker(host) {
50869
51182
  void 0
50870
51183
  );
50871
51184
  }
51185
+ if (objectFlags & 3 /* ClassOrInterface */ && shouldExpandType(type, context)) {
51186
+ context.depth += 1;
51187
+ return createAnonymousTypeNode(
51188
+ type,
51189
+ /*forceClassExpansion*/
51190
+ true,
51191
+ /*forceExpansion*/
51192
+ true
51193
+ );
51194
+ }
50872
51195
  if (type.symbol) {
50873
51196
  return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
50874
51197
  }
@@ -50883,7 +51206,7 @@ function createTypeChecker(host) {
50883
51206
  type = type.origin;
50884
51207
  }
50885
51208
  if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
50886
- const types = type.flags & 1048576 /* Union */ ? formatUnionTypes(type.types) : type.types;
51209
+ const types = type.flags & 1048576 /* Union */ ? formatUnionTypes(type.types, expandingEnum) : type.types;
50887
51210
  if (length(types) === 1) {
50888
51211
  return typeToTypeNodeHelper(types[0], context);
50889
51212
  }
@@ -51072,7 +51395,7 @@ function createTypeChecker(host) {
51072
51395
  }
51073
51396
  return result;
51074
51397
  }
51075
- function createAnonymousTypeNode(type2) {
51398
+ function createAnonymousTypeNode(type2, forceClassExpansion = false, forceExpansion = false) {
51076
51399
  var _a2, _b2;
51077
51400
  const typeId = type2.id;
51078
51401
  const symbol = type2.symbol;
@@ -51095,15 +51418,20 @@ function createTypeChecker(host) {
51095
51418
  const isInstanceType = isClassInstanceSide(type2) ? 788968 /* Type */ : 111551 /* Value */;
51096
51419
  if (isJSConstructor(symbol.valueDeclaration)) {
51097
51420
  return symbolToTypeNode(symbol, context, isInstanceType);
51098
- } else if (symbol.flags & 32 /* Class */ && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
51421
+ } else if (!forceExpansion && (symbol.flags & 32 /* Class */ && !forceClassExpansion && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
51099
51422
  symbol,
51100
51423
  context.enclosingDeclaration,
51101
51424
  isInstanceType,
51102
51425
  /*shouldComputeAliasesToMakeVisible*/
51103
51426
  false
51104
- ).accessibility !== 0 /* Accessible */)) || symbol.flags & (384 /* Enum */ | 512 /* ValueModule */) || shouldWriteTypeOfFunctionSymbol()) {
51105
- return symbolToTypeNode(symbol, context, isInstanceType);
51106
- } else if ((_b2 = context.visitedTypes) == null ? void 0 : _b2.has(typeId)) {
51427
+ ).accessibility !== 0 /* Accessible */)) || symbol.flags & (384 /* Enum */ | 512 /* ValueModule */) || shouldWriteTypeOfFunctionSymbol())) {
51428
+ if (shouldExpandType(type2, context)) {
51429
+ context.depth += 1;
51430
+ } else {
51431
+ return symbolToTypeNode(symbol, context, isInstanceType);
51432
+ }
51433
+ }
51434
+ if ((_b2 = context.visitedTypes) == null ? void 0 : _b2.has(typeId)) {
51107
51435
  const typeAlias = getTypeAliasForTypeLiteral(type2);
51108
51436
  if (typeAlias) {
51109
51437
  return symbolToTypeNode(typeAlias, context, 788968 /* Type */);
@@ -51139,7 +51467,7 @@ function createTypeChecker(host) {
51139
51467
  if (id && !context.symbolDepth) {
51140
51468
  context.symbolDepth = /* @__PURE__ */ new Map();
51141
51469
  }
51142
- const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
51470
+ const links = context.maxExpansionDepth >= 0 ? void 0 : context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
51143
51471
  const key = `${getTypeId(type2)}|${context.flags}|${context.internalFlags}`;
51144
51472
  if (links) {
51145
51473
  links.serializedTypes || (links.serializedTypes = /* @__PURE__ */ new Map());
@@ -51456,6 +51784,7 @@ function createTypeChecker(host) {
51456
51784
  }
51457
51785
  function createTypeNodesFromResolvedType(resolvedType) {
51458
51786
  if (checkTruncationLength(context)) {
51787
+ context.out.truncated = true;
51459
51788
  if (context.flags & 1 /* NoTruncation */) {
51460
51789
  return [addSyntheticTrailingComment(factory.createNotEmittedTypeElement(), 3 /* MultiLineCommentTrivia */, "elided")];
51461
51790
  }
@@ -51469,6 +51798,7 @@ function createTypeChecker(host) {
51469
51798
  void 0
51470
51799
  )];
51471
51800
  }
51801
+ context.typeStack.push(-1);
51472
51802
  const typeElements = [];
51473
51803
  for (const signature of resolvedType.callSignatures) {
51474
51804
  typeElements.push(signatureToSignatureDeclarationHelper(signature, 179 /* CallSignature */, context));
@@ -51482,10 +51812,14 @@ function createTypeChecker(host) {
51482
51812
  }
51483
51813
  const properties = resolvedType.properties;
51484
51814
  if (!properties) {
51815
+ context.typeStack.pop();
51485
51816
  return typeElements;
51486
51817
  }
51487
51818
  let i = 0;
51488
51819
  for (const propertySymbol of properties) {
51820
+ if (isExpanding(context) && propertySymbol.flags & 4194304 /* Prototype */) {
51821
+ continue;
51822
+ }
51489
51823
  i++;
51490
51824
  if (context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */) {
51491
51825
  if (propertySymbol.flags & 4194304 /* Prototype */) {
@@ -51496,6 +51830,7 @@ function createTypeChecker(host) {
51496
51830
  }
51497
51831
  }
51498
51832
  if (checkTruncationLength(context) && i + 2 < properties.length - 1) {
51833
+ context.out.truncated = true;
51499
51834
  if (context.flags & 1 /* NoTruncation */) {
51500
51835
  const typeElement = typeElements.pop();
51501
51836
  typeElements.push(addSyntheticTrailingComment(typeElement, 3 /* MultiLineCommentTrivia */, `... ${properties.length - i} more elided ...`));
@@ -51515,6 +51850,7 @@ function createTypeChecker(host) {
51515
51850
  }
51516
51851
  addPropertyToElementList(propertySymbol, context, typeElements);
51517
51852
  }
51853
+ context.typeStack.pop();
51518
51854
  return typeElements.length ? typeElements : void 0;
51519
51855
  }
51520
51856
  }
@@ -51663,6 +51999,7 @@ function createTypeChecker(host) {
51663
51999
  function mapToTypeNodes(types, context, isBareList) {
51664
52000
  if (some(types)) {
51665
52001
  if (checkTruncationLength(context)) {
52002
+ context.out.truncated = true;
51666
52003
  if (!isBareList) {
51667
52004
  return [
51668
52005
  context.flags & 1 /* NoTruncation */ ? addSyntheticLeadingComment(factory.createKeywordTypeNode(133 /* AnyKeyword */), 3 /* MultiLineCommentTrivia */, "elided") : factory.createTypeReferenceNode(
@@ -51690,6 +52027,7 @@ function createTypeChecker(host) {
51690
52027
  for (const type of types) {
51691
52028
  i++;
51692
52029
  if (checkTruncationLength(context) && i + 2 < types.length - 1) {
52030
+ context.out.truncated = true;
51693
52031
  result.push(
51694
52032
  context.flags & 1 /* NoTruncation */ ? addSyntheticLeadingComment(factory.createKeywordTypeNode(133 /* AnyKeyword */), 3 /* MultiLineCommentTrivia */, `... ${types.length - i} more elided ...`) : factory.createTypeReferenceNode(
51695
52033
  `... ${types.length - i} more ...`,
@@ -52087,7 +52425,7 @@ function createTypeChecker(host) {
52087
52425
  return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
52088
52426
  }
52089
52427
  function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
52090
- return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
52428
+ return !canPossiblyExpandType(type, context) && typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
52091
52429
  }
52092
52430
  function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
52093
52431
  const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
@@ -52606,12 +52944,15 @@ function createTypeChecker(host) {
52606
52944
  }
52607
52945
  let firstChar = symbolName2.charCodeAt(0);
52608
52946
  if (isSingleOrDoubleQuote(firstChar) && some(symbol2.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
52609
- return factory.createStringLiteral(getSpecifierForModuleSymbol(symbol2, context));
52947
+ const specifier = getSpecifierForModuleSymbol(symbol2, context);
52948
+ context.approximateLength += 2 + specifier.length;
52949
+ return factory.createStringLiteral(specifier);
52610
52950
  }
52611
52951
  if (index === 0 || canUsePropertyAccess(symbolName2, languageVersion)) {
52612
52952
  const identifier = setEmitFlags(factory.createIdentifier(symbolName2), 16777216 /* NoAsciiEscaping */);
52613
52953
  if (typeParameterNodes) setIdentifierTypeArguments(identifier, factory.createNodeArray(typeParameterNodes));
52614
52954
  identifier.symbol = symbol2;
52955
+ context.approximateLength += 1 + symbolName2.length;
52615
52956
  return index > 0 ? factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain2, index - 1), identifier) : identifier;
52616
52957
  } else {
52617
52958
  if (firstChar === 91 /* openBracket */) {
@@ -52620,16 +52961,21 @@ function createTypeChecker(host) {
52620
52961
  }
52621
52962
  let expression;
52622
52963
  if (isSingleOrDoubleQuote(firstChar) && !(symbol2.flags & 8 /* EnumMember */)) {
52623
- expression = factory.createStringLiteral(stripQuotes(symbolName2).replace(/\\./g, (s) => s.substring(1)), firstChar === 39 /* singleQuote */);
52964
+ const literalText = stripQuotes(symbolName2).replace(/\\./g, (s) => s.substring(1));
52965
+ context.approximateLength += literalText.length + 2;
52966
+ expression = factory.createStringLiteral(literalText, firstChar === 39 /* singleQuote */);
52624
52967
  } else if ("" + +symbolName2 === symbolName2) {
52968
+ context.approximateLength += symbolName2.length;
52625
52969
  expression = factory.createNumericLiteral(+symbolName2);
52626
52970
  }
52627
52971
  if (!expression) {
52628
52972
  const identifier = setEmitFlags(factory.createIdentifier(symbolName2), 16777216 /* NoAsciiEscaping */);
52629
52973
  if (typeParameterNodes) setIdentifierTypeArguments(identifier, factory.createNodeArray(typeParameterNodes));
52630
52974
  identifier.symbol = symbol2;
52975
+ context.approximateLength += symbolName2.length;
52631
52976
  expression = identifier;
52632
52977
  }
52978
+ context.approximateLength += 2;
52633
52979
  return factory.createElementAccessExpression(createExpressionFromSymbolChain(chain2, index - 1), expression);
52634
52980
  }
52635
52981
  }
@@ -52658,6 +53004,10 @@ function createTypeChecker(host) {
52658
53004
  ), "'")));
52659
53005
  }
52660
53006
  function getPropertyNameNodeForSymbol(symbol, context) {
53007
+ const hashPrivateName = getClonedHashPrivateName(symbol);
53008
+ if (hashPrivateName) {
53009
+ return hashPrivateName;
53010
+ }
52661
53011
  const stringNamed = !!length(symbol.declarations) && every(symbol.declarations, isStringNamed);
52662
53012
  const singleQuote = !!length(symbol.declarations) && every(symbol.declarations, isSingleQuotedStringNamed);
52663
53013
  const isMethod = !!(symbol.flags & 8192 /* Method */);
@@ -52734,7 +53084,7 @@ function createTypeChecker(host) {
52734
53084
  let result;
52735
53085
  const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
52736
53086
  const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
52737
- if (decl) {
53087
+ if (!canPossiblyExpandType(type, context) && decl) {
52738
53088
  const restore = addSymbolTypeToContext(context, symbol, type);
52739
53089
  if (isAccessor(decl)) {
52740
53090
  result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
@@ -52773,7 +53123,7 @@ function createTypeChecker(host) {
52773
53123
  let returnTypeNode;
52774
53124
  const returnType = getReturnTypeOfSignature(signature);
52775
53125
  if (!(suppressAny && isTypeAny(returnType))) {
52776
- if (signature.declaration && !nodeIsSynthesized(signature.declaration)) {
53126
+ if (signature.declaration && !nodeIsSynthesized(signature.declaration) && !canPossiblyExpandType(returnType, context)) {
52777
53127
  const declarationSymbol = getSymbolOfDeclaration(signature.declaration);
52778
53128
  const restore = addSymbolTypeToContext(context, declarationSymbol, returnType);
52779
53129
  returnTypeNode = syntacticNodeBuilder.serializeReturnTypeForSignature(signature.declaration, declarationSymbol, context);
@@ -53184,14 +53534,28 @@ function createTypeChecker(host) {
53184
53534
  if (!suppressNewPrivateContext) {
53185
53535
  deferredPrivatesStack.push(/* @__PURE__ */ new Map());
53186
53536
  }
53187
- symbolTable2.forEach((symbol) => {
53537
+ let i = 0;
53538
+ const symbols = Array.from(symbolTable2.values());
53539
+ for (const symbol of symbols) {
53540
+ i++;
53541
+ if (checkTruncationLengthIfExpanding(context) && i + 2 < symbolTable2.size - 1) {
53542
+ context.out.truncated = true;
53543
+ results.push(createTruncationStatement(`... (${symbolTable2.size - i} more ...)`));
53544
+ serializeSymbol(
53545
+ symbols[symbols.length - 1],
53546
+ /*isPrivate*/
53547
+ false,
53548
+ !!propertyAsAlias
53549
+ );
53550
+ break;
53551
+ }
53188
53552
  serializeSymbol(
53189
53553
  symbol,
53190
53554
  /*isPrivate*/
53191
53555
  false,
53192
53556
  !!propertyAsAlias
53193
53557
  );
53194
- });
53558
+ }
53195
53559
  if (!suppressNewPrivateContext) {
53196
53560
  deferredPrivatesStack[deferredPrivatesStack.length - 1].forEach((symbol) => {
53197
53561
  serializeSymbol(
@@ -53221,7 +53585,7 @@ function createTypeChecker(host) {
53221
53585
  }
53222
53586
  }
53223
53587
  function serializeSymbolWorker(symbol, isPrivate, propertyAsAlias, escapedSymbolName = symbol.escapedName) {
53224
- var _a2, _b, _c, _d, _e, _f;
53588
+ var _a2, _b, _c, _d, _e, _f, _g;
53225
53589
  const symbolName2 = unescapeLeadingUnderscores(escapedSymbolName);
53226
53590
  const isDefault = escapedSymbolName === "default" /* Default */;
53227
53591
  if (isPrivate && !(context.flags & 131072 /* AllowAnonymousIdentifier */) && isStringANonContextualKeyword(symbolName2) && !isDefault) {
@@ -53271,6 +53635,7 @@ function createTypeChecker(host) {
53271
53635
  const propertyAccessRequire = (_e = symbol.declarations) == null ? void 0 : _e.find(isPropertyAccessExpression);
53272
53636
  if (propertyAccessRequire && isBinaryExpression(propertyAccessRequire.parent) && isIdentifier(propertyAccessRequire.parent.right) && ((_f = type.symbol) == null ? void 0 : _f.valueDeclaration) && isSourceFile(type.symbol.valueDeclaration)) {
53273
53637
  const alias = localName === propertyAccessRequire.parent.right.escapedText ? void 0 : propertyAccessRequire.parent.right;
53638
+ context.approximateLength += 12 + (((_g = alias == null ? void 0 : alias.escapedText) == null ? void 0 : _g.length) ?? 0);
53274
53639
  addResult(
53275
53640
  factory.createExportDeclaration(
53276
53641
  /*modifiers*/
@@ -53310,8 +53675,10 @@ function createTypeChecker(host) {
53310
53675
  ),
53311
53676
  textRange
53312
53677
  );
53678
+ context.approximateLength += 7 + name.length;
53313
53679
  addResult(statement, name !== localName ? modifierFlags & ~32 /* Export */ : modifierFlags);
53314
53680
  if (name !== localName && !isPrivate) {
53681
+ context.approximateLength += 16 + name.length + localName.length;
53315
53682
  addResult(
53316
53683
  factory.createExportDeclaration(
53317
53684
  /*modifiers*/
@@ -53361,27 +53728,33 @@ function createTypeChecker(host) {
53361
53728
  for (const node of symbol.declarations) {
53362
53729
  const resolvedModule = resolveExternalModuleName(node, node.moduleSpecifier);
53363
53730
  if (!resolvedModule) continue;
53731
+ const isTypeOnly = node.isTypeOnly;
53732
+ const specifier = getSpecifierForModuleSymbol(resolvedModule, context);
53733
+ context.approximateLength += 17 + specifier.length;
53364
53734
  addResult(factory.createExportDeclaration(
53365
53735
  /*modifiers*/
53366
53736
  void 0,
53367
- /*isTypeOnly*/
53368
- node.isTypeOnly,
53737
+ isTypeOnly,
53369
53738
  /*exportClause*/
53370
53739
  void 0,
53371
- factory.createStringLiteral(getSpecifierForModuleSymbol(resolvedModule, context))
53740
+ factory.createStringLiteral(specifier)
53372
53741
  ), 0 /* None */);
53373
53742
  }
53374
53743
  }
53375
53744
  }
53376
53745
  if (needsPostExportDefault) {
53746
+ const internalSymbolName = getInternalSymbolName(symbol, symbolName2);
53747
+ context.approximateLength += 16 + internalSymbolName.length;
53377
53748
  addResult(factory.createExportAssignment(
53378
53749
  /*modifiers*/
53379
53750
  void 0,
53380
53751
  /*isExportEquals*/
53381
53752
  false,
53382
- factory.createIdentifier(getInternalSymbolName(symbol, symbolName2))
53753
+ factory.createIdentifier(internalSymbolName)
53383
53754
  ), 0 /* None */);
53384
53755
  } else if (needsExportDeclaration) {
53756
+ const internalSymbolName = getInternalSymbolName(symbol, symbolName2);
53757
+ context.approximateLength += 22 + symbolName2.length + internalSymbolName.length;
53385
53758
  addResult(
53386
53759
  factory.createExportDeclaration(
53387
53760
  /*modifiers*/
@@ -53391,7 +53764,7 @@ function createTypeChecker(host) {
53391
53764
  factory.createNamedExports([factory.createExportSpecifier(
53392
53765
  /*isTypeOnly*/
53393
53766
  false,
53394
- getInternalSymbolName(symbol, symbolName2),
53767
+ internalSymbolName,
53395
53768
  symbolName2
53396
53769
  )])
53397
53770
  ),
@@ -53411,6 +53784,7 @@ function createTypeChecker(host) {
53411
53784
  }
53412
53785
  function addResult(node, additionalModifierFlags) {
53413
53786
  if (canHaveModifiers(node)) {
53787
+ const oldModifierFlags = getEffectiveModifierFlags(node);
53414
53788
  let newModifierFlags = 0 /* None */;
53415
53789
  const enclosingDeclaration2 = context.enclosingDeclaration && (isJSDocTypeAlias(context.enclosingDeclaration) ? getSourceFileOfNode(context.enclosingDeclaration) : context.enclosingDeclaration);
53416
53790
  if (additionalModifierFlags & 32 /* Export */ && enclosingDeclaration2 && (isExportingScope(enclosingDeclaration2) || isModuleDeclaration(enclosingDeclaration2)) && canHaveExportModifier(node)) {
@@ -53423,8 +53797,9 @@ function createTypeChecker(host) {
53423
53797
  newModifierFlags |= 2048 /* Default */;
53424
53798
  }
53425
53799
  if (newModifierFlags) {
53426
- node = factory.replaceModifiers(node, newModifierFlags | getEffectiveModifierFlags(node));
53800
+ node = factory.replaceModifiers(node, newModifierFlags | oldModifierFlags);
53427
53801
  }
53802
+ context.approximateLength += modifiersLength(newModifierFlags | oldModifierFlags);
53428
53803
  }
53429
53804
  results.push(node);
53430
53805
  }
@@ -53440,12 +53815,14 @@ function createTypeChecker(host) {
53440
53815
  const oldEnclosingDecl = context.enclosingDeclaration;
53441
53816
  context.enclosingDeclaration = jsdocAliasDecl;
53442
53817
  const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) && syntacticNodeBuilder.tryReuseExistingTypeNode(context, jsdocAliasDecl.typeExpression.type) || typeToTypeNodeHelper(aliasType, context);
53818
+ const internalSymbolName = getInternalSymbolName(symbol, symbolName2);
53819
+ context.approximateLength += 8 + ((commentText == null ? void 0 : commentText.length) ?? 0) + internalSymbolName.length;
53443
53820
  addResult(
53444
53821
  setSyntheticLeadingComments(
53445
53822
  factory.createTypeAliasDeclaration(
53446
53823
  /*modifiers*/
53447
53824
  void 0,
53448
- getInternalSymbolName(symbol, symbolName2),
53825
+ internalSymbolName,
53449
53826
  typeParamDecls,
53450
53827
  typeNode
53451
53828
  ),
@@ -53457,12 +53834,19 @@ function createTypeChecker(host) {
53457
53834
  context.enclosingDeclaration = oldEnclosingDecl;
53458
53835
  }
53459
53836
  function serializeInterface(symbol, symbolName2, modifierFlags) {
53837
+ const internalSymbolName = getInternalSymbolName(symbol, symbolName2);
53838
+ context.approximateLength += 14 + internalSymbolName.length;
53460
53839
  const interfaceType = getDeclaredTypeOfClassOrInterface(symbol);
53461
53840
  const localParams = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
53462
53841
  const typeParamDecls = map(localParams, (p) => typeParameterToDeclaration(p, context));
53463
53842
  const baseTypes = getBaseTypes(interfaceType);
53464
53843
  const baseType = length(baseTypes) ? getIntersectionType(baseTypes) : void 0;
53465
- const members = flatMap(getPropertiesOfType(interfaceType), (p) => serializePropertySymbolForInterface(p, baseType));
53844
+ const members = serializePropertySymbolsForClassOrInterface(
53845
+ getPropertiesOfType(interfaceType),
53846
+ /*isClass*/
53847
+ false,
53848
+ baseType
53849
+ );
53466
53850
  const callSignatures = serializeSignatures(0 /* Call */, interfaceType, baseType, 179 /* CallSignature */);
53467
53851
  const constructSignatures = serializeSignatures(1 /* Construct */, interfaceType, baseType, 180 /* ConstructSignature */);
53468
53852
  const indexSignatures = serializeIndexSignatures(interfaceType, baseType);
@@ -53471,7 +53855,7 @@ function createTypeChecker(host) {
53471
53855
  factory.createInterfaceDeclaration(
53472
53856
  /*modifiers*/
53473
53857
  void 0,
53474
- getInternalSymbolName(symbol, symbolName2),
53858
+ internalSymbolName,
53475
53859
  typeParamDecls,
53476
53860
  heritageClauses,
53477
53861
  [...indexSignatures, ...constructSignatures, ...callSignatures, ...members]
@@ -53479,6 +53863,57 @@ function createTypeChecker(host) {
53479
53863
  modifierFlags
53480
53864
  );
53481
53865
  }
53866
+ function serializePropertySymbolsForClassOrInterface(props, isClass, baseType, isStatic2) {
53867
+ const elements = [];
53868
+ let i = 0;
53869
+ for (const prop of props) {
53870
+ i++;
53871
+ if (checkTruncationLengthIfExpanding(context) && i + 2 < props.length - 1) {
53872
+ context.out.truncated = true;
53873
+ const placeholder = createTruncationProperty(`... ${props.length - i} more ... `, isClass);
53874
+ elements.push(placeholder);
53875
+ const result2 = isClass ? serializePropertySymbolForClass(props[props.length - 1], isStatic2, baseType) : serializePropertySymbolForInterface(props[props.length - 1], baseType);
53876
+ if (isArray(result2)) {
53877
+ elements.push(...result2);
53878
+ } else {
53879
+ elements.push(result2);
53880
+ }
53881
+ break;
53882
+ }
53883
+ context.approximateLength += 1;
53884
+ const result = isClass ? serializePropertySymbolForClass(prop, isStatic2, baseType) : serializePropertySymbolForInterface(prop, baseType);
53885
+ if (isArray(result)) {
53886
+ elements.push(...result);
53887
+ } else {
53888
+ elements.push(result);
53889
+ }
53890
+ }
53891
+ return elements;
53892
+ }
53893
+ function createTruncationProperty(dotDotDotText, isClass) {
53894
+ if (context.flags & 1 /* NoTruncation */) {
53895
+ return addSyntheticLeadingComment(factory.createNotEmittedTypeElement(), 3 /* MultiLineCommentTrivia */, dotDotDotText);
53896
+ }
53897
+ return isClass ? factory.createPropertyDeclaration(
53898
+ /*modifiers*/
53899
+ void 0,
53900
+ dotDotDotText,
53901
+ /*questionOrExclamationToken*/
53902
+ void 0,
53903
+ /*type*/
53904
+ void 0,
53905
+ /*initializer*/
53906
+ void 0
53907
+ ) : factory.createPropertySignature(
53908
+ /*modifiers*/
53909
+ void 0,
53910
+ dotDotDotText,
53911
+ /*questionToken*/
53912
+ void 0,
53913
+ /*type*/
53914
+ void 0
53915
+ );
53916
+ }
53482
53917
  function getNamespaceMembersForSerialization(symbol) {
53483
53918
  let exports2 = arrayFrom(getExportsOfSymbol(symbol).values());
53484
53919
  const merged = getMergedSymbol(symbol);
@@ -53498,11 +53933,27 @@ function createTypeChecker(host) {
53498
53933
  }
53499
53934
  function serializeModule(symbol, symbolName2, modifierFlags) {
53500
53935
  const members = getNamespaceMembersForSerialization(symbol);
53501
- const locationMap = arrayToMultiMap(members, (m) => m.parent && m.parent === symbol ? "real" : "merged");
53936
+ const expanding = isExpanding(context);
53937
+ const locationMap = arrayToMultiMap(members, (m) => m.parent && m.parent === symbol || expanding ? "real" : "merged");
53502
53938
  const realMembers = locationMap.get("real") || emptyArray;
53503
53939
  const mergedMembers = locationMap.get("merged") || emptyArray;
53504
- if (length(realMembers)) {
53505
- const localName = getInternalSymbolName(symbol, symbolName2);
53940
+ if (length(realMembers) || expanding) {
53941
+ let localName;
53942
+ if (expanding) {
53943
+ const oldFlags = context.flags;
53944
+ context.flags |= 512 /* WriteTypeParametersInQualifiedName */ | 2 /* UseOnlyExternalAliasing */;
53945
+ localName = symbolToNode(
53946
+ symbol,
53947
+ context,
53948
+ /*meaning*/
53949
+ -1 /* All */
53950
+ );
53951
+ context.flags = oldFlags;
53952
+ } else {
53953
+ const localText = getInternalSymbolName(symbol, symbolName2);
53954
+ localName = factory.createIdentifier(localText);
53955
+ context.approximateLength += localText.length;
53956
+ }
53506
53957
  serializeAsNamespaceDeclaration(realMembers, localName, modifierFlags, !!(symbol.flags & (16 /* Function */ | 67108864 /* Assignment */)));
53507
53958
  }
53508
53959
  if (length(mergedMembers)) {
@@ -53550,17 +54001,51 @@ function createTypeChecker(host) {
53550
54001
  }
53551
54002
  }
53552
54003
  function serializeEnum(symbol, symbolName2, modifierFlags) {
54004
+ const internalSymbolName = getInternalSymbolName(symbol, symbolName2);
54005
+ context.approximateLength += 9 + internalSymbolName.length;
54006
+ const members = [];
54007
+ const memberProps = filter(getPropertiesOfType(getTypeOfSymbol(symbol)), (p) => !!(p.flags & 8 /* EnumMember */));
54008
+ let i = 0;
54009
+ for (const p of memberProps) {
54010
+ i++;
54011
+ if (checkTruncationLengthIfExpanding(context) && i + 2 < memberProps.length - 1) {
54012
+ context.out.truncated = true;
54013
+ members.push(factory.createEnumMember(` ... ${memberProps.length - i} more ... `));
54014
+ const last2 = memberProps[memberProps.length - 1];
54015
+ const initializedValue = last2.declarations && last2.declarations[0] && isEnumMember(last2.declarations[0]) ? getConstantValue2(last2.declarations[0]) : void 0;
54016
+ const initializer2 = initializedValue === void 0 ? void 0 : typeof initializedValue === "string" ? factory.createStringLiteral(initializedValue) : factory.createNumericLiteral(initializedValue);
54017
+ const memberName2 = unescapeLeadingUnderscores(last2.escapedName);
54018
+ const member2 = factory.createEnumMember(
54019
+ memberName2,
54020
+ initializer2
54021
+ );
54022
+ members.push(member2);
54023
+ break;
54024
+ }
54025
+ const memberDecl = p.declarations && p.declarations[0] && isEnumMember(p.declarations[0]) ? p.declarations[0] : void 0;
54026
+ let initializer;
54027
+ let initializerLength;
54028
+ if (isExpanding(context) && memberDecl && memberDecl.initializer) {
54029
+ initializer = getSynthesizedDeepClone(memberDecl.initializer);
54030
+ initializerLength = memberDecl.initializer.end - memberDecl.initializer.pos;
54031
+ } else {
54032
+ const initializedValue = memberDecl && getConstantValue2(memberDecl);
54033
+ initializer = initializedValue === void 0 ? void 0 : typeof initializedValue === "string" ? factory.createStringLiteral(initializedValue) : factory.createNumericLiteral(initializedValue);
54034
+ initializerLength = (initializer == null ? void 0 : initializer.text.length) ?? 0;
54035
+ }
54036
+ const memberName = unescapeLeadingUnderscores(p.escapedName);
54037
+ context.approximateLength += 4 + memberName.length + initializerLength;
54038
+ const member = factory.createEnumMember(
54039
+ memberName,
54040
+ initializer
54041
+ );
54042
+ members.push(member);
54043
+ }
53553
54044
  addResult(
53554
54045
  factory.createEnumDeclaration(
53555
54046
  factory.createModifiersFromModifierFlags(isConstEnumSymbol(symbol) ? 4096 /* Const */ : 0),
53556
- getInternalSymbolName(symbol, symbolName2),
53557
- map(filter(getPropertiesOfType(getTypeOfSymbol(symbol)), (p) => !!(p.flags & 8 /* EnumMember */)), (p) => {
53558
- const initializedValue = p.declarations && p.declarations[0] && isEnumMember(p.declarations[0]) ? getConstantValue2(p.declarations[0]) : void 0;
53559
- return factory.createEnumMember(
53560
- unescapeLeadingUnderscores(p.escapedName),
53561
- initializedValue === void 0 ? void 0 : typeof initializedValue === "string" ? factory.createStringLiteral(initializedValue) : factory.createNumericLiteral(initializedValue)
53562
- );
53563
- })
54047
+ internalSymbolName,
54048
+ members
53564
54049
  ),
53565
54050
  modifierFlags
53566
54051
  );
@@ -53568,20 +54053,28 @@ function createTypeChecker(host) {
53568
54053
  function serializeAsFunctionNamespaceMerge(type, symbol, localName, modifierFlags) {
53569
54054
  const signatures = getSignaturesOfType(type, 0 /* Call */);
53570
54055
  for (const sig of signatures) {
54056
+ context.approximateLength += 1;
53571
54057
  const decl = signatureToSignatureDeclarationHelper(sig, 262 /* FunctionDeclaration */, context, { name: factory.createIdentifier(localName) });
53572
54058
  addResult(setTextRange2(context, decl, getSignatureTextRangeLocation(sig)), modifierFlags);
53573
54059
  }
53574
54060
  if (!(symbol.flags & (512 /* ValueModule */ | 1024 /* NamespaceModule */) && !!symbol.exports && !!symbol.exports.size)) {
53575
54061
  const props = filter(getPropertiesOfType(type), isNamespaceMember);
54062
+ context.approximateLength += localName.length;
53576
54063
  serializeAsNamespaceDeclaration(
53577
54064
  props,
53578
- localName,
54065
+ factory.createIdentifier(localName),
53579
54066
  modifierFlags,
53580
54067
  /*suppressNewPrivateContext*/
53581
54068
  true
53582
54069
  );
53583
54070
  }
53584
54071
  }
54072
+ function createTruncationStatement(dotDotDotText) {
54073
+ if (context.flags & 1 /* NoTruncation */) {
54074
+ return addSyntheticLeadingComment(factory.createEmptyStatement(), 3 /* MultiLineCommentTrivia */, dotDotDotText);
54075
+ }
54076
+ return factory.createExpressionStatement(factory.createIdentifier(dotDotDotText));
54077
+ }
53585
54078
  function getSignatureTextRangeLocation(signature) {
53586
54079
  if (signature.declaration && signature.declaration.parent) {
53587
54080
  if (isBinaryExpression(signature.declaration.parent) && getAssignmentDeclarationKind(signature.declaration.parent) === 5 /* Property */) {
@@ -53594,15 +54087,18 @@ function createTypeChecker(host) {
53594
54087
  return signature.declaration;
53595
54088
  }
53596
54089
  function serializeAsNamespaceDeclaration(props, localName, modifierFlags, suppressNewPrivateContext) {
54090
+ const nodeFlags = isIdentifier(localName) ? 32 /* Namespace */ : 0 /* None */;
54091
+ const expanding = isExpanding(context);
53597
54092
  if (length(props)) {
53598
- const localVsRemoteMap = arrayToMultiMap(props, (p) => !length(p.declarations) || some(p.declarations, (d) => getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration)) ? "local" : "remote");
54093
+ context.approximateLength += 14;
54094
+ const localVsRemoteMap = arrayToMultiMap(props, (p) => !length(p.declarations) || some(p.declarations, (d) => getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration)) || expanding ? "local" : "remote");
53599
54095
  const localProps = localVsRemoteMap.get("local") || emptyArray;
53600
54096
  let fakespace = parseNodeFactory.createModuleDeclaration(
53601
54097
  /*modifiers*/
53602
54098
  void 0,
53603
- factory.createIdentifier(localName),
54099
+ localName,
53604
54100
  factory.createModuleBlock([]),
53605
- 32 /* Namespace */
54101
+ nodeFlags
53606
54102
  );
53607
54103
  setParent(fakespace, enclosingDeclaration);
53608
54104
  fakespace.locals = createSymbolTable(props);
@@ -53644,6 +54140,18 @@ function createTypeChecker(host) {
53644
54140
  factory.createModuleBlock(exportModifierStripped)
53645
54141
  );
53646
54142
  addResult(fakespace, modifierFlags);
54143
+ } else if (expanding) {
54144
+ context.approximateLength += 14;
54145
+ addResult(
54146
+ factory.createModuleDeclaration(
54147
+ /*modifiers*/
54148
+ void 0,
54149
+ localName,
54150
+ factory.createModuleBlock([]),
54151
+ nodeFlags
54152
+ ),
54153
+ modifierFlags
54154
+ );
53647
54155
  }
53648
54156
  }
53649
54157
  function isNamespaceMember(p) {
@@ -53686,11 +54194,13 @@ function createTypeChecker(host) {
53686
54194
  }
53687
54195
  function serializeAsClass(symbol, localName, modifierFlags) {
53688
54196
  var _a2, _b;
54197
+ context.approximateLength += 9 + localName.length;
53689
54198
  const originalDecl = (_a2 = symbol.declarations) == null ? void 0 : _a2.find(isClassLike);
53690
54199
  const oldEnclosing = context.enclosingDeclaration;
53691
54200
  context.enclosingDeclaration = originalDecl || oldEnclosing;
53692
54201
  const localParams = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
53693
54202
  const typeParamDecls = map(localParams, (p) => typeParameterToDeclaration(p, context));
54203
+ forEach(localParams, (p) => context.approximateLength += symbolName(p.symbol).length);
53694
54204
  const classType = getTypeWithThisArgument(getDeclaredTypeOfClassOrInterface(symbol));
53695
54205
  const baseTypes = getBaseTypes(classType);
53696
54206
  const originalImplements = originalDecl && getEffectiveImplementsTypeNodes(originalDecl);
@@ -53698,20 +54208,22 @@ function createTypeChecker(host) {
53698
54208
  const staticType = getTypeOfSymbol(symbol);
53699
54209
  const isClass = !!((_b = staticType.symbol) == null ? void 0 : _b.valueDeclaration) && isClassLike(staticType.symbol.valueDeclaration);
53700
54210
  const staticBaseType = isClass ? getBaseConstructorTypeOfClass(staticType) : anyType;
54211
+ context.approximateLength += (length(baseTypes) ? 8 : 0) + (length(implementsExpressions) ? 11 : 0);
53701
54212
  const heritageClauses = [
53702
54213
  ...!length(baseTypes) ? [] : [factory.createHeritageClause(96 /* ExtendsKeyword */, map(baseTypes, (b) => serializeBaseType(b, staticBaseType, localName)))],
53703
54214
  ...!length(implementsExpressions) ? [] : [factory.createHeritageClause(119 /* ImplementsKeyword */, implementsExpressions)]
53704
54215
  ];
53705
54216
  const symbolProps = getNonInheritedProperties(classType, baseTypes, getPropertiesOfType(classType));
53706
- const publicSymbolProps = filter(symbolProps, (s) => {
53707
- const valueDecl = s.valueDeclaration;
53708
- return !!valueDecl && !(isNamedDeclaration(valueDecl) && isPrivateIdentifier(valueDecl.name));
53709
- });
53710
- const hasPrivateIdentifier = some(symbolProps, (s) => {
53711
- const valueDecl = s.valueDeclaration;
53712
- return !!valueDecl && isNamedDeclaration(valueDecl) && isPrivateIdentifier(valueDecl.name);
53713
- });
53714
- const privateProperties = hasPrivateIdentifier ? [factory.createPropertyDeclaration(
54217
+ const publicSymbolProps = filter(symbolProps, (s) => !isHashPrivate(s));
54218
+ const hasPrivateIdentifier = some(symbolProps, isHashPrivate);
54219
+ const privateProperties = hasPrivateIdentifier ? isExpanding(context) ? serializePropertySymbolsForClassOrInterface(
54220
+ filter(symbolProps, isHashPrivate),
54221
+ /*isClass*/
54222
+ true,
54223
+ baseTypes[0],
54224
+ /*isStatic*/
54225
+ false
54226
+ ) : [factory.createPropertyDeclaration(
53715
54227
  /*modifiers*/
53716
54228
  void 0,
53717
54229
  factory.createPrivateIdentifier("#private"),
@@ -53722,22 +54234,27 @@ function createTypeChecker(host) {
53722
54234
  /*initializer*/
53723
54235
  void 0
53724
54236
  )] : emptyArray;
53725
- const publicProperties = flatMap(publicSymbolProps, (p) => serializePropertySymbolForClass(
53726
- p,
54237
+ if (hasPrivateIdentifier && !isExpanding(context)) {
54238
+ context.approximateLength += 9;
54239
+ }
54240
+ const publicProperties = serializePropertySymbolsForClassOrInterface(
54241
+ publicSymbolProps,
54242
+ /*isClass*/
54243
+ true,
54244
+ baseTypes[0],
53727
54245
  /*isStatic*/
53728
- false,
53729
- baseTypes[0]
53730
- ));
53731
- const staticMembers = flatMap(
54246
+ false
54247
+ );
54248
+ const staticMembers = serializePropertySymbolsForClassOrInterface(
53732
54249
  filter(getPropertiesOfType(staticType), (p) => !(p.flags & 4194304 /* Prototype */) && p.escapedName !== "prototype" && !isNamespaceMember(p)),
53733
- (p) => serializePropertySymbolForClass(
53734
- p,
53735
- /*isStatic*/
53736
- true,
53737
- staticBaseType
53738
- )
54250
+ /*isClass*/
54251
+ true,
54252
+ staticBaseType,
54253
+ /*isStatic*/
54254
+ true
53739
54255
  );
53740
54256
  const isNonConstructableClassLikeInJsFile = !isClass && !!symbol.valueDeclaration && isInJSFile(symbol.valueDeclaration) && !some(getSignaturesOfType(staticType, 1 /* Construct */));
54257
+ if (isNonConstructableClassLikeInJsFile) context.approximateLength += 21;
53741
54258
  const constructors = isNonConstructableClassLikeInJsFile ? [factory.createConstructorDeclaration(
53742
54259
  factory.createModifiersFromModifierFlags(2 /* Private */),
53743
54260
  [],
@@ -53805,6 +54322,8 @@ function createTypeChecker(host) {
53805
54322
  if (((_b = (_a2 = node.parent) == null ? void 0 : _a2.parent) == null ? void 0 : _b.kind) === 260 /* VariableDeclaration */) {
53806
54323
  const specifier2 = getSpecifierForModuleSymbol(target.parent || target, context);
53807
54324
  const { propertyName } = node;
54325
+ const propertyNameText = propertyName && isIdentifier(propertyName) ? idText(propertyName) : void 0;
54326
+ context.approximateLength += 24 + localName.length + specifier2.length + ((propertyNameText == null ? void 0 : propertyNameText.length) ?? 0);
53808
54327
  addResult(
53809
54328
  factory.createImportDeclaration(
53810
54329
  /*modifiers*/
@@ -53817,7 +54336,7 @@ function createTypeChecker(host) {
53817
54336
  factory.createNamedImports([factory.createImportSpecifier(
53818
54337
  /*isTypeOnly*/
53819
54338
  false,
53820
- propertyName && isIdentifier(propertyName) ? factory.createIdentifier(idText(propertyName)) : void 0,
54339
+ propertyNameText ? factory.createIdentifier(propertyNameText) : void 0,
53821
54340
  factory.createIdentifier(localName)
53822
54341
  )])
53823
54342
  ),
@@ -53844,6 +54363,7 @@ function createTypeChecker(host) {
53844
54363
  const initializer = node.initializer;
53845
54364
  const uniqueName = factory.createUniqueName(localName);
53846
54365
  const specifier2 = getSpecifierForModuleSymbol(target.parent || target, context);
54366
+ context.approximateLength += 22 + specifier2.length + idText(uniqueName).length;
53847
54367
  addResult(
53848
54368
  factory.createImportEqualsDeclaration(
53849
54369
  /*modifiers*/
@@ -53855,6 +54375,7 @@ function createTypeChecker(host) {
53855
54375
  ),
53856
54376
  0 /* None */
53857
54377
  );
54378
+ context.approximateLength += 12 + localName.length + idText(uniqueName).length + idText(initializer.name).length;
53858
54379
  addResult(
53859
54380
  factory.createImportEqualsDeclaration(
53860
54381
  /*modifiers*/
@@ -53875,6 +54396,7 @@ function createTypeChecker(host) {
53875
54396
  break;
53876
54397
  }
53877
54398
  const isLocalImport = !(target.flags & 512 /* ValueModule */) && !isVariableDeclaration(node);
54399
+ context.approximateLength += 11 + localName.length + unescapeLeadingUnderscores(target.escapedName).length;
53878
54400
  addResult(
53879
54401
  factory.createImportEqualsDeclaration(
53880
54402
  /*modifiers*/
@@ -53901,6 +54423,7 @@ function createTypeChecker(host) {
53901
54423
  const specifier2 = context.bundled ? factory.createStringLiteral(generatedSpecifier) : node.parent.moduleSpecifier;
53902
54424
  const attributes = isImportDeclaration(node.parent) ? node.parent.attributes : void 0;
53903
54425
  const isTypeOnly = isJSDocImportTag(node.parent);
54426
+ context.approximateLength += 14 + localName.length + 3 + (isTypeOnly ? 4 : 0);
53904
54427
  addResult(
53905
54428
  factory.createImportDeclaration(
53906
54429
  /*modifiers*/
@@ -53922,6 +54445,7 @@ function createTypeChecker(host) {
53922
54445
  const generatedSpecifier = getSpecifierForModuleSymbol(target.parent || target, context);
53923
54446
  const specifier2 = context.bundled ? factory.createStringLiteral(generatedSpecifier) : node.parent.parent.moduleSpecifier;
53924
54447
  const isTypeOnly = isJSDocImportTag(node.parent.parent);
54448
+ context.approximateLength += 19 + localName.length + 3 + (isTypeOnly ? 4 : 0);
53925
54449
  addResult(
53926
54450
  factory.createImportDeclaration(
53927
54451
  /*modifiers*/
@@ -53940,6 +54464,7 @@ function createTypeChecker(host) {
53940
54464
  break;
53941
54465
  }
53942
54466
  case 280 /* NamespaceExport */:
54467
+ context.approximateLength += 19 + localName.length + 3;
53943
54468
  addResult(
53944
54469
  factory.createExportDeclaration(
53945
54470
  /*modifiers*/
@@ -53956,6 +54481,7 @@ function createTypeChecker(host) {
53956
54481
  const generatedSpecifier = getSpecifierForModuleSymbol(target.parent || target, context);
53957
54482
  const specifier2 = context.bundled ? factory.createStringLiteral(generatedSpecifier) : node.parent.parent.parent.moduleSpecifier;
53958
54483
  const isTypeOnly = isJSDocImportTag(node.parent.parent.parent);
54484
+ context.approximateLength += 19 + localName.length + 3 + (isTypeOnly ? 4 : 0);
53959
54485
  addResult(
53960
54486
  factory.createImportDeclaration(
53961
54487
  /*modifiers*/
@@ -54011,6 +54537,7 @@ function createTypeChecker(host) {
54011
54537
  }
54012
54538
  }
54013
54539
  function serializeExportSpecifier(localName, targetName, specifier) {
54540
+ context.approximateLength += 16 + localName.length + (localName !== targetName ? targetName.length : 0);
54014
54541
  addResult(
54015
54542
  factory.createExportDeclaration(
54016
54543
  /*modifiers*/
@@ -54061,6 +54588,7 @@ function createTypeChecker(host) {
54061
54588
  const prevDisableTrackSymbol = context.tracker.disableTrackSymbol;
54062
54589
  context.tracker.disableTrackSymbol = true;
54063
54590
  if (isExportAssignmentCompatibleSymbolName) {
54591
+ context.approximateLength += 10;
54064
54592
  results.push(factory.createExportAssignment(
54065
54593
  /*modifiers*/
54066
54594
  void 0,
@@ -54074,6 +54602,7 @@ function createTypeChecker(host) {
54074
54602
  serializeExportSpecifier(name, getInternalSymbolName(target, symbolName(target)));
54075
54603
  } else {
54076
54604
  const varName = getUnusedName(name, symbol);
54605
+ context.approximateLength += varName.length + 10;
54077
54606
  addResult(
54078
54607
  factory.createImportEqualsDeclaration(
54079
54608
  /*modifiers*/
@@ -54103,6 +54632,7 @@ function createTypeChecker(host) {
54103
54632
  serializeAsFunctionNamespaceMerge(typeToSerialize, symbol, varName, isExportAssignmentCompatibleSymbolName ? 0 /* None */ : 32 /* Export */);
54104
54633
  } else {
54105
54634
  const flags = ((_a2 = context.enclosingDeclaration) == null ? void 0 : _a2.kind) === 267 /* ModuleDeclaration */ && (!(symbol.flags & 98304 /* Accessor */) || symbol.flags & 65536 /* SetAccessor */) ? 1 /* Let */ : 2 /* Const */;
54635
+ context.approximateLength += varName.length + 5;
54106
54636
  const statement = factory.createVariableStatement(
54107
54637
  /*modifiers*/
54108
54638
  void 0,
@@ -54127,6 +54657,7 @@ function createTypeChecker(host) {
54127
54657
  );
54128
54658
  }
54129
54659
  if (isExportAssignmentCompatibleSymbolName) {
54660
+ context.approximateLength += varName.length + 10;
54130
54661
  results.push(factory.createExportAssignment(
54131
54662
  /*modifiers*/
54132
54663
  void 0,
@@ -54161,7 +54692,7 @@ function createTypeChecker(host) {
54161
54692
  return function serializePropertySymbol(p, isStatic2, baseType) {
54162
54693
  var _a2, _b, _c, _d, _e, _f;
54163
54694
  const modifierFlags = getDeclarationModifierFlagsFromSymbol(p);
54164
- const isPrivate = !!(modifierFlags & 2 /* Private */);
54695
+ const omitType = !!(modifierFlags & 2 /* Private */) && !isExpanding(context);
54165
54696
  if (isStatic2 && p.flags & (788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */)) {
54166
54697
  return [];
54167
54698
  }
@@ -54190,6 +54721,7 @@ function createTypeChecker(host) {
54190
54721
  Debug.assert(!!setter);
54191
54722
  const paramSymbol = isFunctionLikeDeclaration(setter) ? getSignatureFromDeclaration(setter).parameters[0] : void 0;
54192
54723
  const setterDeclaration = (_b = p.declarations) == null ? void 0 : _b.find(isSetAccessor);
54724
+ context.approximateLength += modifiersLength(flag) + 7 + (paramSymbol ? symbolName(paramSymbol).length : 5) + (omitType ? 0 : 2);
54193
54725
  result.push(setTextRange2(
54194
54726
  context,
54195
54727
  factory.createSetAccessorDeclaration(
@@ -54203,7 +54735,7 @@ function createTypeChecker(host) {
54203
54735
  paramSymbol ? parameterToParameterDeclarationName(paramSymbol, getEffectiveParameterDeclaration(paramSymbol), context) : "value",
54204
54736
  /*questionToken*/
54205
54737
  void 0,
54206
- isPrivate ? void 0 : serializeTypeForDeclaration(context, setterDeclaration, getWriteTypeOfSymbol(p), p)
54738
+ omitType ? void 0 : serializeTypeForDeclaration(context, setterDeclaration, getWriteTypeOfSymbol(p), p)
54207
54739
  )],
54208
54740
  /*body*/
54209
54741
  void 0
@@ -54212,15 +54744,15 @@ function createTypeChecker(host) {
54212
54744
  ));
54213
54745
  }
54214
54746
  if (p.flags & 32768 /* GetAccessor */) {
54215
- const isPrivate2 = modifierFlags & 2 /* Private */;
54216
54747
  const getterDeclaration = (_c = p.declarations) == null ? void 0 : _c.find(isGetAccessor);
54748
+ context.approximateLength += modifiersLength(flag) + 8 + (omitType ? 0 : 2);
54217
54749
  result.push(setTextRange2(
54218
54750
  context,
54219
54751
  factory.createGetAccessorDeclaration(
54220
54752
  factory.createModifiersFromModifierFlags(flag),
54221
54753
  name,
54222
54754
  [],
54223
- isPrivate2 ? void 0 : serializeTypeForDeclaration(context, getterDeclaration, getTypeOfSymbol(p), p),
54755
+ omitType ? void 0 : serializeTypeForDeclaration(context, getterDeclaration, getTypeOfSymbol(p), p),
54224
54756
  /*body*/
54225
54757
  void 0
54226
54758
  ),
@@ -54229,13 +54761,15 @@ function createTypeChecker(host) {
54229
54761
  }
54230
54762
  return result;
54231
54763
  } else if (p.flags & (4 /* Property */ | 3 /* Variable */ | 98304 /* Accessor */)) {
54764
+ const modifierFlags2 = (isReadonlySymbol(p) ? 8 /* Readonly */ : 0) | flag;
54765
+ context.approximateLength += 2 + (omitType ? 0 : 2) + modifiersLength(modifierFlags2);
54232
54766
  return setTextRange2(
54233
54767
  context,
54234
54768
  createProperty2(
54235
- factory.createModifiersFromModifierFlags((isReadonlySymbol(p) ? 8 /* Readonly */ : 0) | flag),
54769
+ factory.createModifiersFromModifierFlags(modifierFlags2),
54236
54770
  name,
54237
54771
  p.flags & 16777216 /* Optional */ ? factory.createToken(58 /* QuestionToken */) : void 0,
54238
- isPrivate ? void 0 : serializeTypeForDeclaration(context, (_d = p.declarations) == null ? void 0 : _d.find(isSetAccessorDeclaration), getWriteTypeOfSymbol(p), p),
54772
+ omitType ? void 0 : serializeTypeForDeclaration(context, (_d = p.declarations) == null ? void 0 : _d.find(isSetAccessorDeclaration), getWriteTypeOfSymbol(p), p),
54239
54773
  // TODO: https://github.com/microsoft/TypeScript/pull/32372#discussion_r328386357
54240
54774
  // interface members can't have initializers, however class members _can_
54241
54775
  /*initializer*/
@@ -54247,11 +54781,13 @@ function createTypeChecker(host) {
54247
54781
  if (p.flags & (8192 /* Method */ | 16 /* Function */)) {
54248
54782
  const type = getTypeOfSymbol(p);
54249
54783
  const signatures = getSignaturesOfType(type, 0 /* Call */);
54250
- if (flag & 2 /* Private */) {
54784
+ if (omitType) {
54785
+ const modifierFlags2 = (isReadonlySymbol(p) ? 8 /* Readonly */ : 0) | flag;
54786
+ context.approximateLength += 1 + modifiersLength(modifierFlags2);
54251
54787
  return setTextRange2(
54252
54788
  context,
54253
54789
  createProperty2(
54254
- factory.createModifiersFromModifierFlags((isReadonlySymbol(p) ? 8 /* Readonly */ : 0) | flag),
54790
+ factory.createModifiersFromModifierFlags(modifierFlags2),
54255
54791
  name,
54256
54792
  p.flags & 16777216 /* Optional */ ? factory.createToken(58 /* QuestionToken */) : void 0,
54257
54793
  /*type*/
@@ -54264,6 +54800,7 @@ function createTypeChecker(host) {
54264
54800
  }
54265
54801
  const results2 = [];
54266
54802
  for (const sig of signatures) {
54803
+ context.approximateLength += 1;
54267
54804
  const decl = signatureToSignatureDeclarationHelper(
54268
54805
  sig,
54269
54806
  methodKind,
@@ -54282,6 +54819,25 @@ function createTypeChecker(host) {
54282
54819
  return Debug.fail(`Unhandled class member kind! ${p.__debugFlags || p.flags}`);
54283
54820
  };
54284
54821
  }
54822
+ function modifiersLength(flags) {
54823
+ let result = 0;
54824
+ if (flags & 32 /* Export */) result += 7;
54825
+ if (flags & 128 /* Ambient */) result += 8;
54826
+ if (flags & 2048 /* Default */) result += 8;
54827
+ if (flags & 4096 /* Const */) result += 6;
54828
+ if (flags & 1 /* Public */) result += 7;
54829
+ if (flags & 2 /* Private */) result += 8;
54830
+ if (flags & 4 /* Protected */) result += 10;
54831
+ if (flags & 64 /* Abstract */) result += 9;
54832
+ if (flags & 256 /* Static */) result += 7;
54833
+ if (flags & 16 /* Override */) result += 9;
54834
+ if (flags & 8 /* Readonly */) result += 9;
54835
+ if (flags & 512 /* Accessor */) result += 9;
54836
+ if (flags & 1024 /* Async */) result += 6;
54837
+ if (flags & 8192 /* In */) result += 3;
54838
+ if (flags & 16384 /* Out */) result += 4;
54839
+ return result;
54840
+ }
54285
54841
  function serializePropertySymbolForInterface(p, baseType) {
54286
54842
  return serializePropertySymbolForInterfaceWorker(
54287
54843
  p,
@@ -54346,6 +54902,7 @@ function createTypeChecker(host) {
54346
54902
  }
54347
54903
  const results2 = [];
54348
54904
  for (const sig of signatures) {
54905
+ context.approximateLength += 1;
54349
54906
  const decl = signatureToSignatureDeclarationHelper(sig, outputKind, context);
54350
54907
  results2.push(setTextRange2(context, decl, sig.declaration));
54351
54908
  }
@@ -54471,6 +55028,23 @@ function createTypeChecker(host) {
54471
55028
  return localName;
54472
55029
  }
54473
55030
  }
55031
+ function isExpanding(context) {
55032
+ return context.maxExpansionDepth !== -1;
55033
+ }
55034
+ function isHashPrivate(s) {
55035
+ return !!s.valueDeclaration && isNamedDeclaration(s.valueDeclaration) && isPrivateIdentifier(s.valueDeclaration.name);
55036
+ }
55037
+ function getClonedHashPrivateName(s) {
55038
+ if (s.valueDeclaration && isNamedDeclaration(s.valueDeclaration) && isPrivateIdentifier(s.valueDeclaration.name)) {
55039
+ return factory.cloneNode(s.valueDeclaration.name);
55040
+ }
55041
+ return void 0;
55042
+ }
55043
+ }
55044
+ function isLibType(type) {
55045
+ var _a;
55046
+ const symbol = (getObjectFlags(type) & 4 /* Reference */) !== 0 ? type.target.symbol : type.symbol;
55047
+ return isTupleType(type) || !!((_a = symbol == null ? void 0 : symbol.declarations) == null ? void 0 : _a.some((decl) => host.isSourceFileDefaultLibrary(getSourceFileOfNode(decl))));
54474
55048
  }
54475
55049
  function typePredicateToString(typePredicate, enclosingDeclaration, flags = 16384 /* UseAliasDefinedOutsideCurrentScope */, writer) {
54476
55050
  return writer ? typePredicateToStringWorker(writer).getText() : usingSingleLineStringWriter(typePredicateToStringWorker);
@@ -54489,14 +55063,14 @@ function createTypeChecker(host) {
54489
55063
  return writer2;
54490
55064
  }
54491
55065
  }
54492
- function formatUnionTypes(types) {
55066
+ function formatUnionTypes(types, expandingEnum) {
54493
55067
  const result = [];
54494
55068
  let flags = 0;
54495
55069
  for (let i = 0; i < types.length; i++) {
54496
55070
  const t = types[i];
54497
55071
  flags |= t.flags;
54498
55072
  if (!(t.flags & 98304 /* Nullable */)) {
54499
- if (t.flags & (512 /* BooleanLiteral */ | 1056 /* EnumLike */)) {
55073
+ if (t.flags & 512 /* BooleanLiteral */ || !expandingEnum && t.flags | 1056 /* EnumLike */) {
54500
55074
  const baseType = t.flags & 512 /* BooleanLiteral */ ? booleanType : getBaseTypeOfEnumLikeType(t);
54501
55075
  if (baseType.flags & 1048576 /* Union */) {
54502
55076
  const count = baseType.types.length;
@@ -58579,7 +59153,7 @@ function createTypeChecker(host) {
58579
59153
  let hasThisParameter = false;
58580
59154
  const iife = getImmediatelyInvokedFunctionExpression(declaration);
58581
59155
  const isJSConstructSignature = isJSDocConstructSignature(declaration);
58582
- const isUntypedSignatureInJSFile = !iife && isInJSFile(declaration) && isValueSignatureDeclaration(declaration) && !hasJSDocParameterTags(declaration) && !getJSDocType(declaration) && !getContextualSignatureForFunctionLikeDeclaration(declaration);
59156
+ const isUntypedSignatureInJSFile = !iife && isInJSFile(declaration) && isValueSignatureDeclaration(declaration) && !hasJSDocParameterTags(declaration) && !some(declaration.parameters, (p) => !!getJSDocType(p)) && !getJSDocType(declaration) && !getContextualSignatureForFunctionLikeDeclaration(declaration);
58583
59157
  if (isUntypedSignatureInJSFile) {
58584
59158
  flags |= 32 /* IsUntypedSignatureInJSFile */;
58585
59159
  }
@@ -59443,14 +60017,11 @@ function createTypeChecker(host) {
59443
60017
  function isNoInferType(type) {
59444
60018
  return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
59445
60019
  }
59446
- function isNarrowingSubstitutionType(type) {
59447
- return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
60020
+ function getSubstitutionType(baseType, constraint) {
60021
+ return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint);
59448
60022
  }
59449
- function getSubstitutionType(baseType, constraint, isNarrowed) {
59450
- return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
59451
- }
59452
- function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
59453
- const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
60023
+ function getOrCreateSubstitutionType(baseType, constraint) {
60024
+ const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
59454
60025
  const cached = substitutionTypes.get(id);
59455
60026
  if (cached) {
59456
60027
  return cached;
@@ -59458,9 +60029,6 @@ function createTypeChecker(host) {
59458
60029
  const result = createType(33554432 /* Substitution */);
59459
60030
  result.baseType = baseType;
59460
60031
  result.constraint = constraint;
59461
- if (isNarrowed) {
59462
- result.objectFlags |= 16777216 /* IsNarrowingType */;
59463
- }
59464
60032
  substitutionTypes.set(id, result);
59465
60033
  return result;
59466
60034
  }
@@ -61666,7 +62234,7 @@ function createTypeChecker(host) {
61666
62234
  function isDeferredType(type, checkTuples) {
61667
62235
  return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
61668
62236
  }
61669
- function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
62237
+ function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
61670
62238
  let result;
61671
62239
  let extraTypes;
61672
62240
  let tailCount = 0;
@@ -61683,11 +62251,10 @@ function createTypeChecker(host) {
61683
62251
  if (checkType === wildcardType || extendsType === wildcardType) {
61684
62252
  return wildcardType;
61685
62253
  }
61686
- const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
61687
62254
  const checkTypeNode = skipTypeParentheses(root.node.checkType);
61688
62255
  const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
61689
62256
  const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
61690
- const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
62257
+ const checkTypeDeferred = isDeferredType(checkType, checkTuples);
61691
62258
  let combinedMapper;
61692
62259
  if (root.inferTypeParameters) {
61693
62260
  const context = createInferenceContext(
@@ -61700,14 +62267,14 @@ function createTypeChecker(host) {
61700
62267
  context.nonFixingMapper = combineTypeMappers(context.nonFixingMapper, mapper);
61701
62268
  }
61702
62269
  if (!checkTypeDeferred) {
61703
- inferTypes(context.inferences, checkType, extendsType, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
62270
+ inferTypes(context, context.inferences, checkType, extendsType, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
61704
62271
  }
61705
62272
  combinedMapper = mapper ? combineTypeMappers(context.mapper, mapper) : context.mapper;
61706
62273
  }
61707
62274
  const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
61708
62275
  if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
61709
- if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
61710
- if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
62276
+ if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (checkType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
62277
+ if (checkType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(checkType)))) {
61711
62278
  (extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
61712
62279
  }
61713
62280
  const falseType2 = getTypeFromTypeNode(root.node.falseType);
@@ -61724,7 +62291,7 @@ function createTypeChecker(host) {
61724
62291
  result = instantiateType(falseType2, mapper);
61725
62292
  break;
61726
62293
  }
61727
- if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
62294
+ if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
61728
62295
  const trueType2 = getTypeFromTypeNode(root.node.trueType);
61729
62296
  const trueMapper = combinedMapper || mapper;
61730
62297
  if (canTailRecurse(trueType2, trueMapper)) {
@@ -62690,44 +63257,8 @@ function createTypeChecker(host) {
62690
63257
  if (!result) {
62691
63258
  const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
62692
63259
  const checkType = root.checkType;
62693
- let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
62694
- let narrowingBaseType;
62695
- const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(
62696
- type,
62697
- /*hadNonPrimitiveExtendsType*/
62698
- [],
62699
- mapper
62700
- );
62701
- if (forNarrowing) {
62702
- narrowingBaseType = distributionType.baseType;
62703
- distributionType = getReducedType(distributionType.constraint);
62704
- }
62705
- if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
62706
- if (narrowingBaseType) {
62707
- result = mapTypeToIntersection(
62708
- distributionType,
62709
- (t) => getConditionalType(
62710
- root,
62711
- prependTypeMapping(checkType, getSubstitutionType(
62712
- narrowingBaseType,
62713
- t,
62714
- /*isNarrowed*/
62715
- true
62716
- ), newMapper),
62717
- forConstraint,
62718
- /*aliasSymbol*/
62719
- void 0,
62720
- /*aliasTypeArguments*/
62721
- void 0,
62722
- forNarrowing
62723
- )
62724
- );
62725
- } else {
62726
- result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
62727
- }
62728
- } else {
62729
- result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
62730
- }
63260
+ const distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
63261
+ result = distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments) : getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments);
62731
63262
  root.instantiations.set(id, result);
62732
63263
  }
62733
63264
  return result;
@@ -62754,10 +63285,25 @@ function createTypeChecker(host) {
62754
63285
  error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
62755
63286
  return errorType;
62756
63287
  }
63288
+ const index = findActiveMapper(mapper);
63289
+ if (index === -1) {
63290
+ pushActiveMapper(mapper);
63291
+ }
63292
+ const key = type.id + getAliasId(aliasSymbol, aliasTypeArguments);
63293
+ const mapperCache = activeTypeMappersCaches[index !== -1 ? index : activeTypeMappersCount - 1];
63294
+ const cached = mapperCache.get(key);
63295
+ if (cached) {
63296
+ return cached;
63297
+ }
62757
63298
  totalInstantiationCount++;
62758
63299
  instantiationCount++;
62759
63300
  instantiationDepth++;
62760
63301
  const result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
63302
+ if (index === -1) {
63303
+ popActiveMapper();
63304
+ } else {
63305
+ mapperCache.set(key, result);
63306
+ }
62761
63307
  instantiationDepth--;
62762
63308
  return result;
62763
63309
  }
@@ -63870,12 +64416,10 @@ function createTypeChecker(host) {
63870
64416
  function shouldNormalizeIntersection(type) {
63871
64417
  let hasInstantiable = false;
63872
64418
  let hasNullableOrEmpty = false;
63873
- let hasSubstitution = false;
63874
64419
  for (const t of type.types) {
63875
64420
  hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
63876
64421
  hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
63877
- hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
63878
- if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
64422
+ if (hasInstantiable && hasNullableOrEmpty) return true;
63879
64423
  }
63880
64424
  return false;
63881
64425
  }
@@ -65382,7 +65926,7 @@ function createTypeChecker(host) {
65382
65926
  0 /* None */,
65383
65927
  isRelatedToWorker
65384
65928
  );
65385
- inferTypes(ctx.inferences, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
65929
+ inferTypes(ctx, ctx.inferences, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
65386
65930
  sourceExtends = instantiateType(sourceExtends, ctx.mapper);
65387
65931
  mapper = ctx.mapper;
65388
65932
  }
@@ -67262,7 +67806,7 @@ function createTypeChecker(host) {
67262
67806
  map(context.inferences, (inference, i) => () => {
67263
67807
  if (!inference.isFixed) {
67264
67808
  inferFromIntraExpressionSites(context);
67265
- clearCachedInferences(context.inferences);
67809
+ clearCachedInferences(context, context.inferences);
67266
67810
  inference.isFixed = true;
67267
67811
  }
67268
67812
  return getInferredType(context, i);
@@ -67277,7 +67821,10 @@ function createTypeChecker(host) {
67277
67821
  })
67278
67822
  );
67279
67823
  }
67280
- function clearCachedInferences(inferences) {
67824
+ function clearCachedInferences(context, inferences) {
67825
+ if (context) {
67826
+ clearActiveMapperCache(context.nonFixingMapper);
67827
+ }
67281
67828
  for (const inference of inferences) {
67282
67829
  if (!inference.isFixed) {
67283
67830
  inference.inferredType = void 0;
@@ -67292,7 +67839,7 @@ function createTypeChecker(host) {
67292
67839
  for (const { node, type } of context.intraExpressionInferenceSites) {
67293
67840
  const contextualType = node.kind === 174 /* MethodDeclaration */ ? getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) : getContextualType(node, 2 /* NoConstraints */);
67294
67841
  if (contextualType) {
67295
- inferTypes(context.inferences, type, contextualType);
67842
+ inferTypes(context, context.inferences, type, contextualType);
67296
67843
  }
67297
67844
  }
67298
67845
  context.intraExpressionInferenceSites = void 0;
@@ -67436,7 +67983,13 @@ function createTypeChecker(host) {
67436
67983
  const typeParameter = getIndexedAccessType(constraint.type, getTypeParameterFromMappedType(target));
67437
67984
  const templateType = getTemplateTypeFromMappedType(target);
67438
67985
  const inference = createInferenceInfo(typeParameter);
67439
- inferTypes([inference], sourceType, templateType);
67986
+ inferTypes(
67987
+ /*context*/
67988
+ void 0,
67989
+ [inference],
67990
+ sourceType,
67991
+ templateType
67992
+ );
67440
67993
  return getTypeFromInference(inference) || unknownType;
67441
67994
  }
67442
67995
  function inferReverseMappedType(source, target, constraint) {
@@ -67638,7 +68191,7 @@ function createTypeChecker(host) {
67638
68191
  function isTupleOfSelf(typeParameter, type) {
67639
68192
  return isTupleType(type) && getTupleElementType(type, 0) === getIndexedAccessType(typeParameter, getNumberLiteralType(0)) && !getTypeOfPropertyOfType(type, "1");
67640
68193
  }
67641
- function inferTypes(inferences, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
68194
+ function inferTypes(context, inferences, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
67642
68195
  let bivariant = false;
67643
68196
  let propagationType;
67644
68197
  let inferencePriority = 2048 /* MaxValue */;
@@ -67729,16 +68282,16 @@ function createTypeChecker(host) {
67729
68282
  if (contravariant && !bivariant) {
67730
68283
  if (!contains(inference.contraCandidates, candidate)) {
67731
68284
  inference.contraCandidates = append(inference.contraCandidates, candidate);
67732
- clearCachedInferences(inferences);
68285
+ clearCachedInferences(context, inferences);
67733
68286
  }
67734
68287
  } else if (!contains(inference.candidates, candidate)) {
67735
68288
  inference.candidates = append(inference.candidates, candidate);
67736
- clearCachedInferences(inferences);
68289
+ clearCachedInferences(context, inferences);
67737
68290
  }
67738
68291
  }
67739
68292
  if (!(priority & 128 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
67740
68293
  inference.topLevel = false;
67741
- clearCachedInferences(inferences);
68294
+ clearCachedInferences(context, inferences);
67742
68295
  }
67743
68296
  }
67744
68297
  inferencePriority = Math.min(inferencePriority, priority);
@@ -68304,6 +68857,7 @@ function createTypeChecker(host) {
68304
68857
  const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
68305
68858
  if (!inferredType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
68306
68859
  inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint;
68860
+ clearActiveMapperCache(context.nonFixingMapper);
68307
68861
  }
68308
68862
  }
68309
68863
  }
@@ -69035,18 +69589,6 @@ function createTypeChecker(host) {
69035
69589
  }
69036
69590
  return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
69037
69591
  }
69038
- function mapTypeToIntersection(type, mapper) {
69039
- if (type.flags & 131072 /* Never */) {
69040
- return type;
69041
- }
69042
- if (!(type.flags & 1048576 /* Union */)) {
69043
- return mapper(type);
69044
- }
69045
- const origin = type.origin;
69046
- const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
69047
- const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
69048
- return getIntersectionType(mappedTypes);
69049
- }
69050
69592
  function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
69051
69593
  return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
69052
69594
  }
@@ -70631,11 +71173,11 @@ function createTypeChecker(host) {
70631
71173
  ));
70632
71174
  return contextualType && !isGenericType(contextualType);
70633
71175
  }
70634
- function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
71176
+ function getNarrowableTypeForReference(type, reference, checkMode) {
70635
71177
  if (isNoInferType(type)) {
70636
71178
  type = type.baseType;
70637
71179
  }
70638
- const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
71180
+ const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
70639
71181
  return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
70640
71182
  }
70641
71183
  function isExportOrExportExpression(location) {
@@ -71762,16 +72304,9 @@ function createTypeChecker(host) {
71762
72304
  function getContextualTypeForReturnExpression(node, contextFlags) {
71763
72305
  const func = getContainingFunction(node);
71764
72306
  if (func) {
71765
- const functionFlags = getFunctionFlags(func);
71766
- const links = getNodeLinks(node);
71767
- if (links.contextualReturnType) {
71768
- if (functionFlags & 2 /* Async */) {
71769
- return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
71770
- }
71771
- return links.contextualReturnType;
71772
- }
71773
72307
  let contextualReturnType = getContextualReturnType(func, contextFlags);
71774
72308
  if (contextualReturnType) {
72309
+ const functionFlags = getFunctionFlags(func);
71775
72310
  if (functionFlags & 1 /* Generator */) {
71776
72311
  const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
71777
72312
  if (contextualReturnType.flags & 1048576 /* Union */) {
@@ -72469,13 +73004,6 @@ function createTypeChecker(host) {
72469
73004
  if (index >= 0) {
72470
73005
  return contextualTypes[index];
72471
73006
  }
72472
- const links = getNodeLinks(node);
72473
- if (links.contextualReturnType) {
72474
- if (node.flags & 65536 /* AwaitContext */) {
72475
- return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
72476
- }
72477
- return links.contextualReturnType;
72478
- }
72479
73007
  const { parent } = node;
72480
73008
  switch (parent.kind) {
72481
73009
  case 260 /* VariableDeclaration */:
@@ -72593,6 +73121,28 @@ function createTypeChecker(host) {
72593
73121
  }
72594
73122
  }
72595
73123
  }
73124
+ function pushActiveMapper(mapper) {
73125
+ activeTypeMappers[activeTypeMappersCount] = mapper;
73126
+ activeTypeMappersCaches[activeTypeMappersCount] = /* @__PURE__ */ new Map();
73127
+ activeTypeMappersCount++;
73128
+ }
73129
+ function popActiveMapper() {
73130
+ activeTypeMappersCount--;
73131
+ }
73132
+ function findActiveMapper(mapper) {
73133
+ for (let i = activeTypeMappersCount - 1; i >= 0; i--) {
73134
+ if (mapper === activeTypeMappers[i]) {
73135
+ return i;
73136
+ }
73137
+ }
73138
+ return -1;
73139
+ }
73140
+ function clearActiveMapperCache(mapper) {
73141
+ const index = findActiveMapper(mapper);
73142
+ if (index !== -1) {
73143
+ activeTypeMappersCaches[index] = /* @__PURE__ */ new Map();
73144
+ }
73145
+ }
72596
73146
  function getContextualImportAttributeType(node) {
72597
73147
  return getTypeOfPropertyOfContextualType(getGlobalImportAttributesType(
72598
73148
  /*reportErrors*/
@@ -74457,7 +75007,7 @@ function createTypeChecker(host) {
74457
75007
  addErrorOrSuggestion(!isUncheckedJS || errorInfo.code !== Diagnostics.Property_0_may_not_exist_on_type_1_Did_you_mean_2.code, resultDiagnostic);
74458
75008
  }
74459
75009
  function containerSeemsToBeEmptyDomElement(containingType) {
74460
- return compilerOptions.lib && !compilerOptions.lib.includes("dom") && everyContainedType(containingType, (type) => type.symbol && /^(?:EventTarget|Node|(?:HTML[a-zA-Z]*)?Element)$/.test(unescapeLeadingUnderscores(type.symbol.escapedName))) && isEmptyObjectType(containingType);
75010
+ return compilerOptions.lib && !compilerOptions.lib.includes("lib.dom.d.ts") && everyContainedType(containingType, (type) => type.symbol && /^(?:EventTarget|Node|(?:HTML[a-zA-Z]*)?Element)$/.test(unescapeLeadingUnderscores(type.symbol.escapedName))) && isEmptyObjectType(containingType);
74461
75011
  }
74462
75012
  function typeHasStaticProperty(propName, containingType) {
74463
75013
  const prop = containingType.symbol && getPropertyOfType(getTypeOfSymbol(containingType.symbol), propName);
@@ -74904,11 +75454,11 @@ function createTypeChecker(host) {
74904
75454
  const mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
74905
75455
  const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
74906
75456
  applyToParameterTypes(sourceSignature, signature, (source, target) => {
74907
- inferTypes(context.inferences, source, target);
75457
+ inferTypes(context, context.inferences, source, target);
74908
75458
  });
74909
75459
  if (!inferenceContext) {
74910
75460
  applyToReturnTypes(contextualSignature, signature, (source, target) => {
74911
- inferTypes(context.inferences, source, target, 128 /* ReturnType */);
75461
+ inferTypes(context, context.inferences, source, target, 128 /* ReturnType */);
74912
75462
  });
74913
75463
  }
74914
75464
  return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
@@ -74916,7 +75466,7 @@ function createTypeChecker(host) {
74916
75466
  function inferJsxTypeArguments(node, signature, checkMode, context) {
74917
75467
  const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
74918
75468
  const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode);
74919
- inferTypes(context.inferences, checkAttrType, paramType);
75469
+ inferTypes(context, context.inferences, checkAttrType, paramType);
74920
75470
  return getInferredTypes(context);
74921
75471
  }
74922
75472
  function getThisArgumentType(thisArgumentNode) {
@@ -74943,11 +75493,11 @@ function createTypeChecker(host) {
74943
75493
  const instantiatedType = instantiateType(contextualType, outerMapper);
74944
75494
  const contextualSignature = getSingleCallSignature(instantiatedType);
74945
75495
  const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : instantiatedType;
74946
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75496
+ inferTypes(context, context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
74947
75497
  }
74948
75498
  const returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
74949
75499
  const returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
74950
- inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
75500
+ inferTypes(returnContext, returnContext.inferences, returnSourceType, inferenceTargetType);
74951
75501
  context.returnMapper = some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : void 0;
74952
75502
  }
74953
75503
  }
@@ -74963,7 +75513,7 @@ function createTypeChecker(host) {
74963
75513
  const thisType = getThisTypeOfSignature(signature);
74964
75514
  if (thisType && couldContainTypeVariables(thisType)) {
74965
75515
  const thisArgumentNode = getThisArgumentOfCall(node);
74966
- inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
75516
+ inferTypes(context, context.inferences, getThisArgumentType(thisArgumentNode), thisType);
74967
75517
  }
74968
75518
  for (let i = 0; i < argCount; i++) {
74969
75519
  const arg = args[i];
@@ -74971,13 +75521,13 @@ function createTypeChecker(host) {
74971
75521
  const paramType = getTypeAtPosition(signature, i);
74972
75522
  if (couldContainTypeVariables(paramType)) {
74973
75523
  const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
74974
- inferTypes(context.inferences, argType, paramType);
75524
+ inferTypes(context, context.inferences, argType, paramType);
74975
75525
  }
74976
75526
  }
74977
75527
  }
74978
75528
  if (restType && couldContainTypeVariables(restType)) {
74979
75529
  const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
74980
- inferTypes(context.inferences, spreadType, restType);
75530
+ inferTypes(context, context.inferences, spreadType, restType);
74981
75531
  }
74982
75532
  return getInferredTypes(context);
74983
75533
  }
@@ -77350,14 +77900,14 @@ function createTypeChecker(host) {
77350
77900
  isOptionalDeclaration(declaration)
77351
77901
  );
77352
77902
  const target = getTypeAtPosition(context, i);
77353
- inferTypes(inferenceContext.inferences, source, target);
77903
+ inferTypes(inferenceContext, inferenceContext.inferences, source, target);
77354
77904
  }
77355
77905
  }
77356
77906
  const typeNode = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
77357
77907
  if (typeNode) {
77358
77908
  const source = getTypeFromTypeNode(typeNode);
77359
77909
  const target = getReturnTypeOfSignature(context);
77360
- inferTypes(inferenceContext.inferences, source, target);
77910
+ inferTypes(inferenceContext, inferenceContext.inferences, source, target);
77361
77911
  }
77362
77912
  }
77363
77913
  function assignContextualParameterTypes(signature, context) {
@@ -79773,6 +80323,7 @@ function createTypeChecker(host) {
79773
80323
  const inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
79774
80324
  applyToParameterTypes(instantiatedSignature, contextualSignature, (source, target) => {
79775
80325
  inferTypes(
80326
+ context,
79776
80327
  inferences,
79777
80328
  source,
79778
80329
  target,
@@ -79784,7 +80335,7 @@ function createTypeChecker(host) {
79784
80335
  });
79785
80336
  if (some(inferences, hasInferenceCandidates)) {
79786
80337
  applyToReturnTypes(instantiatedSignature, contextualSignature, (source, target) => {
79787
- inferTypes(inferences, source, target);
80338
+ inferTypes(context, inferences, source, target);
79788
80339
  });
79789
80340
  if (!hasOverlappingInferences(context.inferences, inferences)) {
79790
80341
  mergeInferences(context.inferences, inferences);
@@ -83490,374 +84041,7 @@ function createTypeChecker(host) {
83490
84041
  ) : exprType;
83491
84042
  const effectiveExpr = expr && getEffectiveCheckNode(expr);
83492
84043
  const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
83493
- if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
83494
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83495
- return;
83496
- }
83497
- if (checkTypeAssignableTo(
83498
- unwrappedExprType,
83499
- unwrappedReturnType,
83500
- /*errorNode*/
83501
- void 0
83502
- )) {
83503
- return;
83504
- }
83505
- let narrowPosition = node;
83506
- let narrowFlowNode = inReturnStatement && node.flowNode;
83507
- if (expr && isConditionalExpression(expr.parent)) {
83508
- narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
83509
- narrowPosition = expr;
83510
- }
83511
- if (!narrowFlowNode) {
83512
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83513
- return;
83514
- }
83515
- const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
83516
- container,
83517
- /*includeThisTypes*/
83518
- false
83519
- ), getEffectiveTypeParameterDeclarations(container));
83520
- const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
83521
- if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
83522
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83523
- return;
83524
- }
83525
- const narrowedTypeParameters = [];
83526
- const narrowedTypes = [];
83527
- for (const [typeParam, symbol, narrowReference] of narrowableTypeParameters) {
83528
- resetNodeId(narrowReference);
83529
- let baseReference = narrowReference;
83530
- while (isAccessExpression(baseReference)) {
83531
- baseReference = baseReference.expression;
83532
- }
83533
- getNodeLinks(baseReference).resolvedSymbol = symbol;
83534
- setParent(narrowReference, narrowPosition.parent);
83535
- narrowReference.flowNode = narrowFlowNode;
83536
- const initialType = getNarrowableTypeForReference(
83537
- typeParam,
83538
- narrowReference,
83539
- /*checkMode*/
83540
- void 0,
83541
- /*forReturnTypeNarrowing*/
83542
- true
83543
- );
83544
- if (initialType === typeParam) {
83545
- continue;
83546
- }
83547
- const flowType = getFlowTypeOfReference(narrowReference, initialType);
83548
- const exprType2 = getTypeFromFlowType(flowType);
83549
- if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
83550
- continue;
83551
- }
83552
- const narrowedType = getSubstitutionType(
83553
- typeParam,
83554
- exprType2,
83555
- /*isNarrowed*/
83556
- true
83557
- );
83558
- narrowedTypeParameters.push(typeParam);
83559
- narrowedTypes.push(narrowedType);
83560
- }
83561
- const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
83562
- const narrowedReturnType = instantiateType(
83563
- unwrappedReturnType,
83564
- narrowMapper
83565
- );
83566
- if (expr) {
83567
- const links = getNodeLinks(expr);
83568
- if (!links.contextualReturnType) {
83569
- links.contextualReturnType = narrowedReturnType;
83570
- }
83571
- }
83572
- const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
83573
- const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
83574
- narrowedExprType,
83575
- /*withAlias*/
83576
- false,
83577
- node,
83578
- Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
83579
- ) : narrowedExprType;
83580
- checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
83581
- }
83582
- function resetNodeId(node) {
83583
- node.id = void 0;
83584
- forEachChildRecursively(node, resetNodeId);
83585
- }
83586
- function getNarrowableTypeParameters(candidates) {
83587
- const narrowableParams = [];
83588
- for (const typeParam of candidates) {
83589
- const constraint = getConstraintOfTypeParameter(typeParam);
83590
- if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
83591
- if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
83592
- const declaration = typeParam.symbol.declarations[0];
83593
- const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
83594
- if (!isFunctionLike(container)) continue;
83595
- let paramReference;
83596
- let referencePath;
83597
- let hasInvalidReference = false;
83598
- for (const paramDecl of container.parameters) {
83599
- const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
83600
- if (!typeNode) continue;
83601
- const result = getValidTypeParameterReference(typeNode, typeParam, []);
83602
- if (!result) {
83603
- hasInvalidReference = true;
83604
- break;
83605
- }
83606
- if (isArray(result)) {
83607
- if (referencePath) {
83608
- hasInvalidReference = true;
83609
- break;
83610
- }
83611
- referencePath = result;
83612
- paramReference = paramDecl;
83613
- }
83614
- }
83615
- if (!hasInvalidReference && referencePath && validateOptionality(paramReference, constraint, referencePath)) {
83616
- const symbolAndReference = constructNarrowableReference(paramReference, referencePath);
83617
- if (symbolAndReference) {
83618
- if (symbolAndReference[0] && symbolAndReference[0] !== unknownSymbol) {
83619
- narrowableParams.push([typeParam, symbolAndReference[0], symbolAndReference[1]]);
83620
- }
83621
- }
83622
- }
83623
- }
83624
- }
83625
- return narrowableParams;
83626
- function isReferenceToTypeParameter(typeParam, node) {
83627
- return getTypeFromTypeReference(node) === typeParam;
83628
- }
83629
- function isTypeParameterReferenced(typeParam, node) {
83630
- return isReferenced(node);
83631
- function isReferenced(node2) {
83632
- if (isTypeReferenceNode(node2)) {
83633
- return isReferenceToTypeParameter(typeParam, node2) || some(node2.typeArguments, isReferenced);
83634
- }
83635
- if (isTypeQueryNode(node2)) {
83636
- return isTypeParameterPossiblyReferenced(typeParam, node2);
83637
- }
83638
- return !!forEachChild(node2, isReferenced);
83639
- }
83640
- }
83641
- function getValidTypeParameterReference(typeNode, typeParam, path) {
83642
- var _a;
83643
- switch (typeNode.kind) {
83644
- case 183 /* TypeReference */:
83645
- const type = getTypeFromTypeReference(typeNode);
83646
- if (type === typeParam) {
83647
- return path;
83648
- }
83649
- const typeArgs = typeNode.typeArguments;
83650
- const typeArgsReferencingT = typeArgs == null ? void 0 : typeArgs.filter((node) => isTypeParameterReferenced(typeParam, node));
83651
- if (!typeArgsReferencingT || typeArgsReferencingT.length === 0) return true;
83652
- if (typeArgsReferencingT && typeArgsReferencingT.length > 1) return false;
83653
- const typeArg = typeArgsReferencingT[0];
83654
- if (!(typeArg.kind & 183 /* TypeReference */)) return false;
83655
- if (!type.symbol || !type.symbol.declarations || type.symbol.declarations.length !== 1) return false;
83656
- const typeDeclaration = type.symbol.declarations[0];
83657
- let aliasDeclaration;
83658
- if (isTypeLiteralNode(typeDeclaration)) {
83659
- aliasDeclaration = walkUpParenthesizedTypes(typeDeclaration.parent);
83660
- if (!isTypeAliasDeclaration(aliasDeclaration)) return false;
83661
- } else if (isInterfaceDeclaration(typeDeclaration)) {
83662
- aliasDeclaration = typeDeclaration;
83663
- } else {
83664
- return false;
83665
- }
83666
- const typeArgIndex = typeArgs.findIndex((arg) => arg === typeArg);
83667
- const matchingTypeParamDecl = (_a = aliasDeclaration.typeParameters) == null ? void 0 : _a[typeArgIndex];
83668
- if (!matchingTypeParamDecl) return false;
83669
- const matchingTypeParam = getDeclaredTypeOfTypeParameter(matchingTypeParamDecl.symbol);
83670
- return getValidTypeParameterReference(typeDeclaration, matchingTypeParam, path);
83671
- case 264 /* InterfaceDeclaration */:
83672
- const extendsTypes = flatMap(typeNode.heritageClauses, (clause) => clause.types);
83673
- const relevantExtendsTypes = extendsTypes.filter((node) => isTypeParameterReferenced(typeParam, node));
83674
- if (relevantExtendsTypes && relevantExtendsTypes.length > 1) {
83675
- return false;
83676
- }
83677
- const result = getValidTypeParameterReferenceFromTypeElements(typeNode.members, typeParam, path);
83678
- if (relevantExtendsTypes && relevantExtendsTypes.length === 1) {
83679
- if (result !== true) {
83680
- return false;
83681
- }
83682
- return getValidTypeParameterReference(relevantExtendsTypes[0], typeParam, path);
83683
- }
83684
- return result;
83685
- case 187 /* TypeLiteral */:
83686
- return getValidTypeParameterReferenceFromTypeElements(typeNode.members, typeParam, path);
83687
- case 193 /* IntersectionType */:
83688
- let validPath;
83689
- for (const type2 of typeNode.types) {
83690
- const result2 = getValidTypeParameterReference(type2, typeParam, path);
83691
- if (!result2) {
83692
- return false;
83693
- }
83694
- if (isArray(result2)) {
83695
- if (validPath) {
83696
- return false;
83697
- }
83698
- validPath = result2;
83699
- }
83700
- }
83701
- return validPath ?? true;
83702
- default:
83703
- return !isTypeParameterReferenced(typeParam, typeNode);
83704
- }
83705
- }
83706
- function getValidTypeParameterReferenceFromTypeElements(members, typeParam, path) {
83707
- let validPath;
83708
- for (const member of members) {
83709
- if (!isTypeParameterReferenced(typeParam, member)) {
83710
- continue;
83711
- }
83712
- if (!isPropertySignature(member)) {
83713
- return false;
83714
- }
83715
- if (!isIdentifier(member.name) && !isStringLiteral(member.name)) {
83716
- return false;
83717
- }
83718
- const result = getValidTypeParameterReference(member.type, typeParam, [...path, member]);
83719
- if (!result) {
83720
- return false;
83721
- }
83722
- if (isArray(result)) {
83723
- if (validPath) {
83724
- return false;
83725
- }
83726
- validPath = result;
83727
- }
83728
- }
83729
- return validPath ?? true;
83730
- }
83731
- function validateOptionality(paramDecl, constraint, path) {
83732
- for (let i = 0; i < path.length - 1; i++) {
83733
- if (path[i].questionToken) {
83734
- return false;
83735
- }
83736
- }
83737
- const paramIsOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
83738
- if (paramIsOptional && path.length > 0) {
83739
- return false;
83740
- }
83741
- const isOptional = paramIsOptional || path.length > 0 && path[path.length - 1].questionToken;
83742
- if (isOptional && strictNullChecks && !containsUndefinedType(constraint)) {
83743
- return false;
83744
- }
83745
- return true;
83746
- }
83747
- function constructNarrowableReference(paramDecl, path) {
83748
- let currentName = paramDecl.name;
83749
- let i = 0;
83750
- for (; i < path.length; i++) {
83751
- if (isIdentifier(currentName)) {
83752
- break;
83753
- } else if (isObjectBindingPattern(currentName)) {
83754
- const name = path[i].name;
83755
- let nameText;
83756
- if (isIdentifier(name)) nameText = name.escapedText;
83757
- else {
83758
- const rawText = getLiteralPropertyNameText(name);
83759
- if (rawText) nameText = escapeLeadingUnderscores(rawText);
83760
- }
83761
- const element = currentName.elements.find((element2) => {
83762
- const propertyName = getDestructuringPropertyName(element2);
83763
- const propertyNameText = propertyName && escapeLeadingUnderscores(propertyName);
83764
- return nameText && propertyNameText && nameText === propertyNameText;
83765
- });
83766
- if (!element) {
83767
- return void 0;
83768
- }
83769
- currentName = element.name;
83770
- } else {
83771
- return void 0;
83772
- }
83773
- }
83774
- if (!isIdentifier(currentName)) {
83775
- return void 0;
83776
- }
83777
- let result = factory.cloneNode(currentName);
83778
- const initialSymbol = getSymbolOfDeclaration(currentName.parent);
83779
- for (let j = i; j < path.length; j++) {
83780
- result = addName(result, path[j].name);
83781
- }
83782
- return [initialSymbol, result];
83783
- }
83784
- function addName(exp, name) {
83785
- name = factory.cloneNode(name);
83786
- if (isIdentifier(name)) {
83787
- const accessExp = factory.createPropertyAccessExpression(exp, name);
83788
- setParent(name, accessExp);
83789
- setParent(exp, accessExp);
83790
- return accessExp;
83791
- } else {
83792
- const accessExp = factory.createElementAccessExpression(exp, name);
83793
- setParent(name, accessExp);
83794
- setParent(exp, accessExp);
83795
- return accessExp;
83796
- }
83797
- }
83798
- }
83799
- function isNarrowableReturnType(returnType) {
83800
- return isConditionalType(returnType) ? isNarrowableConditionalType(
83801
- returnType,
83802
- /*hadNonPrimitiveExtendsType*/
83803
- []
83804
- ) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
83805
- }
83806
- function isNarrowableConditionalType(type, hadNonPrimitiveExtendsType, mapper) {
83807
- const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
83808
- const mapped = getMappedType(t, mapper);
83809
- if (isNarrowingSubstitutionType(mapped)) {
83810
- return mapped.baseType;
83811
- }
83812
- return mapped;
83813
- });
83814
- const id = `${type.id}:${getTypeListId(typeArguments)}:${getTypeListId(hadNonPrimitiveExtendsType)}`;
83815
- let result = narrowableReturnTypeCache.get(id);
83816
- if (result === void 0) {
83817
- const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
83818
- const instantiatedType = instantiateType(type, nonNarrowingMapper);
83819
- result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType, hadNonPrimitiveExtendsType);
83820
- narrowableReturnTypeCache.set(id, result);
83821
- }
83822
- return result;
83823
- }
83824
- function isNarrowableConditionalTypeWorker(type, hadNonPrimitiveExtendsType) {
83825
- if (!type.root.isDistributive) {
83826
- return false;
83827
- }
83828
- if (type.root.inferTypeParameters) {
83829
- return false;
83830
- }
83831
- if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
83832
- return false;
83833
- }
83834
- const constraintType = getConstraintOfTypeParameter(type.checkType);
83835
- if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
83836
- return false;
83837
- }
83838
- if (!everyType(type.extendsType, (extendsType) => some(
83839
- constraintType.types,
83840
- (constraintType2) => isTypeAssignableTo(constraintType2, extendsType)
83841
- ))) {
83842
- return false;
83843
- }
83844
- const hasNonPrimitive = someType(type.extendsType, (type2) => (type2.flags & 402784252 /* Primitive */) === 0);
83845
- if (hasNonPrimitive && hadNonPrimitiveExtendsType.includes(type.checkType)) {
83846
- return false;
83847
- }
83848
- if (hasNonPrimitive) {
83849
- hadNonPrimitiveExtendsType = hadNonPrimitiveExtendsType.slice();
83850
- hadNonPrimitiveExtendsType.push(type.checkType);
83851
- }
83852
- const trueType2 = getTrueTypeFromConditionalType(type);
83853
- const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2, hadNonPrimitiveExtendsType) : true;
83854
- if (!isValidTrueType) return false;
83855
- const falseType2 = getFalseTypeFromConditionalType(type);
83856
- const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2, hadNonPrimitiveExtendsType) : falseType2 === neverType;
83857
- return isValidFalseType;
83858
- }
83859
- function isConditionalType(type) {
83860
- return !!(type.flags & 16777216 /* Conditional */);
84044
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83861
84045
  }
83862
84046
  function checkWithStatement(node) {
83863
84047
  if (!checkGrammarStatementInAmbientContext(node)) {
@@ -87879,6 +88063,9 @@ function createTypeChecker(host) {
87879
88063
  tracker.trackSymbol(name, enclosing, 111551 /* Value */);
87880
88064
  }
87881
88065
  }
88066
+ },
88067
+ symbolToDeclarations: (symbol, meaning, flags, verbosityLevel, out) => {
88068
+ return nodeBuilder.symbolToDeclarations(symbol, meaning, flags, verbosityLevel, out);
87882
88069
  }
87883
88070
  };
87884
88071
  function isImportRequiredByAugmentation(node) {
@@ -115782,7 +115969,8 @@ var notImplementedResolver = {
115782
115969
  getDeclarationStatementsForSourceFile: notImplemented,
115783
115970
  isImportRequiredByAugmentation: notImplemented,
115784
115971
  isDefinitelyReferenceToGlobalSymbolObject: notImplemented,
115785
- createLateBoundIndexSignatures: notImplemented
115972
+ createLateBoundIndexSignatures: notImplemented,
115973
+ symbolToDeclarations: notImplemented
115786
115974
  };
115787
115975
  var createPrinterWithDefaults = /* @__PURE__ */ memoize(() => createPrinter({}));
115788
115976
  var createPrinterWithRemoveComments = /* @__PURE__ */ memoize(() => createPrinter({ removeComments: true }));