@typescript-deploys/pr-build 5.4.0-pr-56908-56 → 5.4.0-pr-49218-45

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.4";
21
- var version = `${versionMajorMinor}.0-insiders.20240108`;
21
+ var version = `${versionMajorMinor}.0-insiders.20240110`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -12673,7 +12673,7 @@ function isPartOfTypeNode(node) {
12673
12673
  case 116 /* VoidKeyword */:
12674
12674
  return node.parent.kind !== 222 /* VoidExpression */;
12675
12675
  case 233 /* ExpressionWithTypeArguments */:
12676
- return isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
12676
+ return isPartOfTypeExpressionWithTypeArguments(node);
12677
12677
  case 168 /* TypeParameter */:
12678
12678
  return node.parent.kind === 200 /* MappedType */ || node.parent.kind === 195 /* InferType */;
12679
12679
  case 80 /* Identifier */:
@@ -12698,7 +12698,7 @@ function isPartOfTypeNode(node) {
12698
12698
  }
12699
12699
  switch (parent.kind) {
12700
12700
  case 233 /* ExpressionWithTypeArguments */:
12701
- return isHeritageClause(parent.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
12701
+ return isPartOfTypeExpressionWithTypeArguments(parent);
12702
12702
  case 168 /* TypeParameter */:
12703
12703
  return node === parent.constraint;
12704
12704
  case 352 /* JSDocTemplateTag */:
@@ -12732,6 +12732,9 @@ function isPartOfTypeNode(node) {
12732
12732
  }
12733
12733
  return false;
12734
12734
  }
12735
+ function isPartOfTypeExpressionWithTypeArguments(node) {
12736
+ return isJSDocImplementsTag(node.parent) || isJSDocAugmentsTag(node.parent) || isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
12737
+ }
12735
12738
  function forEachReturnStatement(body, visitor) {
12736
12739
  return traverse(body);
12737
12740
  function traverse(node) {
@@ -17492,6 +17495,9 @@ function hasContextSensitiveParameters(node) {
17492
17495
  function isInfinityOrNaNString(name) {
17493
17496
  return name === "Infinity" || name === "-Infinity" || name === "NaN";
17494
17497
  }
17498
+ function isCatchClauseVariableDeclaration(node) {
17499
+ return node.kind === 260 /* VariableDeclaration */ && node.parent.kind === 299 /* CatchClause */;
17500
+ }
17495
17501
  function isFunctionExpressionOrArrowFunction(node) {
17496
17502
  return node.kind === 218 /* FunctionExpression */ || node.kind === 219 /* ArrowFunction */;
17497
17503
  }
@@ -44278,6 +44284,14 @@ function createTypeChecker(host) {
44278
44284
  emptyArray,
44279
44285
  emptyArray
44280
44286
  );
44287
+ var resolvingApparentMappedType = createAnonymousType(
44288
+ /*symbol*/
44289
+ void 0,
44290
+ emptySymbols,
44291
+ emptyArray,
44292
+ emptyArray,
44293
+ emptyArray
44294
+ );
44281
44295
  var markerSuperType = createTypeParameter();
44282
44296
  var markerSubType = createTypeParameter();
44283
44297
  markerSubType.constraint = markerSuperType;
@@ -47327,29 +47341,7 @@ function createTypeChecker(host) {
47327
47341
  function getContainersOfSymbol(symbol, enclosingDeclaration, meaning) {
47328
47342
  const container = getParentOfSymbol(symbol);
47329
47343
  if (container && !(symbol.flags & 262144 /* TypeParameter */)) {
47330
- const additionalContainers = mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer);
47331
- const reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration);
47332
- const objectLiteralContainer = getVariableDeclarationOfObjectLiteral(container, meaning);
47333
- if (enclosingDeclaration && container.flags & getQualifiedLeftMeaning(meaning) && getAccessibleSymbolChain(
47334
- container,
47335
- enclosingDeclaration,
47336
- 1920 /* Namespace */,
47337
- /*useOnlyExternalAliasing*/
47338
- false
47339
- )) {
47340
- return append(concatenate(concatenate([container], additionalContainers), reexportContainers), objectLiteralContainer);
47341
- }
47342
- const firstVariableMatch = !(container.flags & getQualifiedLeftMeaning(meaning)) && container.flags & 788968 /* Type */ && getDeclaredTypeOfSymbol(container).flags & 524288 /* Object */ && meaning === 111551 /* Value */ ? forEachSymbolTableInScope(enclosingDeclaration, (t) => {
47343
- return forEachEntry(t, (s) => {
47344
- if (s.flags & getQualifiedLeftMeaning(meaning) && getTypeOfSymbol(s) === getDeclaredTypeOfSymbol(container)) {
47345
- return s;
47346
- }
47347
- });
47348
- }) : void 0;
47349
- let res = firstVariableMatch ? [firstVariableMatch, ...additionalContainers, container] : [...additionalContainers, container];
47350
- res = append(res, objectLiteralContainer);
47351
- res = addRange(res, reexportContainers);
47352
- return res;
47344
+ return getWithAlternativeContainers(container);
47353
47345
  }
47354
47346
  const candidates = mapDefined(symbol.declarations, (d) => {
47355
47347
  if (!isAmbientModule(d) && d.parent) {
@@ -47371,7 +47363,40 @@ function createTypeChecker(host) {
47371
47363
  if (!length(candidates)) {
47372
47364
  return void 0;
47373
47365
  }
47374
- return mapDefined(candidates, (candidate) => getAliasForSymbolInContainer(candidate, symbol) ? candidate : void 0);
47366
+ const containers = mapDefined(candidates, (candidate) => getAliasForSymbolInContainer(candidate, symbol) ? candidate : void 0);
47367
+ let bestContainers = [];
47368
+ let alternativeContainers = [];
47369
+ for (const container2 of containers) {
47370
+ const [bestMatch, ...rest] = getWithAlternativeContainers(container2);
47371
+ bestContainers = append(bestContainers, bestMatch);
47372
+ alternativeContainers = addRange(alternativeContainers, rest);
47373
+ }
47374
+ return concatenate(bestContainers, alternativeContainers);
47375
+ function getWithAlternativeContainers(container2) {
47376
+ const additionalContainers = mapDefined(container2.declarations, fileSymbolIfFileSymbolExportEqualsContainer);
47377
+ const reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration);
47378
+ const objectLiteralContainer = getVariableDeclarationOfObjectLiteral(container2, meaning);
47379
+ if (enclosingDeclaration && container2.flags & getQualifiedLeftMeaning(meaning) && getAccessibleSymbolChain(
47380
+ container2,
47381
+ enclosingDeclaration,
47382
+ 1920 /* Namespace */,
47383
+ /*useOnlyExternalAliasing*/
47384
+ false
47385
+ )) {
47386
+ return append(concatenate(concatenate([container2], additionalContainers), reexportContainers), objectLiteralContainer);
47387
+ }
47388
+ const firstVariableMatch = !(container2.flags & getQualifiedLeftMeaning(meaning)) && container2.flags & 788968 /* Type */ && getDeclaredTypeOfSymbol(container2).flags & 524288 /* Object */ && meaning === 111551 /* Value */ ? forEachSymbolTableInScope(enclosingDeclaration, (t) => {
47389
+ return forEachEntry(t, (s) => {
47390
+ if (s.flags & getQualifiedLeftMeaning(meaning) && getTypeOfSymbol(s) === getDeclaredTypeOfSymbol(container2)) {
47391
+ return s;
47392
+ }
47393
+ });
47394
+ }) : void 0;
47395
+ let res = firstVariableMatch ? [firstVariableMatch, ...additionalContainers, container2] : [...additionalContainers, container2];
47396
+ res = append(res, objectLiteralContainer);
47397
+ res = addRange(res, reexportContainers);
47398
+ return res;
47399
+ }
47375
47400
  function fileSymbolIfFileSymbolExportEqualsContainer(d) {
47376
47401
  return container && getFileSymbolIfFileSymbolExportEqualsContainer(d, container);
47377
47402
  }
@@ -47409,6 +47434,13 @@ function createTypeChecker(host) {
47409
47434
  });
47410
47435
  }
47411
47436
  function getSymbolIfSameReference(s1, s2) {
47437
+ var _a, _b;
47438
+ if (s1.flags & 524288 /* TypeAlias */ && ((_a = s2.declarations) == null ? void 0 : _a.find(isTypeAlias))) {
47439
+ s2 = getDeclaredTypeOfTypeAlias(s2).aliasSymbol || s2;
47440
+ }
47441
+ if (s2.flags & 524288 /* TypeAlias */ && ((_b = s1.declarations) == null ? void 0 : _b.find(isTypeAlias))) {
47442
+ s1 = getDeclaredTypeOfTypeAlias(s1).aliasSymbol || s1;
47443
+ }
47412
47444
  if (getMergedSymbol(resolveSymbol(getMergedSymbol(s1))) === getMergedSymbol(resolveSymbol(getMergedSymbol(s2)))) {
47413
47445
  return s1;
47414
47446
  }
@@ -55147,14 +55179,30 @@ function createTypeChecker(host) {
55147
55179
  return !!(typeParameter.symbol && forEach(typeParameter.symbol.declarations, (decl) => isTypeParameterDeclaration(decl) && decl.default));
55148
55180
  }
55149
55181
  function getApparentTypeOfMappedType(type) {
55150
- return type.resolvedApparentType || (type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type));
55182
+ if (type.resolvedApparentType) {
55183
+ if (type.resolvedApparentType === resolvingApparentMappedType) {
55184
+ return type.resolvedApparentType = type;
55185
+ }
55186
+ return type.resolvedApparentType;
55187
+ }
55188
+ type.resolvedApparentType = resolvingApparentMappedType;
55189
+ return type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type);
55151
55190
  }
55152
55191
  function getResolvedApparentTypeOfMappedType(type) {
55153
- const typeVariable = getHomomorphicTypeVariable(type);
55154
- if (typeVariable && !type.declaration.nameType) {
55155
- const constraint = getConstraintOfTypeParameter(typeVariable);
55192
+ const mappedType = type.target || type;
55193
+ const typeVariable = getHomomorphicTypeVariable(mappedType);
55194
+ if (typeVariable && !mappedType.declaration.nameType) {
55195
+ let constraint;
55196
+ if (!type.target) {
55197
+ constraint = getConstraintOfTypeParameter(typeVariable);
55198
+ } else {
55199
+ const modifiersConstraint = getConstraintOfType(getModifiersTypeFromMappedType(type));
55200
+ if (modifiersConstraint) {
55201
+ constraint = getApparentType(modifiersConstraint);
55202
+ }
55203
+ }
55156
55204
  if (constraint && everyType(constraint, isArrayOrTupleType)) {
55157
- return instantiateType(type, prependTypeMapping(typeVariable, constraint, type.mapper));
55205
+ return instantiateType(mappedType, prependTypeMapping(typeVariable, constraint, mappedType.mapper));
55158
55206
  }
55159
55207
  }
55160
55208
  return type;
@@ -55245,6 +55293,7 @@ function createTypeChecker(host) {
55245
55293
  clone2.parent = (_c = (_b = singleProp.valueDeclaration) == null ? void 0 : _b.symbol) == null ? void 0 : _c.parent;
55246
55294
  clone2.links.containingType = containingType;
55247
55295
  clone2.links.mapper = links == null ? void 0 : links.mapper;
55296
+ clone2.links.writeType = getWriteTypeOfSymbol(singleProp);
55248
55297
  return clone2;
55249
55298
  } else {
55250
55299
  return singleProp;
@@ -60480,7 +60529,37 @@ function createTypeChecker(host) {
60480
60529
  const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
60481
60530
  for (let i = 0; i < paramCount; i++) {
60482
60531
  const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i);
60483
- const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
60532
+ let targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
60533
+ if (i === restIndex && targetType && sourceType && isTupleType(sourceType)) {
60534
+ targetType = mapType(targetType, (t) => {
60535
+ if (!isTupleType(t) || // When both sides are tuples of the same structure, we don't want to "propagate" types from elements of variable positions
60536
+ // to the following positions as that would disallow signatures of the exact same structures when trailing fixed elements are involved:
60537
+ //
60538
+ // let fn: (...rest: [...string[], number]) => void = (...rest: [...string[], number]) => {}; // ok
60539
+ //
60540
+ // Since we want to allow contextual types to flow into paremeters, we don't need to differentiate between rest and variadic elements
60541
+ // as that doesn't affect the contextual type of the parameter
60542
+ isTupleTypeStructureMatching(sourceType, t, 2 /* MatchVariable */)) {
60543
+ return t;
60544
+ }
60545
+ const elementTypes = [];
60546
+ const elementFlags = [];
60547
+ const sourceArity = getTypeReferenceArity(sourceType);
60548
+ const targetArity = getTypeReferenceArity(t);
60549
+ for (let i2 = 0; i2 < sourceArity; i2++) {
60550
+ if (i2 >= targetArity) {
60551
+ if (sourceType.target.elementFlags[i2] & 3 /* Fixed */) {
60552
+ elementTypes.push(undefinedType);
60553
+ elementFlags.push(sourceType.target.elementFlags[i2]);
60554
+ }
60555
+ continue;
60556
+ }
60557
+ elementTypes.push(getTupleElementType(t, i2));
60558
+ elementFlags.push(sourceType.target.elementFlags[i2]);
60559
+ }
60560
+ return createTupleType(elementTypes, elementFlags);
60561
+ });
60562
+ }
60484
60563
  if (sourceType && targetType) {
60485
60564
  const sourceSig = checkMode & 3 /* Callback */ || isInstantiatedGenericParameter(source, i) ? void 0 : getSingleCallSignature(getNonNullableType(sourceType));
60486
60565
  const targetSig = checkMode & 3 /* Callback */ || isInstantiatedGenericParameter(target, i) ? void 0 : getSingleCallSignature(getNonNullableType(targetType));
@@ -61870,6 +61949,18 @@ function createTypeChecker(host) {
61870
61949
  }
61871
61950
  return result2;
61872
61951
  }
61952
+ function getApparentMappedTypeKeys(nameType, targetType) {
61953
+ const modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType));
61954
+ const mappedKeys = [];
61955
+ forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(
61956
+ modifiersType,
61957
+ 8576 /* StringOrNumberLiteralOrUnique */,
61958
+ /*stringsOnly*/
61959
+ false,
61960
+ (t) => void mappedKeys.push(instantiateType(nameType, appendTypeMapping(targetType.mapper, getTypeParameterFromMappedType(targetType), t)))
61961
+ );
61962
+ return getUnionType(mappedKeys);
61963
+ }
61873
61964
  function structuredTypeRelatedToWorker(source2, target2, reportErrors2, intersectionState, saveErrorInfo) {
61874
61965
  let result2;
61875
61966
  let originalErrorInfo;
@@ -62052,16 +62143,8 @@ function createTypeChecker(host) {
62052
62143
  const constraintType = getConstraintTypeFromMappedType(targetType);
62053
62144
  let targetKeys;
62054
62145
  if (nameType && isMappedTypeWithKeyofConstraintDeclaration(targetType)) {
62055
- const modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType));
62056
- const mappedKeys = [];
62057
- forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(
62058
- modifiersType,
62059
- 8576 /* StringOrNumberLiteralOrUnique */,
62060
- /*stringsOnly*/
62061
- false,
62062
- (t) => void mappedKeys.push(instantiateType(nameType, appendTypeMapping(targetType.mapper, getTypeParameterFromMappedType(targetType), t)))
62063
- );
62064
- targetKeys = getUnionType([...mappedKeys, nameType]);
62146
+ const mappedKeys = getApparentMappedTypeKeys(nameType, targetType);
62147
+ targetKeys = getUnionType([mappedKeys, nameType]);
62065
62148
  } else {
62066
62149
  targetKeys = nameType || constraintType;
62067
62150
  }
@@ -62232,9 +62315,18 @@ function createTypeChecker(host) {
62232
62315
  }
62233
62316
  }
62234
62317
  } else if (sourceFlags & 4194304 /* Index */) {
62235
- if (result2 = isRelatedTo(keyofConstraintType, target2, 1 /* Source */, reportErrors2)) {
62318
+ const isDeferredMappedIndex = shouldDeferIndexType(source2.type, source2.indexFlags) && getObjectFlags(source2.type) & 32 /* Mapped */;
62319
+ if (result2 = isRelatedTo(keyofConstraintType, target2, 1 /* Source */, reportErrors2 && !isDeferredMappedIndex)) {
62236
62320
  return result2;
62237
62321
  }
62322
+ if (isDeferredMappedIndex) {
62323
+ const mappedType = source2.type;
62324
+ const nameType = getNameTypeFromMappedType(mappedType);
62325
+ const sourceMappedKeys = nameType && isMappedTypeWithKeyofConstraintDeclaration(mappedType) ? getApparentMappedTypeKeys(nameType, mappedType) : nameType || getConstraintTypeFromMappedType(mappedType);
62326
+ if (result2 = isRelatedTo(sourceMappedKeys, target2, 1 /* Source */, reportErrors2)) {
62327
+ return result2;
62328
+ }
62329
+ }
62238
62330
  } else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
62239
62331
  if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
62240
62332
  const constraint = getBaseConstraintOfType(source2);
@@ -63724,8 +63816,11 @@ function createTypeChecker(host) {
63724
63816
  }
63725
63817
  return void 0;
63726
63818
  }
63727
- function isTupleTypeStructureMatching(t1, t2) {
63728
- return getTypeReferenceArity(t1) === getTypeReferenceArity(t2) && every(t1.target.elementFlags, (f, i) => (f & 12 /* Variable */) === (t2.target.elementFlags[i] & 12 /* Variable */));
63819
+ function isTupleTypeStructureMatching(t1, t2, tupleStructureComparisonKind) {
63820
+ return getTypeReferenceArity(t1) === getTypeReferenceArity(t2) && every(t1.target.elementFlags, (f1, i) => {
63821
+ const f2 = t2.target.elementFlags[i];
63822
+ return f1 === f2 || !!(tupleStructureComparisonKind & 1 /* MatchFixed */ && f1 & 3 /* Fixed */ && f2 & 3 /* Fixed */) || !!(tupleStructureComparisonKind & 2 /* MatchVariable */ && f1 & 12 /* Variable */ && f2 & 12 /* Variable */);
63823
+ });
63729
63824
  }
63730
63825
  function isZeroBigInt({ value }) {
63731
63826
  return value.base10Value === "0";
@@ -64933,7 +65028,7 @@ function createTypeChecker(host) {
64933
65028
  const targetArity = getTypeReferenceArity(target);
64934
65029
  const elementTypes = getTypeArguments(target);
64935
65030
  const elementFlags = target.target.elementFlags;
64936
- if (isTupleType(source) && isTupleTypeStructureMatching(source, target)) {
65031
+ if (isTupleType(source) && isTupleTypeStructureMatching(source, target, 1 /* MatchFixed */)) {
64937
65032
  for (let i = 0; i < targetArity; i++) {
64938
65033
  inferFromTypes(getTypeArguments(source)[i], elementTypes[i]);
64939
65034
  }
@@ -66180,7 +66275,7 @@ function createTypeChecker(host) {
66180
66275
  case 206 /* ObjectBindingPattern */:
66181
66276
  case 207 /* ArrayBindingPattern */:
66182
66277
  const rootDeclaration = getRootDeclaration(node.parent);
66183
- return isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
66278
+ return isParameter(rootDeclaration) || isCatchClauseVariableDeclaration(rootDeclaration) ? !isSomeSymbolAssigned(rootDeclaration) : isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
66184
66279
  }
66185
66280
  return false;
66186
66281
  }
@@ -113474,7 +113569,14 @@ function createPrinter(printerOptions = {}, handlers = {}) {
113474
113569
  function willEmitLeadingNewLine(node) {
113475
113570
  if (!currentSourceFile)
113476
113571
  return false;
113477
- if (some(getLeadingCommentRanges(currentSourceFile.text, node.pos), commentWillEmitNewLine))
113572
+ const leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos);
113573
+ if (leadingCommentRanges) {
113574
+ const parseNode = getParseTreeNode(node);
113575
+ if (parseNode && isParenthesizedExpression(parseNode.parent)) {
113576
+ return true;
113577
+ }
113578
+ }
113579
+ if (some(leadingCommentRanges, commentWillEmitNewLine))
113478
113580
  return true;
113479
113581
  if (some(getSyntheticLeadingComments(node), commentWillEmitNewLine))
113480
113582
  return true;