typescript 5.0.0-dev.20230111 → 5.0.0-dev.20230112

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
@@ -23,7 +23,7 @@ var __export = (target, all) => {
23
23
 
24
24
  // src/compiler/corePublic.ts
25
25
  var versionMajorMinor = "5.0";
26
- var version = `${versionMajorMinor}.0-dev.20230111`;
26
+ var version = `${versionMajorMinor}.0-dev.20230112`;
27
27
 
28
28
  // src/compiler/core.ts
29
29
  var emptyArray = [];
@@ -8404,7 +8404,8 @@ function isIdentifierStart(ch, languageVersion) {
8404
8404
  return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion);
8405
8405
  }
8406
8406
  function isIdentifierPart(ch, languageVersion, identifierVariant) {
8407
- return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || (identifierVariant === 1 /* JSX */ ? ch === 45 /* minus */ || ch === 58 /* colon */ : false) || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion);
8407
+ return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || // "-" and ":" are valid in JSX Identifiers
8408
+ (identifierVariant === 1 /* JSX */ ? ch === 45 /* minus */ || ch === 58 /* colon */ : false) || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion);
8408
8409
  }
8409
8410
  function isIdentifierText(name, languageVersion, identifierVariant) {
8410
8411
  let ch = codePointAt(name, 0);
@@ -34297,7 +34298,8 @@ function convertToObjectWorker(sourceFile, rootExpression, errors, returnValue,
34297
34298
  if (returnValue) {
34298
34299
  result[keyText] = value;
34299
34300
  }
34300
- if (jsonConversionNotifier && (parentOption || isRootOptionMap(knownOptions))) {
34301
+ if (jsonConversionNotifier && // Current callbacks are only on known parent option or if we are setting values in the root
34302
+ (parentOption || isRootOptionMap(knownOptions))) {
34301
34303
  const isValidOptionValue = isCompilerOptionsValue(option, value);
34302
34304
  if (parentOption) {
34303
34305
  if (isValidOptionValue) {
@@ -40575,8 +40577,12 @@ function createBinder() {
40575
40577
  return false;
40576
40578
  }
40577
40579
  if (currentFlow === unreachableFlow) {
40578
- const reportError = isStatementButNotDeclaration(node) && node.kind !== 239 /* EmptyStatement */ || // report error on class declarations
40579
- node.kind === 260 /* ClassDeclaration */ || node.kind === 264 /* ModuleDeclaration */ && shouldReportErrorOnModuleDeclaration(node);
40580
+ const reportError = (
40581
+ // report error on all statements except empty ones
40582
+ isStatementButNotDeclaration(node) && node.kind !== 239 /* EmptyStatement */ || // report error on class declarations
40583
+ node.kind === 260 /* ClassDeclaration */ || // report error on instantiated modules or const-enums only modules if preserveConstEnums is set
40584
+ node.kind === 264 /* ModuleDeclaration */ && shouldReportErrorOnModuleDeclaration(node)
40585
+ );
40580
40586
  if (reportError) {
40581
40587
  currentFlow = reportedUnreachableFlow;
40582
40588
  if (!options.allowUnreachableCode) {
@@ -46382,7 +46388,8 @@ function createTypeChecker(host) {
46382
46388
  const isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) && (symbol.parent || // is exported function symbol
46383
46389
  forEach(symbol.declarations, (declaration) => declaration.parent.kind === 308 /* SourceFile */ || declaration.parent.kind === 265 /* ModuleBlock */));
46384
46390
  if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
46385
- return (!!(context.flags & 4096 /* UseTypeOfFunction */) || ((_a4 = context.visitedTypes) == null ? void 0 : _a4.has(typeId))) && (!(context.flags & 8 /* UseStructuralFallback */) || isValueSymbolAccessible(symbol, context.enclosingDeclaration));
46391
+ return (!!(context.flags & 4096 /* UseTypeOfFunction */) || ((_a4 = context.visitedTypes) == null ? void 0 : _a4.has(typeId))) && // it is type of the symbol uses itself recursively
46392
+ (!(context.flags & 8 /* UseStructuralFallback */) || isValueSymbolAccessible(symbol, context.enclosingDeclaration));
46386
46393
  }
46387
46394
  }
46388
46395
  }
@@ -46474,7 +46481,9 @@ function createTypeChecker(host) {
46474
46481
  const abstractSignatures = filter(resolved.constructSignatures, (signature) => !!(signature.flags & 4 /* Abstract */));
46475
46482
  if (some(abstractSignatures)) {
46476
46483
  const types = map(abstractSignatures, getOrCreateTypeFromSignature);
46477
- const typeElementCount = resolved.callSignatures.length + (resolved.constructSignatures.length - abstractSignatures.length) + resolved.indexInfos.length + (context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ ? countWhere(resolved.properties, (p) => !(p.flags & 4194304 /* Prototype */)) : length(resolved.properties));
46484
+ const typeElementCount = resolved.callSignatures.length + (resolved.constructSignatures.length - abstractSignatures.length) + resolved.indexInfos.length + // exclude `prototype` when writing a class expression as a type literal, as per
46485
+ // the logic in `createTypeNodesFromResolvedType`.
46486
+ (context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ ? countWhere(resolved.properties, (p) => !(p.flags & 4194304 /* Prototype */)) : length(resolved.properties));
46478
46487
  if (typeElementCount) {
46479
46488
  types.push(getResolvedTypeWithoutAbstractConstructSignatures(resolved));
46480
46489
  }
@@ -47136,9 +47145,11 @@ function createTypeChecker(host) {
47136
47145
  if (accessibleSymbolChain) {
47137
47146
  return accessibleSymbolChain;
47138
47147
  }
47139
- if (// If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols.
47140
- endOfChain || // If a parent symbol is an anonymous type, don't write it.
47141
- !(symbol2.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) {
47148
+ if (
47149
+ // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols.
47150
+ endOfChain || // If a parent symbol is an anonymous type, don't write it.
47151
+ !(symbol2.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))
47152
+ ) {
47142
47153
  if (!endOfChain && !yieldModuleSymbol && !!forEach(symbol2.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
47143
47154
  return;
47144
47155
  }
@@ -47760,7 +47771,8 @@ function createTypeChecker(host) {
47760
47771
  }
47761
47772
  if (isLiteralImportTypeNode(node)) {
47762
47773
  const nodeSymbol = getNodeLinks(node).resolvedSymbol;
47763
- if (isInJSDoc(node) && nodeSymbol && (!node.isTypeOf && !(nodeSymbol.flags & 788968 /* Type */) || // The import type had type arguments autofilled by js fallback logic
47774
+ if (isInJSDoc(node) && nodeSymbol && // The import type resolved using jsdoc fallback logic
47775
+ (!node.isTypeOf && !(nodeSymbol.flags & 788968 /* Type */) || // The import type had type arguments autofilled by js fallback logic
47764
47776
  !(length(node.typeArguments) >= getMinTypeArgumentCount(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(nodeSymbol))))) {
47765
47777
  return setOriginalNode(typeToTypeNodeHelper(getTypeFromTypeNode(node), context), node);
47766
47778
  }
@@ -49277,8 +49289,10 @@ function createTypeChecker(host) {
49277
49289
  }
49278
49290
  }
49279
49291
  function getNameOfSymbolAsWritten(symbol, context) {
49280
- if (context && symbol.escapedName === "default" /* Default */ && !(context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */) && (!(context.flags & 16777216 /* InInitialEntityName */) || // if the symbol is synthesized, it will only be referenced externally it must print as `default`
49281
- !symbol.declarations || context.enclosingDeclaration && findAncestor(symbol.declarations[0], isDefaultBindingContext) !== findAncestor(context.enclosingDeclaration, isDefaultBindingContext))) {
49292
+ if (context && symbol.escapedName === "default" /* Default */ && !(context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */) && // If it's not the first part of an entity name, it must print as `default`
49293
+ (!(context.flags & 16777216 /* InInitialEntityName */) || // if the symbol is synthesized, it will only be referenced externally it must print as `default`
49294
+ !symbol.declarations || // if not in the same binding context (source file, module declaration), it must print as `default`
49295
+ context.enclosingDeclaration && findAncestor(symbol.declarations[0], isDefaultBindingContext) !== findAncestor(context.enclosingDeclaration, isDefaultBindingContext))) {
49282
49296
  return "default";
49283
49297
  }
49284
49298
  if (symbol.declarations && symbol.declarations.length) {
@@ -50605,7 +50619,10 @@ function createTypeChecker(host) {
50605
50619
  function getWriteTypeOfSymbol(symbol) {
50606
50620
  const checkFlags = getCheckFlags(symbol);
50607
50621
  if (symbol.flags & 4 /* Property */) {
50608
- return checkFlags & 2 /* SyntheticProperty */ ? checkFlags & 65536 /* DeferredType */ ? getWriteTypeOfSymbolWithDeferredType(symbol) || getTypeOfSymbolWithDeferredType(symbol) : symbol.links.writeType || symbol.links.type : getTypeOfSymbol(symbol);
50622
+ return checkFlags & 2 /* SyntheticProperty */ ? checkFlags & 65536 /* DeferredType */ ? getWriteTypeOfSymbolWithDeferredType(symbol) || getTypeOfSymbolWithDeferredType(symbol) : (
50623
+ // NOTE: cast to TransientSymbol should be safe because only TransientSymbols can have CheckFlags.SyntheticProperty
50624
+ symbol.links.writeType || symbol.links.type
50625
+ ) : getTypeOfSymbol(symbol);
50609
50626
  }
50610
50627
  if (symbol.flags & 98304 /* Accessor */) {
50611
50628
  return checkFlags & 1 /* Instantiated */ ? getWriteTypeOfInstantiatedSymbol(symbol) : getWriteTypeOfAccessors(symbol);
@@ -59022,7 +59039,11 @@ function createTypeChecker(host) {
59022
59039
  if (variances === emptyArray) {
59023
59040
  return 1 /* Unknown */;
59024
59041
  }
59025
- const varianceResult = relateVariances(source2.aliasTypeArguments, target2.aliasTypeArguments, variances, intersectionState);
59042
+ const params = getSymbolLinks(source2.aliasSymbol).typeParameters;
59043
+ const minParams = getMinTypeArgumentCount(params);
59044
+ const sourceTypes = fillMissingTypeArguments(source2.aliasTypeArguments, params, minParams, isInJSFile(source2.aliasSymbol.valueDeclaration));
59045
+ const targetTypes = fillMissingTypeArguments(target2.aliasTypeArguments, params, minParams, isInJSFile(source2.aliasSymbol.valueDeclaration));
59046
+ const varianceResult = relateVariances(sourceTypes, targetTypes, variances, intersectionState);
59026
59047
  if (varianceResult !== void 0) {
59027
59048
  return varianceResult;
59028
59049
  }
@@ -61479,7 +61500,11 @@ function createTypeChecker(host) {
61479
61500
  }
61480
61501
  if (source.aliasSymbol && source.aliasSymbol === target.aliasSymbol) {
61481
61502
  if (source.aliasTypeArguments) {
61482
- inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments, getAliasVariances(source.aliasSymbol));
61503
+ const params = getSymbolLinks(source.aliasSymbol).typeParameters;
61504
+ const minParams = getMinTypeArgumentCount(params);
61505
+ const sourceTypes = fillMissingTypeArguments(source.aliasTypeArguments, params, minParams, isInJSFile(source.aliasSymbol.valueDeclaration));
61506
+ const targetTypes = fillMissingTypeArguments(target.aliasTypeArguments, params, minParams, isInJSFile(source.aliasSymbol.valueDeclaration));
61507
+ inferFromTypeArguments(sourceTypes, targetTypes, getAliasVariances(source.aliasSymbol));
61483
61508
  }
61484
61509
  return;
61485
61510
  }
@@ -63886,18 +63911,20 @@ function createTypeChecker(host) {
63886
63911
  return narrowTypeByTypeFacts(type, nonPrimitiveType, 128 /* TypeofEQHostObject */);
63887
63912
  }
63888
63913
  function narrowTypeByTypeFacts(type, impliedType, facts) {
63889
- return mapType(type, (t) => // We first check if a constituent is a subtype of the implied type. If so, we either keep or eliminate
63890
- // the constituent based on its type facts. We use the strict subtype relation because it treats `object`
63891
- // as a subtype of `{}`, and we need the type facts check because function types are subtypes of `object`,
63892
- // but are classified as "function" according to `typeof`.
63893
- isTypeRelatedTo(t, impliedType, strictSubtypeRelation) ? getTypeFacts(t) & facts ? t : neverType : (
63894
- // We next check if the consituent is a supertype of the implied type. If so, we substitute the implied
63895
- // type. This handles top types like `unknown` and `{}`, and supertypes like `{ toString(): string }`.
63896
- isTypeSubtypeOf(impliedType, t) ? impliedType : (
63897
- // Neither the constituent nor the implied type is a subtype of the other, however their domains may still
63898
- // overlap. For example, an unconstrained type parameter and type `string`. If the type facts indicate
63899
- // possible overlap, we form an intersection. Otherwise, we eliminate the constituent.
63900
- getTypeFacts(t) & facts ? getIntersectionType([t, impliedType]) : neverType
63914
+ return mapType(type, (t) => (
63915
+ // We first check if a constituent is a subtype of the implied type. If so, we either keep or eliminate
63916
+ // the constituent based on its type facts. We use the strict subtype relation because it treats `object`
63917
+ // as a subtype of `{}`, and we need the type facts check because function types are subtypes of `object`,
63918
+ // but are classified as "function" according to `typeof`.
63919
+ isTypeRelatedTo(t, impliedType, strictSubtypeRelation) ? getTypeFacts(t) & facts ? t : neverType : (
63920
+ // We next check if the consituent is a supertype of the implied type. If so, we substitute the implied
63921
+ // type. This handles top types like `unknown` and `{}`, and supertypes like `{ toString(): string }`.
63922
+ isTypeSubtypeOf(impliedType, t) ? impliedType : (
63923
+ // Neither the constituent nor the implied type is a subtype of the other, however their domains may still
63924
+ // overlap. For example, an unconstrained type parameter and type `string`. If the type facts indicate
63925
+ // possible overlap, we form an intersection. Otherwise, we eliminate the constituent.
63926
+ getTypeFacts(t) & facts ? getIntersectionType([t, impliedType]) : neverType
63927
+ )
63901
63928
  )
63902
63929
  ));
63903
63930
  }
@@ -71468,7 +71495,8 @@ function createTypeChecker(host) {
71468
71495
  }
71469
71496
  }
71470
71497
  function isIndirectCall(node) {
71471
- return node.parent.kind === 214 /* ParenthesizedExpression */ && isNumericLiteral(node.left) && node.left.text === "0" && (isCallExpression(node.parent.parent) && node.parent.parent.expression === node.parent || node.parent.parent.kind === 212 /* TaggedTemplateExpression */) && (isAccessExpression(node.right) || isIdentifier(node.right) && node.right.escapedText === "eval");
71498
+ return node.parent.kind === 214 /* ParenthesizedExpression */ && isNumericLiteral(node.left) && node.left.text === "0" && (isCallExpression(node.parent.parent) && node.parent.parent.expression === node.parent || node.parent.parent.kind === 212 /* TaggedTemplateExpression */) && // special-case for "eval" because it's the only non-access case where an indirect call actually affects behavior.
71499
+ (isAccessExpression(node.right) || isIdentifier(node.right) && node.right.escapedText === "eval");
71472
71500
  }
71473
71501
  function checkForDisallowedESSymbolOperand(operator2) {
71474
71502
  const offendingSymbolOperand = maybeTypeOfKindConsideringBaseConstraint(leftType, 12288 /* ESSymbolLike */) ? left : maybeTypeOfKindConsideringBaseConstraint(rightType, 12288 /* ESSymbolLike */) ? right : void 0;
@@ -78553,7 +78581,12 @@ function createTypeChecker(host) {
78553
78581
  return false;
78554
78582
  const symbol = getSymbolOfDeclaration(node);
78555
78583
  const signaturesOfSymbol = getSignaturesOfSymbol(symbol);
78556
- return signaturesOfSymbol.length > 1 || signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node;
78584
+ return signaturesOfSymbol.length > 1 || // If there is single signature for the symbol, it is overload if that signature isn't coming from the node
78585
+ // e.g.: function foo(a: string): string;
78586
+ // function foo(a: any) { // This is implementation of the overloads
78587
+ // return a;
78588
+ // }
78589
+ signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node;
78557
78590
  }
78558
78591
  return false;
78559
78592
  }
@@ -108966,7 +108999,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
108966
108999
  const oldSourceFiles = oldProgram.getSourceFiles();
108967
109000
  for (const oldSourceFile of oldSourceFiles) {
108968
109001
  const newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
108969
- if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat || oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path) {
109002
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat || // old file wasn't redirect but new file is
109003
+ oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path) {
108970
109004
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
108971
109005
  }
108972
109006
  }
@@ -113662,7 +113696,8 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
113662
113696
  const name = loader.nameAndMode.getName(entry);
113663
113697
  const mode = loader.nameAndMode.getMode(entry, containingSourceFile);
113664
113698
  let resolution = resolutionsInFile.get(name, mode);
113665
- if (!seenNamesInFile.has(name, mode) && unmatchedRedirects || !resolution || resolution.isInvalidated || hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution)) {
113699
+ if (!seenNamesInFile.has(name, mode) && unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate
113700
+ hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution)) {
113666
113701
  const existingResolution = resolution;
113667
113702
  resolution = loader.resolve(name, mode);
113668
113703
  if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {