typescript 5.0.0-dev.20221216 → 5.0.0-dev.20221218

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.
@@ -42,7 +42,7 @@ var ts = (() => {
42
42
  "src/compiler/corePublic.ts"() {
43
43
  "use strict";
44
44
  versionMajorMinor = "5.0";
45
- version = `${versionMajorMinor}.0-dev.20221216`;
45
+ version = `${versionMajorMinor}.0-dev.20221218`;
46
46
  Comparison = /* @__PURE__ */ ((Comparison3) => {
47
47
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
48
48
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -7202,6 +7202,7 @@ ${lanes.join("\n")}
7202
7202
  _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"),
7203
7203
  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."),
7204
7204
  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."),
7205
+ _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"),
7205
7206
  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."),
7206
7207
  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."),
7207
7208
  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."),
@@ -11478,12 +11479,10 @@ ${lanes.join("\n")}
11478
11479
  }
11479
11480
  function getEffectiveTypeParameterDeclarations(node) {
11480
11481
  if (isJSDocSignature(node)) {
11481
- if (isJSDoc(node.parent)) {
11482
- const overloadTag = find(node.parent.tags, (tag) => {
11483
- return isJSDocOverloadTag(tag) && tag.typeExpression === node;
11484
- });
11485
- if (overloadTag) {
11486
- return flatMap(node.parent.tags, (tag) => isJSDocTemplateTag(tag) ? tag.typeParameters : void 0);
11482
+ if (isJSDocOverloadTag(node.parent)) {
11483
+ const jsDoc = getJSDocRoot(node.parent);
11484
+ if (jsDoc && length(jsDoc.tags)) {
11485
+ return flatMap(jsDoc.tags, (tag) => isJSDocTemplateTag(tag) ? tag.typeParameters : void 0);
11487
11486
  }
11488
11487
  }
11489
11488
  return emptyArray;
@@ -26524,6 +26523,7 @@ ${lanes.join("\n")}
26524
26523
  [346 /* JSDocThisTag */]: forEachChildInJSDocTypeLikeTag,
26525
26524
  [343 /* JSDocEnumTag */]: forEachChildInJSDocTypeLikeTag,
26526
26525
  [352 /* JSDocThrowsTag */]: forEachChildInJSDocTypeLikeTag,
26526
+ [342 /* JSDocOverloadTag */]: forEachChildInJSDocTypeLikeTag,
26527
26527
  [326 /* JSDocSignature */]: function forEachChildInJSDocSignature(node, cbNode, _cbNodes) {
26528
26528
  return forEach(node.typeParameters, cbNode) || forEach(node.parameters, cbNode) || visitNode2(cbNode, node.type);
26529
26529
  },
@@ -27480,7 +27480,7 @@ ${lanes.join("\n")}
27480
27480
  case ParsingContext.ArrayBindingElements:
27481
27481
  return token() === 27 /* CommaToken */ || token() === 25 /* DotDotDotToken */ || isBindingIdentifierOrPrivateIdentifierOrPattern();
27482
27482
  case ParsingContext.TypeParameters:
27483
- return token() === 101 /* InKeyword */ || isIdentifier2();
27483
+ return token() === 101 /* InKeyword */ || token() === 85 /* ConstKeyword */ || isIdentifier2();
27484
27484
  case ParsingContext.ArrayLiteralMembers:
27485
27485
  switch (token()) {
27486
27486
  case 27 /* CommaToken */:
@@ -28185,7 +28185,7 @@ ${lanes.join("\n")}
28185
28185
  }
28186
28186
  function parseTypeParameter() {
28187
28187
  const pos = getNodePos();
28188
- const modifiers = parseModifiers();
28188
+ const modifiers = parseModifiers(true);
28189
28189
  const name = parseIdentifier();
28190
28190
  let constraint;
28191
28191
  let expression;
@@ -29148,11 +29148,12 @@ ${lanes.join("\n")}
29148
29148
  return Tristate.False;
29149
29149
  } else {
29150
29150
  Debug.assert(first2 === 29 /* LessThanToken */);
29151
- if (!isIdentifier2()) {
29151
+ if (!isIdentifier2() && token() !== 85 /* ConstKeyword */) {
29152
29152
  return Tristate.False;
29153
29153
  }
29154
29154
  if (languageVariant === 1 /* JSX */) {
29155
29155
  const isArrowFunctionInJsx = lookAhead(() => {
29156
+ parseOptional(85 /* ConstKeyword */);
29156
29157
  const third = nextToken();
29157
29158
  if (third === 94 /* ExtendsKeyword */) {
29158
29159
  const fourth = nextToken();
@@ -30875,10 +30876,10 @@ ${lanes.join("\n")}
30875
30876
  }
30876
30877
  return list && createNodeArray2(list, pos);
30877
30878
  }
30878
- function tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
30879
+ function tryParseModifier(permitConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
30879
30880
  const pos = getNodePos();
30880
30881
  const kind = token();
30881
- if (token() === 85 /* ConstKeyword */ && permitInvalidConstAsModifier) {
30882
+ if (token() === 85 /* ConstKeyword */ && permitConstAsModifier) {
30882
30883
  if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) {
30883
30884
  return void 0;
30884
30885
  }
@@ -30902,10 +30903,10 @@ ${lanes.join("\n")}
30902
30903
  setTextRangePosEnd(decoratorsAndModifiers, decorators.pos, modifiers.end);
30903
30904
  return decoratorsAndModifiers;
30904
30905
  }
30905
- function parseModifiers(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock) {
30906
+ function parseModifiers(permitConstAsModifier, stopOnStartOfClassStaticBlock) {
30906
30907
  const pos = getNodePos();
30907
30908
  let list, modifier, hasSeenStatic = false;
30908
- while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
30909
+ while (modifier = tryParseModifier(permitConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
30909
30910
  if (modifier.kind === 124 /* StaticKeyword */)
30910
30911
  hasSeenStatic = true;
30911
30912
  list = append(list, modifier);
@@ -42055,6 +42056,11 @@ ${lanes.join("\n")}
42055
42056
  let lastFlowNode;
42056
42057
  let lastFlowNodeReachable;
42057
42058
  let flowTypeCache;
42059
+ const contextualTypeNodes = [];
42060
+ const contextualTypes = [];
42061
+ let contextualTypeCount = 0;
42062
+ let currentInferenceNode;
42063
+ let currentInferenceContext;
42058
42064
  const emptyStringType = getStringLiteralType("");
42059
42065
  const zeroType = getNumberLiteralType(0);
42060
42066
  const zeroBigIntType = getBigIntLiteralType({ negative: false, base10Value: "0" });
@@ -42499,9 +42505,6 @@ ${lanes.join("\n")}
42499
42505
  const nodeId = getNodeId(node);
42500
42506
  return nodeLinks[nodeId] || (nodeLinks[nodeId] = new NodeLinks());
42501
42507
  }
42502
- function tryGetNodeLinks(node) {
42503
- return node.id ? nodeLinks[node.id] : void 0;
42504
- }
42505
42508
  function isGlobalSourceFile(node) {
42506
42509
  return node.kind === 308 /* SourceFile */ && !isExternalOrCommonJsModule(node);
42507
42510
  }
@@ -45978,7 +45981,7 @@ ${lanes.join("\n")}
45978
45981
  function typeParameterToDeclarationWithConstraint(type, context, constraintNode) {
45979
45982
  const savedContextFlags = context.flags;
45980
45983
  context.flags &= ~512 /* WriteTypeParametersInQualifiedName */;
45981
- const modifiers = factory.createModifiersFromModifierFlags(getVarianceModifiers(type));
45984
+ const modifiers = factory.createModifiersFromModifierFlags(getTypeParameterModifiers(type));
45982
45985
  const name = typeParameterToName(type, context);
45983
45986
  const defaultParameter = getDefaultFromTypeParameter(type);
45984
45987
  const defaultParameterNode = defaultParameter && typeToTypeNodeHelper(defaultParameter, context);
@@ -50646,6 +50649,10 @@ ${lanes.join("\n")}
50646
50649
  function getConstraintOfTypeParameter(typeParameter) {
50647
50650
  return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : void 0;
50648
50651
  }
50652
+ function isConstTypeVariable(type) {
50653
+ var _a2;
50654
+ 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));
50655
+ }
50649
50656
  function getConstraintOfIndexedAccess(type) {
50650
50657
  return hasNonCircularBaseConstraint(type) ? getConstraintFromIndexedAccess(type) : void 0;
50651
50658
  }
@@ -55073,13 +55080,10 @@ ${lanes.join("\n")}
55073
55080
  }
55074
55081
  }
55075
55082
  function checkExpressionForMutableLocationWithContextualType(next, sourcePropType) {
55076
- const links = getNodeLinks(next);
55077
- links.contextualType = sourcePropType;
55078
- try {
55079
- return checkExpressionForMutableLocation(next, 1 /* Contextual */, sourcePropType);
55080
- } finally {
55081
- links.contextualType = void 0;
55082
- }
55083
+ pushContextualType(next, sourcePropType);
55084
+ const result = checkExpressionForMutableLocation(next, 1 /* Contextual */);
55085
+ popContextualType();
55086
+ return result;
55083
55087
  }
55084
55088
  function elaborateElementwise(iterator, source, target, relation, containingMessageChain, errorOutputContainer) {
55085
55089
  let reportedError = false;
@@ -55278,19 +55282,13 @@ ${lanes.join("\n")}
55278
55282
  if (isTupleLikeType(source)) {
55279
55283
  return elaborateElementwise(generateLimitedTupleElements(node, target), source, target, relation, containingMessageChain, errorOutputContainer);
55280
55284
  }
55281
- const links = getNodeLinks(node);
55282
- const oldContext = links.contextualType;
55283
- links.contextualType = target;
55284
- try {
55285
- const tupleizedType = checkArrayLiteral(node, 1 /* Contextual */, true);
55286
- links.contextualType = oldContext;
55287
- if (isTupleLikeType(tupleizedType)) {
55288
- return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
55289
- }
55290
- return false;
55291
- } finally {
55292
- links.contextualType = oldContext;
55285
+ pushContextualType(node, target);
55286
+ const tupleizedType = checkArrayLiteral(node, 1 /* Contextual */, true);
55287
+ popContextualType();
55288
+ if (isTupleLikeType(tupleizedType)) {
55289
+ return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
55293
55290
  }
55291
+ return false;
55294
55292
  }
55295
55293
  function* generateObjectLiteralElements(node) {
55296
55294
  if (!length(node.properties))
@@ -56392,6 +56390,9 @@ ${lanes.join("\n")}
56392
56390
  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 */)))) {
56393
56391
  inPropertyCheck = true;
56394
56392
  result2 &= propertiesRelatedTo(source2, target2, reportErrors2, void 0, 0 /* None */);
56393
+ if (result2 && isObjectLiteralType2(source2) && getObjectFlags(source2) & 8192 /* FreshLiteral */) {
56394
+ result2 &= indexSignaturesRelatedTo(source2, target2, false, reportErrors2, 0 /* None */);
56395
+ }
56395
56396
  inPropertyCheck = false;
56396
56397
  }
56397
56398
  }
@@ -57293,7 +57294,7 @@ ${lanes.join("\n")}
57293
57294
  }
57294
57295
  return result2;
57295
57296
  }
57296
- function membersRelatedToIndexInfo(source2, targetInfo, reportErrors2) {
57297
+ function membersRelatedToIndexInfo(source2, targetInfo, reportErrors2, intersectionState) {
57297
57298
  let result2 = -1 /* True */;
57298
57299
  const keyType = targetInfo.keyType;
57299
57300
  const props = source2.flags & 2097152 /* Intersection */ ? getPropertiesOfUnionOrIntersectionType(source2) : getPropertiesOfObjectType(source2);
@@ -57304,7 +57305,7 @@ ${lanes.join("\n")}
57304
57305
  if (isApplicableIndexType(getLiteralTypeFromProperty(prop, 8576 /* StringOrNumberLiteralOrUnique */), keyType)) {
57305
57306
  const propType = getNonMissingTypeOfSymbol(prop);
57306
57307
  const type = exactOptionalPropertyTypes || propType.flags & 32768 /* Undefined */ || keyType === numberType || !(prop.flags & 16777216 /* Optional */) ? propType : getTypeWithFacts(propType, 524288 /* NEUndefined */);
57307
- const related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors2);
57308
+ const related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors2, void 0, intersectionState);
57308
57309
  if (!related) {
57309
57310
  if (reportErrors2) {
57310
57311
  reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop));
@@ -57358,7 +57359,7 @@ ${lanes.join("\n")}
57358
57359
  return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors2);
57359
57360
  }
57360
57361
  if (!(intersectionState & 1 /* Source */) && isObjectTypeWithInferableIndex(source2)) {
57361
- return membersRelatedToIndexInfo(source2, targetInfo, reportErrors2);
57362
+ return membersRelatedToIndexInfo(source2, targetInfo, reportErrors2, intersectionState);
57362
57363
  }
57363
57364
  if (reportErrors2) {
57364
57365
  reportError(Diagnostics.Index_signature_for_type_0_is_missing_in_type_1, typeToString(targetInfo.keyType), typeToString(source2));
@@ -57492,7 +57493,7 @@ ${lanes.join("\n")}
57492
57493
  links.variances = emptyArray;
57493
57494
  const variances = [];
57494
57495
  for (const tp of typeParameters) {
57495
- const modifiers = getVarianceModifiers(tp);
57496
+ const modifiers = getTypeParameterModifiers(tp);
57496
57497
  let variance = modifiers & 65536 /* Out */ ? modifiers & 32768 /* In */ ? 0 /* Invariant */ : 1 /* Covariant */ : modifiers & 32768 /* In */ ? 2 /* Contravariant */ : void 0;
57497
57498
  if (variance === void 0) {
57498
57499
  let unmeasurable = false;
@@ -57535,9 +57536,9 @@ ${lanes.join("\n")}
57535
57536
  function isMarkerType(type) {
57536
57537
  return markerTypes.has(getTypeId(type));
57537
57538
  }
57538
- function getVarianceModifiers(tp) {
57539
- var _a2, _b;
57540
- 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);
57539
+ function getTypeParameterModifiers(tp) {
57540
+ var _a2;
57541
+ return reduceLeft((_a2 = tp.symbol) == null ? void 0 : _a2.declarations, (modifiers, d) => modifiers | getEffectiveModifierFlags(d), 0 /* None */) & (32768 /* In */ | 65536 /* Out */ | 2048 /* Const */);
57541
57542
  }
57542
57543
  function hasCovariantVoidArgument(typeArguments, variances) {
57543
57544
  for (let i = 0; i < variances.length; i++) {
@@ -59174,7 +59175,7 @@ ${lanes.join("\n")}
59174
59175
  }
59175
59176
  function getCovariantInference(inference, signature) {
59176
59177
  const candidates = unionObjectAndArrayLiteralCandidates(inference.candidates);
59177
- const primitiveConstraint = hasPrimitiveConstraint(inference.typeParameter);
59178
+ const primitiveConstraint = hasPrimitiveConstraint(inference.typeParameter) || isConstTypeVariable(inference.typeParameter);
59178
59179
  const widenLiteralTypes = !primitiveConstraint && inference.topLevel && (inference.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), inference.typeParameter));
59179
59180
  const baseCandidates = primitiveConstraint ? sameMap(candidates, getRegularTypeOfLiteralType) : widenLiteralTypes ? sameMap(candidates, getWidenedLiteralType) : candidates;
59180
59181
  const unwidenedType = inference.priority & 416 /* PriorityImpliesCombination */ ? getUnionType(baseCandidates, 2 /* Subtype */) : getCommonSupertype(baseCandidates);
@@ -62229,13 +62230,12 @@ ${lanes.join("\n")}
62229
62230
  return type;
62230
62231
  }
62231
62232
  function getContextualType2(node, contextFlags) {
62232
- var _a2;
62233
62233
  if (node.flags & 33554432 /* InWithStatement */) {
62234
62234
  return void 0;
62235
62235
  }
62236
- const contextualType = (_a2 = tryGetNodeLinks(node)) == null ? void 0 : _a2.contextualType;
62237
- if (contextualType) {
62238
- return contextualType;
62236
+ const index = findContextualNode(node);
62237
+ if (index >= 0) {
62238
+ return contextualTypes[index];
62239
62239
  }
62240
62240
  const { parent: parent2 } = node;
62241
62241
  switch (parent2.kind) {
@@ -62257,7 +62257,7 @@ ${lanes.join("\n")}
62257
62257
  return getContextualTypeForArgument(parent2, node);
62258
62258
  case 213 /* TypeAssertionExpression */:
62259
62259
  case 231 /* AsExpression */:
62260
- return isConstTypeReference(parent2.type) ? tryFindWhenConstTypeReference(parent2) : getTypeFromTypeNode(parent2.type);
62260
+ return isConstTypeReference(parent2.type) ? getContextualType2(parent2, contextFlags) : getTypeFromTypeNode(parent2.type);
62261
62261
  case 223 /* BinaryExpression */:
62262
62262
  return getContextualTypeForBinaryOperand(node, contextFlags);
62263
62263
  case 299 /* PropertyAssignment */:
@@ -62277,7 +62277,7 @@ ${lanes.join("\n")}
62277
62277
  return getContextualTypeForSubstitutionExpression(parent2.parent, node);
62278
62278
  case 214 /* ParenthesizedExpression */: {
62279
62279
  const tag = isInJSFile(parent2) ? getJSDocTypeTag(parent2) : void 0;
62280
- return !tag ? getContextualType2(parent2, contextFlags) : isJSDocTypeTag(tag) && isConstTypeReference(tag.typeExpression.type) ? tryFindWhenConstTypeReference(parent2) : getTypeFromTypeNode(tag.typeExpression.type);
62280
+ return !tag ? getContextualType2(parent2, contextFlags) : isJSDocTypeTag(tag) && isConstTypeReference(tag.typeExpression.type) ? getContextualType2(parent2, contextFlags) : getTypeFromTypeNode(tag.typeExpression.type);
62281
62281
  }
62282
62282
  case 232 /* NonNullExpression */:
62283
62283
  return getContextualType2(parent2, contextFlags);
@@ -62295,22 +62295,31 @@ ${lanes.join("\n")}
62295
62295
  return getContextualJsxElementAttributesType(parent2, contextFlags);
62296
62296
  }
62297
62297
  return void 0;
62298
- function tryFindWhenConstTypeReference(node2) {
62299
- return getContextualType2(node2, contextFlags);
62298
+ }
62299
+ function pushContextualType(node, type) {
62300
+ contextualTypeNodes[contextualTypeCount] = node;
62301
+ contextualTypes[contextualTypeCount] = type;
62302
+ contextualTypeCount++;
62303
+ }
62304
+ function popContextualType() {
62305
+ contextualTypeCount--;
62306
+ }
62307
+ function findContextualNode(node) {
62308
+ for (let i = contextualTypeCount - 1; i >= 0; i--) {
62309
+ if (node === contextualTypeNodes[i]) {
62310
+ return i;
62311
+ }
62300
62312
  }
62313
+ return -1;
62301
62314
  }
62302
62315
  function getInferenceContext(node) {
62303
- return forEachAncestor(node, (n) => {
62304
- var _a2;
62305
- return (_a2 = tryGetNodeLinks(n)) == null ? void 0 : _a2.inferenceContext;
62306
- });
62316
+ return isNodeDescendantOf(node, currentInferenceNode) ? currentInferenceContext : void 0;
62307
62317
  }
62308
62318
  function getContextualJsxElementAttributesType(node, contextFlags) {
62309
- var _a2;
62310
62319
  if (isJsxOpeningElement(node) && contextFlags !== 4 /* Completions */) {
62311
- const contextualType = (_a2 = tryGetNodeLinks(node.parent)) == null ? void 0 : _a2.contextualType;
62312
- if (contextualType) {
62313
- return contextualType;
62320
+ const index = findContextualNode(node.parent);
62321
+ if (index >= 0) {
62322
+ return contextualTypes[index];
62314
62323
  }
62315
62324
  }
62316
62325
  return getContextualTypeForArgumentAtIndex(node, 0);
@@ -62567,9 +62576,11 @@ ${lanes.join("\n")}
62567
62576
  const elementCount = elements.length;
62568
62577
  const elementTypes = [];
62569
62578
  const elementFlags = [];
62570
- const contextualType = getApparentTypeOfContextualType(node, void 0);
62579
+ pushContextualType(node, getContextualType2(node, void 0));
62571
62580
  const inDestructuringPattern = isAssignmentTarget(node);
62572
62581
  const inConstContext = isConstContext(node);
62582
+ const contextualType = getApparentTypeOfContextualType(node, void 0);
62583
+ const inTupleContext = !!contextualType && someType(contextualType, isTupleLikeType);
62573
62584
  let hasOmittedExpression = false;
62574
62585
  for (let i = 0; i < elementCount; i++) {
62575
62586
  const e = elements[i];
@@ -62594,21 +62605,21 @@ ${lanes.join("\n")}
62594
62605
  elementTypes.push(undefinedOrMissingType);
62595
62606
  elementFlags.push(2 /* Optional */);
62596
62607
  } else {
62597
- const elementContextualType = getContextualTypeForElementExpression(contextualType, elementTypes.length);
62598
- const type = checkExpressionForMutableLocation(e, checkMode, elementContextualType, forceTuple);
62608
+ const type = checkExpressionForMutableLocation(e, checkMode, forceTuple);
62599
62609
  elementTypes.push(addOptionality(type, true, hasOmittedExpression));
62600
62610
  elementFlags.push(hasOmittedExpression ? 2 /* Optional */ : 1 /* Required */);
62601
- if (contextualType && someType(contextualType, isTupleLikeType) && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
62611
+ if (inTupleContext && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
62602
62612
  const inferenceContext = getInferenceContext(node);
62603
62613
  Debug.assert(inferenceContext);
62604
62614
  addIntraExpressionInferenceSite(inferenceContext, e, type);
62605
62615
  }
62606
62616
  }
62607
62617
  }
62618
+ popContextualType();
62608
62619
  if (inDestructuringPattern) {
62609
62620
  return createTupleType(elementTypes, elementFlags);
62610
62621
  }
62611
- if (forceTuple || inConstContext || contextualType && someType(contextualType, isTupleLikeType)) {
62622
+ if (forceTuple || inConstContext || inTupleContext) {
62612
62623
  return createArrayLiteralType(createTupleType(elementTypes, elementFlags, inConstContext));
62613
62624
  }
62614
62625
  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));
@@ -62702,6 +62713,7 @@ ${lanes.join("\n")}
62702
62713
  let propertiesTable = createSymbolTable();
62703
62714
  let propertiesArray = [];
62704
62715
  let spread = emptyObjectType;
62716
+ pushContextualType(node, getContextualType2(node, void 0));
62705
62717
  const contextualType = getApparentTypeOfContextualType(node, void 0);
62706
62718
  const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === 203 /* ObjectBindingPattern */ || contextualType.pattern.kind === 207 /* ObjectLiteralExpression */);
62707
62719
  const inConstContext = isConstContext(node);
@@ -62823,6 +62835,7 @@ ${lanes.join("\n")}
62823
62835
  }
62824
62836
  propertiesArray.push(member);
62825
62837
  }
62838
+ popContextualType();
62826
62839
  if (contextualTypeHasPattern) {
62827
62840
  const rootPatternParent = findAncestor(
62828
62841
  contextualType.pattern.parent,
@@ -64410,6 +64423,7 @@ ${lanes.join("\n")}
64410
64423
  const types = [];
64411
64424
  const flags = [];
64412
64425
  const names = [];
64426
+ const inConstContext = isConstTypeVariable(restType);
64413
64427
  for (let i = index; i < argCount; i++) {
64414
64428
  const arg = args[i];
64415
64429
  if (isSpreadArgument(arg)) {
@@ -64424,7 +64438,7 @@ ${lanes.join("\n")}
64424
64438
  } else {
64425
64439
  const contextualType = getIndexedAccessType(restType, getNumberLiteralType(i - index), 256 /* Contextual */);
64426
64440
  const argType = checkExpressionWithContextualType(arg, contextualType, context, checkMode);
64427
- const hasPrimitiveContextualType = maybeTypeOfKind(contextualType, 131068 /* Primitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */);
64441
+ const hasPrimitiveContextualType = inConstContext || maybeTypeOfKind(contextualType, 131068 /* Primitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */);
64428
64442
  types.push(hasPrimitiveContextualType ? getRegularTypeOfLiteralType(argType) : getWidenedLiteralType(argType));
64429
64443
  flags.push(1 /* Required */);
64430
64444
  }
@@ -64432,7 +64446,7 @@ ${lanes.join("\n")}
64432
64446
  names.push(arg.tupleNameSource);
64433
64447
  }
64434
64448
  }
64435
- return createTupleType(types, flags, false, length(names) === length(types) ? names : void 0);
64449
+ return createTupleType(types, flags, inConstContext, length(names) === length(types) ? names : void 0);
64436
64450
  }
64437
64451
  function checkTypeArguments(signature, typeArgumentNodes, reportErrors2, headMessage) {
64438
64452
  const isJavascript = isInJSFile(signature.declaration);
@@ -65896,12 +65910,9 @@ ${lanes.join("\n")}
65896
65910
  return op === 40 /* MinusToken */ && (arg.kind === 8 /* NumericLiteral */ || arg.kind === 9 /* BigIntLiteral */) || op === 39 /* PlusToken */ && arg.kind === 8 /* NumericLiteral */;
65897
65911
  case 208 /* PropertyAccessExpression */:
65898
65912
  case 209 /* ElementAccessExpression */:
65899
- const expr = node.expression;
65900
- let symbol = getTypeOfNode(expr).symbol;
65901
- if (symbol && symbol.flags & 2097152 /* Alias */) {
65902
- symbol = resolveAlias(symbol);
65903
- }
65904
- return !!(symbol && getAllSymbolFlags(symbol) & 384 /* Enum */);
65913
+ const expr = skipParentheses(node.expression);
65914
+ const symbol = isEntityNameExpression(expr) ? resolveEntityName(expr, 111551 /* Value */, true) : void 0;
65915
+ return !!(symbol && symbol.flags & 384 /* Enum */);
65905
65916
  }
65906
65917
  return false;
65907
65918
  }
@@ -67809,23 +67820,21 @@ ${lanes.join("\n")}
67809
67820
  return node;
67810
67821
  }
67811
67822
  function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
67812
- const context = getContextNode2(node);
67813
- const links = getNodeLinks(context);
67814
- const saveContextualType = links.contextualType;
67815
- const saveInferenceContext = links.inferenceContext;
67816
- try {
67817
- links.contextualType = contextualType;
67818
- links.inferenceContext = inferenceContext;
67819
- const type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
67820
- if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
67821
- inferenceContext.intraExpressionInferenceSites = void 0;
67822
- }
67823
- const result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, void 0)) ? getRegularTypeOfLiteralType(type) : type;
67824
- return result;
67825
- } finally {
67826
- links.contextualType = saveContextualType;
67827
- links.inferenceContext = saveInferenceContext;
67828
- }
67823
+ const contextNode = getContextNode2(node);
67824
+ pushContextualType(contextNode, contextualType);
67825
+ const saveInferenceNode = currentInferenceNode;
67826
+ const saveInferenceContext = currentInferenceContext;
67827
+ currentInferenceNode = contextNode;
67828
+ currentInferenceContext = inferenceContext;
67829
+ const type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
67830
+ if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
67831
+ inferenceContext.intraExpressionInferenceSites = void 0;
67832
+ }
67833
+ const result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, void 0)) ? getRegularTypeOfLiteralType(type) : type;
67834
+ currentInferenceNode = saveInferenceNode;
67835
+ currentInferenceContext = saveInferenceContext;
67836
+ popContextualType();
67837
+ return result;
67829
67838
  }
