@typescript-deploys/pr-build 5.5.0-pr-57772-2 → 5.5.0-pr-57465-110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsc.js CHANGED
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.5";
21
- var version = `${versionMajorMinor}.0-insiders.20240314`;
21
+ var version = `${versionMajorMinor}.0-insiders.20240315`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -39813,7 +39813,7 @@ function createBinder() {
39813
39813
  inAssignmentPattern = saveInAssignmentPattern;
39814
39814
  return;
39815
39815
  }
39816
- if (node.kind >= 243 /* FirstStatement */ && node.kind <= 259 /* LastStatement */ && !options.allowUnreachableCode) {
39816
+ if (node.kind >= 243 /* FirstStatement */ && node.kind <= 259 /* LastStatement */ && (!options.allowUnreachableCode || node.kind === 253 /* ReturnStatement */)) {
39817
39817
  node.flowNode = currentFlow;
39818
39818
  }
39819
39819
  switch (node.kind) {
@@ -47787,18 +47787,7 @@ function createTypeChecker(host) {
47787
47787
  function createNodeBuilder() {
47788
47788
  return {
47789
47789
  typeToTypeNode: (type, enclosingDeclaration, flags, tracker) => withContext(enclosingDeclaration, flags, tracker, (context) => typeToTypeNodeHelper(type, context)),
47790
- expressionOrTypeToTypeNode: (type, expr, addUndefined, enclosingDeclaration, flags, tracker) => withContext(enclosingDeclaration, flags, tracker, (context) => expressionOrTypeToTypeNode(context, expr, type, addUndefined)),
47791
- serializeTypeForDeclaration: (type, symbol, addUndefined, enclosingDeclaration, flags, tracker) => withContext(enclosingDeclaration, flags, tracker, (context) => serializeTypeForDeclaration(
47792
- context,
47793
- type,
47794
- symbol,
47795
- enclosingDeclaration,
47796
- /*includePrivateSymbol*/
47797
- void 0,
47798
- /*bundled*/
47799
- void 0,
47800
- addUndefined
47801
- )),
47790
+ typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, tracker) => withContext(enclosingDeclaration, flags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
47802
47791
  indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, tracker) => withContext(enclosingDeclaration, flags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
47803
47792
  indexInfo,
47804
47793
  context,
@@ -47820,47 +47809,6 @@ function createTypeChecker(host) {
47820
47809
  symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, tracker, bundled) => withContext(enclosingDeclaration, flags, tracker, (context) => symbolTableToDeclarationStatements(symbolTable, context, bundled)),
47821
47810
  symbolToNode: (symbol, meaning, enclosingDeclaration, flags, tracker) => withContext(enclosingDeclaration, flags, tracker, (context) => symbolToNode(symbol, context, meaning))
47822
47811
  };
47823
- function expressionOrTypeToTypeNode(context, expr, type, addUndefined) {
47824
- if (expr) {
47825
- const typeNode = isAssertionExpression(expr) ? expr.type : isJSDocTypeAssertion(expr) ? getJSDocTypeAssertionType(expr) : void 0;
47826
- if (typeNode && !isConstTypeReference(typeNode)) {
47827
- const result = tryReuseExistingTypeNode(context, typeNode, type, expr.parent, addUndefined);
47828
- if (result) {
47829
- return result;
47830
- }
47831
- }
47832
- }
47833
- if (addUndefined) {
47834
- type = getOptionalType(type);
47835
- }
47836
- return typeToTypeNodeHelper(type, context);
47837
- }
47838
- function tryReuseExistingTypeNode(context, typeNode, type, host2, addUndefined, includePrivateSymbol, bundled) {
47839
- const originalType = type;
47840
- if (addUndefined) {
47841
- type = getOptionalType(type);
47842
- }
47843
- const clone = tryReuseExistingNonParameterTypeNode(context, typeNode, type, host2, includePrivateSymbol, bundled);
47844
- if (clone) {
47845
- return clone;
47846
- }
47847
- if (addUndefined && originalType !== type) {
47848
- const cloneMissingUndefined = tryReuseExistingNonParameterTypeNode(context, typeNode, originalType, host2, includePrivateSymbol, bundled);
47849
- if (cloneMissingUndefined) {
47850
- return factory.createUnionTypeNode([cloneMissingUndefined, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
47851
- }
47852
- }
47853
- return void 0;
47854
- }
47855
- function tryReuseExistingNonParameterTypeNode(context, existing, type, host2 = context.enclosingDeclaration, includePrivateSymbol, bundled, annotationType) {
47856
- if (typeNodeIsEquivalentToType(existing, host2, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type)) {
47857
- const result = serializeExistingTypeNode(context, existing, includePrivateSymbol, bundled);
47858
- if (result) {
47859
- return result;
47860
- }
47861
- }
47862
- return void 0;
47863
- }
47864
47812
  function symbolToNode(symbol, context, meaning) {
47865
47813
  if (context.flags & 1073741824 /* WriteComputedProps */) {
47866
47814
  if (symbol.valueDeclaration) {
@@ -48302,8 +48250,8 @@ function createTypeChecker(host) {
48302
48250
  if (isInstantiationExpressionType) {
48303
48251
  const instantiationExpressionType = type2;
48304
48252
  const existing = instantiationExpressionType.node;
48305
- if (isTypeQueryNode(existing)) {
48306
- const typeNode = tryReuseExistingNonParameterTypeNode(context, existing, type2);
48253
+ if (isTypeQueryNode(existing) && getTypeFromTypeNode(existing) === type2) {
48254
+ const typeNode = serializeExistingTypeNode(context, existing);
48307
48255
  if (typeNode) {
48308
48256
  return typeNode;
48309
48257
  }
@@ -48966,10 +48914,7 @@ function createTypeChecker(host) {
48966
48914
  let returnTypeNode;
48967
48915
  const typePredicate = getTypePredicateOfSignature(signature);
48968
48916
  if (typePredicate) {
48969
- const assertsModifier = typePredicate.kind === 2 /* AssertsThis */ || typePredicate.kind === 3 /* AssertsIdentifier */ ? factory.createToken(131 /* AssertsKeyword */) : void 0;
48970
- const parameterName = typePredicate.kind === 1 /* Identifier */ || typePredicate.kind === 3 /* AssertsIdentifier */ ? setEmitFlags(factory.createIdentifier(typePredicate.parameterName), 16777216 /* NoAsciiEscaping */) : factory.createThisTypeNode();
48971
- const typeNode = typePredicate.type && typeToTypeNodeHelper(typePredicate.type, context);
48972
- returnTypeNode = factory.createTypePredicateNode(assertsModifier, parameterName, typeNode);
48917
+ returnTypeNode = typePredicateToTypePredicateNodeHelper(typePredicate, context);
48973
48918
  } else {
48974
48919
  const returnType = getReturnTypeOfSignature(signature);
48975
48920
  if (returnType && !(suppressAny && isTypeAny(returnType))) {
@@ -49095,6 +49040,12 @@ function createTypeChecker(host) {
49095
49040
  const constraintNode = constraint && typeToTypeNodeHelper(constraint, context);
49096
49041
  return typeParameterToDeclarationWithConstraint(type, context, constraintNode);
49097
49042
  }
49043
+ function typePredicateToTypePredicateNodeHelper(typePredicate, context) {
49044
+ const assertsModifier = typePredicate.kind === 2 /* AssertsThis */ || typePredicate.kind === 3 /* AssertsIdentifier */ ? factory.createToken(131 /* AssertsKeyword */) : void 0;
49045
+ const parameterName = typePredicate.kind === 1 /* Identifier */ || typePredicate.kind === 3 /* AssertsIdentifier */ ? setEmitFlags(factory.createIdentifier(typePredicate.parameterName), 16777216 /* NoAsciiEscaping */) : factory.createThisTypeNode();
49046
+ const typeNode = typePredicate.type && typeToTypeNodeHelper(typePredicate.type, context);
49047
+ return factory.createTypePredicateNode(assertsModifier, parameterName, typeNode);
49048
+ }
49098
49049
  function getEffectiveParameterDeclaration(parameterSymbol) {
49099
49050
  const parameterDeclaration = getDeclarationOfKind(parameterSymbol, 169 /* Parameter */);
49100
49051
  if (parameterDeclaration) {
@@ -49106,9 +49057,11 @@ function createTypeChecker(host) {
49106
49057
  }
49107
49058
  function symbolToParameterDeclaration(parameterSymbol, context, preserveModifierFlags, privateSymbolVisitor, bundledImports) {
49108
49059
  const parameterDeclaration = getEffectiveParameterDeclaration(parameterSymbol);
49109
- const parameterType = getTypeOfSymbol(parameterSymbol);
49110
- const addUndefined = parameterDeclaration && isRequiredInitializedParameter(parameterDeclaration);
49111
- const parameterTypeNode = serializeTypeForDeclaration(context, parameterType, parameterSymbol, context.enclosingDeclaration, privateSymbolVisitor, bundledImports, addUndefined);
49060
+ let parameterType = getTypeOfSymbol(parameterSymbol);
49061
+ if (parameterDeclaration && isRequiredInitializedParameter(parameterDeclaration)) {
49062
+ parameterType = getOptionalType(parameterType);
49063
+ }
49064
+ const parameterTypeNode = serializeTypeForDeclaration(context, parameterType, parameterSymbol, context.enclosingDeclaration, privateSymbolVisitor, bundledImports);
49112
49065
  const modifiers = !(context.flags & 8192 /* OmitParameterModifiers */) && preserveModifierFlags && parameterDeclaration && canHaveModifiers(parameterDeclaration) ? map(getModifiers(parameterDeclaration), factory.cloneNode) : void 0;
49113
49066
  const isRest = parameterDeclaration && isRestParameter(parameterDeclaration) || getCheckFlags(parameterSymbol) & 32768 /* RestParameter */;
49114
49067
  const dotDotDotToken = isRest ? factory.createToken(26 /* DotDotDotToken */) : void 0;
@@ -49698,15 +49651,16 @@ function createTypeChecker(host) {
49698
49651
  }
49699
49652
  return enclosingDeclaration;
49700
49653
  }
49701
- function serializeTypeForDeclaration(context, type, symbol, enclosingDeclaration, includePrivateSymbol, bundled, addUndefined) {
49702
- var _a;
49654
+ function serializeTypeForDeclaration(context, type, symbol, enclosingDeclaration, includePrivateSymbol, bundled) {
49703
49655
  if (!isErrorType(type) && enclosingDeclaration) {
49704
49656
  const declWithExistingAnnotation = getDeclarationWithTypeAnnotation(symbol, getEnclosingDeclarationIgnoringFakeScope(enclosingDeclaration));
49705
49657
  if (declWithExistingAnnotation && !isFunctionLikeDeclaration(declWithExistingAnnotation) && !isGetAccessorDeclaration(declWithExistingAnnotation)) {
49706
49658
  const existing = getEffectiveTypeAnnotationNode(declWithExistingAnnotation);
49707
- const result2 = tryReuseExistingTypeNode(context, existing, type, declWithExistingAnnotation, addUndefined, includePrivateSymbol, bundled);
49708
- if (result2) {
49709
- return result2;
49659
+ if (typeNodeIsEquivalentToType(existing, declWithExistingAnnotation, type) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type)) {
49660
+ const result2 = serializeExistingTypeNode(context, existing, includePrivateSymbol, bundled);
49661
+ if (result2) {
49662
+ return result2;
49663
+ }
49710
49664
  }
49711
49665
  }
49712
49666
  }
@@ -49714,17 +49668,16 @@ function createTypeChecker(host) {
49714
49668
  if (type.flags & 8192 /* UniqueESSymbol */ && type.symbol === symbol && (!context.enclosingDeclaration || some(symbol.declarations, (d) => getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration)))) {
49715
49669
  context.flags |= 1048576 /* AllowUniqueESSymbolType */;
49716
49670
  }
49717
- const decl = symbol.valueDeclaration || ((_a = symbol.declarations) == null ? void 0 : _a[0]);
49718
- const expr = decl && isDeclarationWithPossibleInnerTypeNodeReuse(decl) ? getPossibleTypeNodeReuseExpression(decl) : void 0;
49719
- const result = expressionOrTypeToTypeNode(context, expr, type, addUndefined);
49671
+ const result = typeToTypeNodeHelper(type, context);
49720
49672
  context.flags = oldFlags;
49721
49673
  return result;
49722
49674
  }
49723
- function typeNodeIsEquivalentToType(typeNode, annotatedDeclaration, type, typeFromTypeNode = getTypeFromTypeNode(typeNode)) {
49675
+ function typeNodeIsEquivalentToType(typeNode, annotatedDeclaration, type) {
49676
+ const typeFromTypeNode = getTypeFromTypeNode(typeNode);
49724
49677
  if (typeFromTypeNode === type) {
49725
49678
  return true;
49726
49679
  }
49727
- if (annotatedDeclaration && (isParameter(annotatedDeclaration) || isPropertyDeclaration(annotatedDeclaration)) && annotatedDeclaration.questionToken) {
49680
+ if (isParameter(annotatedDeclaration) && annotatedDeclaration.questionToken) {
49728
49681
  return getTypeWithFacts(type, 524288 /* NEUndefined */) === typeFromTypeNode;
49729
49682
  }
49730
49683
  return false;
@@ -49736,9 +49689,11 @@ function createTypeChecker(host) {
49736
49689
  if (!!findAncestor(annotation, (n) => n === enclosingDeclarationIgnoringFakeScope) && annotation) {
49737
49690
  const annotated = getTypeFromTypeNode(annotation);
49738
49691
  const thisInstantiated = annotated.flags & 262144 /* TypeParameter */ && annotated.isThisType ? instantiateType(annotated, signature.mapper) : annotated;
49739
- const result = tryReuseExistingNonParameterTypeNode(context, annotation, type, signature.declaration, includePrivateSymbol, bundled, thisInstantiated);
49740
- if (result) {
49741
- return result;
49692
+ if (thisInstantiated === type && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(annotation, type)) {
49693
+ const result = serializeExistingTypeNode(context, annotation, includePrivateSymbol, bundled);
49694
+ if (result) {
49695
+ return result;
49696
+ }
49742
49697
  }
49743
49698
  }
49744
49699
  }
@@ -49767,9 +49722,7 @@ function createTypeChecker(host) {
49767
49722
  /*shouldComputeAliasesToMakeVisible*/
49768
49723
  false
49769
49724
  ).accessibility !== 0 /* Accessible */) {
49770
- if (!isDeclarationName(node)) {
49771
- introducesError = true;
49772
- }
49725
+ introducesError = true;
49773
49726
  } else {
49774
49727
  context.tracker.trackSymbol(sym, context.enclosingDeclaration, -1 /* All */);
49775
49728
  includePrivateSymbol == null ? void 0 : includePrivateSymbol(sym);
@@ -49907,31 +49860,6 @@ function createTypeChecker(host) {
49907
49860
  node.isTypeOf
49908
49861
  );
49909
49862
  }
49910
- if (isParameter(node)) {
49911
- if (!node.type && !node.initializer) {
49912
- return factory.updateParameterDeclaration(
49913
- node,
49914
- /*modifiers*/
49915
- void 0,
49916
- node.dotDotDotToken,
49917
- visitEachChild(
49918
- node.name,
49919
- visitExistingNodeTreeSymbols,
49920
- /*context*/
49921
- void 0
49922
- ),
49923
- node.questionToken,
49924
- factory.createKeywordTypeNode(133 /* AnyKeyword */),
49925
- /*initializer*/
49926
- void 0
49927
- );
49928
- }
49929
- }
49930
- if (isPropertySignature(node)) {
49931
- if (!node.type && !node.initializer) {
49932
- return factory.updatePropertySignature(node, node.modifiers, node.name, node.questionToken, factory.createKeywordTypeNode(133 /* AnyKeyword */));
49933
- }
49934
- }
49935
49863
  if (isEntityName(node) || isEntityNameExpression(node)) {
49936
49864
  const { introducesError, node: result } = trackExistingEntityName(node, context, includePrivateSymbol);
49937
49865
  hadError = hadError || introducesError;
@@ -49939,7 +49867,7 @@ function createTypeChecker(host) {
49939
49867
  return result;
49940
49868
  }
49941
49869
  }
49942
- if (file && isTupleTypeNode(node) && !nodeIsSynthesized(node) && getLineAndCharacterOfPosition(file, node.pos).line === getLineAndCharacterOfPosition(file, node.end).line) {
49870
+ if (file && isTupleTypeNode(node) && getLineAndCharacterOfPosition(file, node.pos).line === getLineAndCharacterOfPosition(file, node.end).line) {
49943
49871
  setEmitFlags(node, 1 /* SingleLine */);
49944
49872
  }
49945
49873
  return visitEachChild(
@@ -50463,15 +50391,7 @@ function createTypeChecker(host) {
50463
50391
  context.flags |= 8388608 /* InTypeAlias */;
50464
50392
  const oldEnclosingDecl = context.enclosingDeclaration;
50465
50393
  context.enclosingDeclaration = jsdocAliasDecl;
50466
- const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) && tryReuseExistingNonParameterTypeNode(
50467
- context,
50468
- jsdocAliasDecl.typeExpression.type,
50469
- aliasType,
50470
- /*host*/
50471
- void 0,
50472
- includePrivateSymbol,
50473
- bundled
50474
- ) || typeToTypeNodeHelper(aliasType, context);
50394
+ const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) && serializeExistingTypeNode(context, jsdocAliasDecl.typeExpression.type, includePrivateSymbol, bundled) || typeToTypeNodeHelper(aliasType, context);
50475
50395
  addResult(
50476
50396
  setSyntheticLeadingComments(
50477
50397
  factory.createTypeAliasDeclaration(
@@ -50704,15 +50624,7 @@ function createTypeChecker(host) {
50704
50624
  }
50705
50625
  return cleanup(factory.createExpressionWithTypeArguments(
50706
50626
  expr,
50707
- map(e.typeArguments, (a) => tryReuseExistingNonParameterTypeNode(
50708
- context,
50709
- a,
50710
- getTypeFromTypeNode(a),
50711
- /*host*/
50712
- void 0,
50713
- includePrivateSymbol,
50714
- bundled
50715
- ) || typeToTypeNodeHelper(getTypeFromTypeNode(a), context))
50627
+ map(e.typeArguments, (a) => serializeExistingTypeNode(context, a, includePrivateSymbol, bundled) || typeToTypeNodeHelper(getTypeFromTypeNode(a), context))
50716
50628
  ));
50717
50629
  function cleanup(result2) {
50718
50630
  context.enclosingDeclaration = oldEnclosing;
@@ -51171,10 +51083,8 @@ function createTypeChecker(host) {
51171
51083
  }
51172
51084
  }
51173
51085
  function isTypeRepresentableAsFunctionNamespaceMerge(typeToSerialize, hostSymbol) {
51174
- var _a2;
51175
51086
  const ctxSrc = getSourceFileOfNode(context.enclosingDeclaration);
51176
- return getObjectFlags(typeToSerialize) & (16 /* Anonymous */ | 32 /* Mapped */) && !some((_a2 = typeToSerialize.symbol) == null ? void 0 : _a2.declarations, isTypeNode) && // If the type comes straight from a type node, we shouldn't try to break it up
51177
- !length(getIndexInfosOfType(typeToSerialize)) && !isClassInstanceSide(typeToSerialize) && // While a class instance is potentially representable as a NS, prefer printing a reference to the instance type and serializing the class
51087
+ return getObjectFlags(typeToSerialize) & (16 /* Anonymous */ | 32 /* Mapped */) && !length(getIndexInfosOfType(typeToSerialize)) && !isClassInstanceSide(typeToSerialize) && // While a class instance is potentially representable as a NS, prefer printing a reference to the instance type and serializing the class
51178
51088
  !!(length(filter(getPropertiesOfType(typeToSerialize), isNamespaceMember)) || length(getSignaturesOfType(typeToSerialize, 0 /* Call */))) && !length(getSignaturesOfType(typeToSerialize, 1 /* Construct */)) && // TODO: could probably serialize as function + ns + class, now that that's OK
51179
51089
  !getDeclarationWithTypeAnnotation(hostSymbol, enclosingDeclaration) && !(typeToSerialize.symbol && some(typeToSerialize.symbol.declarations, (d) => getSourceFileOfNode(d) !== ctxSrc)) && !some(getPropertiesOfType(typeToSerialize), (p) => isLateBoundName(p.escapedName)) && !some(getPropertiesOfType(typeToSerialize), (p) => some(p.declarations, (d) => getSourceFileOfNode(d) !== ctxSrc)) && every(getPropertiesOfType(typeToSerialize), (p) => {
51180
51090
  if (!isIdentifierText(symbolName(p), languageVersion)) {
@@ -51497,12 +51407,8 @@ function createTypeChecker(host) {
51497
51407
  function typePredicateToString(typePredicate, enclosingDeclaration, flags = 16384 /* UseAliasDefinedOutsideCurrentScope */, writer) {
51498
51408
  return writer ? typePredicateToStringWorker(writer).getText() : usingSingleLineStringWriter(typePredicateToStringWorker);
51499
51409
  function typePredicateToStringWorker(writer2) {
51500
- const predicate = factory.createTypePredicateNode(
51501
- typePredicate.kind === 2 /* AssertsThis */ || typePredicate.kind === 3 /* AssertsIdentifier */ ? factory.createToken(131 /* AssertsKeyword */) : void 0,
51502
- typePredicate.kind === 1 /* Identifier */ || typePredicate.kind === 3 /* AssertsIdentifier */ ? factory.createIdentifier(typePredicate.parameterName) : factory.createThisTypeNode(),
51503
- typePredicate.type && nodeBuilder.typeToTypeNode(typePredicate.type, enclosingDeclaration, toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | 512 /* WriteTypeParametersInQualifiedName */)
51504
- // TODO: GH#18217
51505
- );
51410
+ const nodeBuilderFlags = toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | 512 /* WriteTypeParametersInQualifiedName */;
51411
+ const predicate = nodeBuilder.typePredicateToTypePredicateNode(typePredicate, enclosingDeclaration, nodeBuilderFlags);
51506
51412
  const printer = createPrinterWithRemoveComments();
51507
51413
  const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
51508
51414
  printer.writeNode(
@@ -55753,7 +55659,15 @@ function createTypeChecker(host) {
55753
55659
  jsdocPredicate = getTypePredicateOfSignature(jsdocSignature);
55754
55660
  }
55755
55661
  }
55756
- signature.resolvedTypePredicate = type && isTypePredicateNode(type) ? createTypePredicateFromTypePredicateNode(type, signature) : jsdocPredicate || noTypePredicate;
55662
+ if (type || jsdocPredicate) {
55663
+ signature.resolvedTypePredicate = type && isTypePredicateNode(type) ? createTypePredicateFromTypePredicateNode(type, signature) : jsdocPredicate || noTypePredicate;
55664
+ } else if (signature.declaration && isFunctionLikeDeclaration(signature.declaration) && (!signature.resolvedReturnType || signature.resolvedReturnType.flags & 16 /* Boolean */) && getParameterCount(signature) > 0) {
55665
+ const { declaration } = signature;
55666
+ signature.resolvedTypePredicate = noTypePredicate;
55667
+ signature.resolvedTypePredicate = getTypePredicateFromBody(declaration) || noTypePredicate;
55668
+ } else {
55669
+ signature.resolvedTypePredicate = noTypePredicate;
55670
+ }
55757
55671
  }
55758
55672
  Debug.assert(!!signature.resolvedTypePredicate);
55759
55673
  }
@@ -57941,6 +57855,7 @@ function createTypeChecker(host) {
57941
57855
  return links.resolvedType;
57942
57856
  }
57943
57857
  function getTemplateLiteralType(texts, types) {
57858
+ var _a, _b;
57944
57859
  const unionIndex = findIndex(types, (t) => !!(t.flags & (131072 /* Never */ | 1048576 /* Union */)));
57945
57860
  if (unionIndex >= 0) {
57946
57861
  return checkCrossProductUnion(types) ? mapType(types[unionIndex], (t) => getTemplateLiteralType(texts, replaceElement(types, unionIndex, t))) : errorType;
@@ -57948,6 +57863,9 @@ function createTypeChecker(host) {
57948
57863
  if (contains(types, wildcardType)) {
57949
57864
  return wildcardType;
57950
57865
  }
57866
+ if (texts.length === 2 && texts[0] === "" && texts[1] === "" && !(types[0].flags & 2944 /* Literal */) && !((_b = (_a = types[0].symbol) == null ? void 0 : _a.declarations) == null ? void 0 : _b.some((d) => d.parent.kind === 195 /* InferType */)) && isTypeAssignableTo(types[0], stringType)) {
57867
+ return types[0];
57868
+ }
57951
57869
  const newTypes = [];
57952
57870
  const newTexts = [];
57953
57871
  let text = texts[0];
@@ -74183,6 +74101,67 @@ function createTypeChecker(host) {
74183
74101
  return false;
74184
74102
  }
74185
74103
  }
74104
+ function getTypePredicateFromBody(func) {
74105
+ switch (func.kind) {
74106
+ case 176 /* Constructor */:
74107
+ case 177 /* GetAccessor */:
74108
+ case 178 /* SetAccessor */:
74109
+ return void 0;
74110
+ }
74111
+ const functionFlags = getFunctionFlags(func);
74112
+ if (functionFlags !== 0 /* Normal */)
74113
+ return void 0;
74114
+ let singleReturn;
74115
+ if (func.body && func.body.kind !== 241 /* Block */) {
74116
+ singleReturn = func.body;
74117
+ } else {
74118
+ const bailedEarly = forEachReturnStatement(func.body, (returnStatement) => {
74119
+ if (singleReturn || !returnStatement.expression)
74120
+ return true;
74121
+ singleReturn = returnStatement.expression;
74122
+ });
74123
+ if (bailedEarly || !singleReturn || functionHasImplicitReturn(func))
74124
+ return void 0;
74125
+ }
74126
+ return checkIfExpressionRefinesAnyParameter(func, singleReturn);
74127
+ }
74128
+ function checkIfExpressionRefinesAnyParameter(func, expr) {
74129
+ expr = skipParentheses(
74130
+ expr,
74131
+ /*excludeJSDocTypeAssertions*/
74132
+ true
74133
+ );
74134
+ const returnType = checkExpressionCached(expr);
74135
+ if (!(returnType.flags & 16 /* Boolean */))
74136
+ return void 0;
74137
+ return forEach(func.parameters, (param, i) => {
74138
+ const initType = getTypeOfSymbol(param.symbol);
74139
+ if (!initType || initType.flags & 16 /* Boolean */ || !isIdentifier(param.name) || isSymbolAssigned(param.symbol) || isRestParameter(param)) {
74140
+ return;
74141
+ }
74142
+ const trueType2 = checkIfExpressionRefinesParameter(func, expr, param, initType);
74143
+ if (trueType2) {
74144
+ return createTypePredicate(1 /* Identifier */, unescapeLeadingUnderscores(param.name.escapedText), i, trueType2);
74145
+ }
74146
+ });
74147
+ }
74148
+ function checkIfExpressionRefinesParameter(func, expr, param, initType) {
74149
+ const antecedent = expr.flowNode || expr.parent.kind === 253 /* ReturnStatement */ && expr.parent.flowNode || { flags: 2 /* Start */ };
74150
+ const trueCondition = {
74151
+ flags: 32 /* TrueCondition */,
74152
+ node: expr,
74153
+ antecedent
74154
+ };
74155
+ const trueType2 = getFlowTypeOfReference(param.name, initType, initType, func, trueCondition);
74156
+ if (trueType2 === initType)
74157
+ return void 0;
74158
+ const falseCondition = {
74159
+ ...trueCondition,
74160
+ flags: 64 /* FalseCondition */
74161
+ };
74162
+ const falseSubtype = getFlowTypeOfReference(param.name, trueType2, trueType2, func, falseCondition);
74163
+ return falseSubtype.flags & 131072 /* Never */ ? trueType2 : void 0;
74164
+ }
74186
74165
  function checkAllCodePathsInNonVoidFunctionReturnOrThrow(func, returnType) {
74187
74166
  addLazyDiagnostic(checkAllCodePathsInNonVoidFunctionReturnOrThrowDiagnostics);
74188
74167
  return;
@@ -82935,34 +82914,14 @@ function createTypeChecker(host) {
82935
82914
  return factory.createToken(133 /* AnyKeyword */);
82936
82915
  }
82937
82916
  const symbol = getSymbolOfDeclaration(declaration);
82938
- const type = symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) ? getWidenedLiteralType(getTypeOfSymbol(symbol)) : errorType;
82939
- return nodeBuilder.serializeTypeForDeclaration(type, symbol, addUndefined, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, tracker);
82940
- }
82941
- function isDeclarationWithPossibleInnerTypeNodeReuse(declaration) {
82942
- return isFunctionLike(declaration) || isExportAssignment(declaration) || isVariableLike(declaration);
82943
- }
82944
- function getPossibleTypeNodeReuseExpression(declaration) {
82945
- var _a;
82946
- return isFunctionLike(declaration) && !isSetAccessor(declaration) ? getSingleReturnExpression(declaration) : isExportAssignment(declaration) ? declaration.expression : !!declaration.initializer ? declaration.initializer : isParameter(declaration) && isSetAccessor(declaration.parent) ? getSingleReturnExpression(getAllAccessorDeclarations((_a = getSymbolOfDeclaration(declaration.parent)) == null ? void 0 : _a.declarations, declaration.parent).getAccessor) : void 0;
82947
- }
82948
- function getSingleReturnExpression(declaration) {
82949
- let candidateExpr;
82950
- if (declaration && !nodeIsMissing(declaration.body)) {
82951
- const body = declaration.body;
82952
- if (body && isBlock(body)) {
82953
- forEachReturnStatement(body, (s) => {
82954
- if (!candidateExpr) {
82955
- candidateExpr = s.expression;
82956
- } else {
82957
- candidateExpr = void 0;
82958
- return true;
82959
- }
82960
- });
82961
- } else {
82962
- candidateExpr = body;
82963
- }
82917
+ let type = symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) ? getWidenedLiteralType(getTypeOfSymbol(symbol)) : errorType;
82918
+ if (type.flags & 8192 /* UniqueESSymbol */ && type.symbol === symbol) {
82919
+ flags |= 1048576 /* AllowUniqueESSymbolType */;
82920
+ }
82921
+ if (addUndefined) {
82922
+ type = getOptionalType(type);
82964
82923
  }
82965
- return candidateExpr;
82924
+ return nodeBuilder.typeToTypeNode(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, tracker);
82966
82925
  }
82967
82926
  function createReturnTypeOfSignatureDeclaration(signatureDeclarationIn, enclosingDeclaration, flags, tracker) {
82968
82927
  const signatureDeclaration = getParseTreeNode(signatureDeclarationIn, isFunctionLike);
@@ -82970,15 +82929,11 @@ function createTypeChecker(host) {
82970
82929
  return factory.createToken(133 /* AnyKeyword */);
82971
82930
  }
82972
82931
  const signature = getSignatureFromDeclaration(signatureDeclaration);
82973
- return nodeBuilder.expressionOrTypeToTypeNode(
82974
- getReturnTypeOfSignature(signature),
82975
- getPossibleTypeNodeReuseExpression(signatureDeclaration),
82976
- /*addUndefined*/
82977
- void 0,
82978
- enclosingDeclaration,
82979
- flags | 1024 /* MultilineObjectLiterals */,
82980
- tracker
82981
- );
82932
+ const typePredicate = getTypePredicateOfSignature(signature);
82933
+ if (typePredicate) {
82934
+ return nodeBuilder.typePredicateToTypePredicateNode(typePredicate, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, tracker);
82935
+ }
82936
+ return nodeBuilder.typeToTypeNode(getReturnTypeOfSignature(signature), enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, tracker);
82982
82937
  }
82983
82938
  function createTypeOfExpression(exprIn, enclosingDeclaration, flags, tracker) {
82984
82939
  const expr = getParseTreeNode(exprIn, isExpression);
@@ -82986,15 +82941,7 @@ function createTypeChecker(host) {
82986
82941
  return factory.createToken(133 /* AnyKeyword */);
82987
82942
  }
82988
82943
  const type = getWidenedType(getRegularTypeOfExpression(expr));
82989
- return nodeBuilder.expressionOrTypeToTypeNode(
82990
- type,
82991
- expr,
82992
- /*addUndefined*/
82993
- void 0,
82994
- enclosingDeclaration,
82995
- flags | 1024 /* MultilineObjectLiterals */,
82996
- tracker
82997
- );
82944
+ return nodeBuilder.typeToTypeNode(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, tracker);
82998
82945
  }
82999
82946
  function hasGlobalName(name) {
83000
82947
  return globals.has(escapeLeadingUnderscores(name));