typescript 5.7.0-dev.20240930 → 5.7.0-dev.20241002

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.
Files changed (3) hide show
  1. package/lib/_tsc.js +1350 -995
  2. package/lib/typescript.js +1351 -999
  3. package/package.json +17 -17
package/lib/typescript.js CHANGED
@@ -1577,6 +1577,7 @@ __export(typescript_exports, {
1577
1577
  isNamespaceReexportDeclaration: () => isNamespaceReexportDeclaration,
1578
1578
  isNewExpression: () => isNewExpression,
1579
1579
  isNewExpressionTarget: () => isNewExpressionTarget,
1580
+ isNewScopeNode: () => isNewScopeNode,
1580
1581
  isNoSubstitutionTemplateLiteral: () => isNoSubstitutionTemplateLiteral,
1581
1582
  isNodeArray: () => isNodeArray,
1582
1583
  isNodeArrayMultiLine: () => isNodeArrayMultiLine,
@@ -1803,7 +1804,6 @@ __export(typescript_exports, {
1803
1804
  isVariableDeclarationInitializedToRequire: () => isVariableDeclarationInitializedToRequire,
1804
1805
  isVariableDeclarationList: () => isVariableDeclarationList,
1805
1806
  isVariableLike: () => isVariableLike,
1806
- isVariableLikeOrAccessor: () => isVariableLikeOrAccessor,
1807
1807
  isVariableStatement: () => isVariableStatement,
1808
1808
  isVoidExpression: () => isVoidExpression,
1809
1809
  isWatchSet: () => isWatchSet,
@@ -2277,7 +2277,7 @@ module.exports = __toCommonJS(typescript_exports);
2277
2277
 
2278
2278
  // src/compiler/corePublic.ts
2279
2279
  var versionMajorMinor = "5.7";
2280
- var version = `${versionMajorMinor}.0-dev.20240930`;
2280
+ var version = `${versionMajorMinor}.0-dev.20241002`;
2281
2281
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2282
2282
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2283
2283
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -10944,7 +10944,7 @@ var Diagnostics = {
10944
10944
  Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit: diag(9006, 1 /* Error */, "Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotati_9006", "Declaration emit for this file requires using private name '{0}' from module '{1}'. An explicit type annotation may unblock declaration emit."),
10945
10945
  Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations: diag(9007, 1 /* Error */, "Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9007", "Function must have an explicit return type annotation with --isolatedDeclarations."),
10946
10946
  Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations: diag(9008, 1 /* Error */, "Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9008", "Method must have an explicit return type annotation with --isolatedDeclarations."),
10947
- At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations: diag(9009, 1 /* Error */, "At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9009", "At least one accessor must have an explicit return type annotation with --isolatedDeclarations."),
10947
+ At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9009, 1 /* Error */, "At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009", "At least one accessor must have an explicit type annotation with --isolatedDeclarations."),
10948
10948
  Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9010, 1 /* Error */, "Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9010", "Variable must have an explicit type annotation with --isolatedDeclarations."),
10949
10949
  Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9011, 1 /* Error */, "Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9011", "Parameter must have an explicit type annotation with --isolatedDeclarations."),
10950
10950
  Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9012, 1 /* Error */, "Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9012", "Property must have an explicit type annotation with --isolatedDeclarations."),
@@ -17873,9 +17873,6 @@ function isVariableLike(node) {
17873
17873
  }
17874
17874
  return false;
17875
17875
  }
17876
- function isVariableLikeOrAccessor(node) {
17877
- return isVariableLike(node) || isAccessor(node);
17878
- }
17879
17876
  function isVariableDeclarationInVariableStatement(node) {
17880
17877
  return node.parent.kind === 261 /* VariableDeclarationList */ && node.parent.parent.kind === 243 /* VariableStatement */;
17881
17878
  }
@@ -23806,6 +23803,9 @@ function hasInferredType(node) {
23806
23803
  case 260 /* VariableDeclaration */:
23807
23804
  case 277 /* ExportAssignment */:
23808
23805
  case 303 /* PropertyAssignment */:
23806
+ case 304 /* ShorthandPropertyAssignment */:
23807
+ case 341 /* JSDocParameterTag */:
23808
+ case 348 /* JSDocPropertyTag */:
23809
23809
  return true;
23810
23810
  default:
23811
23811
  assertType(node);
@@ -23925,6 +23925,9 @@ function getNodeAtPosition(sourceFile, position, includeJSDoc) {
23925
23925
  current = child;
23926
23926
  }
23927
23927
  }
23928
+ function isNewScopeNode(node) {
23929
+ return isFunctionLike(node) || isJSDocSignature(node) || isMappedTypeNode(node);
23930
+ }
23928
23931
 
23929
23932
  // src/compiler/factory/baseNodeFactory.ts
23930
23933
  function createBaseNodeFactory() {
@@ -46377,7 +46380,7 @@ function createBinder() {
46377
46380
  var inStrictMode;
46378
46381
  var inAssignmentPattern = false;
46379
46382
  var symbolCount = 0;
46380
- var Symbol47;
46383
+ var Symbol48;
46381
46384
  var classifiableNames;
46382
46385
  var unreachableFlow = createFlowNode(
46383
46386
  1 /* Unreachable */,
@@ -46406,7 +46409,7 @@ function createBinder() {
46406
46409
  inStrictMode = bindInStrictMode(file, opts);
46407
46410
  classifiableNames = /* @__PURE__ */ new Set();
46408
46411
  symbolCount = 0;
46409
- Symbol47 = objectAllocator.getSymbolConstructor();
46412
+ Symbol48 = objectAllocator.getSymbolConstructor();
46410
46413
  Debug.attachFlowNodeDebugInfo(unreachableFlow);
46411
46414
  Debug.attachFlowNodeDebugInfo(reportedUnreachableFlow);
46412
46415
  if (!file.locals) {
@@ -46457,7 +46460,7 @@ function createBinder() {
46457
46460
  }
46458
46461
  function createSymbol(flags, name) {
46459
46462
  symbolCount++;
46460
- return new Symbol47(flags, name);
46463
+ return new Symbol48(flags, name);
46461
46464
  }
46462
46465
  function addDeclarationToSymbol(symbol, node, symbolFlags) {
46463
46466
  symbol.flags |= symbolFlags;
@@ -50514,7 +50517,7 @@ function createTypeChecker(host) {
50514
50517
  };
50515
50518
  var cancellationToken;
50516
50519
  var scanner2;
50517
- var Symbol47 = objectAllocator.getSymbolConstructor();
50520
+ var Symbol48 = objectAllocator.getSymbolConstructor();
50518
50521
  var Type29 = objectAllocator.getTypeConstructor();
50519
50522
  var Signature14 = objectAllocator.getSignatureConstructor();
50520
50523
  var typeCount = 0;
@@ -50548,17 +50551,7 @@ function createTypeChecker(host) {
50548
50551
  var checkBinaryExpression = createCheckBinaryExpression();
50549
50552
  var emitResolver = createResolver();
50550
50553
  var nodeBuilder = createNodeBuilder();
50551
- var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions, {
50552
- isEntityNameVisible,
50553
- isExpandoFunctionDeclaration,
50554
- getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration,
50555
- requiresAddingImplicitUndefined,
50556
- isUndefinedIdentifierExpression(node) {
50557
- Debug.assert(isExpressionNode(node));
50558
- return getSymbolAtLocation(node) === undefinedSymbol;
50559
- },
50560
- isDefinitelyReferenceToGlobalSymbolObject
50561
- });
50554
+ var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions, nodeBuilder.syntacticBuilderResolver);
50562
50555
  var evaluate = createEvaluator({
50563
50556
  evaluateElementAccessExpression,
50564
50557
  evaluateEntityNameExpression
@@ -51703,7 +51696,7 @@ function createTypeChecker(host) {
51703
51696
  }
51704
51697
  function createSymbol(flags, name, checkFlags) {
51705
51698
  symbolCount++;
51706
- const symbol = new Symbol47(flags | 33554432 /* Transient */, name);
51699
+ const symbol = new Symbol48(flags | 33554432 /* Transient */, name);
51707
51700
  symbol.links = new SymbolLinks();
51708
51701
  symbol.links.checkFlags = checkFlags || 0 /* None */;
51709
51702
  return symbol;
@@ -54716,12 +54709,191 @@ function createTypeChecker(host) {
54716
54709
  return getTypeFromTypeNode(node);
54717
54710
  }
54718
54711
  function createNodeBuilder() {
54712
+ const syntacticBuilderResolver = {
54713
+ evaluateEntityNameExpression,
54714
+ isExpandoFunctionDeclaration,
54715
+ hasLateBindableName,
54716
+ shouldRemoveDeclaration(context, node) {
54717
+ return !(context.internalFlags & 8 /* AllowUnresolvedNames */ && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & 1 /* Any */);
54718
+ },
54719
+ createRecoveryBoundary(context) {
54720
+ return createRecoveryBoundary(context);
54721
+ },
54722
+ isDefinitelyReferenceToGlobalSymbolObject,
54723
+ getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration,
54724
+ requiresAddingImplicitUndefined(declaration, symbol, enclosingDeclaration) {
54725
+ var _a;
54726
+ switch (declaration.kind) {
54727
+ case 172 /* PropertyDeclaration */:
54728
+ case 171 /* PropertySignature */:
54729
+ case 348 /* JSDocPropertyTag */:
54730
+ symbol ?? (symbol = getSymbolOfDeclaration(declaration));
54731
+ const type = getTypeOfSymbol(symbol);
54732
+ return !!(symbol.flags & 4 /* Property */ && symbol.flags & 16777216 /* Optional */ && isOptionalDeclaration(declaration) && ((_a = symbol.links) == null ? void 0 : _a.mappedType) && containsNonMissingUndefinedType(type));
54733
+ case 169 /* Parameter */:
54734
+ case 341 /* JSDocParameterTag */:
54735
+ return requiresAddingImplicitUndefined(declaration, enclosingDeclaration);
54736
+ default:
54737
+ Debug.assertNever(declaration);
54738
+ }
54739
+ },
54740
+ isOptionalParameter,
54741
+ isUndefinedIdentifierExpression(node) {
54742
+ Debug.assert(isExpressionNode(node));
54743
+ return getSymbolAtLocation(node) === undefinedSymbol;
54744
+ },
54745
+ isEntityNameVisible(context, entityName, shouldComputeAliasToMakeVisible) {
54746
+ return isEntityNameVisible(entityName, context.enclosingDeclaration, shouldComputeAliasToMakeVisible);
54747
+ },
54748
+ serializeExistingTypeNode(context, typeNode, addUndefined) {
54749
+ return serializeExistingTypeNode(context, typeNode, !!addUndefined);
54750
+ },
54751
+ serializeReturnTypeForSignature(syntacticContext, signatureDeclaration) {
54752
+ const context = syntacticContext;
54753
+ const signature = getSignatureFromDeclaration(signatureDeclaration);
54754
+ const returnType = context.enclosingSymbolTypes.get(getSymbolId(getSymbolOfDeclaration(signatureDeclaration))) ?? instantiateType(getReturnTypeOfSignature(signature), context.mapper);
54755
+ return serializeInferredReturnTypeForSignature(context, signature, returnType);
54756
+ },
54757
+ serializeTypeOfExpression(syntacticContext, expr) {
54758
+ const context = syntacticContext;
54759
+ const type = instantiateType(getWidenedType(getRegularTypeOfExpression(expr)), context.mapper);
54760
+ return typeToTypeNodeHelper(type, context);
54761
+ },
54762
+ serializeTypeOfDeclaration(syntacticContext, declaration, symbol) {
54763
+ var _a;
54764
+ const context = syntacticContext;
54765
+ symbol ?? (symbol = getSymbolOfDeclaration(declaration));
54766
+ let type = (_a = context.enclosingSymbolTypes) == null ? void 0 : _a.get(getSymbolId(symbol));
54767
+ if (type === void 0) {
54768
+ type = symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) ? instantiateType(getWidenedLiteralType(getTypeOfSymbol(symbol)), context.mapper) : errorType;
54769
+ }
54770
+ const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
54771
+ if (addUndefinedForParameter) {
54772
+ type = getOptionalType(type);
54773
+ }
54774
+ return serializeInferredTypeForDeclaration(symbol, context, type);
54775
+ },
54776
+ serializeNameOfParameter(context, parameter) {
54777
+ return parameterToParameterDeclarationName(getSymbolOfDeclaration(parameter), parameter, context);
54778
+ },
54779
+ serializeEntityName(syntacticContext, node) {
54780
+ const context = syntacticContext;
54781
+ const symbol = getSymbolAtLocation(
54782
+ node,
54783
+ /*ignoreErrors*/
54784
+ true
54785
+ );
54786
+ if (!symbol) return void 0;
54787
+ if (!isValueSymbolAccessible(symbol, context.enclosingDeclaration)) return void 0;
54788
+ return symbolToExpression(symbol, context, 111551 /* Value */ | 1048576 /* ExportValue */);
54789
+ },
54790
+ serializeTypeName(context, node, isTypeOf, typeArguments) {
54791
+ return serializeTypeName(context, node, isTypeOf, typeArguments);
54792
+ },
54793
+ getJsDocPropertyOverride(syntacticContext, jsDocTypeLiteral, jsDocProperty) {
54794
+ const context = syntacticContext;
54795
+ const name = isIdentifier(jsDocProperty.name) ? jsDocProperty.name : jsDocProperty.name.right;
54796
+ const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode2(context, jsDocTypeLiteral), name.escapedText);
54797
+ const overrideTypeNode = typeViaParent && jsDocProperty.typeExpression && getTypeFromTypeNode2(context, jsDocProperty.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : void 0;
54798
+ return overrideTypeNode;
54799
+ },
54800
+ enterNewScope(context, node) {
54801
+ if (isFunctionLike(node) || isJSDocSignature(node)) {
54802
+ const signature = getSignatureFromDeclaration(node);
54803
+ const expandedParams = getExpandedParameters(
54804
+ signature,
54805
+ /*skipUnionExpanding*/
54806
+ true
54807
+ )[0];
54808
+ return enterNewScope(context, node, expandedParams, signature.typeParameters);
54809
+ } else {
54810
+ const typeParameters = isConditionalTypeNode(node) ? getInferTypeParameters(node) : [getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node.typeParameter))];
54811
+ return enterNewScope(
54812
+ context,
54813
+ node,
54814
+ /*expandedParams*/
54815
+ void 0,
54816
+ typeParameters
54817
+ );
54818
+ }
54819
+ },
54820
+ markNodeReuse(context, range, location) {
54821
+ return setTextRange2(context, range, location);
54822
+ },
54823
+ trackExistingEntityName(context, node) {
54824
+ return trackExistingEntityName(node, context);
54825
+ },
54826
+ trackComputedName(context, accessExpression) {
54827
+ trackComputedName(accessExpression, context.enclosingDeclaration, context);
54828
+ },
54829
+ getModuleSpecifierOverride(syntacticContext, parent2, lit) {
54830
+ const context = syntacticContext;
54831
+ if (context.bundled || context.enclosingFile !== getSourceFileOfNode(lit)) {
54832
+ let name = lit.text;
54833
+ const nodeSymbol = getNodeLinks(parent2).resolvedSymbol;
54834
+ const meaning = parent2.isTypeOf ? 111551 /* Value */ : 788968 /* Type */;
54835
+ const parentSymbol = nodeSymbol && isSymbolAccessible(
54836
+ nodeSymbol,
54837
+ context.enclosingDeclaration,
54838
+ meaning,
54839
+ /*shouldComputeAliasesToMakeVisible*/
54840
+ false
54841
+ ).accessibility === 0 /* Accessible */ && lookupSymbolChain(
54842
+ nodeSymbol,
54843
+ context,
54844
+ meaning,
54845
+ /*yieldModuleSymbol*/
54846
+ true
54847
+ )[0];
54848
+ if (parentSymbol && isExternalModuleSymbol(parentSymbol)) {
54849
+ name = getSpecifierForModuleSymbol(parentSymbol, context);
54850
+ } else {
54851
+ const targetFile = getExternalModuleFileFromDeclaration(parent2);
54852
+ if (targetFile) {
54853
+ name = getSpecifierForModuleSymbol(targetFile.symbol, context);
54854
+ }
54855
+ }
54856
+ if (name.includes("/node_modules/")) {
54857
+ context.encounteredError = true;
54858
+ if (context.tracker.reportLikelyUnsafeImportRequiredError) {
54859
+ context.tracker.reportLikelyUnsafeImportRequiredError(name);
54860
+ }
54861
+ }
54862
+ return name;
54863
+ }
54864
+ },
54865
+ canReuseTypeNode(context, typeNode) {
54866
+ return canReuseTypeNode(context, typeNode);
54867
+ },
54868
+ canReuseTypeNodeAnnotation(syntacticContext, node, existing, symbol, requiresAddingUndefined) {
54869
+ var _a;
54870
+ const context = syntacticContext;
54871
+ if (context.enclosingDeclaration === void 0) return false;
54872
+ symbol ?? (symbol = getSymbolOfDeclaration(node));
54873
+ let type = (_a = context.enclosingSymbolTypes) == null ? void 0 : _a.get(getSymbolId(symbol));
54874
+ if (type === void 0) {
54875
+ if (symbol.flags & 98304 /* Accessor */) {
54876
+ type = node.kind === 178 /* SetAccessor */ ? getWriteTypeOfSymbol(symbol) : getTypeOfAccessors(symbol);
54877
+ } else if (isValueSignatureDeclaration(node)) {
54878
+ type = getReturnTypeOfSignature(getSignatureFromDeclaration(node));
54879
+ } else {
54880
+ type = getTypeOfSymbol(symbol);
54881
+ }
54882
+ }
54883
+ let annotationType = getTypeFromTypeNodeWithoutContext(existing);
54884
+ if (requiresAddingUndefined && annotationType) {
54885
+ annotationType = getOptionalType(annotationType, !isParameter(node));
54886
+ }
54887
+ return !!annotationType && typeNodeIsEquivalentToType(node, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type);
54888
+ }
54889
+ };
54719
54890
  return {
54891
+ syntacticBuilderResolver,
54720
54892
  typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
54721
54893
  typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
54722
- expressionOrTypeToTypeNode: (expr, type, addUndefined, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => expressionOrTypeToTypeNode(context, expr, type, addUndefined)),
54723
- serializeTypeForDeclaration: (declaration, type, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => serializeTypeForDeclaration(context, declaration, type, symbol)),
54724
- serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => serializeReturnTypeForSignature(context, signature)),
54894
+ serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)),
54895
+ serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)),
54896
+ serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)),
54725
54897
  indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
54726
54898
  indexInfo,
54727
54899
  context,
@@ -54769,65 +54941,6 @@ function createTypeChecker(host) {
54769
54941
  }
54770
54942
  return range;
54771
54943
  }