67830
67839
  function checkExpressionCached(node, checkMode) {
67831
67840
  if (checkMode) {
@@ -67897,11 +67906,15 @@ ${lanes.join("\n")}
67897
67906
  }
67898
67907
  function isConstContext(node) {
67899
67908
  const parent2 = node.parent;
67900
- return isAssertionExpression(parent2) && isConstTypeReference(parent2.type) || isJSDocTypeAssertion(parent2) && isConstTypeReference(getJSDocTypeAssertionType(parent2)) || (isParenthesizedExpression(parent2) || isArrayLiteralExpression(parent2) || isSpreadElement(parent2)) && isConstContext(parent2) || (isPropertyAssignment(parent2) || isShorthandPropertyAssignment(parent2) || isTemplateSpan(parent2)) && isConstContext(parent2.parent);
67909
+ return isAssertionExpression(parent2) && isConstTypeReference(parent2.type) || isJSDocTypeAssertion(parent2) && isConstTypeReference(getJSDocTypeAssertionType(parent2)) || isValidConstAssertionArgument(node) && isConstTypeParameterContext(node) || (isParenthesizedExpression(parent2) || isArrayLiteralExpression(parent2) || isSpreadElement(parent2)) && isConstContext(parent2) || (isPropertyAssignment(parent2) || isShorthandPropertyAssignment(parent2) || isTemplateSpan(parent2)) && isConstContext(parent2.parent);
67910
+ }
67911
+ function isConstTypeParameterContext(node) {
67912
+ const contextualType = getContextualType2(node, 0 /* None */);
67913
+ return !!contextualType && someType(contextualType, isConstTypeVariable);
67901
67914
  }
67902
- function checkExpressionForMutableLocation(node, checkMode, contextualType, forceTuple) {
67915
+ function checkExpressionForMutableLocation(node, checkMode, forceTuple) {
67903
67916
  const type = checkExpression(node, checkMode, forceTuple);
67904
- return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) : isTypeAssertion3(node) ? type : getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType2(node, void 0) : contextualType, node, void 0));
67917
+ return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) : isTypeAssertion3(node) ? type : getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(getContextualType2(node, void 0), node, void 0));
67905
67918
  }
