typescript 5.0.0-dev.20221216 → 5.0.0-dev.20221217

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.20221216`;
26
+ var version = `${versionMajorMinor}.0-dev.20221217`;
27
27
 
28
28
  // src/compiler/core.ts
29
29
  var emptyArray = [];
@@ -5807,6 +5807,7 @@ var Diagnostics = {
5807
5807
  _0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias: diag(1274, 1 /* Error */, "_0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias_1274", "'{0}' modifier can only appear on a type parameter of a class, interface or type alias"),
5808
5808
  accessor_modifier_can_only_appear_on_a_property_declaration: diag(1275, 1 /* Error */, "accessor_modifier_can_only_appear_on_a_property_declaration_1275", "'accessor' modifier can only appear on a property declaration."),
5809
5809
  An_accessor_property_cannot_be_declared_optional: diag(1276, 1 /* Error */, "An_accessor_property_cannot_be_declared_optional_1276", "An 'accessor' property cannot be declared optional."),
5810
+ _0_modifier_can_only_appear_on_a_type_parameter_of_a_function_method_or_class: diag(1277, 1 /* Error */, "_0_modifier_can_only_appear_on_a_type_parameter_of_a_function_method_or_class_1277", "'{0}' modifier can only appear on a type parameter of a function, method or class"),
5810
5811
  with_statements_are_not_allowed_in_an_async_function_block: diag(1300, 1 /* Error */, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."),
5811
5812
  await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, 1 /* Error */, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."),
5812
5813
  The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level: diag(1309, 1 /* Error */, "The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level_1309", "The current file is a CommonJS module and cannot use 'await' at the top level."),
@@ -9956,12 +9957,10 @@ function formatJSDocLink(link) {
9956
9957
  }
9957
9958
  function getEffectiveTypeParameterDeclarations(node) {
9958
9959
  if (isJSDocSignature(node)) {
9959
- if (isJSDoc(node.parent)) {
9960
- const overloadTag = find(node.parent.tags, (tag) => {
9961
- return isJSDocOverloadTag(tag) && tag.typeExpression === node;
9962
- });
9963
- if (overloadTag) {
9964
- return flatMap(node.parent.tags, (tag) => isJSDocTemplateTag(tag) ? tag.typeParameters : void 0);
9960
+ if (isJSDocOverloadTag(node.parent)) {
9961
+ const jsDoc = getJSDocRoot(node.parent);
9962
+ if (jsDoc && length(jsDoc.tags)) {
9963
+ return flatMap(jsDoc.tags, (tag) => isJSDocTemplateTag(tag) ? tag.typeParameters : void 0);
9965
9964
  }
9966
9965
  }
9967
9966
  return emptyArray;
@@ -10778,18 +10777,6 @@ function changesAffectingProgramStructure(oldOptions, newOptions) {
10778
10777
  function optionsHaveChanges(oldOptions, newOptions, optionDeclarations2) {
10779
10778
  return oldOptions !== newOptions && optionDeclarations2.some((o) => !isJsonEqual(getCompilerOptionValue(oldOptions, o), getCompilerOptionValue(newOptions, o)));
10780
10779
  }
10781
- function forEachAncestor(node, callback) {
10782
- while (true) {
10783
- const res = callback(node);
10784
- if (res === "quit")
10785
- return void 0;
10786
- if (res !== void 0)
10787
- return res;
10788
- if (isSourceFile(node))
10789
- return void 0;
10790
- node = node.parent;
10791
- }
10792
- }
10793
10780
  function forEachEntry(map2, callback) {
10794
10781
  const iterator = map2.entries();
10795
10782
  for (let iterResult = iterator.next(); !iterResult.done; iterResult = iterator.next()) {
@@ -23881,6 +23868,7 @@ var forEachChildTable = {
23881
23868
  [346 /* JSDocThisTag */]: forEachChildInJSDocTypeLikeTag,
23882
23869
  [343 /* JSDocEnumTag */]: forEachChildInJSDocTypeLikeTag,
23883
23870
  [352 /* JSDocThrowsTag */]: forEachChildInJSDocTypeLikeTag,
23871
+ [342 /* JSDocOverloadTag */]: forEachChildInJSDocTypeLikeTag,
23884
23872
  [326 /* JSDocSignature */]: function forEachChildInJSDocSignature(node, cbNode, _cbNodes) {
23885
23873
  return forEach(node.typeParameters, cbNode) || forEach(node.parameters, cbNode) || visitNode2(cbNode, node.type);
23886
23874
  },
@@ -24980,7 +24968,7 @@ var Parser;
24980
24968
  case ParsingContext.ArrayBindingElements:
24981
24969
  return token() === 27 /* CommaToken */ || token() === 25 /* DotDotDotToken */ || isBindingIdentifierOrPrivateIdentifierOrPattern();
24982
24970
  case ParsingContext.TypeParameters:
24983
- return token() === 101 /* InKeyword */ || isIdentifier2();
24971
+ return token() === 101 /* InKeyword */ || token() === 85 /* ConstKeyword */ || isIdentifier2();
24984
24972
  case ParsingContext.ArrayLiteralMembers:
24985
24973
  switch (token()) {
24986
24974
  case 27 /* CommaToken */:
@@ -25685,7 +25673,7 @@ var Parser;
25685
25673
  }
25686
25674
  function parseTypeParameter() {
25687
25675
  const pos = getNodePos();
25688
- const modifiers = parseModifiers();
25676
+ const modifiers = parseModifiers(true);
25689
25677
  const name = parseIdentifier();
25690
25678
  let constraint;
25691
25679
  let expression;
@@ -26648,11 +26636,12 @@ var Parser;
26648
26636
  return Tristate.False;
26649
26637
  } else {
26650
26638
  Debug.assert(first2 === 29 /* LessThanToken */);
26651
- if (!isIdentifier2()) {
26639
+ if (!isIdentifier2() && token() !== 85 /* ConstKeyword */) {
26652
26640
  return Tristate.False;
26653
26641
  }
26654
26642
  if (languageVariant === 1 /* JSX */) {
26655
26643
  const isArrowFunctionInJsx = lookAhead(() => {
26644
+ parseOptional(85 /* ConstKeyword */);
26656
26645
  const third = nextToken();
26657
26646
  if (third === 94 /* ExtendsKeyword */) {
26658
26647
  const fourth = nextToken();
@@ -28375,10 +28364,10 @@ var Parser;
28375
28364
  }
28376
28365
  return list && createNodeArray(list, pos);
28377
28366
  }
28378
- function tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
28367
+ function tryParseModifier(permitConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
28379
28368
  const pos = getNodePos();
28380
28369
  const kind = token();
28381
- if (token() === 85 /* ConstKeyword */ && permitInvalidConstAsModifier) {
28370
+ if (token() === 85 /* ConstKeyword */ && permitConstAsModifier) {
28382
28371
  if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) {
28383
28372
  return void 0;
28384
28373
  }
@@ -28402,10 +28391,10 @@ var Parser;
28402
28391
  setTextRangePosEnd(decoratorsAndModifiers, decorators.pos, modifiers.end);
28403
28392
  return decoratorsAndModifiers;
28404
28393
  }
28405
- function parseModifiers(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock) {
28394
+ function parseModifiers(permitConstAsModifier, stopOnStartOfClassStaticBlock) {
28406
28395
  const pos = getNodePos();
28407
28396
  let list, modifier, hasSeenStatic = false;
28408
- while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
28397
+ while (modifier = tryParseModifier(permitConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
28409
28398
  if (modifier.kind === 124 /* StaticKeyword */)
28410
28399
  hasSeenStatic = true;
28411
28400
  list = append(list, modifier);
@@ -39657,6 +39646,11 @@ function createTypeChecker(host) {
39657
39646
  let lastFlowNode;
39658
39647
  let lastFlowNodeReachable;
39659
39648
  let flowTypeCache;
39649
+ const contextualTypeNodes = [];
39650
+ const contextualTypes = [];
39651
+ let contextualTypeCount = 0;
39652
+ let currentInferenceNode;
39653
+ let currentInferenceContext;
39660
39654
  const emptyStringType = getStringLiteralType("");
39661
39655
  const zeroType = getNumberLiteralType(0);
39662
39656
  const zeroBigIntType = getBigIntLiteralType({ negative: false, base10Value: "0" });
@@ -40101,9 +40095,6 @@ function createTypeChecker(host) {
40101
40095
  const nodeId = getNodeId(node);
40102
40096
  return nodeLinks[nodeId] || (nodeLinks[nodeId] = new NodeLinks());
40103
40097
  }
40104
- function tryGetNodeLinks(node) {
40105
- return node.id ? nodeLinks[node.id] : void 0;
40106
- }
40107
40098
  function isGlobalSourceFile(node) {
40108
40099
  return node.kind === 308 /* SourceFile */ && !isExternalOrCommonJsModule(node);
40109
40100
  }
@@ -43580,7 +43571,7 @@ function createTypeChecker(host) {
43580
43571
  function typeParameterToDeclarationWithConstraint(type, context, constraintNode) {
43581
43572
  const savedContextFlags = context.flags;
43582
43573
  context.flags &= ~512 /* WriteTypeParametersInQualifiedName */;
43583
- const modifiers = factory.createModifiersFromModifierFlags(getVarianceModifiers(type));
43574
+ const modifiers = factory.createModifiersFromModifierFlags(getTypeParameterModifiers(type));
43584
43575
  const name = typeParameterToName(type, context);
43585
43576
  const defaultParameter = getDefaultFromTypeParameter(type);
43586
43577
  const defaultParameterNode = defaultParameter && typeToTypeNodeHelper(defaultParameter, context);
@@ -48248,6 +48239,10 @@ function createTypeChecker(host) {
48248
48239
  function getConstraintOfTypeParameter(typeParameter) {
48249
48240
  return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : void 0;
48250
48241
  }
48242
+ function isConstTypeVariable(type) {
48243
+ var _a2;
48244
+ return !!(type.flags & 262144 /* TypeParameter */ && some((_a2 = type.symbol) == null ? void 0 : _a2.declarations, (d) => hasSyntacticModifier(d, 2048 /* Const */)) || type.flags & 8388608 /* IndexedAccess */ && isConstTypeVariable(type.objectType));
48245
+ }
48251
48246
  function getConstraintOfIndexedAccess(type) {
48252
48247
  return hasNonCircularBaseConstraint(type) ? getConstraintFromIndexedAccess(type) : void 0;
48253
48248
  }
@@ -52675,13 +52670,10 @@ function createTypeChecker(host) {
52675
52670
  }
52676
52671
  }
52677
52672
  function checkExpressionForMutableLocationWithContextualType(next, sourcePropType) {
52678
- const links = getNodeLinks(next);
52679
- links.contextualType = sourcePropType;
52680
- try {
52681
- return checkExpressionForMutableLocation(next, 1 /* Contextual */, sourcePropType);
52682
- } finally {
52683
- links.contextualType = void 0;
52684
- }
52673
+ pushContextualType(next, sourcePropType);
52674
+ const result = checkExpressionForMutableLocation(next, 1 /* Contextual */);
52675
+ popContextualType();
52676
+ return result;
52685
52677
  }
52686
52678
  function elaborateElementwise(iterator, source, target, relation, containingMessageChain, errorOutputContainer) {
52687
52679
  let reportedError = false;
@@ -52880,19 +52872,13 @@ function createTypeChecker(host) {
52880
52872
  if (isTupleLikeType(source)) {
52881
52873
  return elaborateElementwise(generateLimitedTupleElements(node, target), source, target, relation, containingMessageChain, errorOutputContainer);
52882
52874
  }
52883
- const links = getNodeLinks(node);
52884
- const oldContext = links.contextualType;
52885
- links.contextualType = target;
52886
- try {
52887
- const tupleizedType = checkArrayLiteral(node, 1 /* Contextual */, true);
52888
- links.contextualType = oldContext;
52889
- if (isTupleLikeType(tupleizedType)) {
52890
- return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
52891
- }
52892
- return false;
52893
- } finally {
52894
- links.contextualType = oldContext;
52875
+ pushContextualType(node, target);
52876
+ const tupleizedType = checkArrayLiteral(node, 1 /* Contextual */, true);
52877
+ popContextualType();
52878
+ if (isTupleLikeType(tupleizedType)) {
52879
+ return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
52895
52880
  }
52881
+ return false;
52896
52882
  }
52897
52883
  function* generateObjectLiteralElements(node) {
52898
52884
  if (!length(node.properties))
@@ -53994,6 +53980,9 @@ function createTypeChecker(host) {
53994
53980
  if (result2 && !inPropertyCheck && (target2.flags & 2097152 /* Intersection */ && !isGenericObjectType(target2) && source2.flags & (524288 /* Object */ | 2097152 /* Intersection */) || isNonGenericObjectType(target2) && !isArrayOrTupleType(target2) && source2.flags & 2097152 /* Intersection */ && getApparentType(source2).flags & 3670016 /* StructuredType */ && !some(source2.types, (t) => !!(getObjectFlags(t) & 262144 /* NonInferrableType */)))) {
53995
53981
  inPropertyCheck = true;
53996
53982
  result2 &= propertiesRelatedTo(source2, target2, reportErrors2, void 0, 0 /* None */);
53983
+ if (result2 && isObjectLiteralType(source2) && getObjectFlags(source2) & 8192 /* FreshLiteral */) {
53984
+ result2 &= indexSignaturesRelatedTo(source2, target2, false, reportErrors2, 0 /* None */);
53985
+ }
53997
53986
  inPropertyCheck = false;
53998
53987
  }
53999
53988
  }
@@ -54895,7 +54884,7 @@ function createTypeChecker(host) {
54895
54884
  }
54896
54885
  return result2;
54897
54886
  }
54898
- function membersRelatedToIndexInfo(source2, targetInfo, reportErrors2) {
54887
+ function membersRelatedToIndexInfo(source2, targetInfo, reportErrors2, intersectionState) {
54899
54888
  let result2 = -1 /* True */;
54900
54889
  const keyType = targetInfo.keyType;
54901
54890
  const props = source2.flags & 2097152 /* Intersection */ ? getPropertiesOfUnionOrIntersectionType(source2) : getPropertiesOfObjectType(source2);
@@ -54906,7 +54895,7 @@ function createTypeChecker(host) {
54906
54895
  if (isApplicableIndexType(getLiteralTypeFromProperty(prop, 8576 /* StringOrNumberLiteralOrUnique */), keyType)) {
54907
54896
  const propType = getNonMissingTypeOfSymbol(prop);
54908
54897
  const type = exactOptionalPropertyTypes || propType.flags & 32768 /* Undefined */ || keyType === numberType || !(prop.flags & 16777216 /* Optional */) ? propType : getTypeWithFacts(propType, 524288 /* NEUndefined */);
54909
- const related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors2);
54898
+ const related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors2, void 0, intersectionState);
54910
54899
  if (!related) {
54911
54900
  if (reportErrors2) {
54912
54901
  reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop));
@@ -54960,7 +54949,7 @@ function createTypeChecker(host) {
54960
54949
  return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors2);
54961
54950
  }
54962
54951
  if (!(intersectionState & 1 /* Source */) && isObjectTypeWithInferableIndex(source2)) {
54963
- return membersRelatedToIndexInfo(source2, targetInfo, reportErrors2);
54952
+ return membersRelatedToIndexInfo(source2, targetInfo, reportErrors2, intersectionState);
54964
54953
  }
54965
54954
  if (reportErrors2) {
54966
54955
  reportError(Diagnostics.Index_signature_for_type_0_is_missing_in_type_1, typeToString(targetInfo.keyType), typeToString(source2));
@@ -55094,7 +55083,7 @@ function createTypeChecker(host) {
55094
55083
  links.variances = emptyArray;
55095
55084
  const variances = [];
55096
55085
  for (const tp of typeParameters) {
55097
- const modifiers = getVarianceModifiers(tp);
55086
+ const modifiers = getTypeParameterModifiers(tp);
55098
55087
  let variance = modifiers & 65536 /* Out */ ? modifiers & 32768 /* In */ ? 0 /* Invariant */ : 1 /* Covariant */ : modifiers & 32768 /* In */ ? 2 /* Contravariant */ : void 0;
55099
55088
  if (variance === void 0) {
55100
55089
  let unmeasurable = false;
@@ -55137,9 +55126,9 @@ function createTypeChecker(host) {
55137
55126
  function isMarkerType(type) {
55138
55127
  return markerTypes.has(getTypeId(type));
55139
55128
  }
55140
- function getVarianceModifiers(tp) {
55141
- var _a2, _b;
55142
- return (some((_a2 = tp.symbol) == null ? void 0 : _a2.declarations, (d) => hasSyntacticModifier(d, 32768 /* In */)) ? 32768 /* In */ : 0) | (some((_b = tp.symbol) == null ? void 0 : _b.declarations, (d) => hasSyntacticModifier(d, 65536 /* Out */)) ? 65536 /* Out */ : 0);
55129
+ function getTypeParameterModifiers(tp) {
55130
+ var _a2;
55131
+ return reduceLeft((_a2 = tp.symbol) == null ? void 0 : _a2.declarations, (modifiers, d) => modifiers | getEffectiveModifierFlags(d), 0 /* None */) & (32768 /* In */ | 65536 /* Out */ | 2048 /* Const */);
55143
55132
  }
55144
55133
  function hasCovariantVoidArgument(typeArguments, variances) {
55145
55134
  for (let i = 0; i < variances.length; i++) {
@@ -56776,7 +56765,7 @@ function createTypeChecker(host) {
56776
56765
  }
56777
56766
  function getCovariantInference(inference, signature) {
56778
56767
  const candidates = unionObjectAndArrayLiteralCandidates(inference.candidates);
56779
- const primitiveConstraint = hasPrimitiveConstraint(inference.typeParameter);
56768
+ const primitiveConstraint = hasPrimitiveConstraint(inference.typeParameter) || isConstTypeVariable(inference.typeParameter);
56780
56769
  const widenLiteralTypes = !primitiveConstraint && inference.topLevel && (inference.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), inference.typeParameter));
56781
56770
  const baseCandidates = primitiveConstraint ? sameMap(candidates, getRegularTypeOfLiteralType) : widenLiteralTypes ? sameMap(candidates, getWidenedLiteralType) : candidates;
56782
56771
  const unwidenedType = inference.priority & 416 /* PriorityImpliesCombination */ ? getUnionType(baseCandidates, 2 /* Subtype */) : getCommonSupertype(baseCandidates);
@@ -59831,13 +59820,12 @@ function createTypeChecker(host) {
59831
59820
  return type;
59832
59821
  }
59833
59822
  function getContextualType(node, contextFlags) {
59834
- var _a2;
59835
59823
  if (node.flags & 33554432 /* InWithStatement */) {
59836
59824
  return void 0;
59837
59825
  }
59838
- const contextualType = (_a2 = tryGetNodeLinks(node)) == null ? void 0 : _a2.contextualType;
59839
- if (contextualType) {
59840
- return contextualType;
59826
+ const index = findContextualNode(node);
59827
+ if (index >= 0) {
59828
+ return contextualTypes[index];
59841
59829
  }
59842
59830
  const { parent } = node;
59843
59831
  switch (parent.kind) {
@@ -59859,7 +59847,7 @@ function createTypeChecker(host) {
59859
59847
  return getContextualTypeForArgument(parent, node);
59860
59848
  case 213 /* TypeAssertionExpression */:
59861
59849
  case 231 /* AsExpression */:
59862
- return isConstTypeReference(parent.type) ? tryFindWhenConstTypeReference(parent) : getTypeFromTypeNode(parent.type);
59850
+ return isConstTypeReference(parent.type) ? getContextualType(parent, contextFlags) : getTypeFromTypeNode(parent.type);
59863
59851
  case 223 /* BinaryExpression */:
59864
59852
  return getContextualTypeForBinaryOperand(node, contextFlags);
59865
59853
  case 299 /* PropertyAssignment */:
@@ -59879,7 +59867,7 @@ function createTypeChecker(host) {
59879
59867
  return getContextualTypeForSubstitutionExpression(parent.parent, node);
59880
59868
  case 214 /* ParenthesizedExpression */: {
59881
59869
  const tag = isInJSFile(parent) ? getJSDocTypeTag(parent) : void 0;
59882
- return !tag ? getContextualType(parent, contextFlags) : isJSDocTypeTag(tag) && isConstTypeReference(tag.typeExpression.type) ? tryFindWhenConstTypeReference(parent) : getTypeFromTypeNode(tag.typeExpression.type);
59870
+ return !tag ? getContextualType(parent, contextFlags) : isJSDocTypeTag(tag) && isConstTypeReference(tag.typeExpression.type) ? getContextualType(parent, contextFlags) : getTypeFromTypeNode(tag.typeExpression.type);
59883
59871
  }
59884
59872
  case 232 /* NonNullExpression */:
59885
59873
  return getContextualType(parent, contextFlags);
@@ -59897,22 +59885,31 @@ function createTypeChecker(host) {
59897
59885
  return getContextualJsxElementAttributesType(parent, contextFlags);
59898
59886
  }
59899
59887
  return void 0;
59900
- function tryFindWhenConstTypeReference(node2) {
59901
- return getContextualType(node2, contextFlags);
59888
+ }
59889
+ function pushContextualType(node, type) {
59890
+ contextualTypeNodes[contextualTypeCount] = node;
59891
+ contextualTypes[contextualTypeCount] = type;
59892
+ contextualTypeCount++;
59893
+ }
59894
+ function popContextualType() {
59895
+ contextualTypeCount--;
59896
+ }
59897
+ function findContextualNode(node) {
59898
+ for (let i = contextualTypeCount - 1; i >= 0; i--) {
59899
+ if (node === contextualTypeNodes[i]) {
59900
+ return i;
59901
+ }
59902
59902
  }
59903
+ return -1;
59903
59904
  }
59904
59905
  function getInferenceContext(node) {
59905
- return forEachAncestor(node, (n) => {
59906
- var _a2;
59907
- return (_a2 = tryGetNodeLinks(n)) == null ? void 0 : _a2.inferenceContext;
59908
- });
59906
+ return isNodeDescendantOf(node, currentInferenceNode) ? currentInferenceContext : void 0;
59909
59907
  }
59910
59908
  function getContextualJsxElementAttributesType(node, contextFlags) {
59911
- var _a2;
59912
59909
  if (isJsxOpeningElement(node) && contextFlags !== 4 /* Completions */) {
59913
- const contextualType = (_a2 = tryGetNodeLinks(node.parent)) == null ? void 0 : _a2.contextualType;
59914
- if (contextualType) {
59915
- return contextualType;
59910
+ const index = findContextualNode(node.parent);
59911
+ if (index >= 0) {
59912
+ return contextualTypes[index];
59916
59913
  }
59917
59914
  }
59918
59915
  return getContextualTypeForArgumentAtIndex(node, 0);
@@ -60169,9 +60166,11 @@ function createTypeChecker(host) {
60169
60166
  const elementCount = elements.length;
60170
60167
  const elementTypes = [];
60171
60168
  const elementFlags = [];
60172
- const contextualType = getApparentTypeOfContextualType(node, void 0);
60169
+ pushContextualType(node, getContextualType(node, void 0));
60173
60170
  const inDestructuringPattern = isAssignmentTarget(node);
60174
60171
  const inConstContext = isConstContext(node);
60172
+ const contextualType = getApparentTypeOfContextualType(node, void 0);
60173
+ const inTupleContext = !!contextualType && someType(contextualType, isTupleLikeType);
60175
60174
  let hasOmittedExpression = false;
60176
60175
  for (let i = 0; i < elementCount; i++) {
60177
60176
  const e = elements[i];
@@ -60196,21 +60195,21 @@ function createTypeChecker(host) {
60196
60195
  elementTypes.push(undefinedOrMissingType);
60197
60196
  elementFlags.push(2 /* Optional */);
60198
60197
  } else {
60199
- const elementContextualType = getContextualTypeForElementExpression(contextualType, elementTypes.length);
60200
- const type = checkExpressionForMutableLocation(e, checkMode, elementContextualType, forceTuple);
60198
+ const type = checkExpressionForMutableLocation(e, checkMode, forceTuple);
60201
60199
  elementTypes.push(addOptionality(type, true, hasOmittedExpression));
60202
60200
  elementFlags.push(hasOmittedExpression ? 2 /* Optional */ : 1 /* Required */);
60203
- if (contextualType && someType(contextualType, isTupleLikeType) && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
60201
+ if (inTupleContext && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
60204
60202
  const inferenceContext = getInferenceContext(node);
60205
60203
  Debug.assert(inferenceContext);
60206
60204
  addIntraExpressionInferenceSite(inferenceContext, e, type);
60207
60205
  }
60208
60206
  }
60209
60207
  }
60208
+ popContextualType();
60210
60209
  if (inDestructuringPattern) {
60211
60210
  return createTupleType(elementTypes, elementFlags);
60212
60211
  }
60213
- if (forceTuple || inConstContext || contextualType && someType(contextualType, isTupleLikeType)) {
60212
+ if (forceTuple || inConstContext || inTupleContext) {
60214
60213
  return createArrayLiteralType(createTupleType(elementTypes, elementFlags, inConstContext));
60215
60214
  }
60216
60215
  return createArrayLiteralType(createArrayType(elementTypes.length ? getUnionType(sameMap(elementTypes, (t, i) => elementFlags[i] & 8 /* Variadic */ ? getIndexedAccessTypeOrUndefined(t, numberType) || anyType : t), 2 /* Subtype */) : strictNullChecks ? implicitNeverType : undefinedWideningType, inConstContext));
@@ -60304,6 +60303,7 @@ function createTypeChecker(host) {
60304
60303
  let propertiesTable = createSymbolTable();
60305
60304
  let propertiesArray = [];
60306
60305
  let spread = emptyObjectType;
60306
+ pushContextualType(node, getContextualType(node, void 0));
60307
60307
  const contextualType = getApparentTypeOfContextualType(node, void 0);
60308
60308
  const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === 203 /* ObjectBindingPattern */ || contextualType.pattern.kind === 207 /* ObjectLiteralExpression */);
60309
60309
  const inConstContext = isConstContext(node);
@@ -60425,6 +60425,7 @@ function createTypeChecker(host) {
60425
60425
  }
60426
60426
  propertiesArray.push(member);
60427
60427
  }
60428
+ popContextualType();
60428
60429
  if (contextualTypeHasPattern) {
60429
60430
  const rootPatternParent = findAncestor(
60430
60431
  contextualType.pattern.parent,
@@ -62012,6 +62013,7 @@ function createTypeChecker(host) {
62012
62013
  const types = [];
62013
62014
  const flags = [];
62014
62015
  const names = [];
62016
+ const inConstContext = isConstTypeVariable(restType);
62015
62017
  for (let i = index; i < argCount; i++) {
62016
62018
  const arg = args[i];
62017
62019
  if (isSpreadArgument(arg)) {
@@ -62026,7 +62028,7 @@ function createTypeChecker(host) {
62026
62028
  } else {
62027
62029
  const contextualType = getIndexedAccessType(restType, getNumberLiteralType(i - index), 256 /* Contextual */);
62028
62030
  const argType = checkExpressionWithContextualType(arg, contextualType, context, checkMode);
62029
- const hasPrimitiveContextualType = maybeTypeOfKind(contextualType, 131068 /* Primitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */);
62031
+ const hasPrimitiveContextualType = inConstContext || maybeTypeOfKind(contextualType, 131068 /* Primitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */);
62030
62032
  types.push(hasPrimitiveContextualType ? getRegularTypeOfLiteralType(argType) : getWidenedLiteralType(argType));
62031
62033
  flags.push(1 /* Required */);
62032
62034
  }
@@ -62034,7 +62036,7 @@ function createTypeChecker(host) {
62034
62036
  names.push(arg.tupleNameSource);
62035
62037
  }
62036
62038
  }
62037
- return createTupleType(types, flags, false, length(names) === length(types) ? names : void 0);
62039
+ return createTupleType(types, flags, inConstContext, length(names) === length(types) ? names : void 0);
62038
62040
  }
62039
62041
  function checkTypeArguments(signature, typeArgumentNodes, reportErrors2, headMessage) {
62040
62042
  const isJavascript = isInJSFile(signature.declaration);
@@ -63498,12 +63500,9 @@ function createTypeChecker(host) {
63498
63500
  return op === 40 /* MinusToken */ && (arg.kind === 8 /* NumericLiteral */ || arg.kind === 9 /* BigIntLiteral */) || op === 39 /* PlusToken */ && arg.kind === 8 /* NumericLiteral */;
63499
63501
  case 208 /* PropertyAccessExpression */:
63500
63502
  case 209 /* ElementAccessExpression */:
63501
- const expr = node.expression;
63502
- let symbol = getTypeOfNode(expr).symbol;
63503
- if (symbol && symbol.flags & 2097152 /* Alias */) {
63504
- symbol = resolveAlias(symbol);
63505
- }
63506
- return !!(symbol && getAllSymbolFlags(symbol) & 384 /* Enum */);
63503
+ const expr = skipParentheses(node.expression);
63504
+ const symbol = isEntityNameExpression(expr) ? resolveEntityName(expr, 111551 /* Value */, true) : void 0;
63505
+ return !!(symbol && symbol.flags & 384 /* Enum */);
63507
63506
  }
63508
63507
  return false;
63509
63508
  }
@@ -65411,23 +65410,21 @@ function createTypeChecker(host) {
65411
65410
  return node;
65412
65411
  }
65413
65412
  function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
65414
- const context = getContextNode(node);
65415
- const links = getNodeLinks(context);
65416
- const saveContextualType = links.contextualType;
65417
- const saveInferenceContext = links.inferenceContext;
65418
- try {
65419
- links.contextualType = contextualType;
65420
- links.inferenceContext = inferenceContext;
65421
- const type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
65422
- if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
65423
- inferenceContext.intraExpressionInferenceSites = void 0;
65424
- }
65425
- const result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, void 0)) ? getRegularTypeOfLiteralType(type) : type;
65426
- return result;
65427
- } finally {
65428
- links.contextualType = saveContextualType;
65429
- links.inferenceContext = saveInferenceContext;
65430
- }
65413
+ const contextNode = getContextNode(node);
65414
+ pushContextualType(contextNode, contextualType);
65415
+ const saveInferenceNode = currentInferenceNode;
65416
+ const saveInferenceContext = currentInferenceContext;
65417
+ currentInferenceNode = contextNode;
65418
+ currentInferenceContext = inferenceContext;
65419
+ const type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
65420
+ if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
65421
+ inferenceContext.intraExpressionInferenceSites = void 0;
65422
+ }
65423
+ const result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, void 0)) ? getRegularTypeOfLiteralType(type) : type;
65424
+ currentInferenceNode = saveInferenceNode;
65425
+ currentInferenceContext = saveInferenceContext;
65426
+ popContextualType();
65427
+ return result;
65431
65428
  }
65432
65429
  function checkExpressionCached(node, checkMode) {
65433
65430
  if (checkMode) {
@@ -65499,11 +65496,15 @@ function createTypeChecker(host) {
65499
65496
  }
65500
65497
  function isConstContext(node) {
65501
65498
  const parent = node.parent;
65502
- return isAssertionExpression(parent) && isConstTypeReference(parent.type) || isJSDocTypeAssertion(parent) && isConstTypeReference(getJSDocTypeAssertionType(parent)) || (isParenthesizedExpression(parent) || isArrayLiteralExpression(parent) || isSpreadElement(parent)) && isConstContext(parent) || (isPropertyAssignment(parent) || isShorthandPropertyAssignment(parent) || isTemplateSpan(parent)) && isConstContext(parent.parent);
65499
+ return isAssertionExpression(parent) && isConstTypeReference(parent.type) || isJSDocTypeAssertion(parent) && isConstTypeReference(getJSDocTypeAssertionType(parent)) || isValidConstAssertionArgument(node) && isConstTypeParameterContext(node) || (isParenthesizedExpression(parent) || isArrayLiteralExpression(parent) || isSpreadElement(parent)) && isConstContext(parent) || (isPropertyAssignment(parent) || isShorthandPropertyAssignment(parent) || isTemplateSpan(parent)) && isConstContext(parent.parent);
65503
65500
  }
65504
- function checkExpressionForMutableLocation(node, checkMode, contextualType, forceTuple) {
65501
+ function isConstTypeParameterContext(node) {
65502
+ const contextualType = getContextualType(node, 0 /* None */);
65503
+ return !!contextualType && someType(contextualType, isConstTypeVariable);
65504
+ }
65505
+ function checkExpressionForMutableLocation(node, checkMode, forceTuple) {
65505
65506
  const type = checkExpression(node, checkMode, forceTuple);
65506
- return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) : isTypeAssertion(node) ? type : getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node, void 0) : contextualType, node, void 0));
65507
+ return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) : isTypeAssertion(node) ? type : getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(getContextualType(node, void 0), node, void 0));
65507
65508
  }
65508
65509
  function checkPropertyAssignment(node, checkMode) {
65509
65510
  if (node.name.kind === 164 /* ComputedPropertyName */) {
@@ -65687,14 +65688,10 @@ function createTypeChecker(host) {
65687
65688
  if (links.contextFreeType) {
65688
65689
  return links.contextFreeType;
65689
65690
  }
65690
- const saveContextualType = links.contextualType;
65691
- links.contextualType = anyType;
65692
- try {
65693
- const type = links.contextFreeType = checkExpression(node, 4 /* SkipContextSensitive */);
65694
- return type;
65695
- } finally {
65696
- links.contextualType = saveContextualType;
65697
- }
65691
+ pushContextualType(node, anyType);
65692
+ const type = links.contextFreeType = checkExpression(node, 4 /* SkipContextSensitive */);
65693
+ popContextualType();
65694
+ return type;
65698
65695
  }
65699
65696
  function checkExpression(node, checkMode, forceTuple) {
65700
65697
  var _a2, _b;
@@ -65871,7 +65868,7 @@ function createTypeChecker(host) {
65871
65868
  var _a2, _b;
65872
65869
  if (isInterfaceDeclaration(node.parent) || isClassLike(node.parent) || isTypeAliasDeclaration(node.parent)) {
65873
65870
  const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node));
65874
- const modifiers = getVarianceModifiers(typeParameter);
65871
+ const modifiers = getTypeParameterModifiers(typeParameter) & (32768 /* In */ | 65536 /* Out */);
65875
65872
  if (modifiers) {
65876
65873
  const symbol = getSymbolOfDeclaration(node.parent);
65877
65874
  if (isTypeAliasDeclaration(node.parent) && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (16 /* Anonymous */ | 32 /* Mapped */))) {
@@ -72443,16 +72440,20 @@ function createTypeChecker(host) {
72443
72440
  return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_an_index_signature, tokenToString(modifier.kind));
72444
72441
  }
72445
72442
  }
72446
- if (modifier.kind !== 101 /* InKeyword */ && modifier.kind !== 145 /* OutKeyword */) {
72443
+ if (modifier.kind !== 101 /* InKeyword */ && modifier.kind !== 145 /* OutKeyword */ && modifier.kind !== 85 /* ConstKeyword */) {
72447
72444
  if (node.kind === 165 /* TypeParameter */) {
72448
72445
  return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_type_parameter, tokenToString(modifier.kind));
72449
72446
  }
72450
72447
  }
72451
72448
  switch (modifier.kind) {
72452
72449
  case 85 /* ConstKeyword */:
72453
- if (node.kind !== 263 /* EnumDeclaration */) {
72450
+ if (node.kind !== 263 /* EnumDeclaration */ && node.kind !== 165 /* TypeParameter */) {
72454
72451
  return grammarErrorOnNode(node, Diagnostics.A_class_member_cannot_have_the_0_keyword, tokenToString(85 /* ConstKeyword */));
72455
72452
  }
72453
+ const parent = node.parent;
72454
+ if (node.kind === 165 /* TypeParameter */ && !(isFunctionLikeDeclaration(parent) || isClassDeclaration(parent) || isFunctionTypeNode(parent) || isConstructorTypeNode(parent) || isCallSignatureDeclaration(parent) || isConstructSignatureDeclaration(parent) || isMethodSignature(parent))) {
72455
+ return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_type_parameter_of_a_function_method_or_class, tokenToString(modifier.kind));
72456
+ }
72456
72457
  break;
72457
72458
  case 161 /* OverrideKeyword */:
72458
72459
  if (flags & 16384 /* Override */) {