typescript 5.6.0-dev.20240819 → 5.7.0-dev.20240821

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
@@ -17,8 +17,8 @@ and limitations under the License.
17
17
  "use strict";
18
18
 
19
19
  // src/compiler/corePublic.ts
20
- var versionMajorMinor = "5.6";
21
- var version = `${versionMajorMinor}.0-dev.20240819`;
20
+ var versionMajorMinor = "5.7";
21
+ var version = `${versionMajorMinor}.0-dev.20240821`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -17134,6 +17134,9 @@ function accessKind(node) {
17134
17134
  return node === parent.objectAssignmentInitializer ? 0 /* Read */ : accessKind(parent.parent);
17135
17135
  case 209 /* ArrayLiteralExpression */:
17136
17136
  return accessKind(parent);
17137
+ case 249 /* ForInStatement */:
17138
+ case 250 /* ForOfStatement */:
17139
+ return node === parent.initializer ? 1 /* Write */ : 0 /* Read */;
17137
17140
  default:
17138
17141
  return 0 /* Read */;
17139
17142
  }
@@ -69774,6 +69777,12 @@ function createTypeChecker(host) {
69774
69777
  function getControlFlowContainer(node) {
69775
69778
  return findAncestor(node.parent, (node2) => isFunctionLike(node2) && !getImmediatelyInvokedFunctionExpression(node2) || node2.kind === 268 /* ModuleBlock */ || node2.kind === 307 /* SourceFile */ || node2.kind === 172 /* PropertyDeclaration */);
69776
69779
  }
69780
+ function isSymbolAssignedDefinitely(symbol) {
69781
+ if (symbol.lastAssignmentPos !== void 0) {
69782
+ return symbol.lastAssignmentPos < 0;
69783
+ }
69784
+ return isSymbolAssigned(symbol) && symbol.lastAssignmentPos !== void 0 && symbol.lastAssignmentPos < 0;
69785
+ }
69777
69786
  function isSymbolAssigned(symbol) {
69778
69787
  return !isPastLastAssignment(
69779
69788
  symbol,
@@ -69793,7 +69802,7 @@ function createTypeChecker(host) {
69793
69802
  markNodeAssignments(parent);
69794
69803
  }
69795
69804
  }
69796
- return !symbol.lastAssignmentPos || location && symbol.lastAssignmentPos < location.pos;
69805
+ return !symbol.lastAssignmentPos || location && Math.abs(symbol.lastAssignmentPos) < location.pos;
69797
69806
  }
69798
69807
  function isSomeSymbolAssigned(rootDeclaration) {
69799
69808
  Debug.assert(isVariableDeclaration(rootDeclaration) || isParameter(rootDeclaration));
@@ -69814,12 +69823,19 @@ function createTypeChecker(host) {
69814
69823
  function markNodeAssignments(node) {
69815
69824
  switch (node.kind) {
69816
69825
  case 80 /* Identifier */:
69817
- if (isAssignmentTarget(node)) {
69826
+ const assigmentTarget = getAssignmentTargetKind(node);
69827
+ if (assigmentTarget !== 0 /* None */) {
69818
69828
  const symbol = getResolvedSymbol(node);
69819
- if (isParameterOrMutableLocalVariable(symbol) && symbol.lastAssignmentPos !== Number.MAX_VALUE) {
69820
- const referencingFunction = findAncestor(node, isFunctionOrSourceFile);
69821
- const declaringFunction = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
69822
- symbol.lastAssignmentPos = referencingFunction === declaringFunction ? extendAssignmentPosition(node, symbol.valueDeclaration) : Number.MAX_VALUE;
69829
+ const hasDefiniteAssignment = assigmentTarget === 1 /* Definite */ || symbol.lastAssignmentPos !== void 0 && symbol.lastAssignmentPos < 0;
69830
+ if (isParameterOrMutableLocalVariable(symbol)) {
69831
+ if (symbol.lastAssignmentPos === void 0 || Math.abs(symbol.lastAssignmentPos) !== Number.MAX_VALUE) {
69832
+ const referencingFunction = findAncestor(node, isFunctionOrSourceFile);
69833
+ const declaringFunction = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
69834
+ symbol.lastAssignmentPos = referencingFunction === declaringFunction ? extendAssignmentPosition(node, symbol.valueDeclaration) : Number.MAX_VALUE;
69835
+ }
69836
+ if (hasDefiniteAssignment && symbol.lastAssignmentPos > 0) {
69837
+ symbol.lastAssignmentPos *= -1;
69838
+ }
69823
69839
  }
69824
69840
  }
69825
69841
  return;
@@ -69836,7 +69852,8 @@ function createTypeChecker(host) {
69836
69852
  true
69837
69853
  );
69838
69854
  if (symbol && isParameterOrMutableLocalVariable(symbol)) {
69839
- symbol.lastAssignmentPos = Number.MAX_VALUE;
69855
+ const sign = symbol.lastAssignmentPos !== void 0 && symbol.lastAssignmentPos < 0 ? -1 : 1;
69856
+ symbol.lastAssignmentPos = sign * Number.MAX_VALUE;
69840
69857
  }
69841
69858
  }
69842
69859
  return;
@@ -70420,6 +70437,7 @@ function createTypeChecker(host) {
70420
70437
  }
70421
70438
  const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
70422
70439
  let declaration = localOrExportSymbol.valueDeclaration;
70440
+ const immediateDeclaration = declaration;
70423
70441
  if (declaration && declaration.kind === 208 /* BindingElement */ && contains(contextualBindingPatterns, declaration.parent) && findAncestor(node, (parent) => parent === declaration.parent)) {
70424
70442
  return nonInferrableAnyType;
70425
70443
  }
@@ -70465,7 +70483,8 @@ function createTypeChecker(host) {
70465
70483
  while (flowContainer !== declarationContainer && (flowContainer.kind === 218 /* FunctionExpression */ || flowContainer.kind === 219 /* ArrowFunction */ || isObjectLiteralOrClassExpressionMethodOrAccessor(flowContainer)) && (isConstantVariable(localOrExportSymbol) && type !== autoArrayType || isParameterOrMutableLocalVariable(localOrExportSymbol) && isPastLastAssignment(localOrExportSymbol, node))) {
70466
70484
  flowContainer = getControlFlowContainer(flowContainer);
70467
70485
  }
70468
- const assumeInitialized = isParameter2 || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) || type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (3 /* AnyOrUnknown */ | 16384 /* Void */)) !== 0 || isInTypeQuery(node) || isInAmbientOrTypeNode(node) || node.parent.kind === 281 /* ExportSpecifier */) || node.parent.kind === 235 /* NonNullExpression */ || declaration.kind === 260 /* VariableDeclaration */ && declaration.exclamationToken || declaration.flags & 33554432 /* Ambient */;
70486
+ const isNeverInitialized = immediateDeclaration && isVariableDeclaration(immediateDeclaration) && !immediateDeclaration.initializer && !immediateDeclaration.exclamationToken && isMutableLocalVariableDeclaration(immediateDeclaration) && !isSymbolAssignedDefinitely(symbol);
70487
+ const assumeInitialized = isParameter2 || isAlias || isOuterVariable && !isNeverInitialized || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) || type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (3 /* AnyOrUnknown */ | 16384 /* Void */)) !== 0 || isInTypeQuery(node) || isInAmbientOrTypeNode(node) || node.parent.kind === 281 /* ExportSpecifier */) || node.parent.kind === 235 /* NonNullExpression */ || declaration.kind === 260 /* VariableDeclaration */ && declaration.exclamationToken || declaration.flags & 33554432 /* Ambient */;
70469
70488
  const initialType = isAutomaticTypeInNonNull ? undefinedType : assumeInitialized ? isParameter2 ? removeOptionalityFromDeclaredType(type, declaration) : type : typeIsAutomatic ? undefinedType : getOptionalType(type);
70470
70489
  const flowType = isAutomaticTypeInNonNull ? getNonNullableType(getFlowTypeOfReference(node, type, initialType, flowContainer)) : getFlowTypeOfReference(node, type, initialType, flowContainer);
70471
70490
  if (!isEvolvingArrayOperationTarget(node) && (type === autoType || type === autoArrayType)) {
@@ -71370,46 +71389,108 @@ function createTypeChecker(host) {
71370
71389
  function isCircularMappedProperty(symbol) {
71371
71390
  return !!(getCheckFlags(symbol) & 262144 /* Mapped */ && !symbol.links.type && findResolutionCycleStartIndex(symbol, 0 /* Type */) >= 0);
71372
71391
  }
71392
+ function isExcludedMappedPropertyName(constraint, propertyNameType) {
71393
+ if (constraint.flags & 16777216 /* Conditional */) {
71394
+ const type = constraint;
71395
+ return !!(getReducedType(getTrueTypeFromConditionalType(type)).flags & 131072 /* Never */) && getActualTypeVariable(getFalseTypeFromConditionalType(type)) === getActualTypeVariable(type.checkType) && isTypeAssignableTo(propertyNameType, type.extendsType);
71396
+ }
71397
+ if (constraint.flags & 2097152 /* Intersection */) {
71398
+ return some(constraint.types, (t) => isExcludedMappedPropertyName(t, propertyNameType));
71399
+ }
71400
+ return false;
71401
+ }
71373
71402
  function getTypeOfPropertyOfContextualType(type, name, nameType) {
71374
71403
  return mapType(
71375
71404
  type,
71376
71405
  (t) => {
71377
- var _a;
71378
- if (isGenericMappedType(t) && getMappedTypeNameTypeKind(t) !== 2 /* Remapping */) {
71379
- const constraint = getConstraintTypeFromMappedType(t);
71380
- const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
71381
- const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name));
71382
- if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
71383
- return substituteIndexedMappedType(t, propertyNameType);
71384
- }
71385
- } else if (t.flags & 3670016 /* StructuredType */) {
71386
- const prop = getPropertyOfType(t, name);
71387
- if (prop) {
71388
- return isCircularMappedProperty(prop) ? void 0 : removeMissingType(getTypeOfSymbol(prop), !!(prop.flags & 16777216 /* Optional */));
71389
- }
71390
- if (isTupleType(t) && isNumericLiteralName(name) && +name >= 0) {
71391
- const restType = getElementTypeOfSliceOfTupleType(
71392
- t,
71393
- t.target.fixedLength,
71394
- /*endSkipCount*/
71395
- 0,
71396
- /*writing*/
71397
- false,
71398
- /*noReductions*/
71399
- true
71400
- );
71401
- if (restType) {
71402
- return restType;
71406
+ if (t.flags & 2097152 /* Intersection */) {
71407
+ let types;
71408
+ let indexInfoCandidates;
71409
+ let ignoreIndexInfos = false;
71410
+ for (const constituentType of t.types) {
71411
+ if (!(constituentType.flags & 524288 /* Object */)) {
71412
+ continue;
71413
+ }
71414
+ if (isGenericMappedType(constituentType) && getMappedTypeNameTypeKind(constituentType) !== 2 /* Remapping */) {
71415
+ const substitutedType = getIndexedMappedTypeSubstitutedTypeOfContextualType(constituentType, name, nameType);
71416
+ types = appendContextualPropertyTypeConstituent(types, substitutedType);
71417
+ continue;
71403
71418
  }
71419
+ const propertyType = getTypeOfConcretePropertyOfContextualType(constituentType, name);
71420
+ if (!propertyType) {
71421
+ if (!ignoreIndexInfos) {
71422
+ indexInfoCandidates = append(indexInfoCandidates, constituentType);
71423
+ }
71424
+ continue;
71425
+ }
71426
+ ignoreIndexInfos = true;
71427
+ indexInfoCandidates = void 0;
71428
+ types = appendContextualPropertyTypeConstituent(types, propertyType);
71429
+ }
71430
+ if (indexInfoCandidates) {
71431
+ for (const candidate of indexInfoCandidates) {
71432
+ const indexInfoType = getTypeFromIndexInfosOfContextualType(candidate, name, nameType);
71433
+ types = appendContextualPropertyTypeConstituent(types, indexInfoType);
71434
+ }
71435
+ }
71436
+ if (!types) {
71437
+ return;
71404
71438
  }
71405
- return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))) == null ? void 0 : _a.type;
71439
+ if (types.length === 1) {
71440
+ return types[0];
71441
+ }
71442
+ return getIntersectionType(types);
71406
71443
  }
71407
- return void 0;
71444
+ if (!(t.flags & 524288 /* Object */)) {
71445
+ return;
71446
+ }
71447
+ return isGenericMappedType(t) && getMappedTypeNameTypeKind(t) !== 2 /* Remapping */ ? getIndexedMappedTypeSubstitutedTypeOfContextualType(t, name, nameType) : getTypeOfConcretePropertyOfContextualType(t, name) ?? getTypeFromIndexInfosOfContextualType(t, name, nameType);
71408
71448
  },
71409
71449
  /*noReductions*/
71410
71450
  true
71411
71451
  );
71412
71452
  }