67906
67919
  function checkPropertyAssignment(node, checkMode) {
67907
67920
  if (node.name.kind === 164 /* ComputedPropertyName */) {
@@ -68085,14 +68098,10 @@ ${lanes.join("\n")}
68085
68098
  if (links.contextFreeType) {
68086
68099
  return links.contextFreeType;
68087
68100
  }
68088
- const saveContextualType = links.contextualType;
68089
- links.contextualType = anyType;
68090
- try {
68091
- const type = links.contextFreeType = checkExpression(node, 4 /* SkipContextSensitive */);
68092
- return type;
68093
- } finally {
68094
- links.contextualType = saveContextualType;
68095
- }
68101
+ pushContextualType(node, anyType);
68102
+ const type = links.contextFreeType = checkExpression(node, 4 /* SkipContextSensitive */);
68103
+ popContextualType();
68104
+ return type;
68096
68105
  }
68097
68106
  function checkExpression(node, checkMode, forceTuple) {
68098
68107
  var _a2, _b;
@@ -68269,7 +68278,7 @@ ${lanes.join("\n")}
68269
68278
  var _a2, _b;
68270
68279
  if (isInterfaceDeclaration(node.parent) || isClassLike(node.parent) || isTypeAliasDeclaration(node.parent)) {
68271
68280
  const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node));
68272
- const modifiers = getVarianceModifiers(typeParameter);
68281
+ const modifiers = getTypeParameterModifiers(typeParameter) & (32768 /* In */ | 65536 /* Out */);
68273
68282
  if (modifiers) {
68274
68283
  const symbol = getSymbolOfDeclaration(node.parent);
68275
68284
  if (isTypeAliasDeclaration(node.parent) && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (16 /* Anonymous */ | 32 /* Mapped */))) {
@@ -74841,16 +74850,20 @@ ${lanes.join("\n")}
74841
74850
  return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_an_index_signature, tokenToString(modifier.kind));
74842
74851
  }
