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/tsserver.js CHANGED
@@ -2669,7 +2669,7 @@ __export(ts_server_exports3, {
2669
2669
 
2670
2670
  // src/compiler/corePublic.ts
2671
2671
  var versionMajorMinor = "5.0";
2672
- var version = `${versionMajorMinor}.0-dev.20221216`;
2672
+ var version = `${versionMajorMinor}.0-dev.20221217`;
2673
2673
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2674
2674
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2675
2675
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -9754,6 +9754,7 @@ var Diagnostics = {
9754
9754
  _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"),
9755
9755
  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."),
9756
9756
  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."),
9757
+ _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"),
9757
9758
  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."),
9758
9759
  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."),
9759
9760
  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."),
@@ -14023,12 +14024,10 @@ function formatJSDocLink(link) {
14023
14024
  }
14024
14025
  function getEffectiveTypeParameterDeclarations(node) {
14025
14026
  if (isJSDocSignature(node)) {
14026
- if (isJSDoc(node.parent)) {
14027
- const overloadTag = find(node.parent.tags, (tag) => {
14028
- return isJSDocOverloadTag(tag) && tag.typeExpression === node;
14029
- });
14030
- if (overloadTag) {
14031
- return flatMap(node.parent.tags, (tag) => isJSDocTemplateTag(tag) ? tag.typeParameters : void 0);
14027
+ if (isJSDocOverloadTag(node.parent)) {
14028
+ const jsDoc = getJSDocRoot(node.parent);
14029
+ if (jsDoc && length(jsDoc.tags)) {
14030
+ return flatMap(jsDoc.tags, (tag) => isJSDocTemplateTag(tag) ? tag.typeParameters : void 0);
14032
14031
  }
14033
14032
  }
14034
14033
  return emptyArray;
@@ -28630,6 +28629,7 @@ var forEachChildTable = {
28630
28629
  [346 /* JSDocThisTag */]: forEachChildInJSDocTypeLikeTag,
28631
28630
  [343 /* JSDocEnumTag */]: forEachChildInJSDocTypeLikeTag,
28632
28631
  [352 /* JSDocThrowsTag */]: forEachChildInJSDocTypeLikeTag,
28632
+ [342 /* JSDocOverloadTag */]: forEachChildInJSDocTypeLikeTag,
28633
28633
  [326 /* JSDocSignature */]: function forEachChildInJSDocSignature(node, cbNode, _cbNodes) {
28634
28634
  return forEach(node.typeParameters, cbNode) || forEach(node.parameters, cbNode) || visitNode2(cbNode, node.type);
28635
28635
  },
@@ -29744,7 +29744,7 @@ var Parser;
29744
29744
  case ParsingContext.ArrayBindingElements:
29745
29745
  return token() === 27 /* CommaToken */ || token() === 25 /* DotDotDotToken */ || isBindingIdentifierOrPrivateIdentifierOrPattern();
29746
29746
  case ParsingContext.TypeParameters:
29747
- return token() === 101 /* InKeyword */ || isIdentifier2();
29747
+ return token() === 101 /* InKeyword */ || token() === 85 /* ConstKeyword */ || isIdentifier2();
29748
29748
  case ParsingContext.ArrayLiteralMembers:
29749
29749
  switch (token()) {
29750
29750
  case 27 /* CommaToken */:
@@ -30449,7 +30449,7 @@ var Parser;
30449
30449
  }
30450
30450
  function parseTypeParameter() {
30451
30451
  const pos = getNodePos();
30452
- const modifiers = parseModifiers();
30452
+ const modifiers = parseModifiers(true);
30453
30453
  const name = parseIdentifier();
30454
30454
  let constraint;
30455
30455
  let expression;
@@ -31412,11 +31412,12 @@ var Parser;
31412
31412
  return Tristate.False;
31413
31413
  } else {
31414
31414
  Debug.assert(first2 === 29 /* LessThanToken */);
31415
- if (!isIdentifier2()) {
31415
+ if (!isIdentifier2() && token() !== 85 /* ConstKeyword */) {
31416
31416
  return Tristate.False;
31417
31417
  }
31418
31418
  if (languageVariant === 1 /* JSX */) {
31419
31419
  const isArrowFunctionInJsx = lookAhead(() => {
31420
+ parseOptional(85 /* ConstKeyword */);
31420
31421
  const third = nextToken();
31421
31422
  if (third === 94 /* ExtendsKeyword */) {
31422
31423
  const fourth = nextToken();
@@ -33139,10 +33140,10 @@ var Parser;
33139
33140
  }
33140
33141
  return list && createNodeArray2(list, pos);
33141
33142
  }
33142
- function tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
33143
+ function tryParseModifier(permitConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
33143
33144
  const pos = getNodePos();
33144
33145
  const kind = token();
33145
- if (token() === 85 /* ConstKeyword */ && permitInvalidConstAsModifier) {
33146
+ if (token() === 85 /* ConstKeyword */ && permitConstAsModifier) {
33146
33147
  if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) {
33147
33148
  return void 0;
33148
33149
  }
@@ -33166,10 +33167,10 @@ var Parser;
33166
33167
  setTextRangePosEnd(decoratorsAndModifiers, decorators.pos, modifiers.end);
33167
33168
  return decoratorsAndModifiers;
33168
33169
  }
33169
- function parseModifiers(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock) {
33170
+ function parseModifiers(permitConstAsModifier, stopOnStartOfClassStaticBlock) {
33170
33171
  const pos = getNodePos();
33171
33172
  let list, modifier, hasSeenStatic = false;
33172
- while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
33173
+ while (modifier = tryParseModifier(permitConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
33173
33174
  if (modifier.kind === 124 /* StaticKeyword */)
33174
33175
  hasSeenStatic = true;
33175
33176
  list = append(list, modifier);
@@ -44620,6 +44621,11 @@ function createTypeChecker(host) {
44620
44621
  let lastFlowNode;
44621
44622
  let lastFlowNodeReachable;
44622
44623
  let flowTypeCache;
44624
+ const contextualTypeNodes = [];
44625
+ const contextualTypes = [];
44626
+ let contextualTypeCount = 0;
44627
+ let currentInferenceNode;
44628
+ let currentInferenceContext;
44623
44629
  const emptyStringType = getStringLiteralType("");
44624
44630
  const zeroType = getNumberLiteralType(0);
44625
44631
  const zeroBigIntType = getBigIntLiteralType({ negative: false, base10Value: "0" });
@@ -45064,9 +45070,6 @@ function createTypeChecker(host) {
45064
45070
  const nodeId = getNodeId(node);
45065
45071
  return nodeLinks[nodeId] || (nodeLinks[nodeId] = new NodeLinks());
45066
45072
  }
45067
- function tryGetNodeLinks(node) {
45068
- return node.id ? nodeLinks[node.id] : void 0;
45069
- }
45070
45073
  function isGlobalSourceFile(node) {
45071
45074
  return node.kind === 308 /* SourceFile */ && !isExternalOrCommonJsModule(node);
45072
45075
  }
@@ -48543,7 +48546,7 @@ function createTypeChecker(host) {
48543
48546
  function typeParameterToDeclarationWithConstraint(type, context, constraintNode) {
48544
48547
  const savedContextFlags = context.flags;
48545
48548
  context.flags &= ~512 /* WriteTypeParametersInQualifiedName */;
48546
- const modifiers = factory.createModifiersFromModifierFlags(getVarianceModifiers(type));
48549
+ const modifiers = factory.createModifiersFromModifierFlags(getTypeParameterModifiers(type));
48547
48550
  const name = typeParameterToName(type, context);
48548
48551
  const defaultParameter = getDefaultFromTypeParameter(type);
48549
48552
  const defaultParameterNode = defaultParameter && typeToTypeNodeHelper(defaultParameter, context);
@@ -53211,6 +53214,10 @@ function createTypeChecker(host) {
53211
53214
  function getConstraintOfTypeParameter(typeParameter) {
53212
53215
  return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : void 0;
53213
53216
  }
53217
+ function isConstTypeVariable(type) {
53218
+ var _a2;
53219
+ 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));
53220
+ }
53214
53221
  function getConstraintOfIndexedAccess(type) {
53215
53222
  return hasNonCircularBaseConstraint(type) ? getConstraintFromIndexedAccess(type) : void 0;
53216
53223
  }
@@ -57638,13 +57645,10 @@ function createTypeChecker(host) {
57638
57645
  }
57639
57646
  }
57640
57647
  function checkExpressionForMutableLocationWithContextualType(next, sourcePropType) {
57641
- const links = getNodeLinks(next);
57642
- links.contextualType = sourcePropType;
57643
- try {
57644
- return checkExpressionForMutableLocation(next, 1 /* Contextual */, sourcePropType);
57645
- } finally {
57646
- links.contextualType = void 0;
57647
- }
57648
+ pushContextualType(next, sourcePropType);
57649
+ const result = checkExpressionForMutableLocation(next, 1 /* Contextual */);
57650
+ popContextualType();
57651
+ return result;
57648
57652
  }
57649
57653
  function elaborateElementwise(iterator, source, target, relation, containingMessageChain, errorOutputContainer) {
57650
57654
  let reportedError = false;
@@ -57843,19 +57847,13 @@ function createTypeChecker(host) {
57843
57847
  if (isTupleLikeType(source)) {
57844
57848
  return elaborateElementwise(generateLimitedTupleElements(node, target), source, target, relation, containingMessageChain, errorOutputContainer);
57845
57849
  }
57846
- const links = getNodeLinks(node);
57847
- const oldContext = links.contextualType;
57848
- links.contextualType = target;
57849
- try {
57850
- const tupleizedType = checkArrayLiteral(node, 1 /* Contextual */, true);
57851
- links.contextualType = oldContext;
57852
- if (isTupleLikeType(tupleizedType)) {
57853
- return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
57854
- }
57855
- return false;
57856
- } finally {
57857
- links.contextualType = oldContext;
57850
+ pushContextualType(node, target);
57851
+ const tupleizedType = checkArrayLiteral(node, 1 /* Contextual */, true);
57852
+ popContextualType();
57853
+ if (isTupleLikeType(tupleizedType)) {
57854
+ return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
57858
57855
  }
57856
+ return false;
57859
57857
  }
57860
57858
  function* generateObjectLiteralElements(node) {
57861
57859
  if (!length(node.properties))
@@ -58957,6 +58955,9 @@ function createTypeChecker(host) {
58957
58955
  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 */)))) {
58958
58956
  inPropertyCheck = true;
58959
58957
  result2 &= propertiesRelatedTo(source2, target2, reportErrors2, void 0, 0 /* None */);
58958
+ if (result2 && isObjectLiteralType2(source2) && getObjectFlags(source2) & 8192 /* FreshLiteral */) {
58959
+ result2 &= indexSignaturesRelatedTo(source2, target2, false, reportErrors2, 0 /* None */);
58960
+ }
58960
58961
  inPropertyCheck = false;
58961
58962
  }
58962
58963
  }
@@ -59858,7 +59859,7 @@ function createTypeChecker(host) {
59858
59859
  }
59859
59860
  return result2;
59860
59861
  }
59861
- function membersRelatedToIndexInfo(source2, targetInfo, reportErrors2) {
59862
+ function membersRelatedToIndexInfo(source2, targetInfo, reportErrors2, intersectionState) {
59862
59863
  let result2 = -1 /* True */;
59863
59864
  const keyType = targetInfo.keyType;
59864
59865
  const props = source2.flags & 2097152 /* Intersection */ ? getPropertiesOfUnionOrIntersectionType(source2) : getPropertiesOfObjectType(source2);
@@ -59869,7 +59870,7 @@ function createTypeChecker(host) {
59869
59870
  if (isApplicableIndexType(getLiteralTypeFromProperty(prop, 8576 /* StringOrNumberLiteralOrUnique */), keyType)) {
59870
59871
  const propType = getNonMissingTypeOfSymbol(prop);
59871
59872
  const type = exactOptionalPropertyTypes || propType.flags & 32768 /* Undefined */ || keyType === numberType || !(prop.flags & 16777216 /* Optional */) ? propType : getTypeWithFacts(propType, 524288 /* NEUndefined */);
59872
- const related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors2);
59873
+ const related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors2, void 0, intersectionState);
59873
59874
  if (!related) {
59874
59875
  if (reportErrors2) {
59875
59876
  reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop));
@@ -59923,7 +59924,7 @@ function createTypeChecker(host) {
59923
59924
  return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors2);
59924
59925
  }
59925
59926
  if (!(intersectionState & 1 /* Source */) && isObjectTypeWithInferableIndex(source2)) {
59926
- return membersRelatedToIndexInfo(source2, targetInfo, reportErrors2);
59927
+ return membersRelatedToIndexInfo(source2, targetInfo, reportErrors2, intersectionState);
59927
59928
  }
59928
59929
  if (reportErrors2) {
59929
59930
  reportError(Diagnostics.Index_signature_for_type_0_is_missing_in_type_1, typeToString(targetInfo.keyType), typeToString(source2));
@@ -60057,7 +60058,7 @@ function createTypeChecker(host) {
60057
60058
  links.variances = emptyArray;
60058
60059
  const variances = [];
60059
60060
  for (const tp of typeParameters) {
60060
- const modifiers = getVarianceModifiers(tp);
60061
+ const modifiers = getTypeParameterModifiers(tp);
60061
60062
  let variance = modifiers & 65536 /* Out */ ? modifiers & 32768 /* In */ ? 0 /* Invariant */ : 1 /* Covariant */ : modifiers & 32768 /* In */ ? 2 /* Contravariant */ : void 0;
60062
60063
  if (variance === void 0) {
60063
60064
  let unmeasurable = false;
@@ -60100,9 +60101,9 @@ function createTypeChecker(host) {
60100
60101
  function isMarkerType(type) {
60101
60102
  return markerTypes.has(getTypeId(type));
60102
60103
  }
60103
- function getVarianceModifiers(tp) {
60104
- var _a2, _b;
60105
- 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);
60104
+ function getTypeParameterModifiers(tp) {
60105
+ var _a2;
60106
+ return reduceLeft((_a2 = tp.symbol) == null ? void 0 : _a2.declarations, (modifiers, d) => modifiers | getEffectiveModifierFlags(d), 0 /* None */) & (32768 /* In */ | 65536 /* Out */ | 2048 /* Const */);
60106
60107
  }
60107
60108
  function hasCovariantVoidArgument(typeArguments, variances) {
60108
60109
  for (let i = 0; i < variances.length; i++) {
@@ -61739,7 +61740,7 @@ function createTypeChecker(host) {
61739
61740
  }
61740
61741
  function getCovariantInference(inference, signature) {
61741
61742
  const candidates = unionObjectAndArrayLiteralCandidates(inference.candidates);
61742
- const primitiveConstraint = hasPrimitiveConstraint(inference.typeParameter);
61743
+ const primitiveConstraint = hasPrimitiveConstraint(inference.typeParameter) || isConstTypeVariable(inference.typeParameter);
61743
61744
  const widenLiteralTypes = !primitiveConstraint && inference.topLevel && (inference.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), inference.typeParameter));
61744
61745
  const baseCandidates = primitiveConstraint ? sameMap(candidates, getRegularTypeOfLiteralType) : widenLiteralTypes ? sameMap(candidates, getWidenedLiteralType) : candidates;
61745
61746
  const unwidenedType = inference.priority & 416 /* PriorityImpliesCombination */ ? getUnionType(baseCandidates, 2 /* Subtype */) : getCommonSupertype(baseCandidates);
@@ -64794,13 +64795,12 @@ function createTypeChecker(host) {
64794
64795
  return type;
64795
64796
  }
64796
64797
  function getContextualType2(node, contextFlags) {
64797
- var _a2;
64798
64798
  if (node.flags & 33554432 /* InWithStatement */) {
64799
64799
  return void 0;
64800
64800
  }
64801
- const contextualType = (_a2 = tryGetNodeLinks(node)) == null ? void 0 : _a2.contextualType;
64802
- if (contextualType) {
64803
- return contextualType;
64801
+ const index = findContextualNode(node);
64802
+ if (index >= 0) {
64803
+ return contextualTypes[index];
64804
64804
  }
64805
64805
  const { parent: parent2 } = node;
64806
64806
  switch (parent2.kind) {
@@ -64822,7 +64822,7 @@ function createTypeChecker(host) {
64822
64822
  return getContextualTypeForArgument(parent2, node);
64823
64823
  case 213 /* TypeAssertionExpression */:
64824
64824
  case 231 /* AsExpression */:
64825
- return isConstTypeReference(parent2.type) ? tryFindWhenConstTypeReference(parent2) : getTypeFromTypeNode(parent2.type);
64825
+ return isConstTypeReference(parent2.type) ? getContextualType2(parent2, contextFlags) : getTypeFromTypeNode(parent2.type);
64826
64826
  case 223 /* BinaryExpression */:
64827
64827
  return getContextualTypeForBinaryOperand(node, contextFlags);
64828
64828
  case 299 /* PropertyAssignment */:
@@ -64842,7 +64842,7 @@ function createTypeChecker(host) {
64842
64842
  return getContextualTypeForSubstitutionExpression(parent2.parent, node);
64843
64843
  case 214 /* ParenthesizedExpression */: {
64844
64844
  const tag = isInJSFile(parent2) ? getJSDocTypeTag(parent2) : void 0;
64845
- return !tag ? getContextualType2(parent2, contextFlags) : isJSDocTypeTag(tag) && isConstTypeReference(tag.typeExpression.type) ? tryFindWhenConstTypeReference(parent2) : getTypeFromTypeNode(tag.typeExpression.type);
64845
+ return !tag ? getContextualType2(parent2, contextFlags) : isJSDocTypeTag(tag) && isConstTypeReference(tag.typeExpression.type) ? getContextualType2(parent2, contextFlags) : getTypeFromTypeNode(tag.typeExpression.type);
64846
64846
  }
64847
64847
  case 232 /* NonNullExpression */:
64848
64848
  return getContextualType2(parent2, contextFlags);
@@ -64860,22 +64860,31 @@ function createTypeChecker(host) {
64860
64860
  return getContextualJsxElementAttributesType(parent2, contextFlags);
64861
64861
  }
64862
64862
  return void 0;
64863
- function tryFindWhenConstTypeReference(node2) {
64864
- return getContextualType2(node2, contextFlags);
64863
+ }
64864
+ function pushContextualType(node, type) {
64865
+ contextualTypeNodes[contextualTypeCount] = node;
64866
+ contextualTypes[contextualTypeCount] = type;
64867
+ contextualTypeCount++;
64868
+ }
64869
+ function popContextualType() {
64870
+ contextualTypeCount--;
64871
+ }
64872
+ function findContextualNode(node) {
64873
+ for (let i = contextualTypeCount - 1; i >= 0; i--) {
64874
+ if (node === contextualTypeNodes[i]) {
64875
+ return i;
64876
+ }
64865
64877
  }
64878
+ return -1;
64866
64879
  }
64867
64880
  function getInferenceContext(node) {
64868
- return forEachAncestor(node, (n) => {
64869
- var _a2;
64870
- return (_a2 = tryGetNodeLinks(n)) == null ? void 0 : _a2.inferenceContext;
64871
- });
64881
+ return isNodeDescendantOf(node, currentInferenceNode) ? currentInferenceContext : void 0;
64872
64882
  }
64873
64883
  function getContextualJsxElementAttributesType(node, contextFlags) {
64874
- var _a2;
64875
64884
  if (isJsxOpeningElement(node) && contextFlags !== 4 /* Completions */) {
64876
- const contextualType = (_a2 = tryGetNodeLinks(node.parent)) == null ? void 0 : _a2.contextualType;
64877
- if (contextualType) {
64878
- return contextualType;
64885
+ const index = findContextualNode(node.parent);
64886
+ if (index >= 0) {
64887
+ return contextualTypes[index];
64879
64888
  }
64880
64889
  }
64881
64890
  return getContextualTypeForArgumentAtIndex(node, 0);
@@ -65132,9 +65141,11 @@ function createTypeChecker(host) {
65132
65141
  const elementCount = elements.length;
65133
65142
  const elementTypes = [];
65134
65143
  const elementFlags = [];
65135
- const contextualType = getApparentTypeOfContextualType(node, void 0);
65144
+ pushContextualType(node, getContextualType2(node, void 0));
65136
65145
  const inDestructuringPattern = isAssignmentTarget(node);
65137
65146
  const inConstContext = isConstContext(node);
65147
+ const contextualType = getApparentTypeOfContextualType(node, void 0);
65148
+ const inTupleContext = !!contextualType && someType(contextualType, isTupleLikeType);
65138
65149
  let hasOmittedExpression = false;
65139
65150
  for (let i = 0; i < elementCount; i++) {
65140
65151
  const e = elements[i];
@@ -65159,21 +65170,21 @@ function createTypeChecker(host) {
65159
65170
  elementTypes.push(undefinedOrMissingType);
65160
65171
  elementFlags.push(2 /* Optional */);
65161
65172
  } else {
65162
- const elementContextualType = getContextualTypeForElementExpression(contextualType, elementTypes.length);
65163
- const type = checkExpressionForMutableLocation(e, checkMode, elementContextualType, forceTuple);
65173
+ const type = checkExpressionForMutableLocation(e, checkMode, forceTuple);
65164
65174
  elementTypes.push(addOptionality(type, true, hasOmittedExpression));
65165
65175
  elementFlags.push(hasOmittedExpression ? 2 /* Optional */ : 1 /* Required */);
65166
- if (contextualType && someType(contextualType, isTupleLikeType) && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
65176
+ if (inTupleContext && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
65167
65177
  const inferenceContext = getInferenceContext(node);
65168
65178
  Debug.assert(inferenceContext);
65169
65179
  addIntraExpressionInferenceSite(inferenceContext, e, type);
65170
65180
  }
65171
65181
  }
65172
65182
  }
65183
+ popContextualType();
65173
65184
  if (inDestructuringPattern) {
65174
65185
  return createTupleType(elementTypes, elementFlags);
65175
65186
  }
65176
- if (forceTuple || inConstContext || contextualType && someType(contextualType, isTupleLikeType)) {
65187
+ if (forceTuple || inConstContext || inTupleContext) {
65177
65188
  return createArrayLiteralType(createTupleType(elementTypes, elementFlags, inConstContext));
65178
65189
  }
65179
65190
  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));
@@ -65267,6 +65278,7 @@ function createTypeChecker(host) {
65267
65278
  let propertiesTable = createSymbolTable();
65268
65279
  let propertiesArray = [];
65269
65280
  let spread = emptyObjectType;
65281
+ pushContextualType(node, getContextualType2(node, void 0));
65270
65282
  const contextualType = getApparentTypeOfContextualType(node, void 0);
65271
65283
  const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === 203 /* ObjectBindingPattern */ || contextualType.pattern.kind === 207 /* ObjectLiteralExpression */);
65272
65284
  const inConstContext = isConstContext(node);
@@ -65388,6 +65400,7 @@ function createTypeChecker(host) {
65388
65400
  }
65389
65401
  propertiesArray.push(member);
65390
65402
  }
65403
+ popContextualType();
65391
65404
  if (contextualTypeHasPattern) {
65392
65405
  const rootPatternParent = findAncestor(
65393
65406
  contextualType.pattern.parent,
@@ -66975,6 +66988,7 @@ function createTypeChecker(host) {
66975
66988
  const types = [];
66976
66989
  const flags = [];
66977
66990
  const names = [];
66991
+ const inConstContext = isConstTypeVariable(restType);
66978
66992
  for (let i = index; i < argCount; i++) {
66979
66993
  const arg = args[i];
66980
66994
  if (isSpreadArgument(arg)) {
@@ -66989,7 +67003,7 @@ function createTypeChecker(host) {
66989
67003
  } else {
66990
67004
  const contextualType = getIndexedAccessType(restType, getNumberLiteralType(i - index), 256 /* Contextual */);
66991
67005
  const argType = checkExpressionWithContextualType(arg, contextualType, context, checkMode);
66992
- const hasPrimitiveContextualType = maybeTypeOfKind(contextualType, 131068 /* Primitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */);
67006
+ const hasPrimitiveContextualType = inConstContext || maybeTypeOfKind(contextualType, 131068 /* Primitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */);
66993
67007
  types.push(hasPrimitiveContextualType ? getRegularTypeOfLiteralType(argType) : getWidenedLiteralType(argType));
66994
67008
  flags.push(1 /* Required */);
66995
67009
  }
@@ -66997,7 +67011,7 @@ function createTypeChecker(host) {
66997
67011
  names.push(arg.tupleNameSource);
66998
67012
  }
66999
67013
  }
67000
- return createTupleType(types, flags, false, length(names) === length(types) ? names : void 0);
67014
+ return createTupleType(types, flags, inConstContext, length(names) === length(types) ? names : void 0);
67001
67015
  }
67002
67016
  function checkTypeArguments(signature, typeArgumentNodes, reportErrors2, headMessage) {
67003
67017
  const isJavascript = isInJSFile(signature.declaration);
@@ -68461,12 +68475,9 @@ function createTypeChecker(host) {
68461
68475
  return op === 40 /* MinusToken */ && (arg.kind === 8 /* NumericLiteral */ || arg.kind === 9 /* BigIntLiteral */) || op === 39 /* PlusToken */ && arg.kind === 8 /* NumericLiteral */;
68462
68476
  case 208 /* PropertyAccessExpression */:
68463
68477
  case 209 /* ElementAccessExpression */:
68464
- const expr = node.expression;
68465
- let symbol = getTypeOfNode(expr).symbol;
68466
- if (symbol && symbol.flags & 2097152 /* Alias */) {
68467
- symbol = resolveAlias(symbol);
68468
- }
68469
- return !!(symbol && getAllSymbolFlags(symbol) & 384 /* Enum */);
68478
+ const expr = skipParentheses(node.expression);
68479
+ const symbol = isEntityNameExpression(expr) ? resolveEntityName(expr, 111551 /* Value */, true) : void 0;
68480
+ return !!(symbol && symbol.flags & 384 /* Enum */);
68470
68481
  }
68471
68482
  return false;
68472
68483
  }
@@ -70374,23 +70385,21 @@ function createTypeChecker(host) {
70374
70385
  return node;
70375
70386
  }
70376
70387
  function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
70377
- const context = getContextNode2(node);
70378
- const links = getNodeLinks(context);
70379
- const saveContextualType = links.contextualType;
70380
- const saveInferenceContext = links.inferenceContext;
70381
- try {
70382
- links.contextualType = contextualType;
70383
- links.inferenceContext = inferenceContext;
70384
- const type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
70385
- if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
70386
- inferenceContext.intraExpressionInferenceSites = void 0;
70387
- }
70388
- const result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, void 0)) ? getRegularTypeOfLiteralType(type) : type;
70389
- return result;
70390
- } finally {
70391
- links.contextualType = saveContextualType;
70392
- links.inferenceContext = saveInferenceContext;
70393
- }
70388
+ const contextNode = getContextNode2(node);
70389
+ pushContextualType(contextNode, contextualType);
70390
+ const saveInferenceNode = currentInferenceNode;
70391
+ const saveInferenceContext = currentInferenceContext;
70392
+ currentInferenceNode = contextNode;
70393
+ currentInferenceContext = inferenceContext;
70394
+ const type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
70395
+ if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
70396
+ inferenceContext.intraExpressionInferenceSites = void 0;
70397
+ }
70398
+ const result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, void 0)) ? getRegularTypeOfLiteralType(type) : type;
70399
+ currentInferenceNode = saveInferenceNode;
70400
+ currentInferenceContext = saveInferenceContext;
70401
+ popContextualType();
70402
+ return result;
70394
70403
  }
70395
70404
  function checkExpressionCached(node, checkMode) {
70396
70405
  if (checkMode) {
@@ -70462,11 +70471,15 @@ function createTypeChecker(host) {
70462
70471
  }
70463
70472
  function isConstContext(node) {
70464
70473
  const parent2 = node.parent;
70465
- 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);
70474
+ 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);
70475
+ }
70476
+ function isConstTypeParameterContext(node) {
70477
+ const contextualType = getContextualType2(node, 0 /* None */);
70478
+ return !!contextualType && someType(contextualType, isConstTypeVariable);
70466
70479
  }
70467
- function checkExpressionForMutableLocation(node, checkMode, contextualType, forceTuple) {
70480
+ function checkExpressionForMutableLocation(node, checkMode, forceTuple) {
70468
70481
  const type = checkExpression(node, checkMode, forceTuple);
70469
- return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) : isTypeAssertion3(node) ? type : getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType2(node, void 0) : contextualType, node, void 0));
70482
+ return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) : isTypeAssertion3(node) ? type : getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(getContextualType2(node, void 0), node, void 0));
70470
70483
  }
70471
70484
  function checkPropertyAssignment(node, checkMode) {
70472
70485
  if (node.name.kind === 164 /* ComputedPropertyName */) {
@@ -70650,14 +70663,10 @@ function createTypeChecker(host) {
70650
70663
  if (links.contextFreeType) {
70651
70664
  return links.contextFreeType;
70652
70665
  }
70653
- const saveContextualType = links.contextualType;
70654
- links.contextualType = anyType;
70655
- try {
70656
- const type = links.contextFreeType = checkExpression(node, 4 /* SkipContextSensitive */);
70657
- return type;
70658
- } finally {
70659
- links.contextualType = saveContextualType;
70660
- }
70666
+ pushContextualType(node, anyType);
70667
+ const type = links.contextFreeType = checkExpression(node, 4 /* SkipContextSensitive */);
70668
+ popContextualType();
70669
+ return type;
70661
70670
  }
70662
70671
  function checkExpression(node, checkMode, forceTuple) {
70663
70672
  var _a2, _b;
@@ -70834,7 +70843,7 @@ function createTypeChecker(host) {
70834
70843
  var _a2, _b;
70835
70844
  if (isInterfaceDeclaration(node.parent) || isClassLike(node.parent) || isTypeAliasDeclaration(node.parent)) {
70836
70845
  const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node));
70837
- const modifiers = getVarianceModifiers(typeParameter);
70846
+ const modifiers = getTypeParameterModifiers(typeParameter) & (32768 /* In */ | 65536 /* Out */);
70838
70847
  if (modifiers) {
70839
70848
  const symbol = getSymbolOfDeclaration(node.parent);
70840
70849
  if (isTypeAliasDeclaration(node.parent) && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (16 /* Anonymous */ | 32 /* Mapped */))) {
@@ -77406,16 +77415,20 @@ function createTypeChecker(host) {
77406
77415
  return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_an_index_signature, tokenToString(modifier.kind));
77407
77416
  }
77408
77417
  }
77409
- if (modifier.kind !== 101 /* InKeyword */ && modifier.kind !== 145 /* OutKeyword */) {
77418
+ if (modifier.kind !== 101 /* InKeyword */ && modifier.kind !== 145 /* OutKeyword */ && modifier.kind !== 85 /* ConstKeyword */) {
77410
77419
  if (node.kind === 165 /* TypeParameter */) {
77411
77420
  return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_type_parameter, tokenToString(modifier.kind));
77412
77421
  }
77413
77422
  }
77414
77423
  switch (modifier.kind) {
77415
77424
  case 85 /* ConstKeyword */:
77416
- if (node.kind !== 263 /* EnumDeclaration */) {
77425
+ if (node.kind !== 263 /* EnumDeclaration */ && node.kind !== 165 /* TypeParameter */) {
77417
77426
  return grammarErrorOnNode(node, Diagnostics.A_class_member_cannot_have_the_0_keyword, tokenToString(85 /* ConstKeyword */));
77418
77427
  }
77428
+ const parent2 = node.parent;
77429
+ if (node.kind === 165 /* TypeParameter */ && !(isFunctionLikeDeclaration(parent2) || isClassDeclaration(parent2) || isFunctionTypeNode(parent2) || isConstructorTypeNode(parent2) || isCallSignatureDeclaration(parent2) || isConstructSignatureDeclaration(parent2) || isMethodSignature(parent2))) {
77430
+ return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_type_parameter_of_a_function_method_or_class, tokenToString(modifier.kind));
77431
+ }
77419
77432
  break;
77420
77433
  case 161 /* OverrideKeyword */:
77421
77434
  if (flags & 16384 /* Override */) {
@@ -133004,7 +133017,7 @@ function addNewNodeForMemberSymbol(symbol, enclosingDeclaration, sourceFile, con
133004
133017
  if (declaration && isAutoAccessorPropertyDeclaration(declaration)) {
133005
133018
  modifierFlags |= 128 /* Accessor */;
133006
133019
  }
133007
- const modifiers = modifierFlags ? factory.createNodeArray(factory.createModifiersFromModifierFlags(modifierFlags)) : void 0;
133020
+ const modifiers = createModifiers();
133008
133021
  const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
133009
133022
  const optional = !!(symbol.flags & 16777216 /* Optional */);
133010
133023
  const ambient = !!(enclosingDeclaration.flags & 16777216 /* Ambient */) || isAmbient;
@@ -133097,6 +133110,19 @@ function addNewNodeForMemberSymbol(symbol, enclosingDeclaration, sourceFile, con
133097
133110
  if (method)
133098
133111
  addClassElement(method);
133099
133112
  }
133113
+ function createModifiers() {
133114
+ let modifiers2;
133115
+ if (modifierFlags) {
133116
+ modifiers2 = combine(modifiers2, factory.createModifiersFromModifierFlags(modifierFlags));
133117
+ }
133118
+ if (shouldAddOverrideKeyword()) {
133119
+ modifiers2 = append(modifiers2, factory.createToken(161 /* OverrideKeyword */));
133120
+ }
133121
+ return modifiers2 && factory.createNodeArray(modifiers2);
133122
+ }
133123
+ function shouldAddOverrideKeyword() {
133124
+ return !!(context.program.getCompilerOptions().noImplicitOverride && declaration && hasAbstractModifier(declaration));
133125
+ }
133100
133126
  function createName(node) {
133101
133127
  if (isIdentifier(node) && node.escapedText === "constructor") {
133102
133128
  return factory.createComputedPropertyName(factory.createStringLiteral(idText(node), quotePreference === 0 /* Single */));
@@ -133114,14 +133140,15 @@ function createSignatureDeclarationFromSignature(kind, context, quotePreference,
133114
133140
  const program = context.program;
133115
133141
  const checker = program.getTypeChecker();
133116
133142
  const scriptTarget = getEmitScriptTarget(program.getCompilerOptions());
133143
+ const isJs = isInJSFile(enclosingDeclaration);
133117
133144
  const flags = 1 /* NoTruncation */ | 256 /* SuppressAnyReturnType */ | 524288 /* AllowEmptyTuple */ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */);
133118
133145
  const signatureDeclaration = checker.signatureToSignatureDeclaration(signature, kind, enclosingDeclaration, flags, getNoopSymbolTrackerWithResolver(context));
133119
133146
  if (!signatureDeclaration) {
133120
133147
  return void 0;
133121
133148
  }
133122
- let typeParameters = signatureDeclaration.typeParameters;
133149
+ let typeParameters = isJs ? void 0 : signatureDeclaration.typeParameters;
133123
133150
  let parameters = signatureDeclaration.parameters;
133124
- let type = signatureDeclaration.type;
133151
+ let type = isJs ? void 0 : signatureDeclaration.type;
133125
133152
  if (importAdder) {
133126
133153
  if (typeParameters) {
133127
133154
  const newTypeParameters = sameMap(typeParameters, (typeParameterDecl) => {
@@ -133154,18 +133181,20 @@ function createSignatureDeclarationFromSignature(kind, context, quotePreference,
133154
133181
  }
133155
133182
  }
133156
133183
  const newParameters = sameMap(parameters, (parameterDecl) => {
133157
- const importableReference = tryGetAutoImportableReferenceFromTypeNode(parameterDecl.type, scriptTarget);
133158
- let type2 = parameterDecl.type;
133159
- if (importableReference) {
133160
- type2 = importableReference.typeNode;
133161
- importSymbols(importAdder, importableReference.symbols);
133184
+ let type2 = isJs ? void 0 : parameterDecl.type;
133185
+ if (type2) {
133186
+ const importableReference = tryGetAutoImportableReferenceFromTypeNode(type2, scriptTarget);
133187
+ if (importableReference) {
133188
+ type2 = importableReference.typeNode;
133189
+ importSymbols(importAdder, importableReference.symbols);
133190
+ }
133162
133191
  }
133163
133192
  return factory.updateParameterDeclaration(
133164
133193
  parameterDecl,
133165
133194
  parameterDecl.modifiers,
133166
133195
  parameterDecl.dotDotDotToken,
133167
133196
  parameterDecl.name,
133168
- parameterDecl.questionToken,
133197
+ isJs ? void 0 : parameterDecl.questionToken,
133169
133198
  type2,
133170
133199
  parameterDecl.initializer
133171
133200
  );