71453
+ function appendContextualPropertyTypeConstituent(types, type) {
71454
+ return type ? append(types, type.flags & 1 /* Any */ ? unknownType : type) : types;
71455
+ }
71456
+ function getIndexedMappedTypeSubstitutedTypeOfContextualType(type, name, nameType) {
71457
+ const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name));
71458
+ const constraint = getConstraintTypeFromMappedType(type);
71459
+ if (type.nameType && isExcludedMappedPropertyName(type.nameType, propertyNameType) || isExcludedMappedPropertyName(constraint, propertyNameType)) {
71460
+ return;
71461
+ }
71462
+ const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
71463
+ if (!isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
71464
+ return;
71465
+ }
71466
+ return substituteIndexedMappedType(type, propertyNameType);
71467
+ }
71468
+ function getTypeOfConcretePropertyOfContextualType(type, name) {
71469
+ const prop = getPropertyOfType(type, name);
71470
+ if (!prop || isCircularMappedProperty(prop)) {
71471
+ return;
71472
+ }
71473
+ return removeMissingType(getTypeOfSymbol(prop), !!(prop.flags & 16777216 /* Optional */));
71474
+ }
71475
+ function getTypeFromIndexInfosOfContextualType(type, name, nameType) {
71476
+ var _a;
71477
+ if (isTupleType(type) && isNumericLiteralName(name) && +name >= 0) {
71478
+ const restType = getElementTypeOfSliceOfTupleType(
71479
+ type,
71480
+ type.target.fixedLength,
71481
+ /*endSkipCount*/
71482
+ 0,
71483
+ /*writing*/
71484
+ false,
71485
+ /*noReductions*/
71486
+ true
71487
+ );
71488
+ if (restType) {
71489
+ return restType;
71490
+ }
71491
+ }
71492
+ return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(type), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))) == null ? void 0 : _a.type;
71493
+ }
71413
71494
  function getContextualTypeForObjectLiteralMethod(node, contextFlags) {
71414
71495
  Debug.assert(isObjectLiteralMethod(node));
71415
71496
  if (node.flags & 67108864 /* InWithStatement */) {
@@ -91407,7 +91488,7 @@ function transformTypeScript(context) {
91407
91488
  let currentNamespaceContainerName;
91408
91489
  let currentLexicalScope;
91409
91490
  let currentScopeFirstDeclarationsOfName;
91410
- let enabledSubstitutions;
91491
+ let enabledSubstitutions = 0 /* None */;
91411
91492
  let applicableSubstitutions;
91412
91493
  return transformSourceFileOrBundle;
91413
91494
  function transformSourceFileOrBundle(node) {
@@ -93215,7 +93296,7 @@ function transformClassFields(context) {
93215
93296
  const previousOnEmitNode = context.onEmitNode;
93216
93297
  context.onEmitNode = onEmitNode;
93217
93298
  let shouldTransformPrivateStaticElementsInFile = false;
93218
- let enabledSubstitutions;
93299
+ let enabledSubstitutions = 0 /* None */;
93219
93300
  let classAliases;
93220
93301
  let pendingExpressions;
93221
93302
  let pendingStatements;
@@ -98144,7 +98225,7 @@ function transformES2017(context) {
98144
98225
  const resolver = context.getEmitResolver();
98145
98226
  const compilerOptions = context.getCompilerOptions();
98146
98227
  const languageVersion = getEmitScriptTarget(compilerOptions);
98147
- let enabledSubstitutions;
98228
+ let enabledSubstitutions = 0 /* None */;
98148
98229
  let enclosingSuperContainerFlags = 0;
98149
98230
  let enclosingFunctionParameterNames;
98150
98231
  let capturedSuperProperties;
@@ -99019,7 +99100,7 @@ function transformES2018(context) {
99019
99100
  const previousOnSubstituteNode = context.onSubstituteNode;
99020
99101
  context.onSubstituteNode = onSubstituteNode;
99021
99102
  let exportedVariableStatement = false;
99022
- let enabledSubstitutions;
99103
+ let enabledSubstitutions = 0 /* None */;
99023
99104
  let enclosingFunctionFlags;
99024
99105
  let parametersWithPrecedingObjectRestOrSpread;
99025
99106
  let enclosingSuperContainerFlags = 0;
@@ -102154,7 +102235,7 @@ function transformES2015(context) {
102154
102235
  );
102155
102236
  }
102156
102237
  let convertedLoopState;
102157
- let enabledSubstitutions;
102238
+ let enabledSubstitutions = 0 /* None */;
102158
102239
  return chainBundle(context, transformSourceFile);
102159
102240
  function transformSourceFile(node) {
102160
102241
  if (node.isDeclarationFile) {