74843
74852
  }
74844
- if (modifier.kind !== 101 /* InKeyword */ && modifier.kind !== 145 /* OutKeyword */) {
74853
+ if (modifier.kind !== 101 /* InKeyword */ && modifier.kind !== 145 /* OutKeyword */ && modifier.kind !== 85 /* ConstKeyword */) {
74845
74854
  if (node.kind === 165 /* TypeParameter */) {
74846
74855
  return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_type_parameter, tokenToString(modifier.kind));
74847
74856
  }
74848
74857
  }
74849
74858
  switch (modifier.kind) {
74850
74859
  case 85 /* ConstKeyword */:
74851
- if (node.kind !== 263 /* EnumDeclaration */) {
74860
+ if (node.kind !== 263 /* EnumDeclaration */ && node.kind !== 165 /* TypeParameter */) {
74852
74861
  return grammarErrorOnNode(node, Diagnostics.A_class_member_cannot_have_the_0_keyword, tokenToString(85 /* ConstKeyword */));
74853
74862
  }
74863
+ const parent2 = node.parent;
74864
+ if (node.kind === 165 /* TypeParameter */ && !(isFunctionLikeDeclaration(parent2) || isClassLike(parent2) || isFunctionTypeNode(parent2) || isConstructorTypeNode(parent2) || isCallSignatureDeclaration(parent2) || isConstructSignatureDeclaration(parent2) || isMethodSignature(parent2))) {
74865
+ return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_type_parameter_of_a_function_method_or_class, tokenToString(modifier.kind));
74866
+ }
74854
74867
  break;
74855
74868
  case 161 /* OverrideKeyword */:
74856
74869
  if (flags & 16384 /* Override */) {
@@ -128871,7 +128884,7 @@ ${lanes.join("\n")}
128871
128884
  if (declaration && isAutoAccessorPropertyDeclaration(declaration)) {
128872
128885
  modifierFlags |= 128 /* Accessor */;
128873
128886
  }
128874
- const modifiers = modifierFlags ? factory.createNodeArray(factory.createModifiersFromModifierFlags(modifierFlags)) : void 0;
128887
+ const modifiers = createModifiers();
128875
128888
  const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
128876
128889
  const optional = !!(symbol.flags & 16777216 /* Optional */);
128877
128890
  const ambient = !!(enclosingDeclaration.flags & 16777216 /* Ambient */) || isAmbient;
@@ -128964,6 +128977,19 @@ ${lanes.join("\n")}
128964
128977
  if (method)
128965
128978
  addClassElement(method);
128966
128979
  }
128980
+ function createModifiers() {
128981
+ let modifiers2;
128982
+ if (modifierFlags) {
128983
+ modifiers2 = combine(modifiers2, factory.createModifiersFromModifierFlags(modifierFlags));
128984
+ }
128985
+ if (shouldAddOverrideKeyword()) {
128986
+ modifiers2 = append(modifiers2, factory.createToken(161 /* OverrideKeyword */));
128987
+ }
128988
+ return modifiers2 && factory.createNodeArray(modifiers2);
128989
+ }
128990
+ function shouldAddOverrideKeyword() {
128991
+ return !!(context.program.getCompilerOptions().noImplicitOverride && declaration && hasAbstractModifier(declaration));
128992
+ }
128967
128993
  function createName(node) {
128968
128994
  if (isIdentifier(node) && node.escapedText === "constructor") {
128969
128995
  return factory.createComputedPropertyName(factory.createStringLiteral(idText(node), quotePreference === 0 /* Single */));
@@ -128981,14 +129007,15 @@ ${lanes.join("\n")}
128981
129007
  const program = context.program;
128982
129008
  const checker = program.getTypeChecker();
128983
129009
  const scriptTarget = getEmitScriptTarget(program.getCompilerOptions());
129010
+ const isJs = isInJSFile(enclosingDeclaration);
128984
129011
  const flags = 1 /* NoTruncation */ | 256 /* SuppressAnyReturnType */ | 524288 /* AllowEmptyTuple */ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */);
128985
129012
  const signatureDeclaration = checker.signatureToSignatureDeclaration(signature, kind, enclosingDeclaration, flags, getNoopSymbolTrackerWithResolver(context));
128986
129013
  if (!signatureDeclaration) {
128987
129014
  return void 0;
128988
129015
  }
128989
- let typeParameters = signatureDeclaration.typeParameters;
129016
+ let typeParameters = isJs ? void 0 : signatureDeclaration.typeParameters;
128990
129017
  let parameters = signatureDeclaration.parameters;
128991
- let type = signatureDeclaration.type;
129018
+ let type = isJs ? void 0 : signatureDeclaration.type;
128992
129019
  if (importAdder) {
128993
129020
  if (typeParameters) {
128994
129021
  const newTypeParameters = sameMap(typeParameters, (typeParameterDecl) => {
@@ -129021,18 +129048,20 @@ ${lanes.join("\n")}
129021
129048
  }
129022
129049
  }
129023
129050
  const newParameters = sameMap(parameters, (parameterDecl) => {
129024
- const importableReference = tryGetAutoImportableReferenceFromTypeNode(parameterDecl.type, scriptTarget);
129025
- let type2 = parameterDecl.type;
129026
- if (importableReference) {
129027
- type2 = importableReference.typeNode;
129028
- importSymbols(importAdder, importableReference.symbols);
129051
+ let type2 = isJs ? void 0 : parameterDecl.type;
129052
+ if (type2) {
129053
+ const importableReference = tryGetAutoImportableReferenceFromTypeNode(type2, scriptTarget);
129054
+ if (importableReference) {
129055
+ type2 = importableReference.typeNode;
129056
+ importSymbols(importAdder, importableReference.symbols);
129057
+ }
129029
129058
  }
129030
129059
  return factory.updateParameterDeclaration(
129031
129060
  parameterDecl,
129032
129061
  parameterDecl.modifiers,
129033
129062
  parameterDecl.dotDotDotToken,
129034
129063
  parameterDecl.name,
129035
- parameterDecl.questionToken,
129064
+ isJs ? void 0 : parameterDecl.questionToken,
129036
129065
  type2,
129037
129066
  parameterDecl.initializer
129038
129067
  );