54772
- function expressionOrTypeToTypeNode(context, expr, type, addUndefined) {
54773
- const restoreFlags = saveRestoreFlags(context);
54774
- if (expr && !(context.internalFlags & 2 /* NoSyntacticPrinter */)) {
54775
- syntacticNodeBuilder.serializeTypeOfExpression(expr, context, addUndefined);
54776
- }
54777
- context.internalFlags |= 2 /* NoSyntacticPrinter */;
54778
- const result = expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined);
54779
- restoreFlags();
54780
- return result;
54781
- }
54782
- function expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined) {
54783
- if (expr) {
54784
- const typeNode = isAssertionExpression(expr) ? expr.type : isJSDocTypeAssertion(expr) ? getJSDocTypeAssertionType(expr) : void 0;
54785
- if (typeNode && !isConstTypeReference(typeNode)) {
54786
- const result = tryReuseExistingTypeNode(context, typeNode, type, expr.parent, addUndefined);
54787
- if (result) {
54788
- return result;
54789
- }
54790
- }
54791
- }
54792
- if (addUndefined) {
54793
- type = getOptionalType(type);
54794
- }
54795
- return typeToTypeNodeHelper(type, context);
54796
- }
54797
- function tryReuseExistingTypeNode(context, typeNode, type, host2, addUndefined) {
54798
- const originalType = type;
54799
- if (addUndefined) {
54800
- type = getOptionalType(type, !isParameter(host2));
54801
- }
54802
- const clone2 = tryReuseExistingNonParameterTypeNode(context, typeNode, type, host2);
54803
- if (clone2) {
54804
- if (addUndefined && containsNonMissingUndefinedType(type) && !someType(getTypeFromTypeNode2(context, typeNode), (t) => !!(t.flags & 32768 /* Undefined */))) {
54805
- return factory.createUnionTypeNode([clone2, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
54806
- }
54807
- return clone2;
54808
- }
54809
- if (addUndefined && originalType !== type) {
54810
- const cloneMissingUndefined = tryReuseExistingNonParameterTypeNode(context, typeNode, originalType, host2);
54811
- if (cloneMissingUndefined) {
54812
- return factory.createUnionTypeNode([cloneMissingUndefined, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
54813
- }
54814
- }
54815
- return void 0;
54816
- }
54817
- function tryReuseExistingNonParameterTypeNode(context, existing, type, host2 = context.enclosingDeclaration, annotationType = getTypeFromTypeNode2(
54818
- context,
54819
- existing,
54820
- /*noMappedTypes*/
54821
- true
54822
- )) {
54823
- if (annotationType && typeNodeIsEquivalentToType(host2, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type)) {
54824
- const result = tryReuseExistingTypeNodeHelper(context, existing);
54825
- if (result) {
54826
- return result;
54827
- }
54828
- }
54829
- return void 0;
54830
- }
54831
54944
  function symbolToNode(symbol, context, meaning) {
54832
54945
  if (context.internalFlags & 1 /* WriteComputedProps */) {
54833
54946
  if (symbol.valueDeclaration) {
@@ -54851,6 +54964,7 @@ function createTypeChecker(host) {
54851
54964
  internalFlags: internalFlags || 0 /* None */,
54852
54965
  tracker: void 0,
54853
54966
  encounteredError: false,
54967
+ suppressReportInferenceFallback: false,
54854
54968
  reportedDiagnostic: false,
54855
54969
  visitedTypes: void 0,
54856
54970
  symbolDepth: void 0,
@@ -54869,6 +54983,7 @@ function createTypeChecker(host) {
54869
54983
  typeParameterNames: void 0,
54870
54984
  typeParameterNamesByText: void 0,
54871
54985
  typeParameterNamesByTextNextNameCount: void 0,
54986
+ enclosingSymbolTypes: /* @__PURE__ */ new Map(),
54872
54987
  mapper: void 0
54873
54988
  };
54874
54989
  context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
@@ -54878,6 +54993,19 @@ function createTypeChecker(host) {
54878
54993
  }
54879
54994
  return context.encounteredError ? void 0 : resultingNode;
54880
54995
  }
54996
+ function addSymbolTypeToContext(context, symbol, type) {
54997
+ const id = getSymbolId(symbol);
54998
+ const oldType = context.enclosingSymbolTypes.get(id);
54999
+ context.enclosingSymbolTypes.set(id, type);
55000
+ return restore;
55001
+ function restore() {
55002
+ if (oldType) {
55003
+ context.enclosingSymbolTypes.set(id, oldType);
55004
+ } else {
55005
+ context.enclosingSymbolTypes.delete(id);
55006
+ }
55007
+ }
55008
+ }
54881
55009
  function saveRestoreFlags(context) {
54882
55010
  const flags = context.flags;
54883
55011
  const internalFlags = context.internalFlags;
@@ -55289,8 +55417,8 @@ function createTypeChecker(host) {
55289
55417
  if (isInstantiationExpressionType) {
55290
55418
  const instantiationExpressionType = type2;
55291
55419
  const existing = instantiationExpressionType.node;
55292
- if (isTypeQueryNode(existing)) {
55293
- const typeNode = tryReuseExistingNonParameterTypeNode(context, existing, type2);
55420
+ if (isTypeQueryNode(existing) && getTypeFromTypeNode2(context, existing) === type2) {
55421
+ const typeNode = syntacticNodeBuilder.tryReuseExistingTypeNode(context, existing);
55294
55422
  if (typeNode) {
55295
55423
  return typeNode;
55296
55424
  }
@@ -56041,14 +56169,85 @@ function createTypeChecker(host) {
56041
56169
  cleanup == null ? void 0 : cleanup();
56042
56170
  return node;
56043
56171
  }
56044
- function isNewScopeNode(node) {
56045
- return isFunctionLike(node) || isJSDocSignature(node) || isMappedTypeNode(node);
56046
- }
56047
- function getTypeParametersInScope(node) {
56048
- return isFunctionLike(node) || isJSDocSignature(node) ? getSignatureFromDeclaration(node).typeParameters : isConditionalTypeNode(node) ? getInferTypeParameters(node) : [getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node.typeParameter))];
56049
- }
56050
- function getParametersInScope(node) {
56051
- return isFunctionLike(node) || isJSDocSignature(node) ? getSignatureFromDeclaration(node).parameters : void 0;
56172
+ function createRecoveryBoundary(context) {
56173
+ if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
56174
+ cancellationToken.throwIfCancellationRequested();
56175
+ }
56176
+ let trackedSymbols;
56177
+ let unreportedErrors;
56178
+ let hadError = false;
56179
+ const oldTracker = context.tracker;
56180
+ const oldTrackedSymbols = context.trackedSymbols;
56181
+ context.trackedSymbols = void 0;
56182
+ const oldEncounteredError = context.encounteredError;
56183
+ context.tracker = new SymbolTrackerImpl(context, {
56184
+ ...oldTracker.inner,
56185
+ reportCyclicStructureError() {
56186
+ markError(() => oldTracker.reportCyclicStructureError());
56187
+ },
56188
+ reportInaccessibleThisError() {
56189
+ markError(() => oldTracker.reportInaccessibleThisError());
56190
+ },
56191
+ reportInaccessibleUniqueSymbolError() {
56192
+ markError(() => oldTracker.reportInaccessibleUniqueSymbolError());
56193
+ },
56194
+ reportLikelyUnsafeImportRequiredError(specifier) {
56195
+ markError(() => oldTracker.reportLikelyUnsafeImportRequiredError(specifier));
56196
+ },
56197
+ reportNonSerializableProperty(name) {
56198
+ markError(() => oldTracker.reportNonSerializableProperty(name));
56199
+ },
56200
+ reportPrivateInBaseOfClassExpression(propertyName) {
56201
+ markError(() => oldTracker.reportPrivateInBaseOfClassExpression(propertyName));
56202
+ },
56203
+ trackSymbol(sym, decl, meaning) {
56204
+ (trackedSymbols ?? (trackedSymbols = [])).push([sym, decl, meaning]);
56205
+ return false;
56206
+ },
56207
+ moduleResolverHost: context.tracker.moduleResolverHost
56208
+ }, context.tracker.moduleResolverHost);
56209
+ return {
56210
+ startRecoveryScope,
56211
+ finalizeBoundary,
56212
+ markError,
56213
+ hadError: () => hadError
56214
+ };
56215
+ function markError(unreportedError) {
56216
+ hadError = true;
56217
+ if (unreportedError) {
56218
+ (unreportedErrors ?? (unreportedErrors = [])).push(unreportedError);
56219
+ }
56220
+ }
56221
+ function startRecoveryScope() {
56222
+ const trackedSymbolsTop = (trackedSymbols == null ? void 0 : trackedSymbols.length) ?? 0;
56223
+ const unreportedErrorsTop = (unreportedErrors == null ? void 0 : unreportedErrors.length) ?? 0;
56224
+ return () => {
56225
+ hadError = false;
56226
+ if (trackedSymbols) {
56227
+ trackedSymbols.length = trackedSymbolsTop;
56228
+ }
56229
+ if (unreportedErrors) {
56230
+ unreportedErrors.length = unreportedErrorsTop;
56231
+ }
56232
+ };
56233
+ }
56234
+ function finalizeBoundary() {
56235
+ context.tracker = oldTracker;
56236
+ context.trackedSymbols = oldTrackedSymbols;
56237
+ context.encounteredError = oldEncounteredError;
56238
+ unreportedErrors == null ? void 0 : unreportedErrors.forEach((fn) => fn());
56239
+ if (hadError) {
56240
+ return false;
56241
+ }
56242
+ trackedSymbols == null ? void 0 : trackedSymbols.forEach(
56243
+ ([symbol, enclosingDeclaration, meaning]) => context.tracker.trackSymbol(
56244
+ symbol,
56245
+ enclosingDeclaration,
56246
+ meaning
56247
+ )
56248
+ );
56249
+ return true;
56250
+ }
56052
56251
  }
56053
56252
  function enterNewScope(context, declaration, expandedParams, typeParameters, originalParameters, mapper) {
56054
56253
  const cleanupContext = cloneNodeBuilderContext(context);
@@ -56191,7 +56390,7 @@ function createTypeChecker(host) {
56191
56390
  return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
56192
56391
  }
56193
56392
  function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
56194
- return typeNode && tryReuseExistingNonParameterTypeNode(context, typeNode, type) || typeToTypeNodeHelper(type, context);
56393
+ return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
56195
56394
  }
56196
56395
  function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
56197
56396
  const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
@@ -56813,35 +57012,34 @@ function createTypeChecker(host) {
56813
57012
  }
56814
57013
  return enclosingDeclaration;
56815
57014
  }
57015
+ function serializeInferredTypeForDeclaration(symbol, context, type) {
57016
+ if (type.flags & 8192 /* UniqueESSymbol */ && type.symbol === symbol && (!context.enclosingDeclaration || some(symbol.declarations, (d) => getSourceFileOfNode(d) === context.enclosingFile))) {
57017
+ context.flags |= 1048576 /* AllowUniqueESSymbolType */;
57018
+ }
57019
+ const result = typeToTypeNodeHelper(type, context);
57020
+ return result;
57021
+ }
56816
57022
  function serializeTypeForDeclaration(context, declaration, type, symbol) {
56817
- var _a, _b;
57023
+ var _a;
57024
+ let result;
56818
57025
  const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
56819
- const enclosingDeclaration = context.enclosingDeclaration;
56820
- const restoreFlags = saveRestoreFlags(context);
56821
- if (declaration && hasInferredType(declaration) && !(context.internalFlags & 2 /* NoSyntacticPrinter */)) {
56822
- syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, context);
56823
- }
56824
- context.internalFlags |= 2 /* NoSyntacticPrinter */;
56825
- if (enclosingDeclaration && (!isErrorType(type) || context.internalFlags & 8 /* AllowUnresolvedNames */)) {
56826
- const declWithExistingAnnotation = declaration && getNonlocalEffectiveTypeAnnotationNode(declaration) ? declaration : getDeclarationWithTypeAnnotation(symbol);
56827
- if (declWithExistingAnnotation && !isFunctionLikeDeclaration(declWithExistingAnnotation) && !isGetAccessorDeclaration(declWithExistingAnnotation)) {
56828
- const existing = getNonlocalEffectiveTypeAnnotationNode(declWithExistingAnnotation);
56829
- const addUndefined = addUndefinedForParameter || !!(symbol.flags & 4 /* Property */ && symbol.flags & 16777216 /* Optional */ && isOptionalDeclaration(declWithExistingAnnotation) && ((_a = symbol.links) == null ? void 0 : _a.mappedType) && containsNonMissingUndefinedType(type));
56830
- const result2 = !isTypePredicateNode(existing) && tryReuseExistingTypeNode(context, existing, type, declWithExistingAnnotation, addUndefined);
56831
- if (result2) {
56832
- restoreFlags();
56833
- return result2;
56834
- }
57026
+ const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
57027
+ if (decl) {
57028
+ if (isAccessor(decl)) {
57029
+ result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
57030
+ } else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
57031
+ const restore = addSymbolTypeToContext(context, symbol, type);
57032
+ result = syntacticNodeBuilder.serializeTypeOfDeclaration(decl, symbol, context);
57033
+ restore();
56835
57034
  }
56836
57035
  }
56837
- if (type.flags & 8192 /* UniqueESSymbol */ && type.symbol === symbol && (!context.enclosingDeclaration || some(symbol.declarations, (d) => getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration)))) {
56838
- context.flags |= 1048576 /* AllowUniqueESSymbolType */;
57036
+ if (!result) {
57037
+ if (addUndefinedForParameter) {
57038
+ type = getOptionalType(type);
57039
+ }
57040
+ result = serializeInferredTypeForDeclaration(symbol, context, type);
56839
57041
  }
56840
- const decl = declaration ?? symbol.valueDeclaration ?? ((_b = symbol.declarations) == null ? void 0 : _b[0]);
56841
- const expr = decl && isDeclarationWithPossibleInnerTypeNodeReuse(decl) ? getPossibleTypeNodeReuseExpression(decl) : void 0;
56842
- const result = expressionOrTypeToTypeNode(context, expr, type, addUndefinedForParameter);
56843
- restoreFlags();
56844
- return result;
57042
+ return result ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
56845
57043
  }
56846
57044
  function typeNodeIsEquivalentToType(annotatedDeclaration, type, typeFromTypeNode) {
56847
57045
  if (typeFromTypeNode === type) {
@@ -56864,37 +57062,32 @@ function createTypeChecker(host) {
56864
57062
  if (suppressAny) context.flags &= ~256 /* SuppressAnyReturnType */;
56865
57063
  let returnTypeNode;
56866
57064
  const returnType = getReturnTypeOfSignature(signature);
56867
- if (returnType && !(suppressAny && isTypeAny(returnType))) {
56868
- if (signature.declaration && !(context.internalFlags & 2 /* NoSyntacticPrinter */)) {
56869
- syntacticNodeBuilder.serializeReturnTypeForSignature(signature.declaration, context);
57065
+ if (!(suppressAny && isTypeAny(returnType))) {
57066
+ if (signature.declaration && !nodeIsSynthesized(signature.declaration)) {
57067
+ const declarationSymbol = getSymbolOfDeclaration(signature.declaration);
57068
+ const restore = addSymbolTypeToContext(context, declarationSymbol, returnType);
57069
+ returnTypeNode = syntacticNodeBuilder.serializeReturnTypeForSignature(signature.declaration, declarationSymbol, context);
57070
+ restore();
57071
+ }
57072
+ if (!returnTypeNode) {
57073
+ returnTypeNode = serializeInferredReturnTypeForSignature(context, signature, returnType);
56870
57074
  }
56871
- context.internalFlags |= 2 /* NoSyntacticPrinter */;
56872
- returnTypeNode = serializeReturnTypeForSignatureWorker(context, signature);
56873
- } else if (!suppressAny) {
57075
+ }
57076
+ if (!returnTypeNode && !suppressAny) {
56874
57077
  returnTypeNode = factory.createKeywordTypeNode(133 /* AnyKeyword */);
56875
57078
  }
56876
57079
  restoreFlags();
56877
57080
  return returnTypeNode;
56878
57081
  }
56879
- function serializeReturnTypeForSignatureWorker(context, signature) {
57082
+ function serializeInferredReturnTypeForSignature(context, signature, returnType) {
57083
+ const oldSuppressReportInferenceFallback = context.suppressReportInferenceFallback;
57084
+ context.suppressReportInferenceFallback = true;
56880
57085
  const typePredicate = getTypePredicateOfSignature(signature);
56881
- const type = getReturnTypeOfSignature(signature);
56882
- if (context.enclosingDeclaration && (!isErrorType(type) || context.internalFlags & 8 /* AllowUnresolvedNames */) && signature.declaration && !nodeIsSynthesized(signature.declaration)) {
56883
- const annotation = getNonlocalEffectiveReturnTypeAnnotationNode(signature.declaration);
56884
- if (annotation) {
56885
- const result = tryReuseExistingTypeNode(context, annotation, type, context.enclosingDeclaration);
56886
- if (result) {
56887
- return result;
56888
- }
56889
- }
56890
- }
56891
- if (typePredicate) {
56892
- return typePredicateToTypePredicateNodeHelper(typePredicate, context);
56893
- }
56894
- const expr = signature.declaration && getPossibleTypeNodeReuseExpression(signature.declaration);
56895
- return expressionOrTypeToTypeNode(context, expr, type);
57086
+ const returnTypeNode = typePredicate ? typePredicateToTypePredicateNodeHelper(context.mapper ? instantiateTypePredicate(typePredicate, context.mapper) : typePredicate, context) : typeToTypeNodeHelper(returnType, context);
57087
+ context.suppressReportInferenceFallback = oldSuppressReportInferenceFallback;
57088
+ return returnTypeNode;
56896
57089
  }
56897
- function trackExistingEntityName(node, context) {
57090
+ function trackExistingEntityName(node, context, enclosingDeclaration = context.enclosingDeclaration) {
56898
57091
  let introducesError = false;
56899
57092
  const leftmost = getFirstIdentifier(node);
56900
57093
  if (isInJSFile(node) && (isExportsIdentifier(leftmost) || isModuleExportsAccessExpression(leftmost.parent) || isQualifiedName(leftmost.parent) && isModuleIdentifier(leftmost.parent.left) && isExportsIdentifier(leftmost.parent.right))) {
@@ -56945,7 +57138,7 @@ function createTypeChecker(host) {
56945
57138
  if (
56946
57139
  // Check for unusable parameters symbols
56947
57140
  symAtLocation === unknownSymbol || // If the symbol is not found, but was not found in the original scope either we probably have an error, don't reuse the node
56948
- symAtLocation === void 0 && sym !== void 0 || // If the symbol is found both in declaration scope and in current scope then it shoudl point to the same reference
57141
+ symAtLocation === void 0 && sym !== void 0 || // If the symbol is found both in declaration scope and in current scope then it should point to the same reference
56949
57142
  symAtLocation && sym && !getSymbolIfSameReference(getExportSymbolOfValueSymbolIfExported(symAtLocation), sym)
56950
57143
  ) {
56951
57144
  if (symAtLocation !== unknownSymbol) {
@@ -56966,7 +57159,7 @@ function createTypeChecker(host) {
56966
57159
  if (!(sym.flags & 262144 /* TypeParameter */) && // Type parameters are visible in the current context if they are are resolvable
56967
57160
  !isDeclarationName(node) && isSymbolAccessible(
56968
57161
  sym,
56969
- context.enclosingDeclaration,
57162
+ enclosingDeclaration,
56970
57163
  meaning,
56971
57164
  /*shouldComputeAliasesToMakeVisible*/
56972
57165
  false
@@ -56974,7 +57167,7 @@ function createTypeChecker(host) {
56974
57167
  context.tracker.reportInferenceFallback(node);
56975
57168
  introducesError = true;
56976
57169
  } else {
56977
- context.tracker.trackSymbol(sym, context.enclosingDeclaration, meaning);
57170
+ context.tracker.trackSymbol(sym, enclosingDeclaration, meaning);
56978
57171
  }
56979
57172
  return { introducesError, node: attachSymbolToLeftmostIdentifier(node) };
56980
57173
  }
@@ -57018,6 +57211,15 @@ function createTypeChecker(host) {
57018
57211
  return symbolToTypeNode(resolvedSymbol, context, meaning, typeArguments);
57019
57212
  }
57020
57213
  function canReuseTypeNode(context, existing) {
57214
+ const type = getTypeFromTypeNode2(
57215
+ context,
57216
+ existing,
57217
+ /*noMappedTypes*/
57218
+ true
57219
+ );
57220
+ if (!type) {
57221
+ return false;
57222
+ }
57021
57223
  if (isInJSFile(existing)) {
57022
57224
  if (isLiteralImportTypeNode(existing)) {
57023
57225
  void getTypeFromImportTypeNode(existing);
@@ -57027,29 +57229,16 @@ function createTypeChecker(host) {
57027
57229
  !(length(existing.typeArguments) >= getMinTypeArgumentCount(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(nodeSymbol))));
57028
57230
  }
57029
57231
  }
57030
- if (isThisTypeNode(existing)) {
57031
- if (context.mapper === void 0) return true;
57032
- const type = getTypeFromTypeNode2(
57033
- context,
57034
- existing,
57035
- /*noMappedTypes*/
57036
- true
57037
- );
57038
- return !!type;
57039
- }
57040
57232
  if (isTypeReferenceNode(existing)) {
57041
57233
  if (isConstTypeReference(existing)) return false;
57042
- const type = getTypeFromTypeReference(existing);
57043
57234
  const symbol = getNodeLinks(existing).resolvedSymbol;
57044
57235
  if (!symbol) return false;
57045
57236
  if (symbol.flags & 262144 /* TypeParameter */) {
57046
- const type2 = getDeclaredTypeOfSymbol(symbol);
57047
- if (context.mapper && getMappedType(type2, context.mapper) !== type2) {
57048
- return false;
57049
- }
57237
+ const declaredType = getDeclaredTypeOfSymbol(symbol);
57238
+ return !(context.mapper && getMappedType(declaredType, context.mapper) !== declaredType);
57050
57239
  }
57051
57240
  if (isInJSDoc(existing)) {
57052
- return existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type) && !getIntendedTypeFromJSDocTypeReference(existing) && symbol.flags & 788968 /* Type */;
57241
+ return existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type) && !getIntendedTypeFromJSDocTypeReference(existing) && !!(symbol.flags & 788968 /* Type */);
57053
57242
  }
57054
57243
  }
57055
57244
  if (isTypeOperatorNode(existing) && existing.operator === 158 /* UniqueKeyword */ && existing.type.kind === 155 /* SymbolKeyword */) {
@@ -57058,511 +57247,15 @@ function createTypeChecker(host) {
57058
57247
  }
57059
57248
  return true;
57060
57249
  }
57061
- function serializeExistingTypeNode(context, typeNode) {
57250
+ function serializeExistingTypeNode(context, typeNode, addUndefined) {
57062
57251
  const type = getTypeFromTypeNode2(context, typeNode);
57063
- return typeToTypeNodeHelper(type, context);
57064
- }
57065
- function tryReuseExistingTypeNodeHelper(context, existing) {
57066
- if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
57067
- cancellationToken.throwIfCancellationRequested();
57068
- }
57069
- let hadError = false;
57070
- const { finalizeBoundary, startRecoveryScope } = createRecoveryBoundary();
57071
- const transformed = visitNode(existing, visitExistingNodeTreeSymbols, isTypeNode);
57072
- if (!finalizeBoundary()) {
57073
- return void 0;
57074
- }
57075
- context.approximateLength += existing.end - existing.pos;
57076
- return transformed;
57077
- function visitExistingNodeTreeSymbols(node) {
57078
- if (hadError) return node;
57079
- const recover = startRecoveryScope();
57080
- const onExitNewScope = isNewScopeNode(node) ? onEnterNewScope(node) : void 0;
57081
- const result = visitExistingNodeTreeSymbolsWorker(node);
57082
- onExitNewScope == null ? void 0 : onExitNewScope();
57083
- if (hadError) {
57084
- if (isTypeNode(node) && !isTypePredicateNode(node)) {
57085
- recover();
57086
- return serializeExistingTypeNode(context, node);
57087
- }
57088
- return node;
57089
- }
57090
- return result ? setTextRange2(context, result, node) : void 0;
57091
- }
57092
- function createRecoveryBoundary() {
57093
- let trackedSymbols;
57094
- let unreportedErrors;
57095
- const oldTracker = context.tracker;
57096
- const oldTrackedSymbols = context.trackedSymbols;
57097
- context.trackedSymbols = void 0;
57098
- const oldEncounteredError = context.encounteredError;
57099
- context.tracker = new SymbolTrackerImpl(context, {
57100
- ...oldTracker.inner,
57101
- reportCyclicStructureError() {
57102
- markError(() => oldTracker.reportCyclicStructureError());
57103
- },
57104
- reportInaccessibleThisError() {
57105
- markError(() => oldTracker.reportInaccessibleThisError());
57106
- },
57107
- reportInaccessibleUniqueSymbolError() {
57108
- markError(() => oldTracker.reportInaccessibleUniqueSymbolError());
57109
- },
57110
- reportLikelyUnsafeImportRequiredError(specifier) {
57111
- markError(() => oldTracker.reportLikelyUnsafeImportRequiredError(specifier));
57112
- },
57113
- reportNonSerializableProperty(name) {
57114
- markError(() => oldTracker.reportNonSerializableProperty(name));
57115
- },
57116
- trackSymbol(sym, decl, meaning) {
57117
- (trackedSymbols ?? (trackedSymbols = [])).push([sym, decl, meaning]);
57118
- return false;
57119
- },
57120
- moduleResolverHost: context.tracker.moduleResolverHost
57121
- }, context.tracker.moduleResolverHost);
57122
- return {
57123
- startRecoveryScope: startRecoveryScope2,
57124
- finalizeBoundary: finalizeBoundary2
57125
- };
57126
- function markError(unreportedError) {
57127
- hadError = true;
57128
- (unreportedErrors ?? (unreportedErrors = [])).push(unreportedError);
57129
- }
57130
- function startRecoveryScope2() {
57131
- const trackedSymbolsTop = (trackedSymbols == null ? void 0 : trackedSymbols.length) ?? 0;
57132
- const unreportedErrorsTop = (unreportedErrors == null ? void 0 : unreportedErrors.length) ?? 0;
57133
- return () => {
57134
- hadError = false;
57135
- if (trackedSymbols) {
57136
- trackedSymbols.length = trackedSymbolsTop;
57137
- }
57138
- if (unreportedErrors) {
57139
- unreportedErrors.length = unreportedErrorsTop;
57140
- }
57141
- };
57142
- }
57143
- function finalizeBoundary2() {
57144
- context.tracker = oldTracker;
57145
- context.trackedSymbols = oldTrackedSymbols;
57146
- context.encounteredError = oldEncounteredError;
57147
- unreportedErrors == null ? void 0 : unreportedErrors.forEach((fn) => fn());
57148
- if (hadError) {
57149
- return false;
57150
- }
57151
- trackedSymbols == null ? void 0 : trackedSymbols.forEach(
57152
- ([symbol, enclosingDeclaration, meaning]) => context.tracker.trackSymbol(
57153
- symbol,
57154
- enclosingDeclaration,
57155
- meaning
57156
- )
57157
- );
57158
- return true;
57159
- }
57160
- }
57161
- function onEnterNewScope(node) {
57162
- return enterNewScope(context, node, getParametersInScope(node), getTypeParametersInScope(node));
57163
- }
57164
- function tryVisitSimpleTypeNode(node) {
57165
- const innerNode = skipTypeParentheses(node);
57166
- switch (innerNode.kind) {
57167
- case 183 /* TypeReference */:
57168
- return tryVisitTypeReference(innerNode);
57169
- case 186 /* TypeQuery */:
57170
- return tryVisitTypeQuery(innerNode);
57171
- case 199 /* IndexedAccessType */:
57172
- return tryVisitIndexedAccess(innerNode);
57173
- case 198 /* TypeOperator */:
57174
- const typeOperatorNode = innerNode;
57175
- if (typeOperatorNode.operator === 143 /* KeyOfKeyword */) {
57176
- return tryVisitKeyOf(typeOperatorNode);
57177
- }
57178
- }
57179
- return visitNode(node, visitExistingNodeTreeSymbols, isTypeNode);
57180
- }
57181
- function tryVisitIndexedAccess(node) {
57182
- const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
57183
- if (resultObjectType === void 0) {
57184
- return void 0;
57185
- }
57186
- return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode));
57187
- }
57188
- function tryVisitKeyOf(node) {
57189
- Debug.assertEqual(node.operator, 143 /* KeyOfKeyword */);
57190
- const type = tryVisitSimpleTypeNode(node.type);
57191
- if (type === void 0) {
57192
- return void 0;
57193
- }
57194
- return factory.updateTypeOperatorNode(node, type);
57195
- }
57196
- function tryVisitTypeQuery(node) {
57197
- const { introducesError, node: exprName } = trackExistingEntityName(node.exprName, context);
57198
- if (!introducesError) {
57199
- return factory.updateTypeQueryNode(
57200
- node,
57201
- exprName,
57202
- visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode)
57203
- );
57204
- }
57205
- const serializedName = serializeTypeName(
57206
- context,
57207
- node.exprName,
57208
- /*isTypeOf*/
57209
- true
57210
- );
57211
- if (serializedName) {
57212
- return setTextRange2(context, serializedName, node.exprName);
57213
- }
57214
- }
57215
- function tryVisitTypeReference(node) {
57216
- if (canReuseTypeNode(context, node)) {
57217
- const { introducesError, node: newName } = trackExistingEntityName(node.typeName, context);
57218
- const typeArguments = visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode);
57219
- if (!introducesError) {
57220
- const updated = factory.updateTypeReferenceNode(
57221
- node,
57222
- newName,
57223
- typeArguments
57224
- );
57225
- return setTextRange2(context, updated, node);
57226
- } else {
57227
- const serializedName = serializeTypeName(
57228
- context,
57229
- node.typeName,
57230
- /*isTypeOf*/
57231
- false,
57232
- typeArguments
57233
- );
57234
- if (serializedName) {
57235
- return setTextRange2(context, serializedName, node.typeName);
57236
- }
57237
- }
57238
- }
57239
- }
57240
- function visitExistingNodeTreeSymbolsWorker(node) {
57241
- if (isJSDocTypeExpression(node)) {
57242
- return visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode);
57243
- }
57244
- if (isJSDocAllType(node) || node.kind === 319 /* JSDocNamepathType */) {
57245
- return factory.createKeywordTypeNode(133 /* AnyKeyword */);
57246
- }
57247
- if (isJSDocUnknownType(node)) {
57248
- return factory.createKeywordTypeNode(159 /* UnknownKeyword */);
57249
- }
57250
- if (isJSDocNullableType(node)) {
57251
- return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createLiteralTypeNode(factory.createNull())]);
57252
- }
57253
- if (isJSDocOptionalType(node)) {
57254
- return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
57255
- }
57256
- if (isJSDocNonNullableType(node)) {
57257
- return visitNode(node.type, visitExistingNodeTreeSymbols);
57258
- }
57259
- if (isJSDocVariadicType(node)) {
57260
- return factory.createArrayTypeNode(visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
57261
- }
57262
- if (isJSDocTypeLiteral(node)) {
57263
- return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, (t) => {
57264
- const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier);
57265
- const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode2(context, node), name.escapedText);
57266
- const overrideTypeNode = typeViaParent && t.typeExpression && getTypeFromTypeNode2(context, t.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : void 0;
57267
- return factory.createPropertySignature(
57268
- /*modifiers*/
57269
- void 0,
57270
- name,
57271
- t.isBracketed || t.typeExpression && isJSDocOptionalType(t.typeExpression.type) ? factory.createToken(58 /* QuestionToken */) : void 0,
57272
- overrideTypeNode || t.typeExpression && visitNode(t.typeExpression.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
57273
- );
57274
- }));
57275
- }
57276
- if (isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.escapedText === "") {
57277
- return setOriginalNode(factory.createKeywordTypeNode(133 /* AnyKeyword */), node);
57278
- }
57279
- if ((isExpressionWithTypeArguments(node) || isTypeReferenceNode(node)) && isJSDocIndexSignature(node)) {
57280
- return factory.createTypeLiteralNode([factory.createIndexSignature(
57281
- /*modifiers*/
57282
- void 0,
57283
- [factory.createParameterDeclaration(
57284
- /*modifiers*/
57285
- void 0,
57286
- /*dotDotDotToken*/
57287
- void 0,
57288
- "x",
57289
- /*questionToken*/
57290
- void 0,
57291
- visitNode(node.typeArguments[0], visitExistingNodeTreeSymbols, isTypeNode)
57292
- )],
57293
- visitNode(node.typeArguments[1], visitExistingNodeTreeSymbols, isTypeNode)
57294
- )]);
57295
- }
57296
- if (isJSDocFunctionType(node)) {
57297
- if (isJSDocConstructSignature(node)) {
57298
- let newTypeNode;
57299
- return factory.createConstructorTypeNode(
57300
- /*modifiers*/
57301
- void 0,
57302
- visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
57303
- mapDefined(node.parameters, (p, i) => p.name && isIdentifier(p.name) && p.name.escapedText === "new" ? (newTypeNode = p.type, void 0) : factory.createParameterDeclaration(
57304
- /*modifiers*/
57305
- void 0,
57306
- getEffectiveDotDotDotForParameter(p),
57307
- setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
57308
- factory.cloneNode(p.questionToken),
57309
- visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
57310
- /*initializer*/
57311
- void 0
57312
- )),
57313
- visitNode(newTypeNode || node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
57314
- );
57315
- } else {
57316
- return factory.createFunctionTypeNode(
57317
- visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
57318
- map(node.parameters, (p, i) => factory.createParameterDeclaration(
57319
- /*modifiers*/
57320
- void 0,
57321
- getEffectiveDotDotDotForParameter(p),
57322
- setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
57323
- factory.cloneNode(p.questionToken),
57324
- visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
57325
- /*initializer*/
57326
- void 0
57327
- )),
57328
- visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
57329
- );
57330
- }
57331
- }
57332
- if (isThisTypeNode(node)) {
57333
- if (canReuseTypeNode(context, node)) {
57334
- return node;
57335
- }
57336
- hadError = true;
57337
- return node;
57338
- }
57339
- if (isTypeParameterDeclaration(node)) {
57340
- return factory.updateTypeParameterDeclaration(
57341
- node,
57342
- visitNodes2(node.modifiers, visitExistingNodeTreeSymbols, isModifier),
57343
- setTextRange2(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node),
57344
- visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode),
57345
- visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode)
57346
- );
57347
- }
57348
- if (isIndexedAccessTypeNode(node)) {
57349
- const result = tryVisitIndexedAccess(node);
57350
- if (!result) {
57351
- hadError = true;
57352
- return node;
57353
- }
57354
- return result;
57355
- }
57356
- if (isTypeReferenceNode(node)) {
57357
- const result = tryVisitTypeReference(node);
57358
- if (result) {
57359
- return result;
57360
- }
57361
- hadError = true;
57362
- return node;
57363
- }
57364
- if (isLiteralImportTypeNode(node)) {
57365
- const nodeSymbol = getNodeLinks(node).resolvedSymbol;
57366
- if (isInJSDoc(node) && nodeSymbol && // The import type resolved using jsdoc fallback logic
57367
- (!node.isTypeOf && !(nodeSymbol.flags & 788968 /* Type */) || // The import type had type arguments autofilled by js fallback logic
57368
- !(length(node.typeArguments) >= getMinTypeArgumentCount(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(nodeSymbol))))) {
57369
- return setTextRange2(context, typeToTypeNodeHelper(getTypeFromTypeNode2(context, node), context), node);
57370
- }
57371
- return factory.updateImportTypeNode(
57372
- node,
57373
- factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier2(node, node.argument.literal)),
57374
- visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes),
57375
- visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName),
57376
- visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
57377
- node.isTypeOf
57378
- );
57379
- }
57380
- if (isNamedDeclaration(node) && node.name.kind === 167 /* ComputedPropertyName */ && !isLateBindableName(node.name)) {
57381
- if (!hasDynamicName(node)) {
57382
- return visitEachChild2(node, visitExistingNodeTreeSymbols);
57383
- }
57384
- if (!(context.internalFlags & 8 /* AllowUnresolvedNames */ && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & 1 /* Any */)) {
57385
- return void 0;
57386
- }
57387
- }
57388
- if (isFunctionLike(node) && !node.type || isPropertyDeclaration(node) && !node.type && !node.initializer || isPropertySignature(node) && !node.type && !node.initializer || isParameter(node) && !node.type && !node.initializer) {
57389
- let visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
57390
- if (visited === node) {
57391
- visited = setTextRange2(context, factory.cloneNode(node), node);
57392
- }
57393
- visited.type = factory.createKeywordTypeNode(133 /* AnyKeyword */);
57394
- if (isParameter(node)) {
57395
- visited.modifiers = void 0;
57396
- }
57397
- return visited;
57398
- }
57399
- if (isTypeQueryNode(node)) {
57400
- const result = tryVisitTypeQuery(node);
57401
- if (!result) {
57402
- hadError = true;
57403
- return node;
57404
- }
57405
- return result;
57406
- }
57407
- if (isComputedPropertyName(node) && isEntityNameExpression(node.expression)) {
57408
- const { node: result, introducesError } = trackExistingEntityName(node.expression, context);
57409
- if (!introducesError) {
57410
- return factory.updateComputedPropertyName(node, result);
57411
- } else {
57412
- const type = getWidenedType(getRegularTypeOfExpression(node.expression));
57413
- const computedPropertyNameType = typeToTypeNodeHelper(type, context);
57414
- let literal;
57415
- if (isLiteralTypeNode(computedPropertyNameType)) {
57416
- literal = computedPropertyNameType.literal;
57417
- } else {
57418
- const evaluated = evaluateEntityNameExpression(node.expression);
57419
- const literalNode = typeof evaluated.value === "string" ? factory.createStringLiteral(
57420
- evaluated.value,
57421
- /*isSingleQuote*/
57422
- void 0
57423
- ) : typeof evaluated.value === "number" ? factory.createNumericLiteral(
57424
- evaluated.value,
57425
- /*numericLiteralFlags*/
57426
- 0
57427
- ) : void 0;
57428
- if (!literalNode) {
57429
- if (isImportTypeNode(computedPropertyNameType)) {
57430
- trackComputedName(node.expression, context.enclosingDeclaration, context);
57431
- }
57432
- return node;
57433
- }
57434
- literal = literalNode;
57435
- }
57436
- if (literal.kind === 11 /* StringLiteral */ && isIdentifierText(literal.text, getEmitScriptTarget(compilerOptions))) {
57437
- return factory.createIdentifier(literal.text);
57438
- }
57439
- if (literal.kind === 9 /* NumericLiteral */ && !literal.text.startsWith("-")) {
57440
- return literal;
57441
- }
57442
- return factory.updateComputedPropertyName(node, literal);
57443
- }
57444
- }
57445
- if (isTypePredicateNode(node)) {
57446
- let parameterName;
57447
- if (isIdentifier(node.parameterName)) {
57448
- const { node: result, introducesError } = trackExistingEntityName(node.parameterName, context);
57449
- hadError = hadError || introducesError;
57450
- parameterName = result;
57451
- } else {
57452
- parameterName = factory.cloneNode(node.parameterName);
57453
- }
57454
- return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
57455
- }
57456
- if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) {
57457
- const visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
57458
- const clone2 = setTextRange2(context, visited === node ? factory.cloneNode(node) : visited, node);
57459
- const flags = getEmitFlags(clone2);
57460
- setEmitFlags(clone2, flags | (context.flags & 1024 /* MultilineObjectLiterals */ && isTypeLiteralNode(node) ? 0 : 1 /* SingleLine */));
57461
- return clone2;
57462
- }
57463
- if (isStringLiteral(node) && !!(context.flags & 268435456 /* UseSingleQuotesForStringLiteralType */) && !node.singleQuote) {
57464
- const clone2 = factory.cloneNode(node);
57465
- clone2.singleQuote = true;
57466
- return clone2;
57467
- }
57468
- if (isConditionalTypeNode(node)) {
57469
- const checkType = visitNode(node.checkType, visitExistingNodeTreeSymbols, isTypeNode);
57470
- const disposeScope = onEnterNewScope(node);
57471
- const extendType = visitNode(node.extendsType, visitExistingNodeTreeSymbols, isTypeNode);
57472
- const trueType2 = visitNode(node.trueType, visitExistingNodeTreeSymbols, isTypeNode);
57473
- disposeScope();
57474
- const falseType2 = visitNode(node.falseType, visitExistingNodeTreeSymbols, isTypeNode);
57475
- return factory.updateConditionalTypeNode(
57476
- node,
57477
- checkType,
57478
- extendType,
57479
- trueType2,
57480
- falseType2
57481
- );
57482
- }
57483
- if (isTypeOperatorNode(node)) {
57484
- if (node.operator === 158 /* UniqueKeyword */ && node.type.kind === 155 /* SymbolKeyword */) {
57485
- if (!canReuseTypeNode(context, node)) {
57486
- hadError = true;
57487
- return node;
57488
- }
57489
- } else if (node.operator === 143 /* KeyOfKeyword */) {
57490
- const result = tryVisitKeyOf(node);
57491
- if (!result) {
57492
- hadError = true;
57493
- return node;
57494
- }
57495
- return result;
57496
- }
57497
- }
57498
- return visitEachChild2(node, visitExistingNodeTreeSymbols);
57499
- function visitEachChild2(node2, visitor) {
57500
- const nonlocalNode = !context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(node2);
57501
- return visitEachChild(
57502
- node2,
57503
- visitor,
57504
- /*context*/
57505
- void 0,
57506
- nonlocalNode ? visitNodesWithoutCopyingPositions : void 0
57507
- );
57508
- }
57509
- function visitNodesWithoutCopyingPositions(nodes, visitor, test, start, count) {
57510
- let result = visitNodes2(nodes, visitor, test, start, count);
57511
- if (result) {
57512
- if (result.pos !== -1 || result.end !== -1) {
57513
- if (result === nodes) {
57514
- result = factory.createNodeArray(nodes.slice(), nodes.hasTrailingComma);
57515
- }
57516
- setTextRangePosEnd(result, -1, -1);
57517
- }
57518
- }
57519
- return result;
57520
- }
57521
- function getEffectiveDotDotDotForParameter(p) {
57522
- return p.dotDotDotToken || (p.type && isJSDocVariadicType(p.type) ? factory.createToken(26 /* DotDotDotToken */) : void 0);
57523
- }
57524
- function getNameForJSDocFunctionParameter(p, index) {
57525
- return p.name && isIdentifier(p.name) && p.name.escapedText === "this" ? "this" : getEffectiveDotDotDotForParameter(p) ? `args` : `arg${index}`;
57526
- }
57527
- function rewriteModuleSpecifier2(parent2, lit) {
57528
- if (context.bundled || context.enclosingFile !== getSourceFileOfNode(lit)) {
57529
- let name = lit.text;
57530
- const nodeSymbol = getNodeLinks(node).resolvedSymbol;
57531
- const meaning = parent2.isTypeOf ? 111551 /* Value */ : 788968 /* Type */;
57532
- const parentSymbol = nodeSymbol && isSymbolAccessible(
57533
- nodeSymbol,
57534
- context.enclosingDeclaration,
57535
- meaning,
57536
- /*shouldComputeAliasesToMakeVisible*/
57537
- false
57538
- ).accessibility === 0 /* Accessible */ && lookupSymbolChain(
57539
- nodeSymbol,
57540
- context,
57541
- meaning,
57542
- /*yieldModuleSymbol*/
57543
- true
57544
- )[0];
57545
- if (parentSymbol && isExternalModuleSymbol(parentSymbol)) {
57546
- name = getSpecifierForModuleSymbol(parentSymbol, context);
57547
- } else {
57548
- const targetFile = getExternalModuleFileFromDeclaration(parent2);
57549
- if (targetFile) {
57550
- name = getSpecifierForModuleSymbol(targetFile.symbol, context);
57551
- }
57552
- }
57553
- if (name.includes("/node_modules/")) {
57554
- context.encounteredError = true;
57555
- if (context.tracker.reportLikelyUnsafeImportRequiredError) {
57556
- context.tracker.reportLikelyUnsafeImportRequiredError(name);
57557
- }
57558
- }
57559
- if (name !== lit.text) {
57560
- return setOriginalNode(factory.createStringLiteral(name), lit);
57561
- }
57562
- }
57563
- return visitNode(lit, visitExistingNodeTreeSymbols, isStringLiteral);
57252
+ if (addUndefined && !someType(type, (t) => !!(t.flags & 32768 /* Undefined */)) && canReuseTypeNode(context, typeNode)) {
57253
+ const clone2 = syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode);
57254
+ if (clone2) {
57255
+ return factory.createUnionTypeNode([clone2, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
57564
57256
  }
57565
57257
  }
57258
+ return typeToTypeNodeHelper(type, context);
57566
57259
  }
57567
57260
  function symbolTableToDeclarationStatements(symbolTable, context) {
57568
57261
  var _a;
@@ -58039,13 +57732,7 @@ function createTypeChecker(host) {
58039
57732
  context.flags |= 8388608 /* InTypeAlias */;
58040
57733
  const oldEnclosingDecl = context.enclosingDeclaration;
58041
57734
  context.enclosingDeclaration = jsdocAliasDecl;
58042
- const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) && tryReuseExistingNonParameterTypeNode(
58043
- context,
58044
- jsdocAliasDecl.typeExpression.type,
58045
- aliasType,
58046
- /*host*/
58047
- void 0
58048
- ) || typeToTypeNodeHelper(aliasType, context);
57735
+ const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) && syntacticNodeBuilder.tryReuseExistingTypeNode(context, jsdocAliasDecl.typeExpression.type) || typeToTypeNodeHelper(aliasType, context);
58049
57736
  addResult(
58050
57737
  setSyntheticLeadingComments(
58051
57738
  factory.createTypeAliasDeclaration(
@@ -58278,7 +57965,7 @@ function createTypeChecker(host) {
58278
57965
  }
58279
57966
  return cleanup(factory.createExpressionWithTypeArguments(
58280
57967
  expr,
58281
- map(e.typeArguments, (a) => tryReuseExistingNonParameterTypeNode(context, a, getTypeFromTypeNode2(context, a)) || typeToTypeNodeHelper(getTypeFromTypeNode2(context, a), context))
57968
+ map(e.typeArguments, (a) => syntacticNodeBuilder.tryReuseExistingTypeNode(context, a) || typeToTypeNodeHelper(getTypeFromTypeNode2(context, a), context))
58282
57969
  ));
58283
57970
  function cleanup(result2) {
58284
57971
  context.enclosingDeclaration = oldEnclosing;
@@ -58765,7 +58452,7 @@ function createTypeChecker(host) {
58765
58452
  }
58766
58453
  function makeSerializePropertySymbol(createProperty2, methodKind, useAccessors) {
58767
58454
  return function serializePropertySymbol(p, isStatic2, baseType) {
58768
- var _a2, _b, _c, _d, _e;
58455
+ var _a2, _b, _c, _d, _e, _f;
58769
58456
  const modifierFlags = getDeclarationModifierFlagsFromSymbol(p);
58770
58457
  const isPrivate = !!(modifierFlags & 2 /* Private */);
58771
58458
  if (isStatic2 && p.flags & (788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */)) {
@@ -58795,6 +58482,7 @@ function createTypeChecker(host) {
58795
58482
  });
58796
58483
  Debug.assert(!!setter);
58797
58484
  const paramSymbol = isFunctionLikeDeclaration(setter) ? getSignatureFromDeclaration(setter).parameters[0] : void 0;
58485
+ const setterDeclaration = (_b = p.declarations) == null ? void 0 : _b.find(isSetAccessor);
58798
58486
  result.push(setTextRange2(
58799
58487
  context,
58800
58488
  factory.createSetAccessorDeclaration(
@@ -58808,39 +58496,28 @@ function createTypeChecker(host) {
58808
58496
  paramSymbol ? parameterToParameterDeclarationName(paramSymbol, getEffectiveParameterDeclaration(paramSymbol), context) : "value",
58809
58497
  /*questionToken*/
58810
58498
  void 0,
58811
- isPrivate ? void 0 : serializeTypeForDeclaration(
58812
- context,
58813
- /*declaration*/
58814
- void 0,
58815
- getWriteTypeOfSymbol(p),
58816
- p
58817
- )
58499
+ isPrivate ? void 0 : serializeTypeForDeclaration(context, setterDeclaration, getWriteTypeOfSymbol(p), p)
58818
58500
  )],
58819
58501
  /*body*/
58820
58502
  void 0
58821
58503
  ),
58822
- ((_b = p.declarations) == null ? void 0 : _b.find(isSetAccessor)) || firstPropertyLikeDecl
58504
+ setterDeclaration ?? firstPropertyLikeDecl
58823
58505
  ));
58824
58506
  }
58825
58507
  if (p.flags & 32768 /* GetAccessor */) {
58826
58508
  const isPrivate2 = modifierFlags & 2 /* Private */;
58509
+ const getterDeclaration = (_c = p.declarations) == null ? void 0 : _c.find(isGetAccessor);
58827
58510
  result.push(setTextRange2(
58828
58511
  context,
58829
58512
  factory.createGetAccessorDeclaration(
58830
58513
  factory.createModifiersFromModifierFlags(flag),
58831
58514
  name,
58832
58515
  [],
58833
- isPrivate2 ? void 0 : serializeTypeForDeclaration(
58834
- context,
58835
- /*declaration*/
58836
- void 0,
58837
- getTypeOfSymbol(p),
58838
- p
58839
- ),
58516
+ isPrivate2 ? void 0 : serializeTypeForDeclaration(context, getterDeclaration, getTypeOfSymbol(p), p),
58840
58517
  /*body*/
58841
58518
  void 0
58842
58519
  ),
58843
- ((_c = p.declarations) == null ? void 0 : _c.find(isGetAccessor)) || firstPropertyLikeDecl
58520
+ getterDeclaration ?? firstPropertyLikeDecl
58844
58521
  ));
58845
58522
  }
58846
58523
  return result;
@@ -58851,19 +58528,13 @@ function createTypeChecker(host) {
58851
58528
  factory.createModifiersFromModifierFlags((isReadonlySymbol(p) ? 8 /* Readonly */ : 0) | flag),
58852
58529
  name,
58853
58530
  p.flags & 16777216 /* Optional */ ? factory.createToken(58 /* QuestionToken */) : void 0,
58854
- isPrivate ? void 0 : serializeTypeForDeclaration(
58855
- context,
58856
- /*declaration*/
58857
- void 0,
58858
- getWriteTypeOfSymbol(p),
58859
- p
58860
- ),
58531
+ isPrivate ? void 0 : serializeTypeForDeclaration(context, (_d = p.declarations) == null ? void 0 : _d.find(isSetAccessorDeclaration), getWriteTypeOfSymbol(p), p),
58861
58532
  // TODO: https://github.com/microsoft/TypeScript/pull/32372#discussion_r328386357
58862
58533
  // interface members can't have initializers, however class members _can_
58863
58534
  /*initializer*/
58864
58535
  void 0
58865
58536
  ),
58866
- ((_d = p.declarations) == null ? void 0 : _d.find(or(isPropertyDeclaration, isVariableDeclaration))) || firstPropertyLikeDecl
58537
+ ((_e = p.declarations) == null ? void 0 : _e.find(or(isPropertyDeclaration, isVariableDeclaration))) || firstPropertyLikeDecl
58867
58538
  );
58868
58539
  }
58869
58540
  if (p.flags & (8192 /* Method */ | 16 /* Function */)) {
@@ -58881,7 +58552,7 @@ function createTypeChecker(host) {
58881
58552
  /*initializer*/
58882
58553
  void 0
58883
58554
  ),
58884
- ((_e = p.declarations) == null ? void 0 : _e.find(isFunctionLikeDeclaration)) || signatures[0] && signatures[0].declaration || p.declarations && p.declarations[0]
58555
+ ((_f = p.declarations) == null ? void 0 : _f.find(isFunctionLikeDeclaration)) || signatures[0] && signatures[0].declaration || p.declarations && p.declarations[0]
58885
58556
  );
58886
58557
  }
58887
58558
  const results2 = [];
@@ -58924,7 +58595,7 @@ function createTypeChecker(host) {
58924
58595
  return [];
58925
58596
  }
58926
58597
  if (baseSigs.length === signatures.length) {
58927
- let failed = false;
58598
+ let failed2 = false;
58928
58599
  for (let i = 0; i < baseSigs.length; i++) {
58929
58600
  if (!compareSignaturesIdentical(
58930
58601
  signatures[i],
@@ -58937,11 +58608,11 @@ function createTypeChecker(host) {
58937
58608
  true,
58938
58609
  compareTypesIdentical
58939
58610
  )) {
58940
- failed = true;
58611
+ failed2 = true;
58941
58612
  break;
58942
58613
  }
58943
58614
  }
58944
- if (!failed) {
58615
+ if (!failed2) {
58945
58616
  return [];
58946
58617
  }
58947
58618
  }
@@ -60114,7 +59785,7 @@ function createTypeChecker(host) {
60114
59785
  /*reportErrors*/
60115
59786
  false
60116
59787
  ) : unknownType;
60117
- return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
59788
+ return addOptionality(getWidenedLiteralTypeForInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
60118
59789
  }
60119
59790
  if (isBindingPattern(element.name)) {
60120
59791
  return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors2);
@@ -80253,12 +79924,12 @@ function createTypeChecker(host) {
80253
79924
  }
80254
79925
  }
80255
79926
  return result;
80256
- function addImplementationSuccessElaboration(failed, diagnostic) {
79927
+ function addImplementationSuccessElaboration(failed2, diagnostic) {
80257
79928
  var _a, _b;
80258
79929
  const oldCandidatesForArgumentError = candidatesForArgumentError;
80259
79930
  const oldCandidateForArgumentArityError = candidateForArgumentArityError;
80260
79931
  const oldCandidateForTypeArgumentError = candidateForTypeArgumentError;
80261
- const failedSignatureDeclarations = ((_b = (_a = failed.declaration) == null ? void 0 : _a.symbol) == null ? void 0 : _b.declarations) || emptyArray;
79932
+ const failedSignatureDeclarations = ((_b = (_a = failed2.declaration) == null ? void 0 : _a.symbol) == null ? void 0 : _b.declarations) || emptyArray;
80262
79933
  const isOverload2 = failedSignatureDeclarations.length > 1;
80263
79934
  const implDecl = isOverload2 ? find(failedSignatureDeclarations, (d) => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : void 0;
80264
79935
  if (implDecl) {
@@ -84177,7 +83848,7 @@ function createTypeChecker(host) {
84177
83848
  return createTupleType(elementTypes, elementFlags, type.target.readonly);
84178
83849
  }
84179
83850
  function widenTypeInferredFromInitializer(declaration, type) {
84180
- const widened = getCombinedNodeFlagsCached(declaration) & 6 /* Constant */ || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
83851
+ const widened = getWidenedLiteralTypeForInitializer(declaration, type);
84181
83852
  if (isInJSFile(declaration)) {
84182
83853
  if (isEmptyLiteralType(widened)) {
84183
83854
  reportImplicitAny(declaration, anyType);
@@ -84189,6 +83860,9 @@ function createTypeChecker(host) {
84189
83860
  }
84190
83861
  return widened;
84191
83862
  }
83863
+ function getWidenedLiteralTypeForInitializer(declaration, type) {
83864
+ return getCombinedNodeFlagsCached(declaration) & 6 /* Constant */ || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
83865
+ }
84192
83866
  function isLiteralOfContextualType(candidateType, contextualType) {
84193
83867
  if (contextualType) {
84194
83868
  if (contextualType.flags & 3145728 /* UnionOrIntersection */) {
@@ -91577,16 +91251,12 @@ function createTypeChecker(host) {
91577
91251
  }
91578
91252
  }
91579
91253
  function createTypeOfDeclaration(declarationIn, enclosingDeclaration, flags, internalFlags, tracker) {
91580
- const declaration = getParseTreeNode(declarationIn, isVariableLikeOrAccessor);
91254
+ const declaration = getParseTreeNode(declarationIn, hasInferredType);
91581
91255
  if (!declaration) {
91582
91256
  return factory.createToken(133 /* AnyKeyword */);
91583
91257
  }
91584
91258
  const symbol = getSymbolOfDeclaration(declaration);
91585
- const type = symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) ? getWidenedLiteralType(getTypeOfSymbol(symbol)) : errorType;
91586
- return nodeBuilder.serializeTypeForDeclaration(declaration, type, symbol, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
91587
- }
91588
- function isDeclarationWithPossibleInnerTypeNodeReuse(declaration) {
91589
- return isFunctionLike(declaration) || isExportAssignment(declaration) || isVariableLike(declaration);
91259
+ return nodeBuilder.serializeTypeForDeclaration(declaration, symbol, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
91590
91260
  }
91591
91261
  function getAllAccessorDeclarationsForDeclaration(accessor) {
91592
91262
  accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration);
@@ -91603,52 +91273,19 @@ function createTypeChecker(host) {
91603
91273
  getAccessor
91604
91274
  };
91605
91275
  }
91606
- function getPossibleTypeNodeReuseExpression(declaration) {
91607
- return isFunctionLike(declaration) && !isSetAccessor(declaration) ? getSingleReturnExpression(declaration) : isExportAssignment(declaration) ? declaration.expression : !!declaration.initializer ? declaration.initializer : isParameter(declaration) && isSetAccessor(declaration.parent) ? getSingleReturnExpression(getAllAccessorDeclarationsForDeclaration(declaration.parent).getAccessor) : void 0;
91608
- }
91609
- function getSingleReturnExpression(declaration) {
91610
- let candidateExpr;
91611
- if (declaration && !nodeIsMissing(declaration.body)) {
91612
- if (getFunctionFlags(declaration) & 3 /* AsyncGenerator */) return void 0;
91613
- const body = declaration.body;
91614
- if (body && isBlock(body)) {
91615
- forEachReturnStatement(body, (s) => {
91616
- if (!candidateExpr) {
91617
- candidateExpr = s.expression;
91618
- } else {
91619
- candidateExpr = void 0;
91620
- return true;
91621
- }
91622
- });
91623
- } else {
91624
- candidateExpr = body;
91625
- }
91626
- }
91627
- return candidateExpr;
91628
- }
91629
91276
  function createReturnTypeOfSignatureDeclaration(signatureDeclarationIn, enclosingDeclaration, flags, internalFlags, tracker) {
91630
91277
  const signatureDeclaration = getParseTreeNode(signatureDeclarationIn, isFunctionLike);
91631
91278
  if (!signatureDeclaration) {
91632
91279
  return factory.createToken(133 /* AnyKeyword */);
91633
91280
  }
91634
- return nodeBuilder.serializeReturnTypeForSignature(getSignatureFromDeclaration(signatureDeclaration), enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
91281
+ return nodeBuilder.serializeReturnTypeForSignature(signatureDeclaration, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
91635
91282
  }
91636
91283
  function createTypeOfExpression(exprIn, enclosingDeclaration, flags, internalFlags, tracker) {
91637
91284
  const expr = getParseTreeNode(exprIn, isExpression);
91638
91285
  if (!expr) {
91639
91286
  return factory.createToken(133 /* AnyKeyword */);
91640
91287
  }
91641
- const type = getWidenedType(getRegularTypeOfExpression(expr));
91642
- return nodeBuilder.expressionOrTypeToTypeNode(
91643
- expr,
91644
- type,
91645
- /*addUndefined*/
91646
- void 0,
91647
- enclosingDeclaration,
91648
- flags | 1024 /* MultilineObjectLiterals */,
91649
- internalFlags,
91650
- tracker
91651
- );
91288
+ return nodeBuilder.serializeTypeForExpression(expr, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
91652
91289
  }
91653
91290
  function hasGlobalName(name) {
91654
91291
  return globals.has(escapeLeadingUnderscores(name));
@@ -91799,22 +91436,6 @@ function createTypeChecker(host) {
91799
91436
  }
91800
91437
  return void 0;
91801
91438
  }
91802
- function getNonlocalEffectiveReturnTypeAnnotationNode(node) {
91803
- const direct = getEffectiveReturnTypeNode(node);
91804
- if (direct) {
91805
- return direct;
91806
- }
91807
- if (node.kind === 177 /* GetAccessor */) {
91808
- const other = getAllAccessorDeclarationsForDeclaration(node).setAccessor;
91809
- if (other) {
91810
- const param = getSetAccessorValueParameter(other);
91811
- if (param) {
91812
- return getEffectiveTypeAnnotationNode(param);
91813
- }
91814
- }
91815
- }
91816
- return void 0;
91817
- }
91818
91439
  function createResolver() {
91819
91440
  return {
91820
91441
  getReferencedExportContainer,
@@ -93911,7 +93532,8 @@ var SymbolTrackerImpl = class _SymbolTrackerImpl {
93911
93532
  }
93912
93533
  reportInferenceFallback(node) {
93913
93534
  var _a;
93914
- if ((_a = this.inner) == null ? void 0 : _a.reportInferenceFallback) {
93535
+ if (((_a = this.inner) == null ? void 0 : _a.reportInferenceFallback) && !this.context.suppressReportInferenceFallback) {
93536
+ this.onDiagnosticReported();
93915
93537
  this.inner.reportInferenceFallback(node);
93916
93538
  }
93917
93539
  }
@@ -117163,8 +116785,8 @@ function createGetIsolatedDeclarationErrors(resolver) {
117163
116785
  [219 /* ArrowFunction */]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
117164
116786
  [174 /* MethodDeclaration */]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
117165
116787
  [180 /* ConstructSignature */]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
117166
- [177 /* GetAccessor */]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
117167
- [178 /* SetAccessor */]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
116788
+ [177 /* GetAccessor */]: Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
116789
+ [178 /* SetAccessor */]: Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
117168
116790
  [169 /* Parameter */]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
117169
116791
  [260 /* VariableDeclaration */]: Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
117170
116792
  [172 /* PropertyDeclaration */]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
@@ -117732,7 +117354,7 @@ function transformDeclarations(context) {
117732
117354
  );
117733
117355
  }
117734
117356
  }
117735
- function ensureParameter(p, modifierMask, type) {
117357
+ function ensureParameter(p, modifierMask) {
117736
117358
  let oldDiag;
117737
117359
  if (!suppressNewDiagnosticContexts) {
117738
117360
  oldDiag = getSymbolAccessibilityDiagnostic;
@@ -117746,7 +117368,6 @@ function transformDeclarations(context) {
117746
117368
  resolver.isOptionalParameter(p) ? p.questionToken || factory2.createToken(58 /* QuestionToken */) : void 0,
117747
117369
  ensureType(
117748
117370
  p,
117749
- type || p.type,
117750
117371
  /*ignorePrivate*/
117751
117372
  true
117752
117373
  ),
@@ -117771,44 +117392,34 @@ function transformDeclarations(context) {
117771
117392
  }
117772
117393
  return void 0;
117773
117394
  }
117774
- function ensureType(node, type, ignorePrivate) {
117395
+ function ensureType(node, ignorePrivate) {
117775
117396
  if (!ignorePrivate && hasEffectiveModifier(node, 2 /* Private */)) {
117776
117397
  return;
117777
117398
  }
117778
117399
  if (shouldPrintWithInitializer(node)) {
117779
117400
  return;
117780
117401
  }
117781
- const shouldAddImplicitUndefined = node.kind === 169 /* Parameter */ && resolver.requiresAddingImplicitUndefined(node, enclosingDeclaration);
117782
- if (type && !shouldAddImplicitUndefined) {
117783
- return visitNode(type, visitDeclarationSubtree, isTypeNode);
117402
+ if (!isExportAssignment(node) && !isBindingElement(node) && node.type && (!isParameter(node) || !resolver.requiresAddingImplicitUndefined(node, enclosingDeclaration))) {
117403
+ return visitNode(node.type, visitDeclarationSubtree, isTypeNode);
117784
117404
  }
117405
+ const oldErrorNameNode = errorNameNode;
117785
117406
  errorNameNode = node.name;
117786
117407
  let oldDiag;
117787
117408
  if (!suppressNewDiagnosticContexts) {
117788
117409
  oldDiag = getSymbolAccessibilityDiagnostic;
117789
- getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node);
117410
+ if (canProduceDiagnostics(node)) {
117411
+ getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node);
117412
+ }
117790
117413
  }
117791
117414
  let typeNode;
117792
- switch (node.kind) {
117793
- case 169 /* Parameter */:
117794
- case 171 /* PropertySignature */:
117795
- case 172 /* PropertyDeclaration */:
117796
- case 208 /* BindingElement */:
117797
- case 260 /* VariableDeclaration */:
117798
- typeNode = resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
117799
- break;
117800
- case 262 /* FunctionDeclaration */:
117801
- case 180 /* ConstructSignature */:
117802
- case 173 /* MethodSignature */:
117803
- case 174 /* MethodDeclaration */:
117804
- case 177 /* GetAccessor */:
117805
- case 179 /* CallSignature */:
117806
- typeNode = resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
117807
- break;
117808
- default:
117809
- Debug.assertNever(node);
117415
+ if (hasInferredType(node)) {
117416
+ typeNode = resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
117417
+ } else if (isFunctionLike(node)) {
117418
+ typeNode = resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
117419
+ } else {
117420
+ Debug.assertNever(node);
117810
117421
  }
117811
- errorNameNode = void 0;
117422
+ errorNameNode = oldErrorNameNode;
117812
117423
  if (!suppressNewDiagnosticContexts) {
117813
117424
  getSymbolAccessibilityDiagnostic = oldDiag;
117814
117425
  }
@@ -117878,13 +117489,7 @@ function transformDeclarations(context) {
117878
117489
  if (!isPrivate) {
117879
117490
  const valueParameter = getSetAccessorValueParameter(input);
117880
117491
  if (valueParameter) {
117881
- const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, getAllAccessorDeclarations(isObjectLiteralExpression(input.parent) ? input.parent.properties : input.parent.members, input));
117882
- newValueParameter = ensureParameter(
117883
- valueParameter,
117884
- /*modifierMask*/
117885
- void 0,
117886
- accessorType
117887
- );
117492
+ newValueParameter = ensureParameter(valueParameter);
117888
117493
  }
117889
117494
  }
117890
117495
  if (!newValueParameter) {
@@ -118135,7 +117740,7 @@ function transformDeclarations(context) {
118135
117740
  input,
118136
117741
  ensureTypeParams(input, input.typeParameters),
118137
117742
  updateParamsList(input, input.parameters),
118138
- ensureType(input, input.type)
117743
+ ensureType(input)
118139
117744
  ));
118140
117745
  case 176 /* Constructor */: {
118141
117746
  const ctor = factory2.createConstructorDeclaration(
@@ -118162,7 +117767,7 @@ function transformDeclarations(context) {
118162
117767
  input.questionToken,
118163
117768
  ensureTypeParams(input, input.typeParameters),
118164
117769
  updateParamsList(input, input.parameters),
118165
- ensureType(input, input.type),
117770
+ ensureType(input),
118166
117771
  /*body*/
118167
117772
  void 0
118168
117773
  );
@@ -118175,13 +117780,12 @@ function transformDeclarations(context) {
118175
117780
  void 0
118176
117781
  );
118177
117782
  }
118178
- const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, getAllAccessorDeclarations(isObjectLiteralExpression(input.parent) ? input.parent.properties : input.parent.members, input));
118179
117783
  return cleanup(factory2.updateGetAccessorDeclaration(
118180
117784
  input,
118181
117785
  ensureModifiers(input),
118182
117786
  input.name,
118183
117787
  updateAccessorParamsList(input, hasEffectiveModifier(input, 2 /* Private */)),
118184
- ensureType(input, accessorType),
117788
+ ensureType(input),
118185
117789
  /*body*/
118186
117790
  void 0
118187
117791
  ));
@@ -118214,7 +117818,7 @@ function transformDeclarations(context) {
118214
117818
  ensureModifiers(input),
118215
117819
  input.name,
118216
117820
  input.questionToken,
118217
- ensureType(input, input.type),
117821
+ ensureType(input),
118218
117822
  ensureNoInitializer(input)
118219
117823
  ));
118220
117824
  case 171 /* PropertySignature */:
@@ -118229,7 +117833,7 @@ function transformDeclarations(context) {
118229
117833
  ensureModifiers(input),
118230
117834
  input.name,
118231
117835
  input.questionToken,
118232
- ensureType(input, input.type)
117836
+ ensureType(input)
118233
117837
  ));
118234
117838
  case 173 /* MethodSignature */: {
118235
117839
  if (isPrivateIdentifier(input.name)) {
@@ -118245,7 +117849,7 @@ function transformDeclarations(context) {
118245
117849
  input.questionToken,
118246
117850
  ensureTypeParams(input, input.typeParameters),
118247
117851
  updateParamsList(input, input.parameters),
118248
- ensureType(input, input.type)
117852
+ ensureType(input)
118249
117853
  ));
118250
117854
  }
118251
117855
  case 179 /* CallSignature */: {
@@ -118254,7 +117858,7 @@ function transformDeclarations(context) {
118254
117858
  input,
118255
117859
  ensureTypeParams(input, input.typeParameters),
118256
117860
  updateParamsList(input, input.parameters),
118257
- ensureType(input, input.type)
117861
+ ensureType(input)
118258
117862
  )
118259
117863
  );
118260
117864
  }
@@ -118277,7 +117881,7 @@ function transformDeclarations(context) {
118277
117881
  input.name,
118278
117882
  /*exclamationToken*/
118279
117883
  void 0,
118280
- ensureType(input, input.type),
117884
+ ensureType(input),
118281
117885
  ensureNoInitializer(input)
118282
117886
  ));
118283
117887
  }
@@ -118401,11 +118005,12 @@ function transformDeclarations(context) {
118401
118005
  errorNode: input
118402
118006
  });
118403
118007
  errorFallbackNode = input;
118008
+ const type = ensureType(input);
118404
118009
  const varDecl = factory2.createVariableDeclaration(
118405
118010
  newId,
118406
118011
  /*exclamationToken*/
118407
118012
  void 0,
118408
- resolver.createTypeOfExpression(input.expression, input, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker),
118013
+ type,
118409
118014
  /*initializer*/
118410
118015
  void 0
118411
118016
  );
@@ -118502,7 +118107,7 @@ function transformDeclarations(context) {
118502
118107
  input.name,
118503
118108
  ensureTypeParams(input, input.typeParameters),
118504
118109
  updateParamsList(input, input.parameters),
118505
- ensureType(input, input.type),
118110
+ ensureType(input),
118506
118111
  /*body*/
118507
118112
  void 0
118508
118113
  ));
@@ -118670,7 +118275,7 @@ function transformDeclarations(context) {
118670
118275
  ensureModifiers(param),
118671
118276
  param.name,
118672
118277
  param.questionToken,
118673
- ensureType(param, param.type),
118278
+ ensureType(param),
118674
118279
  ensureNoInitializer(param)
118675
118280
  ),
118676
118281
  param
@@ -118691,11 +118296,7 @@ function transformDeclarations(context) {
118691
118296
  elem.name,
118692
118297
  /*questionOrExclamationToken*/
118693
118298
  void 0,
118694
- ensureType(
118695
- elem,
118696
- /*type*/
118697
- void 0
118698
- ),
118299
+ ensureType(elem),
118699
118300
  /*initializer*/
118700
118301
  void 0
118701
118302
  ));
@@ -118846,11 +118447,7 @@ function transformDeclarations(context) {
118846
118447
  e.name,
118847
118448
  /*exclamationToken*/
118848
118449
  void 0,
118849
- ensureType(
118850
- e,
118851
- /*type*/
118852
- void 0
118853
- ),
118450
+ ensureType(e),
118854
118451
  /*initializer*/
118855
118452
  void 0
118856
118453
  );
@@ -118900,18 +118497,6 @@ function transformDeclarations(context) {
118900
118497
  }
118901
118498
  return maskModifierFlags(node, mask2, additions);
118902
118499
  }
118903
- function getTypeAnnotationFromAllAccessorDeclarations(node, accessors) {
118904
- let accessorType = getTypeAnnotationFromAccessor(node);
118905
- if (!accessorType && node !== accessors.firstAccessor) {
118906
- accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor);
118907
- getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.firstAccessor);
118908
- }
118909
- if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) {
118910
- accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor);
118911
- getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.secondAccessor);
118912
- }
118913
- return accessorType;
118914
- }
118915
118500
  function transformHeritageClauses(nodes) {
118916
118501
  return factory2.createNodeArray(filter(
118917
118502
  map(nodes, (clause) => factory2.updateHeritageClause(
@@ -118947,11 +118532,6 @@ function maskModifierFlags(node, modifierMask = 131071 /* All */ ^ 1 /* Public *
118947
118532
  }
118948
118533
  return flags;
118949
118534
  }
118950
- function getTypeAnnotationFromAccessor(accessor) {
118951
- if (accessor) {
118952
- return accessor.kind === 177 /* GetAccessor */ ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : void 0;
118953
- }
118954
- }
118955
118535
  function canHaveLiteralInitializer(node) {
118956
118536
  switch (node.kind) {
118957
118537
  case 172 /* PropertyDeclaration */:
@@ -124985,7 +124565,7 @@ function resolveTripleslashReference(moduleName, containingFile) {
124985
124565
  }
124986
124566
  function computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, getCanonicalFileName) {
124987
124567
  let commonPathComponents;
124988
- const failed = forEach(fileNames, (sourceFile) => {
124568
+ const failed2 = forEach(fileNames, (sourceFile) => {
124989
124569
  const sourcePathComponents = getNormalizedPathComponents(sourceFile, currentDirectory);
124990
124570
  sourcePathComponents.pop();
124991
124571
  if (!commonPathComponents) {
@@ -125006,7 +124586,7 @@ function computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, ge
125006
124586
  commonPathComponents.length = sourcePathComponents.length;
125007
124587
  }
125008
124588
  });
125009
- if (failed) {
124589
+ if (failed2) {
125010
124590
  return "";
125011
124591
  }
125012
124592
  if (!commonPathComponents) {
@@ -136390,39 +135970,518 @@ function writeConfigFile(sys2, reportDiagnostic, options, fileNames) {
136390
135970
  }
136391
135971
 
136392
135972
  // src/compiler/expressionToTypeNode.ts
135973
+ function syntacticResult(type, reportFallback = true) {
135974
+ return { type, reportFallback };
135975
+ }
135976
+ var notImplemented2 = syntacticResult(
135977
+ /*type*/
135978
+ void 0,
135979
+ /*reportFallback*/
135980
+ false
135981
+ );
135982
+ var alreadyReported = syntacticResult(
135983
+ /*type*/
135984
+ void 0,
135985
+ /*reportFallback*/
135986
+ false
135987
+ );
135988
+ var failed = syntacticResult(
135989
+ /*type*/
135990
+ void 0,
135991
+ /*reportFallback*/
135992
+ true
135993
+ );
136393
135994
  function createSyntacticTypeNodeBuilder(options, resolver) {
136394
135995
  const strictNullChecks = getStrictOptionValue(options, "strictNullChecks");
136395
135996
  return {
136396
- typeFromExpression,
136397
135997
  serializeTypeOfDeclaration,
136398
135998
  serializeReturnTypeForSignature,
136399
- serializeTypeOfExpression
135999
+ serializeTypeOfExpression,
136000
+ serializeTypeOfAccessor,
136001
+ tryReuseExistingTypeNode(context, existing) {
136002
+ if (!resolver.canReuseTypeNode(context, existing)) {
136003
+ return void 0;
136004
+ }
136005
+ return tryReuseExistingTypeNode(context, existing);
136006
+ }
136400
136007
  };
136401
- function serializeExistingTypeAnnotation(type, addUndefined) {
136402
- return type !== void 0 && (!addUndefined || type && canAddUndefined(type)) ? true : void 0;
136008
+ function reuseNode(context, node, range = node) {
136009
+ return node === void 0 ? void 0 : resolver.markNodeReuse(context, node.flags & 16 /* Synthesized */ ? node : factory.cloneNode(node), range ?? node);
136010
+ }
136011
+ function tryReuseExistingTypeNode(context, existing) {
136012
+ const { finalizeBoundary, startRecoveryScope, hadError, markError } = resolver.createRecoveryBoundary(context);
136013
+ const transformed = visitNode(existing, visitExistingNodeTreeSymbols, isTypeNode);
136014
+ if (!finalizeBoundary()) {
136015
+ return void 0;
136016
+ }
136017
+ context.approximateLength += existing.end - existing.pos;
136018
+ return transformed;
136019
+ function visitExistingNodeTreeSymbols(node) {
136020
+ if (hadError()) return node;
136021
+ const recover = startRecoveryScope();
136022
+ const onExitNewScope = isNewScopeNode(node) ? resolver.enterNewScope(context, node) : void 0;
136023
+ const result = visitExistingNodeTreeSymbolsWorker(node);
136024
+ onExitNewScope == null ? void 0 : onExitNewScope();
136025
+ if (hadError()) {
136026
+ if (isTypeNode(node) && !isTypePredicateNode(node)) {
136027
+ recover();
136028
+ return resolver.serializeExistingTypeNode(context, node);
136029
+ }
136030
+ return node;
136031
+ }
136032
+ return result ? resolver.markNodeReuse(context, result, node) : void 0;
136033
+ }
136034
+ function tryVisitSimpleTypeNode(node) {
136035
+ const innerNode = skipTypeParentheses(node);
136036
+ switch (innerNode.kind) {
136037
+ case 183 /* TypeReference */:
136038
+ return tryVisitTypeReference(innerNode);
136039
+ case 186 /* TypeQuery */:
136040
+ return tryVisitTypeQuery(innerNode);
136041
+ case 199 /* IndexedAccessType */:
136042
+ return tryVisitIndexedAccess(innerNode);
136043
+ case 198 /* TypeOperator */:
136044
+ const typeOperatorNode = innerNode;
136045
+ if (typeOperatorNode.operator === 143 /* KeyOfKeyword */) {
136046
+ return tryVisitKeyOf(typeOperatorNode);
136047
+ }
136048
+ }
136049
+ return visitNode(node, visitExistingNodeTreeSymbols, isTypeNode);
136050
+ }
136051
+ function tryVisitIndexedAccess(node) {
136052
+ const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
136053
+ if (resultObjectType === void 0) {
136054
+ return void 0;
136055
+ }
136056
+ return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode));
136057
+ }
136058
+ function tryVisitKeyOf(node) {
136059
+ Debug.assertEqual(node.operator, 143 /* KeyOfKeyword */);
136060
+ const type = tryVisitSimpleTypeNode(node.type);
136061
+ if (type === void 0) {
136062
+ return void 0;
136063
+ }
136064
+ return factory.updateTypeOperatorNode(node, type);
136065
+ }
136066
+ function tryVisitTypeQuery(node) {
136067
+ const { introducesError, node: exprName } = resolver.trackExistingEntityName(context, node.exprName);
136068
+ if (!introducesError) {
136069
+ return factory.updateTypeQueryNode(
136070
+ node,
136071
+ exprName,
136072
+ visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode)
136073
+ );
136074
+ }
136075
+ const serializedName = resolver.serializeTypeName(
136076
+ context,
136077
+ node.exprName,
136078
+ /*isTypeOf*/
136079
+ true
136080
+ );
136081
+ if (serializedName) {
136082
+ return resolver.markNodeReuse(context, serializedName, node.exprName);
136083
+ }
136084
+ }
136085
+ function tryVisitTypeReference(node) {
136086
+ if (resolver.canReuseTypeNode(context, node)) {
136087
+ const { introducesError, node: newName } = resolver.trackExistingEntityName(context, node.typeName);
136088
+ const typeArguments = visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode);
136089
+ if (!introducesError) {
136090
+ const updated = factory.updateTypeReferenceNode(
136091
+ node,
136092
+ newName,
136093
+ typeArguments
136094
+ );
136095
+ return resolver.markNodeReuse(context, updated, node);
136096
+ } else {
136097
+ const serializedName = resolver.serializeTypeName(
136098
+ context,
136099
+ node.typeName,
136100
+ /*isTypeOf*/
136101
+ false,
136102
+ typeArguments
136103
+ );
136104
+ if (serializedName) {
136105
+ return resolver.markNodeReuse(context, serializedName, node.typeName);
136106
+ }
136107
+ }
136108
+ }
136109
+ }
136110
+ function visitExistingNodeTreeSymbolsWorker(node) {
136111
+ var _a;
136112
+ if (isJSDocTypeExpression(node)) {
136113
+ return visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode);
136114
+ }
136115
+ if (isJSDocAllType(node) || node.kind === 319 /* JSDocNamepathType */) {
136116
+ return factory.createKeywordTypeNode(133 /* AnyKeyword */);
136117
+ }
136118
+ if (isJSDocUnknownType(node)) {
136119
+ return factory.createKeywordTypeNode(159 /* UnknownKeyword */);
136120
+ }
136121
+ if (isJSDocNullableType(node)) {
136122
+ return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createLiteralTypeNode(factory.createNull())]);
136123
+ }
136124
+ if (isJSDocOptionalType(node)) {
136125
+ return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
136126
+ }
136127
+ if (isJSDocNonNullableType(node)) {
136128
+ return visitNode(node.type, visitExistingNodeTreeSymbols);
136129
+ }
136130
+ if (isJSDocVariadicType(node)) {
136131
+ return factory.createArrayTypeNode(visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
136132
+ }
136133
+ if (isJSDocTypeLiteral(node)) {
136134
+ return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, (t) => {
136135
+ const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier);
136136
+ const overrideTypeNode = resolver.getJsDocPropertyOverride(context, node, t);
136137
+ return factory.createPropertySignature(
136138
+ /*modifiers*/
136139
+ void 0,
136140
+ name,
136141
+ t.isBracketed || t.typeExpression && isJSDocOptionalType(t.typeExpression.type) ? factory.createToken(58 /* QuestionToken */) : void 0,
136142
+ overrideTypeNode || t.typeExpression && visitNode(t.typeExpression.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
136143
+ );
136144
+ }));
136145
+ }
136146
+ if (isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.escapedText === "") {
136147
+ return setOriginalNode(factory.createKeywordTypeNode(133 /* AnyKeyword */), node);
136148
+ }
136149
+ if ((isExpressionWithTypeArguments(node) || isTypeReferenceNode(node)) && isJSDocIndexSignature(node)) {
136150
+ return factory.createTypeLiteralNode([factory.createIndexSignature(
136151
+ /*modifiers*/
136152
+ void 0,
136153
+ [factory.createParameterDeclaration(
136154
+ /*modifiers*/
136155
+ void 0,
136156
+ /*dotDotDotToken*/
136157
+ void 0,
136158
+ "x",
136159
+ /*questionToken*/
136160
+ void 0,
136161
+ visitNode(node.typeArguments[0], visitExistingNodeTreeSymbols, isTypeNode)
136162
+ )],
136163
+ visitNode(node.typeArguments[1], visitExistingNodeTreeSymbols, isTypeNode)
136164
+ )]);
136165
+ }
136166
+ if (isJSDocFunctionType(node)) {
136167
+ if (isJSDocConstructSignature(node)) {
136168
+ let newTypeNode;
136169
+ return factory.createConstructorTypeNode(
136170
+ /*modifiers*/
136171
+ void 0,
136172
+ visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
136173
+ mapDefined(node.parameters, (p, i) => p.name && isIdentifier(p.name) && p.name.escapedText === "new" ? (newTypeNode = p.type, void 0) : factory.createParameterDeclaration(
136174
+ /*modifiers*/
136175
+ void 0,
136176
+ getEffectiveDotDotDotForParameter(p),
136177
+ resolver.markNodeReuse(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
136178
+ factory.cloneNode(p.questionToken),
136179
+ visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
136180
+ /*initializer*/
136181
+ void 0
136182
+ )),
136183
+ visitNode(newTypeNode || node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
136184
+ );
136185
+ } else {
136186
+ return factory.createFunctionTypeNode(
136187
+ visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
136188
+ map(node.parameters, (p, i) => factory.createParameterDeclaration(
136189
+ /*modifiers*/
136190
+ void 0,
136191
+ getEffectiveDotDotDotForParameter(p),
136192
+ resolver.markNodeReuse(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
136193
+ factory.cloneNode(p.questionToken),
136194
+ visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
136195
+ /*initializer*/
136196
+ void 0
136197
+ )),
136198
+ visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
136199
+ );
136200
+ }
136201
+ }
136202
+ if (isThisTypeNode(node)) {
136203
+ if (resolver.canReuseTypeNode(context, node)) {
136204
+ return node;
136205
+ }
136206
+ markError();
136207
+ return node;
136208
+ }
136209
+ if (isTypeParameterDeclaration(node)) {
136210
+ const { node: newName } = resolver.trackExistingEntityName(context, node.name);
136211
+ return factory.updateTypeParameterDeclaration(
136212
+ node,
136213
+ visitNodes2(node.modifiers, visitExistingNodeTreeSymbols, isModifier),
136214
+ // resolver.markNodeReuse(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node),
136215
+ newName,
136216
+ visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode),
136217
+ visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode)
136218
+ );
136219
+ }
136220
+ if (isIndexedAccessTypeNode(node)) {
136221
+ const result = tryVisitIndexedAccess(node);
136222
+ if (!result) {
136223
+ markError();
136224
+ return node;
136225
+ }
136226
+ return result;
136227
+ }
136228
+ if (isTypeReferenceNode(node)) {
136229
+ const result = tryVisitTypeReference(node);
136230
+ if (result) {
136231
+ return result;
136232
+ }
136233
+ markError();
136234
+ return node;
136235
+ }
136236
+ if (isLiteralImportTypeNode(node)) {
136237
+ if (((_a = node.attributes) == null ? void 0 : _a.token) === 132 /* AssertKeyword */) {
136238
+ markError();
136239
+ return node;
136240
+ }
136241
+ if (!resolver.canReuseTypeNode(context, node)) {
136242
+ return resolver.serializeExistingTypeNode(context, node);
136243
+ }
136244
+ return factory.updateImportTypeNode(
136245
+ node,
136246
+ factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier2(node, node.argument.literal)),
136247
+ visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes),
136248
+ visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName),
136249
+ visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
136250
+ node.isTypeOf
136251
+ );
136252
+ }
136253
+ if (isNamedDeclaration(node) && node.name.kind === 167 /* ComputedPropertyName */ && !resolver.hasLateBindableName(node)) {
136254
+ if (!hasDynamicName(node)) {
136255
+ return visitEachChild2(node, visitExistingNodeTreeSymbols);
136256
+ }
136257
+ if (resolver.shouldRemoveDeclaration(context, node)) {
136258
+ return void 0;
136259
+ }
136260
+ }
136261
+ if (isFunctionLike(node) && !node.type || isPropertyDeclaration(node) && !node.type && !node.initializer || isPropertySignature(node) && !node.type && !node.initializer || isParameter(node) && !node.type && !node.initializer) {
136262
+ let visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
136263
+ if (visited === node) {
136264
+ visited = resolver.markNodeReuse(context, factory.cloneNode(node), node);
136265
+ }
136266
+ visited.type = factory.createKeywordTypeNode(133 /* AnyKeyword */);
136267
+ if (isParameter(node)) {
136268
+ visited.modifiers = void 0;
136269
+ }
136270
+ return visited;
136271
+ }
136272
+ if (isTypeQueryNode(node)) {
136273
+ const result = tryVisitTypeQuery(node);
136274
+ if (!result) {
136275
+ markError();
136276
+ return node;
136277
+ }
136278
+ return result;
136279
+ }
136280
+ if (isComputedPropertyName(node) && isEntityNameExpression(node.expression)) {
136281
+ const { node: result, introducesError } = resolver.trackExistingEntityName(context, node.expression);
136282
+ if (!introducesError) {
136283
+ return factory.updateComputedPropertyName(node, result);
136284
+ } else {
136285
+ const computedPropertyNameType = resolver.serializeTypeOfExpression(context, node.expression);
136286
+ let literal;
136287
+ if (isLiteralTypeNode(computedPropertyNameType)) {
136288
+ literal = computedPropertyNameType.literal;
136289
+ } else {
136290
+ const evaluated = resolver.evaluateEntityNameExpression(node.expression);
136291
+ const literalNode = typeof evaluated.value === "string" ? factory.createStringLiteral(
136292
+ evaluated.value,
136293
+ /*isSingleQuote*/
136294
+ void 0
136295
+ ) : typeof evaluated.value === "number" ? factory.createNumericLiteral(
136296
+ evaluated.value,
136297
+ /*numericLiteralFlags*/
136298
+ 0
136299
+ ) : void 0;
136300
+ if (!literalNode) {
136301
+ if (isImportTypeNode(computedPropertyNameType)) {
136302
+ resolver.trackComputedName(context, node.expression);
136303
+ }
136304
+ return node;
136305
+ }
136306
+ literal = literalNode;
136307
+ }
136308
+ if (literal.kind === 11 /* StringLiteral */ && isIdentifierText(literal.text, getEmitScriptTarget(options))) {
136309
+ return factory.createIdentifier(literal.text);
136310
+ }
136311
+ if (literal.kind === 9 /* NumericLiteral */ && !literal.text.startsWith("-")) {
136312
+ return literal;
136313
+ }
136314
+ return factory.updateComputedPropertyName(node, literal);
136315
+ }
136316
+ }
136317
+ if (isTypePredicateNode(node)) {
136318
+ let parameterName;
136319
+ if (isIdentifier(node.parameterName)) {
136320
+ const { node: result, introducesError } = resolver.trackExistingEntityName(context, node.parameterName);
136321
+ if (introducesError) markError();
136322
+ parameterName = result;
136323
+ } else {
136324
+ parameterName = factory.cloneNode(node.parameterName);
136325
+ }
136326
+ return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
136327
+ }
136328
+ if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) {
136329
+ const visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
136330
+ const clone2 = resolver.markNodeReuse(context, visited === node ? factory.cloneNode(node) : visited, node);
136331
+ const flags = getEmitFlags(clone2);
136332
+ setEmitFlags(clone2, flags | (context.flags & 1024 /* MultilineObjectLiterals */ && isTypeLiteralNode(node) ? 0 : 1 /* SingleLine */));
136333
+ return clone2;
136334
+ }
136335
+ if (isStringLiteral(node) && !!(context.flags & 268435456 /* UseSingleQuotesForStringLiteralType */) && !node.singleQuote) {
136336
+ const clone2 = factory.cloneNode(node);
136337
+ clone2.singleQuote = true;
136338
+ return clone2;
136339
+ }
136340
+ if (isConditionalTypeNode(node)) {
136341
+ const checkType = visitNode(node.checkType, visitExistingNodeTreeSymbols, isTypeNode);
136342
+ const disposeScope = resolver.enterNewScope(context, node);
136343
+ const extendType = visitNode(node.extendsType, visitExistingNodeTreeSymbols, isTypeNode);
136344
+ const trueType = visitNode(node.trueType, visitExistingNodeTreeSymbols, isTypeNode);
136345
+ disposeScope();
136346
+ const falseType = visitNode(node.falseType, visitExistingNodeTreeSymbols, isTypeNode);
136347
+ return factory.updateConditionalTypeNode(
136348
+ node,
136349
+ checkType,
136350
+ extendType,
136351
+ trueType,
136352
+ falseType
136353
+ );
136354
+ }
136355
+ if (isTypeOperatorNode(node)) {
136356
+ if (node.operator === 158 /* UniqueKeyword */ && node.type.kind === 155 /* SymbolKeyword */) {
136357
+ if (!resolver.canReuseTypeNode(context, node)) {
136358
+ markError();
136359
+ return node;
136360
+ }
136361
+ } else if (node.operator === 143 /* KeyOfKeyword */) {
136362
+ const result = tryVisitKeyOf(node);
136363
+ if (!result) {
136364
+ markError();
136365
+ return node;
136366
+ }
136367
+ return result;
136368
+ }
136369
+ }
136370
+ return visitEachChild2(node, visitExistingNodeTreeSymbols);
136371
+ function visitEachChild2(node2, visitor) {
136372
+ const nonlocalNode = !context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(node2);
136373
+ return visitEachChild(
136374
+ node2,
136375
+ visitor,
136376
+ /*context*/
136377
+ void 0,
136378
+ nonlocalNode ? visitNodesWithoutCopyingPositions : void 0
136379
+ );
136380
+ }
136381
+ function visitNodesWithoutCopyingPositions(nodes, visitor, test, start, count) {
136382
+ let result = visitNodes2(nodes, visitor, test, start, count);
136383
+ if (result) {
136384
+ if (result.pos !== -1 || result.end !== -1) {
136385
+ if (result === nodes) {
136386
+ result = factory.createNodeArray(nodes.slice(), nodes.hasTrailingComma);
136387
+ }
136388
+ setTextRangePosEnd(result, -1, -1);
136389
+ }
136390
+ }
136391
+ return result;
136392
+ }
136393
+ function getEffectiveDotDotDotForParameter(p) {
136394
+ return p.dotDotDotToken || (p.type && isJSDocVariadicType(p.type) ? factory.createToken(26 /* DotDotDotToken */) : void 0);
136395
+ }
136396
+ function getNameForJSDocFunctionParameter(p, index) {
136397
+ return p.name && isIdentifier(p.name) && p.name.escapedText === "this" ? "this" : getEffectiveDotDotDotForParameter(p) ? `args` : `arg${index}`;
136398
+ }
136399
+ function rewriteModuleSpecifier2(parent2, lit) {
136400
+ const newName = resolver.getModuleSpecifierOverride(context, parent2, lit);
136401
+ if (newName) {
136402
+ return setOriginalNode(factory.createStringLiteral(newName), lit);
136403
+ }
136404
+ return visitNode(lit, visitExistingNodeTreeSymbols, isStringLiteral);
136405
+ }
136406
+ }
136407
+ }
136408
+ function serializeExistingTypeNode(typeNode, context, addUndefined) {
136409
+ if (!typeNode) return void 0;
136410
+ let result;
136411
+ if ((!addUndefined || canAddUndefined(typeNode)) && resolver.canReuseTypeNode(context, typeNode)) {
136412
+ result = tryReuseExistingTypeNode(context, typeNode);
136413
+ if (result !== void 0) {
136414
+ result = addUndefinedIfNeeded(
136415
+ result,
136416
+ addUndefined,
136417
+ /*owner*/
136418
+ void 0,
136419
+ context
136420
+ );
136421
+ }
136422
+ }
136423
+ return result;
136424
+ }
136425
+ function serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol, requiresAddingUndefined, useFallback = requiresAddingUndefined !== void 0) {
136426
+ if (!declaredType) return void 0;
136427
+ if (!resolver.canReuseTypeNodeAnnotation(context, node, declaredType, symbol, requiresAddingUndefined)) {
136428
+ if (!requiresAddingUndefined || !resolver.canReuseTypeNodeAnnotation(
136429
+ context,
136430
+ node,
136431
+ declaredType,
136432
+ symbol,
136433
+ /*requiresAddingUndefined*/
136434
+ false
136435
+ )) {
136436
+ return void 0;
136437
+ }
136438
+ }
136439
+ let result;
136440
+ if (!requiresAddingUndefined || canAddUndefined(declaredType)) {
136441
+ result = serializeExistingTypeNode(declaredType, context, requiresAddingUndefined);
136442
+ }
136443
+ if (result !== void 0 || !useFallback) {
136444
+ return result;
136445
+ }
136446
+ context.tracker.reportInferenceFallback(node);
136447
+ return resolver.serializeExistingTypeNode(context, declaredType, requiresAddingUndefined) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
136448
+ }
136449
+ function serializeExistingTypeNodeWithFallback(typeNode, context, addUndefined, targetNode) {
136450
+ if (!typeNode) return void 0;
136451
+ const result = serializeExistingTypeNode(typeNode, context, addUndefined);
136452
+ if (result !== void 0) {
136453
+ return result;
136454
+ }
136455
+ context.tracker.reportInferenceFallback(targetNode ?? typeNode);
136456
+ return resolver.serializeExistingTypeNode(context, typeNode, addUndefined) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
136457
+ }
136458
+ function serializeTypeOfAccessor(accessor, symbol, context) {
136459
+ return typeFromAccessor(accessor, symbol, context) ?? inferAccessorType(accessor, resolver.getAllAccessorDeclarations(accessor), context, symbol);
136403
136460
  }
136404
136461
  function serializeTypeOfExpression(expr, context, addUndefined, preserveLiterals) {
136405
- return typeFromExpression(
136462
+ const result = typeFromExpression(
136406
136463
  expr,
136407
136464
  context,
136408
136465
  /*isConstContext*/
136409
136466
  false,
136410
136467
  addUndefined,
136411
136468
  preserveLiterals
136412
- ) ?? inferExpressionType(expr, context);
136469
+ );
136470
+ return result.type !== void 0 ? result.type : inferExpressionType(expr, context, result.reportFallback);
136413
136471
  }
136414
- function serializeTypeOfDeclaration(node, context) {
136472
+ function serializeTypeOfDeclaration(node, symbol, context) {
136415
136473
  switch (node.kind) {
136416
- case 171 /* PropertySignature */:
136417
- return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node));
136418
136474
  case 169 /* Parameter */:
136419
- return typeFromParameter(node, context);
136475
+ case 341 /* JSDocParameterTag */:
136476
+ return typeFromParameter(node, symbol, context);
136420
136477
  case 260 /* VariableDeclaration */:
136421
- return typeFromVariable(node, context);
136478
+ return typeFromVariable(node, symbol, context);
136479
+ case 171 /* PropertySignature */:
136480
+ case 348 /* JSDocPropertyTag */:
136422
136481
  case 172 /* PropertyDeclaration */:
136423
- return typeFromProperty(node, context);
136482
+ return typeFromProperty(node, symbol, context);
136424
136483
  case 208 /* BindingElement */:
136425
- return inferTypeOfDeclaration(node, context);
136484
+ return inferTypeOfDeclaration(node, symbol, context);
136426
136485
  case 277 /* ExportAssignment */:
136427
136486
  return serializeTypeOfExpression(
136428
136487
  node.expression,
@@ -136435,17 +136494,39 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136435
136494
  case 211 /* PropertyAccessExpression */:
136436
136495
  case 212 /* ElementAccessExpression */:
136437
136496
  case 226 /* BinaryExpression */:
136438
- return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)) || inferTypeOfDeclaration(node, context);
136497
+ return typeFromExpandoProperty(node, symbol, context);
136439
136498
  case 303 /* PropertyAssignment */:
136440
- return typeFromExpression(node.initializer, context) || inferTypeOfDeclaration(node, context);
136499
+ case 304 /* ShorthandPropertyAssignment */:
136500
+ return typeFromPropertyAssignment(node, symbol, context);
136441
136501
  default:
136442
136502
  Debug.assertNever(node, `Node needs to be an inferrable node, found ${Debug.formatSyntaxKind(node.kind)}`);
136443
136503
  }
136444
136504
  }
136445
- function serializeReturnTypeForSignature(node, context) {
136505
+ function typeFromPropertyAssignment(node, symbol, context) {
136506
+ const typeAnnotation = getEffectiveTypeAnnotationNode(node);
136507
+ let result;
136508
+ if (typeAnnotation && resolver.canReuseTypeNodeAnnotation(context, node, typeAnnotation, symbol)) {
136509
+ result = serializeExistingTypeNode(typeAnnotation, context);
136510
+ }
136511
+ if (!result && node.kind === 303 /* PropertyAssignment */) {
136512
+ const initializer = node.initializer;
136513
+ const type = isJSDocTypeAssertion(initializer) ? getJSDocTypeAssertionType(initializer) : initializer.kind === 234 /* AsExpression */ || initializer.kind === 216 /* TypeAssertionExpression */ ? initializer.type : void 0;
136514
+ if (type && !isConstTypeReference(type)) {
136515
+ result = serializeExistingTypeNode(type, context);
136516
+ }
136517
+ }
136518
+ return result ?? inferTypeOfDeclaration(
136519
+ node,
136520
+ symbol,
136521
+ context,
136522
+ /*reportFallback*/
136523
+ false
136524
+ );
136525
+ }
136526
+ function serializeReturnTypeForSignature(node, symbol, context) {
136446
136527
  switch (node.kind) {
136447
136528
  case 177 /* GetAccessor */:
136448
- return typeFromAccessor(node, context);
136529
+ return serializeTypeOfAccessor(node, symbol, context);
136449
136530
  case 174 /* MethodDeclaration */:
136450
136531
  case 262 /* FunctionDeclaration */:
136451
136532
  case 180 /* ConstructSignature */:
@@ -136460,45 +136541,50 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136460
136541
  case 219 /* ArrowFunction */:
136461
136542
  case 317 /* JSDocFunctionType */:
136462
136543
  case 323 /* JSDocSignature */:
136463
- return createReturnFromSignature(node, context);
136544
+ return createReturnFromSignature(node, symbol, context);
136464
136545
  default:
136465
136546
  Debug.assertNever(node, `Node needs to be an inferrable node, found ${Debug.formatSyntaxKind(node.kind)}`);
136466
136547
  }
136467
136548
  }
136468
- function getTypeAnnotationFromAccessor2(accessor) {
136549
+ function getTypeAnnotationFromAccessor(accessor) {
136469
136550
  if (accessor) {
136470
- return accessor.kind === 177 /* GetAccessor */ ? getEffectiveReturnTypeNode(accessor) : accessor.parameters.length > 0 ? getEffectiveTypeAnnotationNode(accessor.parameters[0]) : void 0;
136551
+ return accessor.kind === 177 /* GetAccessor */ ? isInJSFile(accessor) && getJSDocType(accessor) || getEffectiveReturnTypeNode(accessor) : getEffectiveSetAccessorTypeAnnotationNode(accessor);
136471
136552
  }
136472
136553
  }
136473
136554
  function getTypeAnnotationFromAllAccessorDeclarations(node, accessors) {
136474
- let accessorType = getTypeAnnotationFromAccessor2(node);
136555
+ let accessorType = getTypeAnnotationFromAccessor(node);
136475
136556
  if (!accessorType && node !== accessors.firstAccessor) {
136476
- accessorType = getTypeAnnotationFromAccessor2(accessors.firstAccessor);
136557
+ accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor);
136477
136558
  }
136478
136559
  if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) {
136479
- accessorType = getTypeAnnotationFromAccessor2(accessors.secondAccessor);
136560
+ accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor);
136480
136561
  }
136481
136562
  return accessorType;
136482
136563
  }
136483
- function typeFromAccessor(node, context) {
136564
+ function typeFromAccessor(node, symbol, context) {
136484
136565
  const accessorDeclarations = resolver.getAllAccessorDeclarations(node);
136485
136566
  const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node, accessorDeclarations);
136486
- if (accessorType) {
136487
- return serializeExistingTypeAnnotation(accessorType);
136567
+ if (accessorType && !isTypePredicateNode(accessorType)) {
136568
+ return withNewScope(context, node, () => serializeTypeAnnotationOfDeclaration(accessorType, context, node, symbol) ?? inferTypeOfDeclaration(node, symbol, context));
136488
136569
  }
136489
136570
  if (accessorDeclarations.getAccessor) {
136490
- return createReturnFromSignature(accessorDeclarations.getAccessor, context);
136571
+ return withNewScope(context, accessorDeclarations.getAccessor, () => createReturnFromSignature(
136572
+ accessorDeclarations.getAccessor,
136573
+ /*symbol*/
136574
+ void 0,
136575
+ context
136576
+ ));
136491
136577
  }
136492
- return false;
136578
+ return void 0;
136493
136579
  }
136494
- function typeFromVariable(node, context) {
136580
+ function typeFromVariable(node, symbol, context) {
136581
+ var _a;
136495
136582
  const declaredType = getEffectiveTypeAnnotationNode(node);
136583
+ let resultType = failed;
136496
136584
  if (declaredType) {
136497
- return serializeExistingTypeAnnotation(declaredType);
136498
- }
136499
- let resultType;
136500
- if (node.initializer) {
136501
- if (!resolver.isExpandoFunctionDeclaration(node)) {
136585
+ resultType = syntacticResult(serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol));
136586
+ } else if (node.initializer && (((_a = symbol.declarations) == null ? void 0 : _a.length) === 1 || countWhere(symbol.declarations, isVariableDeclaration) === 1)) {
136587
+ if (!resolver.isExpandoFunctionDeclaration(node) && !isContextuallyTyped(node)) {
136502
136588
  resultType = typeFromExpression(
136503
136589
  node.initializer,
136504
136590
  context,
@@ -136510,71 +136596,119 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136510
136596
  );
136511
136597
  }
136512
136598
  }
136513
- return resultType ?? inferTypeOfDeclaration(node, context);
136599
+ return resultType.type !== void 0 ? resultType.type : inferTypeOfDeclaration(node, symbol, context, resultType.reportFallback);
136514
136600
  }
136515
- function typeFromParameter(node, context) {
136601
+ function typeFromParameter(node, symbol, context) {
136516
136602
  const parent2 = node.parent;
136517
136603
  if (parent2.kind === 178 /* SetAccessor */) {
136518
- return typeFromAccessor(parent2, context);
136604
+ return serializeTypeOfAccessor(
136605
+ parent2,
136606
+ /*symbol*/
136607
+ void 0,
136608
+ context
136609
+ );
136610
+ }
136611
+ const declaredType = getEffectiveTypeAnnotationNode(node);
136612
+ const addUndefined = resolver.requiresAddingImplicitUndefined(node, symbol, context.enclosingDeclaration);
136613
+ let resultType = failed;
136614
+ if (declaredType) {
136615
+ resultType = syntacticResult(serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol, addUndefined));
136616
+ } else if (isParameter(node) && node.initializer && isIdentifier(node.name) && !isContextuallyTyped(node)) {
136617
+ resultType = typeFromExpression(
136618
+ node.initializer,
136619
+ context,
136620
+ /*isConstContext*/
136621
+ void 0,
136622
+ addUndefined
136623
+ );
136519
136624
  }
136625
+ return resultType.type !== void 0 ? resultType.type : inferTypeOfDeclaration(node, symbol, context, resultType.reportFallback);
136626
+ }
136627
+ function typeFromExpandoProperty(node, symbol, context) {
136628
+ const declaredType = getEffectiveTypeAnnotationNode(node);
136629
+ let result;
136630
+ if (declaredType) {
136631
+ result = serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol);
136632
+ }
136633
+ const oldSuppressReportInferenceFallback = context.suppressReportInferenceFallback;
136634
+ context.suppressReportInferenceFallback = true;
136635
+ const resultType = result ?? inferTypeOfDeclaration(
136636
+ node,
136637
+ symbol,
136638
+ context,
136639
+ /*reportFallback*/
136640
+ false
136641
+ );
136642
+ context.suppressReportInferenceFallback = oldSuppressReportInferenceFallback;
136643
+ return resultType;
136644
+ }
136645
+ function typeFromProperty(node, symbol, context) {
136520
136646
  const declaredType = getEffectiveTypeAnnotationNode(node);
136521
- const addUndefined = resolver.requiresAddingImplicitUndefined(node, context.enclosingDeclaration);
136522
- let resultType;
136647
+ const requiresAddingUndefined = resolver.requiresAddingImplicitUndefined(node, symbol, context.enclosingDeclaration);
136648
+ let resultType = failed;
136523
136649
  if (declaredType) {
136524
- resultType = serializeExistingTypeAnnotation(declaredType, addUndefined);
136650
+ resultType = syntacticResult(serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol, requiresAddingUndefined));
136525
136651
  } else {
136526
- if (node.initializer && isIdentifier(node.name)) {
136652
+ const initializer = isPropertyDeclaration(node) ? node.initializer : void 0;
136653
+ if (initializer && !isContextuallyTyped(node)) {
136654
+ const isReadonly = isDeclarationReadonly(node);
136527
136655
  resultType = typeFromExpression(
136528
- node.initializer,
136656
+ initializer,
136529
136657
  context,
136530
136658
  /*isConstContext*/
136531
136659
  void 0,
136532
- addUndefined
136660
+ requiresAddingUndefined,
136661
+ isReadonly
136533
136662
  );
136534
136663
  }
136535
136664
  }
136536
- return resultType ?? inferTypeOfDeclaration(node, context);
136665
+ return resultType.type !== void 0 ? resultType.type : inferTypeOfDeclaration(node, symbol, context, resultType.reportFallback);
136537
136666
  }
136538
- function typeFromProperty(node, context) {
136539
- const declaredType = getEffectiveTypeAnnotationNode(node);
136540
- if (declaredType) {
136541
- return serializeExistingTypeAnnotation(declaredType);
136667
+ function inferTypeOfDeclaration(node, symbol, context, reportFallback = true) {
136668
+ if (reportFallback) {
136669
+ context.tracker.reportInferenceFallback(node);
136542
136670
  }
136543
- let resultType;
136544
- if (node.initializer) {
136545
- const isReadonly = isDeclarationReadonly(node);
136546
- resultType = typeFromExpression(
136547
- node.initializer,
136548
- context,
136549
- /*isConstContext*/
136550
- void 0,
136551
- /*requiresAddingUndefined*/
136552
- void 0,
136553
- isReadonly
136554
- );
136671
+ if (context.noInferenceFallback === true) {
136672
+ return factory.createKeywordTypeNode(133 /* AnyKeyword */);
136555
136673
  }
136556
- return resultType ?? inferTypeOfDeclaration(node, context);
136674
+ return resolver.serializeTypeOfDeclaration(context, node, symbol);
136557
136675
  }
136558
- function inferTypeOfDeclaration(node, context) {
136559
- context.tracker.reportInferenceFallback(node);
136560
- return false;
136561
- }
136562
- function inferExpressionType(node, context) {
136563
- context.tracker.reportInferenceFallback(node);
136564
- return false;
136676
+ function inferExpressionType(node, context, reportFallback = true, requiresAddingUndefined) {
136677
+ Debug.assert(!requiresAddingUndefined);
136678
+ if (reportFallback) {
136679
+ context.tracker.reportInferenceFallback(node);
136680
+ }
136681
+ if (context.noInferenceFallback === true) {
136682
+ return factory.createKeywordTypeNode(133 /* AnyKeyword */);
136683
+ }
136684
+ return resolver.serializeTypeOfExpression(context, node) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
136565
136685
  }
136566
- function inferReturnTypeOfSignatureSignature(node, context) {
136567
- context.tracker.reportInferenceFallback(node);
136568
- return false;
136686
+ function inferReturnTypeOfSignatureSignature(node, context, reportFallback) {
136687
+ if (reportFallback) {
136688
+ context.tracker.reportInferenceFallback(node);
136689
+ }
136690
+ if (context.noInferenceFallback === true) {
136691
+ return factory.createKeywordTypeNode(133 /* AnyKeyword */);
136692
+ }
136693
+ return resolver.serializeReturnTypeForSignature(context, node) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
136569
136694
  }
136570
- function inferAccessorType(node, allAccessors, context) {
136695
+ function inferAccessorType(node, allAccessors, context, symbol, reportFallback = true) {
136571
136696
  if (node.kind === 177 /* GetAccessor */) {
136572
- return createReturnFromSignature(node, context);
136697
+ return createReturnFromSignature(node, symbol, context, reportFallback);
136573
136698
  } else {
136574
- context.tracker.reportInferenceFallback(node);
136575
- return false;
136699
+ if (reportFallback) {
136700
+ context.tracker.reportInferenceFallback(node);
136701
+ }
136702
+ const result = allAccessors.getAccessor && createReturnFromSignature(allAccessors.getAccessor, symbol, context, reportFallback);
136703
+ return result ?? resolver.serializeTypeOfDeclaration(context, node, symbol) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
136576
136704
  }
136577
136705
  }
136706
+ function withNewScope(context, node, fn) {
136707
+ const cleanup = resolver.enterNewScope(context, node);
136708
+ const result = fn();
136709
+ cleanup();
136710
+ return result;
136711
+ }
136578
136712
  function typeFromTypeAssertion(expression, type, context, requiresAddingUndefined) {
136579
136713
  if (isConstTypeReference(type)) {
136580
136714
  return typeFromExpression(
@@ -136585,10 +136719,7 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136585
136719
  requiresAddingUndefined
136586
136720
  );
136587
136721
  }
136588
- if (requiresAddingUndefined && !canAddUndefined(type)) {
136589
- context.tracker.reportInferenceFallback(type);
136590
- }
136591
- return serializeExistingTypeAnnotation(type);
136722
+ return syntacticResult(serializeExistingTypeNodeWithFallback(type, context, requiresAddingUndefined));
136592
136723
  }
136593
136724
  function typeFromExpression(node, context, isConstContext = false, requiresAddingUndefined = false, preserveLiterals = false) {
136594
136725
  switch (node.kind) {
@@ -136599,14 +136730,19 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136599
136730
  return typeFromExpression(node.expression, context, isConstContext, requiresAddingUndefined);
136600
136731
  case 80 /* Identifier */:
136601
136732
  if (resolver.isUndefinedIdentifierExpression(node)) {
136602
- return true;
136733
+ return syntacticResult(createUndefinedTypeNode());
136603
136734
  }
136604
136735
  break;
136605
136736
  case 106 /* NullKeyword */:
136606
- return true;
136737
+ if (strictNullChecks) {
136738
+ return syntacticResult(addUndefinedIfNeeded(factory.createLiteralTypeNode(factory.createNull()), requiresAddingUndefined, node, context));
136739
+ } else {
136740
+ return syntacticResult(factory.createKeywordTypeNode(133 /* AnyKeyword */));
136741
+ }
136607
136742
  case 219 /* ArrowFunction */:
136608
136743
  case 218 /* FunctionExpression */:
136609
- return typeFromFunctionLikeExpression(node, context);
136744
+ Debug.type(node);
136745
+ return withNewScope(context, node, () => typeFromFunctionLikeExpression(node, context));
136610
136746
  case 216 /* TypeAssertionExpression */:
136611
136747
  case 234 /* AsExpression */:
136612
136748
  const asExpression = node;
@@ -136614,43 +136750,73 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136614
136750
  case 224 /* PrefixUnaryExpression */:
136615
136751
  const unaryExpression = node;
136616
136752
  if (isPrimitiveLiteralValue(unaryExpression)) {
136617
- if (unaryExpression.operand.kind === 10 /* BigIntLiteral */) {
136618
- return typeFromPrimitiveLiteral();
136619
- }
136620
- if (unaryExpression.operand.kind === 9 /* NumericLiteral */) {
136621
- return typeFromPrimitiveLiteral();
136622
- }
136753
+ return typeFromPrimitiveLiteral(
136754
+ unaryExpression.operator === 40 /* PlusToken */ ? unaryExpression.operand : unaryExpression,
136755
+ unaryExpression.operand.kind === 10 /* BigIntLiteral */ ? 163 /* BigIntKeyword */ : 150 /* NumberKeyword */,
136756
+ context,
136757
+ isConstContext || preserveLiterals,
136758
+ requiresAddingUndefined
136759
+ );
136623
136760
  }
136624
136761
  break;
136625
- case 9 /* NumericLiteral */:
136626
- return typeFromPrimitiveLiteral();
136762
+ case 209 /* ArrayLiteralExpression */:
136763
+ return typeFromArrayLiteral(node, context, isConstContext, requiresAddingUndefined);
136764
+ case 210 /* ObjectLiteralExpression */:
136765
+ return typeFromObjectLiteral(node, context, isConstContext, requiresAddingUndefined);
136766
+ case 231 /* ClassExpression */:
136767
+ return syntacticResult(inferExpressionType(
136768
+ node,
136769
+ context,
136770
+ /*reportFallback*/
136771
+ true,
136772
+ requiresAddingUndefined
136773
+ ));
136627
136774
  case 228 /* TemplateExpression */:
136628
136775
  if (!isConstContext && !preserveLiterals) {
136629
- return true;
136776
+ return syntacticResult(factory.createKeywordTypeNode(154 /* StringKeyword */));
136630
136777
  }
136631
136778
  break;
136632
- case 15 /* NoSubstitutionTemplateLiteral */:
136633
- case 11 /* StringLiteral */:
136634
- return typeFromPrimitiveLiteral();
136635
- case 10 /* BigIntLiteral */:
136636
- return typeFromPrimitiveLiteral();
136637
- case 112 /* TrueKeyword */:
136638
- case 97 /* FalseKeyword */:
136639
- return typeFromPrimitiveLiteral();
136640
- case 209 /* ArrayLiteralExpression */:
136641
- return typeFromArrayLiteral(node, context, isConstContext);
136642
- case 210 /* ObjectLiteralExpression */:
136643
- return typeFromObjectLiteral(node, context, isConstContext);
136644
- case 231 /* ClassExpression */:
136645
- return inferExpressionType(node, context);
136779
+ default:
136780
+ let typeKind;
136781
+ let primitiveNode = node;
136782
+ switch (node.kind) {
136783
+ case 9 /* NumericLiteral */:
136784
+ typeKind = 150 /* NumberKeyword */;
136785
+ break;
136786
+ case 15 /* NoSubstitutionTemplateLiteral */:
136787
+ primitiveNode = factory.createStringLiteral(node.text);
136788
+ typeKind = 154 /* StringKeyword */;
136789
+ break;
136790
+ case 11 /* StringLiteral */:
136791
+ typeKind = 154 /* StringKeyword */;
136792
+ break;
136793
+ case 10 /* BigIntLiteral */:
136794
+ typeKind = 163 /* BigIntKeyword */;
136795
+ break;
136796
+ case 112 /* TrueKeyword */:
136797
+ case 97 /* FalseKeyword */:
136798
+ typeKind = 136 /* BooleanKeyword */;
136799
+ break;
136800
+ }
136801
+ if (typeKind) {
136802
+ return typeFromPrimitiveLiteral(primitiveNode, typeKind, context, isConstContext || preserveLiterals, requiresAddingUndefined);
136803
+ }
136646
136804
  }
136647
- return void 0;
136805
+ return failed;
136648
136806
  }
136649
136807
  function typeFromFunctionLikeExpression(fnNode, context) {
136650
- const returnType = serializeExistingTypeAnnotation(fnNode.type) ?? createReturnFromSignature(fnNode, context);
136651
- const typeParameters = reuseTypeParameters(fnNode.typeParameters);
136652
- const parameters = fnNode.parameters.every((p) => ensureParameter(p, context));
136653
- return returnType && typeParameters && parameters;
136808
+ const oldNoInferenceFallback = context.noInferenceFallback;
136809
+ context.noInferenceFallback = true;
136810
+ createReturnFromSignature(
136811
+ fnNode,
136812
+ /*symbol*/
136813
+ void 0,
136814
+ context
136815
+ );
136816
+ reuseTypeParameters(fnNode.typeParameters, context);
136817
+ fnNode.parameters.map((p) => ensureParameter(p, context));
136818
+ context.noInferenceFallback = oldNoInferenceFallback;
136819
+ return notImplemented2;
136654
136820
  }
136655
136821
  function canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext) {
136656
136822
  if (!isConstContext) {
@@ -136665,18 +136831,38 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136665
136831
  }
136666
136832
  return true;
136667
136833
  }
136668
- function typeFromArrayLiteral(arrayLiteral, context, isConstContext) {
136834
+ function typeFromArrayLiteral(arrayLiteral, context, isConstContext, requiresAddingUndefined) {
136669
136835
  if (!canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext)) {
136670
- return false;
136836
+ if (requiresAddingUndefined || isDeclaration(walkUpParenthesizedExpressions(arrayLiteral).parent)) {
136837
+ return alreadyReported;
136838
+ }
136839
+ return syntacticResult(inferExpressionType(
136840
+ arrayLiteral,
136841
+ context,
136842
+ /*reportFallback*/
136843
+ false,
136844
+ requiresAddingUndefined
136845
+ ));
136671
136846
  }
136672
- let canInferArray = true;
136847
+ const oldNoInferenceFallback = context.noInferenceFallback;
136848
+ context.noInferenceFallback = true;
136849
+ const elementTypesInfo = [];
136673
136850
  for (const element of arrayLiteral.elements) {
136674
136851
  Debug.assert(element.kind !== 230 /* SpreadElement */);
136675
- if (element.kind !== 232 /* OmittedExpression */) {
136676
- canInferArray = (typeFromExpression(element, context, isConstContext) ?? inferExpressionType(element, context)) && canInferArray;
136852
+ if (element.kind === 232 /* OmittedExpression */) {
136853
+ elementTypesInfo.push(
136854
+ createUndefinedTypeNode()
136855
+ );
136856
+ } else {
136857
+ const expressionType = typeFromExpression(element, context, isConstContext);
136858
+ const elementType = expressionType.type !== void 0 ? expressionType.type : inferExpressionType(element, context, expressionType.reportFallback);
136859
+ elementTypesInfo.push(elementType);
136677
136860
  }
136678
136861
  }
136679
- return true;
136862
+ const tupleType = factory.createTupleTypeNode(elementTypesInfo);
136863
+ tupleType.emitNode = { flags: 1, autoGenerate: void 0, internalFlags: 0 };
136864
+ context.noInferenceFallback = oldNoInferenceFallback;
136865
+ return notImplemented2;
136680
136866
  }
136681
136867
  function canGetTypeFromObjectLiteral(objectLiteral, context) {
136682
136868
  let result = true;
@@ -136707,64 +136893,214 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136707
136893
  }
136708
136894
  return result;
136709
136895
  }
136710
- function typeFromObjectLiteral(objectLiteral, context, isConstContext) {
136711
- if (!canGetTypeFromObjectLiteral(objectLiteral, context)) return false;
136712
- let canInferObjectLiteral = true;
136896
+ function typeFromObjectLiteral(objectLiteral, context, isConstContext, requiresAddingUndefined) {
136897
+ if (!canGetTypeFromObjectLiteral(objectLiteral, context)) {
136898
+ if (requiresAddingUndefined || isDeclaration(walkUpParenthesizedExpressions(objectLiteral).parent)) {
136899
+ return alreadyReported;
136900
+ }
136901
+ return syntacticResult(inferExpressionType(
136902
+ objectLiteral,
136903
+ context,
136904
+ /*reportFallback*/
136905
+ false,
136906
+ requiresAddingUndefined
136907
+ ));
136908
+ }
136909
+ const oldNoInferenceFallback = context.noInferenceFallback;
136910
+ context.noInferenceFallback = true;
136911
+ const properties = [];
136912
+ const oldFlags = context.flags;
136913
+ context.flags |= 4194304 /* InObjectTypeLiteral */;
136713
136914
  for (const prop of objectLiteral.properties) {
136714
136915
  Debug.assert(!isShorthandPropertyAssignment(prop) && !isSpreadAssignment(prop));
136715
136916
  const name = prop.name;
136917
+ let newProp;
136716
136918
  switch (prop.kind) {
136717
136919
  case 174 /* MethodDeclaration */:
136718
- canInferObjectLiteral = !!typeFromObjectLiteralMethod(prop, name, context) && canInferObjectLiteral;
136920
+ newProp = withNewScope(context, prop, () => typeFromObjectLiteralMethod(prop, name, context, isConstContext));
136719
136921
  break;
136720
136922
  case 303 /* PropertyAssignment */:
136721
- canInferObjectLiteral = !!typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext) && canInferObjectLiteral;
136923
+ newProp = typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext);
136722
136924
  break;
136723
136925
  case 178 /* SetAccessor */:
136724
136926
  case 177 /* GetAccessor */:
136725
- canInferObjectLiteral = !!typeFromObjectLiteralAccessor(prop, name, context) && canInferObjectLiteral;
136927
+ newProp = typeFromObjectLiteralAccessor(prop, name, context);
136726
136928
  break;
136727
136929
  }
136930
+ if (newProp) {
136931
+ setCommentRange(newProp, prop);
136932
+ properties.push(newProp);
136933
+ }
136934
+ }
136935
+ context.flags = oldFlags;
136936
+ const typeNode = factory.createTypeLiteralNode(properties);
136937
+ if (!(context.flags & 1024 /* MultilineObjectLiterals */)) {
136938
+ setEmitFlags(typeNode, 1 /* SingleLine */);
136728
136939
  }
136729
- return canInferObjectLiteral;
136940
+ context.noInferenceFallback = oldNoInferenceFallback;
136941
+ return notImplemented2;
136730
136942
  }
136731
136943
  function typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext) {
136732
- return typeFromExpression(prop.initializer, context, isConstContext) ?? inferTypeOfDeclaration(prop, context);
136944
+ const modifiers = isConstContext ? [factory.createModifier(148 /* ReadonlyKeyword */)] : [];
136945
+ const expressionResult = typeFromExpression(prop.initializer, context, isConstContext);
136946
+ const typeNode = expressionResult.type !== void 0 ? expressionResult.type : inferTypeOfDeclaration(
136947
+ prop,
136948
+ /*symbol*/
136949
+ void 0,
136950
+ context,
136951
+ expressionResult.reportFallback
136952
+ );
136953
+ return factory.createPropertySignature(
136954
+ modifiers,
136955
+ reuseNode(context, name),
136956
+ /*questionToken*/
136957
+ void 0,
136958
+ typeNode
136959
+ );
136733
136960
  }
136734
136961
  function ensureParameter(p, context) {
136735
- return typeFromParameter(p, context);
136962
+ return factory.updateParameterDeclaration(
136963
+ p,
136964
+ [],
136965
+ reuseNode(context, p.dotDotDotToken),
136966
+ resolver.serializeNameOfParameter(context, p),
136967
+ resolver.isOptionalParameter(p) ? factory.createToken(58 /* QuestionToken */) : void 0,
136968
+ typeFromParameter(
136969
+ p,
136970
+ /*symbol*/
136971
+ void 0,
136972
+ context
136973
+ ),
136974
+ // Ignore private param props, since this type is going straight back into a param
136975
+ /*initializer*/
136976
+ void 0
136977
+ );
136736
136978
  }
136737
- function reuseTypeParameters(typeParameters) {
136738
- return (typeParameters == null ? void 0 : typeParameters.every(
136739
- (tp) => serializeExistingTypeAnnotation(tp.constraint) && serializeExistingTypeAnnotation(tp.default)
136740
- )) ?? true;
136979
+ function reuseTypeParameters(typeParameters, context) {
136980
+ return typeParameters == null ? void 0 : typeParameters.map(
136981
+ (tp) => {
136982
+ var _a;
136983
+ return factory.updateTypeParameterDeclaration(
136984
+ tp,
136985
+ (_a = tp.modifiers) == null ? void 0 : _a.map((m) => reuseNode(context, m)),
136986
+ reuseNode(context, tp.name),
136987
+ serializeExistingTypeNodeWithFallback(tp.constraint, context),
136988
+ serializeExistingTypeNodeWithFallback(tp.default, context)
136989
+ );
136990
+ }
136991
+ );
136741
136992
  }
136742
- function typeFromObjectLiteralMethod(method, name, context) {
136743
- const returnType = createReturnFromSignature(method, context);
136744
- const typeParameters = reuseTypeParameters(method.typeParameters);
136745
- const parameters = method.parameters.every((p) => ensureParameter(p, context));
136746
- return returnType && typeParameters && parameters;
136993
+ function typeFromObjectLiteralMethod(method, name, context, isConstContext) {
136994
+ const returnType = createReturnFromSignature(
136995
+ method,
136996
+ /*symbol*/
136997
+ void 0,
136998
+ context
136999
+ );
137000
+ const typeParameters = reuseTypeParameters(method.typeParameters, context);
137001
+ const parameters = method.parameters.map((p) => ensureParameter(p, context));
137002
+ if (isConstContext) {
137003
+ return factory.createPropertySignature(
137004
+ [factory.createModifier(148 /* ReadonlyKeyword */)],
137005
+ reuseNode(context, name),
137006
+ reuseNode(context, method.questionToken),
137007
+ factory.createFunctionTypeNode(
137008
+ typeParameters,
137009
+ parameters,
137010
+ returnType
137011
+ )
137012
+ );
137013
+ } else {
137014
+ if (isIdentifier(name) && name.escapedText === "new") {
137015
+ name = factory.createStringLiteral("new");
137016
+ }
137017
+ return factory.createMethodSignature(
137018
+ [],
137019
+ reuseNode(context, name),
137020
+ reuseNode(context, method.questionToken),
137021
+ typeParameters,
137022
+ parameters,
137023
+ returnType
137024
+ );
137025
+ }
136747
137026
  }
136748
137027
  function typeFromObjectLiteralAccessor(accessor, name, context) {
136749
137028
  const allAccessors = resolver.getAllAccessorDeclarations(accessor);
136750
- const getAccessorType = allAccessors.getAccessor && getTypeAnnotationFromAccessor2(allAccessors.getAccessor);
136751
- const setAccessorType = allAccessors.setAccessor && getTypeAnnotationFromAccessor2(allAccessors.setAccessor);
137029
+ const getAccessorType = allAccessors.getAccessor && getTypeAnnotationFromAccessor(allAccessors.getAccessor);
137030
+ const setAccessorType = allAccessors.setAccessor && getTypeAnnotationFromAccessor(allAccessors.setAccessor);
136752
137031
  if (getAccessorType !== void 0 && setAccessorType !== void 0) {
136753
- const parameters = accessor.parameters.every((p) => ensureParameter(p, context));
136754
- if (isGetAccessor(accessor)) {
136755
- return parameters && serializeExistingTypeAnnotation(getAccessorType);
136756
- } else {
136757
- return parameters;
136758
- }
137032
+ return withNewScope(context, accessor, () => {
137033
+ const parameters = accessor.parameters.map((p) => ensureParameter(p, context));
137034
+ if (isGetAccessor(accessor)) {
137035
+ return factory.updateGetAccessorDeclaration(
137036
+ accessor,
137037
+ [],
137038
+ reuseNode(context, name),
137039
+ parameters,
137040
+ serializeExistingTypeNodeWithFallback(getAccessorType, context),
137041
+ /*body*/
137042
+ void 0
137043
+ );
137044
+ } else {
137045
+ return factory.updateSetAccessorDeclaration(
137046
+ accessor,
137047
+ [],
137048
+ reuseNode(context, name),
137049
+ parameters,
137050
+ /*body*/
137051
+ void 0
137052
+ );
137053
+ }
137054
+ });
136759
137055
  } else if (allAccessors.firstAccessor === accessor) {
136760
- const foundType = getAccessorType ?? setAccessorType;
136761
- const propertyType = foundType ? serializeExistingTypeAnnotation(foundType) : inferAccessorType(accessor, allAccessors, context);
136762
- return propertyType;
137056
+ const foundType = getAccessorType ? withNewScope(context, allAccessors.getAccessor, () => serializeExistingTypeNodeWithFallback(getAccessorType, context)) : setAccessorType ? withNewScope(context, allAccessors.setAccessor, () => serializeExistingTypeNodeWithFallback(setAccessorType, context)) : void 0;
137057
+ const propertyType = foundType ?? inferAccessorType(
137058
+ accessor,
137059
+ allAccessors,
137060
+ context,
137061
+ /*symbol*/
137062
+ void 0
137063
+ );
137064
+ const propertySignature = factory.createPropertySignature(
137065
+ allAccessors.setAccessor === void 0 ? [factory.createModifier(148 /* ReadonlyKeyword */)] : [],
137066
+ reuseNode(context, name),
137067
+ /*questionToken*/
137068
+ void 0,
137069
+ propertyType
137070
+ );
137071
+ return propertySignature;
136763
137072
  }
136764
- return false;
136765
137073
  }
136766
- function typeFromPrimitiveLiteral() {
136767
- return true;
137074
+ function createUndefinedTypeNode() {
137075
+ if (strictNullChecks) {
137076
+ return factory.createKeywordTypeNode(157 /* UndefinedKeyword */);
137077
+ } else {
137078
+ return factory.createKeywordTypeNode(133 /* AnyKeyword */);
137079
+ }
137080
+ }
137081
+ function typeFromPrimitiveLiteral(node, baseType, context, preserveLiterals, requiresAddingUndefined) {
137082
+ let result;
137083
+ if (preserveLiterals) {
137084
+ if (node.kind === 224 /* PrefixUnaryExpression */ && node.operator === 40 /* PlusToken */) {
137085
+ result = factory.createLiteralTypeNode(reuseNode(context, node.operand));
137086
+ }
137087
+ result = factory.createLiteralTypeNode(reuseNode(context, node));
137088
+ } else {
137089
+ result = factory.createKeywordTypeNode(baseType);
137090
+ }
137091
+ return syntacticResult(addUndefinedIfNeeded(result, requiresAddingUndefined, node, context));
137092
+ }
137093
+ function addUndefinedIfNeeded(node, addUndefined, owner, context) {
137094
+ const parentDeclaration = owner && walkUpParenthesizedExpressions(owner).parent;
137095
+ const optionalDeclaration = parentDeclaration && isDeclaration(parentDeclaration) && isOptionalDeclaration(parentDeclaration);
137096
+ if (!strictNullChecks || !(addUndefined || optionalDeclaration)) return node;
137097
+ if (!canAddUndefined(node)) {
137098
+ context.tracker.reportInferenceFallback(node);
137099
+ }
137100
+ if (isUnionTypeNode(node)) {
137101
+ return factory.createUnionTypeNode([...node.types, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
137102
+ }
137103
+ return factory.createUnionTypeNode([node, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
136768
137104
  }
136769
137105
  function canAddUndefined(node) {
136770
137106
  if (!strictNullChecks) return true;
@@ -136779,24 +137115,28 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136779
137115
  }
136780
137116
  return false;
136781
137117
  }
136782
- function createReturnFromSignature(fn, context) {
136783
- let returnType;
136784
- const returnTypeNode = getEffectiveReturnTypeNode(fn);
137118
+ function createReturnFromSignature(fn, symbol, context, reportFallback = true) {
137119
+ let returnType = failed;
137120
+ const returnTypeNode = isJSDocConstructSignature(fn) ? getEffectiveTypeAnnotationNode(fn.parameters[0]) : getEffectiveReturnTypeNode(fn);
136785
137121
  if (returnTypeNode) {
136786
- returnType = serializeExistingTypeAnnotation(returnTypeNode);
136787
- }
136788
- if (!returnType && isValueSignatureDeclaration(fn)) {
137122
+ returnType = syntacticResult(serializeTypeAnnotationOfDeclaration(returnTypeNode, context, fn, symbol));
137123
+ } else if (isValueSignatureDeclaration(fn)) {
136789
137124
  returnType = typeFromSingleReturnExpression(fn, context);
136790
137125
  }
136791
- return returnType ?? inferReturnTypeOfSignatureSignature(fn, context);
137126
+ return returnType.type !== void 0 ? returnType.type : inferReturnTypeOfSignatureSignature(fn, context, reportFallback && returnType.reportFallback && !returnTypeNode);
136792
137127
  }
136793
137128
  function typeFromSingleReturnExpression(declaration, context) {
136794
137129
  let candidateExpr;
136795
137130
  if (declaration && !nodeIsMissing(declaration.body)) {
136796
- if (getFunctionFlags(declaration) & 3 /* AsyncGenerator */) return void 0;
137131
+ const flags = getFunctionFlags(declaration);
137132
+ if (flags & 3 /* AsyncGenerator */) return failed;
136797
137133
  const body = declaration.body;
136798
137134
  if (body && isBlock(body)) {
136799
137135
  forEachReturnStatement(body, (s) => {
137136
+ if (s.parent !== body) {
137137
+ candidateExpr = void 0;
137138
+ return true;
137139
+ }
136800
137140
  if (!candidateExpr) {
136801
137141
  candidateExpr = s.expression;
136802
137142
  } else {
@@ -136809,9 +137149,21 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136809
137149
  }
136810
137150
  }
136811
137151
  if (candidateExpr) {
136812
- return typeFromExpression(candidateExpr, context);
137152
+ if (isContextuallyTyped(candidateExpr)) {
137153
+ const type = isJSDocTypeAssertion(candidateExpr) ? getJSDocTypeAssertionType(candidateExpr) : isAsExpression(candidateExpr) || isTypeAssertionExpression(candidateExpr) ? candidateExpr.type : void 0;
137154
+ if (type && !isConstTypeReference(type)) {
137155
+ return syntacticResult(serializeExistingTypeNode(type, context));
137156
+ }
137157
+ } else {
137158
+ return typeFromExpression(candidateExpr, context);
137159
+ }
136813
137160
  }
136814
- return void 0;
137161
+ return failed;
137162
+ }
137163
+ function isContextuallyTyped(node) {
137164
+ return findAncestor(node.parent, (n) => {
137165
+ return isCallExpression(n) || !isFunctionLikeDeclaration(n) && !!getEffectiveTypeAnnotationNode(n) || isJsxElement(n) || isJsxExpression(n);
137166
+ });
136815
137167
  }
136816
137168
  }
136817
137169
 
@@ -160824,7 +161176,7 @@ var extractExpression = "extract-expression";
160824
161176
  var errorCodes48 = [
160825
161177
  Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
160826
161178
  Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
160827
- Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
161179
+ Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
160828
161180
  Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
160829
161181
  Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
160830
161182
  Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
@@ -182539,6 +182891,7 @@ __export(ts_exports2, {
182539
182891
  isNamespaceReexportDeclaration: () => isNamespaceReexportDeclaration,
182540
182892
  isNewExpression: () => isNewExpression,
182541
182893
  isNewExpressionTarget: () => isNewExpressionTarget,
182894
+ isNewScopeNode: () => isNewScopeNode,
182542
182895
  isNoSubstitutionTemplateLiteral: () => isNoSubstitutionTemplateLiteral,
182543
182896
  isNodeArray: () => isNodeArray,
182544
182897
  isNodeArrayMultiLine: () => isNodeArrayMultiLine,
@@ -182765,7 +183118,6 @@ __export(ts_exports2, {
182765
183118
  isVariableDeclarationInitializedToRequire: () => isVariableDeclarationInitializedToRequire,
182766
183119
  isVariableDeclarationList: () => isVariableDeclarationList,
182767
183120
  isVariableLike: () => isVariableLike,
182768
- isVariableLikeOrAccessor: () => isVariableLikeOrAccessor,
182769
183121
  isVariableStatement: () => isVariableStatement,
182770
183122
  isVoidExpression: () => isVoidExpression,
182771
183123
  isWatchSet: () => isWatchSet,
@@ -197283,6 +197635,7 @@ if (typeof console !== "undefined") {
197283
197635
  isNamespaceReexportDeclaration,
197284
197636
  isNewExpression,
197285
197637
  isNewExpressionTarget,
197638
+ isNewScopeNode,
197286
197639
  isNoSubstitutionTemplateLiteral,
197287
197640
  isNodeArray,
197288
197641
  isNodeArrayMultiLine,
@@ -197509,7 +197862,6 @@ if (typeof console !== "undefined") {
197509
197862
  isVariableDeclarationInitializedToRequire,
197510
197863
  isVariableDeclarationList,
197511
197864
  isVariableLike,
197512
- isVariableLikeOrAccessor,
197513
197865
  isVariableStatement,
197514
197866
  isVoidExpression,
197515
197867
  isWatchSet,