typescript 4.6.0-dev.20220211 → 4.7.0-dev.20220217

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
@@ -96,11 +96,11 @@ var ts;
96
96
  (function (ts) {
97
97
  // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
98
98
  // If changing the text in this section, be sure to test `configurePrerelease` too.
99
- ts.versionMajorMinor = "4.6";
99
+ ts.versionMajorMinor = "4.7";
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220211";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220217";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -4840,6 +4840,8 @@ var ts;
4840
4840
  TypeFlags[TypeFlags["ESSymbolLike"] = 12288] = "ESSymbolLike";
4841
4841
  TypeFlags[TypeFlags["VoidLike"] = 49152] = "VoidLike";
4842
4842
  /* @internal */
4843
+ TypeFlags[TypeFlags["DefinitelyNonNullable"] = 470302716] = "DefinitelyNonNullable";
4844
+ /* @internal */
4843
4845
  TypeFlags[TypeFlags["DisjointDomains"] = 469892092] = "DisjointDomains";
4844
4846
  TypeFlags[TypeFlags["UnionOrIntersection"] = 3145728] = "UnionOrIntersection";
4845
4847
  TypeFlags[TypeFlags["StructuredType"] = 3670016] = "StructuredType";
@@ -4918,13 +4920,14 @@ var ts;
4918
4920
  // Flags that require TypeFlags.Object
4919
4921
  ObjectFlags[ObjectFlags["ContainsSpread"] = 4194304] = "ContainsSpread";
4920
4922
  ObjectFlags[ObjectFlags["ObjectRestType"] = 8388608] = "ObjectRestType";
4923
+ ObjectFlags[ObjectFlags["InstantiationExpressionType"] = 16777216] = "InstantiationExpressionType";
4921
4924
  /* @internal */
4922
- ObjectFlags[ObjectFlags["IsClassInstanceClone"] = 16777216] = "IsClassInstanceClone";
4925
+ ObjectFlags[ObjectFlags["IsClassInstanceClone"] = 33554432] = "IsClassInstanceClone";
4923
4926
  // Flags that require TypeFlags.Object and ObjectFlags.Reference
4924
4927
  /* @internal */
4925
- ObjectFlags[ObjectFlags["IdenticalBaseTypeCalculated"] = 33554432] = "IdenticalBaseTypeCalculated";
4928
+ ObjectFlags[ObjectFlags["IdenticalBaseTypeCalculated"] = 67108864] = "IdenticalBaseTypeCalculated";
4926
4929
  /* @internal */
4927
- ObjectFlags[ObjectFlags["IdenticalBaseTypeExists"] = 67108864] = "IdenticalBaseTypeExists";
4930
+ ObjectFlags[ObjectFlags["IdenticalBaseTypeExists"] = 134217728] = "IdenticalBaseTypeExists";
4928
4931
  // Flags that require TypeFlags.UnionOrIntersection or TypeFlags.Substitution
4929
4932
  /* @internal */
4930
4933
  ObjectFlags[ObjectFlags["IsGenericTypeComputed"] = 4194304] = "IsGenericTypeComputed";
@@ -5572,6 +5575,8 @@ var ts;
5572
5575
  BundleFileSectionKind["NoDefaultLib"] = "no-default-lib";
5573
5576
  BundleFileSectionKind["Reference"] = "reference";
5574
5577
  BundleFileSectionKind["Type"] = "type";
5578
+ BundleFileSectionKind["TypeResolutionModeRequire"] = "type-require";
5579
+ BundleFileSectionKind["TypeResolutionModeImport"] = "type-import";
5575
5580
  BundleFileSectionKind["Lib"] = "lib";
5576
5581
  BundleFileSectionKind["Prepend"] = "prepend";
5577
5582
  BundleFileSectionKind["Text"] = "text";
@@ -5688,7 +5693,8 @@ var ts;
5688
5693
  { name: "types", optional: true, captureSpan: true },
5689
5694
  { name: "lib", optional: true, captureSpan: true },
5690
5695
  { name: "path", optional: true, captureSpan: true },
5691
- { name: "no-default-lib", optional: true }
5696
+ { name: "no-default-lib", optional: true },
5697
+ { name: "resolution-mode", optional: true }
5692
5698
  ],
5693
5699
  kind: 1 /* TripleSlashXML */
5694
5700
  },
@@ -7636,18 +7642,6 @@ var ts;
7636
7642
  return getCanonicalFileName(nonCanonicalizedPath);
7637
7643
  }
7638
7644
  ts.toPath = toPath;
7639
- function normalizePathAndParts(path) {
7640
- path = normalizeSlashes(path);
7641
- var _a = reducePathComponents(getPathComponents(path)), root = _a[0], parts = _a.slice(1);
7642
- if (parts.length) {
7643
- var joinedParts = root + parts.join(ts.directorySeparator);
7644
- return { path: hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(joinedParts) : joinedParts, parts: parts };
7645
- }
7646
- else {
7647
- return { path: root, parts: parts };
7648
- }
7649
- }
7650
- ts.normalizePathAndParts = normalizePathAndParts;
7651
7645
  function removeTrailingDirectorySeparator(path) {
7652
7646
  if (hasTrailingDirectorySeparator(path)) {
7653
7647
  return path.substr(0, path.length - 1);
@@ -8081,6 +8075,8 @@ var ts;
8081
8075
  Property_0_cannot_have_an_initializer_because_it_is_marked_abstract: diag(1267, ts.DiagnosticCategory.Error, "Property_0_cannot_have_an_initializer_because_it_is_marked_abstract_1267", "Property '{0}' cannot have an initializer because it is marked abstract."),
8082
8076
  An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type: diag(1268, ts.DiagnosticCategory.Error, "An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type_1268", "An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type."),
8083
8077
  Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided: diag(1269, ts.DiagnosticCategory.Error, "Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided_1269", "Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided."),
8078
+ Decorator_function_return_type_0_is_not_assignable_to_type_1: diag(1270, ts.DiagnosticCategory.Error, "Decorator_function_return_type_0_is_not_assignable_to_type_1_1270", "Decorator function return type '{0}' is not assignable to type '{1}'."),
8079
+ Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any: diag(1271, ts.DiagnosticCategory.Error, "Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any_1271", "Decorator function return type is '{0}' but is expected to be 'void' or 'any'."),
8084
8080
  with_statements_are_not_allowed_in_an_async_function_block: diag(1300, ts.DiagnosticCategory.Error, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."),
8085
8081
  await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, ts.DiagnosticCategory.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."),
8086
8082
  Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern: diag(1312, ts.DiagnosticCategory.Error, "Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_1312", "Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern."),
@@ -8149,7 +8145,6 @@ var ts;
8149
8145
  Unexpected_token_Did_you_mean_or_rbrace: diag(1381, ts.DiagnosticCategory.Error, "Unexpected_token_Did_you_mean_or_rbrace_1381", "Unexpected token. Did you mean `{'}'}` or `}`?"),
8150
8146
  Unexpected_token_Did_you_mean_or_gt: diag(1382, ts.DiagnosticCategory.Error, "Unexpected_token_Did_you_mean_or_gt_1382", "Unexpected token. Did you mean `{'>'}` or `>`?"),
8151
8147
  Only_named_exports_may_use_export_type: diag(1383, ts.DiagnosticCategory.Error, "Only_named_exports_may_use_export_type_1383", "Only named exports may use 'export type'."),
8152
- A_new_expression_with_type_arguments_must_always_be_followed_by_a_parenthesized_argument_list: diag(1384, ts.DiagnosticCategory.Error, "A_new_expression_with_type_arguments_must_always_be_followed_by_a_parenthesized_argument_list_1384", "A 'new' expression with type arguments must always be followed by a parenthesized argument list."),
8153
8148
  Function_type_notation_must_be_parenthesized_when_used_in_a_union_type: diag(1385, ts.DiagnosticCategory.Error, "Function_type_notation_must_be_parenthesized_when_used_in_a_union_type_1385", "Function type notation must be parenthesized when used in a union type."),
8154
8149
  Constructor_type_notation_must_be_parenthesized_when_used_in_a_union_type: diag(1386, ts.DiagnosticCategory.Error, "Constructor_type_notation_must_be_parenthesized_when_used_in_a_union_type_1386", "Constructor type notation must be parenthesized when used in a union type."),
8155
8150
  Function_type_notation_must_be_parenthesized_when_used_in_an_intersection_type: diag(1387, ts.DiagnosticCategory.Error, "Function_type_notation_must_be_parenthesized_when_used_in_an_intersection_type_1387", "Function type notation must be parenthesized when used in an intersection type."),
@@ -8214,6 +8209,8 @@ var ts;
8214
8209
  Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."),
8215
8210
  Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"),
8216
8211
  Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"),
8212
+ Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node12` or `nodenext`."),
8213
+ resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."),
8217
8214
  The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output: diag(1470, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output_1470", "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output."),
8218
8215
  Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead: diag(1471, ts.DiagnosticCategory.Error, "Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_c_1471", "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead."),
8219
8216
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -8533,6 +8530,7 @@ var ts;
8533
8530
  Cannot_assign_to_0_because_it_is_an_import: diag(2632, ts.DiagnosticCategory.Error, "Cannot_assign_to_0_because_it_is_an_import_2632", "Cannot assign to '{0}' because it is an import."),
8534
8531
  JSX_property_access_expressions_cannot_include_JSX_namespace_names: diag(2633, ts.DiagnosticCategory.Error, "JSX_property_access_expressions_cannot_include_JSX_namespace_names_2633", "JSX property access expressions cannot include JSX namespace names"),
8535
8532
  _0_index_signatures_are_incompatible: diag(2634, ts.DiagnosticCategory.Error, "_0_index_signatures_are_incompatible_2634", "'{0}' index signatures are incompatible."),
8533
+ Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable: diag(2635, ts.DiagnosticCategory.Error, "Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable_2635", "Type '{0}' has no signatures for which the type argument list is applicable."),
8536
8534
  Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity: diag(2649, ts.DiagnosticCategory.Error, "Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity_2649", "Cannot augment module '{0}' with value exports because it resolves to a non-module entity."),
8537
8535
  A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: diag(2651, ts.DiagnosticCategory.Error, "A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_memb_2651", "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums."),
8538
8536
  Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: diag(2652, ts.DiagnosticCategory.Error, "Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_d_2652", "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead."),
@@ -13424,6 +13422,7 @@ var ts;
13424
13422
  case 110 /* TrueKeyword */:
13425
13423
  case 106 /* SuperKeyword */:
13426
13424
  case 229 /* NonNullExpression */:
13425
+ case 227 /* ExpressionWithTypeArguments */:
13427
13426
  case 230 /* MetaProperty */:
13428
13427
  case 100 /* ImportKeyword */: // technically this is only an Expression if it's in a CallExpression
13429
13428
  return true;
@@ -14097,7 +14096,11 @@ var ts;
14097
14096
  ts.Debug.assert(names.length === newResolutions.length);
14098
14097
  for (var i = 0; i < names.length; i++) {
14099
14098
  var newResolution = newResolutions[i];
14100
- var oldResolution = oldResolutions && oldResolutions.get(names[i], oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i));
14099
+ var entry = names[i];
14100
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
14101
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
14102
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, oldSourceFile === null || oldSourceFile === void 0 ? void 0 : oldSourceFile.impliedNodeFormat) : oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i);
14103
+ var oldResolution = oldResolutions && oldResolutions.get(name, mode);
14101
14104
  var changed = oldResolution
14102
14105
  ? !newResolution || !comparer(oldResolution, newResolution)
14103
14106
  : newResolution;
@@ -15133,7 +15136,7 @@ var ts;
15133
15136
  case 114 /* VoidKeyword */:
15134
15137
  return node.parent.kind !== 216 /* VoidExpression */;
15135
15138
  case 227 /* ExpressionWithTypeArguments */:
15136
- return !isExpressionWithTypeArgumentsInClassExtendsClause(node);
15139
+ return ts.isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
15137
15140
  case 162 /* TypeParameter */:
15138
15141
  return node.parent.kind === 194 /* MappedType */ || node.parent.kind === 189 /* InferType */;
15139
15142
  // Identifiers and qualified names may be type nodes, depending on their context. Climb
@@ -15170,7 +15173,7 @@ var ts;
15170
15173
  }
15171
15174
  switch (parent.kind) {
15172
15175
  case 227 /* ExpressionWithTypeArguments */:
15173
- return !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
15176
+ return ts.isHeritageClause(parent.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
15174
15177
  case 162 /* TypeParameter */:
15175
15178
  return node === parent.constraint;
15176
15179
  case 342 /* JSDocTemplateTag */:
@@ -15873,7 +15876,7 @@ var ts;
15873
15876
  case 296 /* SpreadAssignment */:
15874
15877
  return true;
15875
15878
  case 227 /* ExpressionWithTypeArguments */:
15876
- return parent.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent);
15879
+ return parent.expression === node && !isPartOfTypeNode(parent);
15877
15880
  case 295 /* ShorthandPropertyAssignment */:
15878
15881
  return parent.objectAssignmentInitializer === node;
15879
15882
  default:
@@ -22860,16 +22863,18 @@ var ts;
22860
22863
  return updateConstructorTypeNode1(node, node.modifiers, typeParameters, parameters, type);
22861
22864
  }
22862
22865
  // @api
22863
- function createTypeQueryNode(exprName) {
22866
+ function createTypeQueryNode(exprName, typeArguments) {
22864
22867
  var node = createBaseNode(180 /* TypeQuery */);
22865
22868
  node.exprName = exprName;
22869
+ node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
22866
22870
  node.transformFlags = 1 /* ContainsTypeScript */;
22867
22871
  return node;
22868
22872
  }
22869
22873
  // @api
22870
- function updateTypeQueryNode(node, exprName) {
22874
+ function updateTypeQueryNode(node, exprName, typeArguments) {
22871
22875
  return node.exprName !== exprName
22872
- ? update(createTypeQueryNode(exprName), node)
22876
+ || node.typeArguments !== typeArguments
22877
+ ? update(createTypeQueryNode(exprName, typeArguments), node)
22873
22878
  : node;
22874
22879
  }
22875
22880
  // @api
@@ -26692,7 +26697,13 @@ var ts;
26692
26697
  referencedFiles = ts.append(referencedFiles, { pos: -1, end: -1, fileName: section.data });
26693
26698
  break;
26694
26699
  case "type" /* Type */:
26695
- typeReferenceDirectives = ts.append(typeReferenceDirectives, section.data);
26700
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
26701
+ break;
26702
+ case "type-import" /* TypeResolutionModeImport */:
26703
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.ESNext });
26704
+ break;
26705
+ case "type-require" /* TypeResolutionModeRequire */:
26706
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.CommonJS });
26696
26707
  break;
26697
26708
  case "lib" /* Lib */:
26698
26709
  libReferenceDirectives = ts.append(libReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
@@ -26751,6 +26762,8 @@ var ts;
26751
26762
  case "no-default-lib" /* NoDefaultLib */:
26752
26763
  case "reference" /* Reference */:
26753
26764
  case "type" /* Type */:
26765
+ case "type-import" /* TypeResolutionModeImport */:
26766
+ case "type-require" /* TypeResolutionModeRequire */:
26754
26767
  case "lib" /* Lib */:
26755
26768
  syntheticReferences = ts.append(syntheticReferences, ts.setTextRange(ts.factory.createUnparsedSyntheticReference(section), section));
26756
26769
  break;
@@ -29985,7 +29998,8 @@ var ts;
29985
29998
  visitNode(cbNode, node.parameterName) ||
29986
29999
  visitNode(cbNode, node.type);
29987
30000
  case 180 /* TypeQuery */:
29988
- return visitNode(cbNode, node.exprName);
30001
+ return visitNode(cbNode, node.exprName) ||
30002
+ visitNodes(cbNode, cbNodes, node.typeArguments);
29989
30003
  case 181 /* TypeLiteral */:
29990
30004
  return visitNodes(cbNode, cbNodes, node.members);
29991
30005
  case 182 /* ArrayType */:
@@ -30664,7 +30678,7 @@ var ts;
30664
30678
  initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, 1 /* JS */);
30665
30679
  // Prime the scanner.
30666
30680
  nextToken();
30667
- var entityName = parseEntityName(/*allowReservedWords*/ true);
30681
+ var entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false);
30668
30682
  var isInvalid = token() === 1 /* EndOfFileToken */ && !parseDiagnostics.length;
30669
30683
  clearState();
30670
30684
  return isInvalid ? entityName : undefined;
@@ -32241,7 +32255,7 @@ var ts;
32241
32255
  }
32242
32256
  return createMissingList();
32243
32257
  }
32244
- function parseEntityName(allowReservedWords, diagnosticMessage) {
32258
+ function parseEntityName(allowReservedWords, allowPrivateIdentifiers, diagnosticMessage) {
32245
32259
  var pos = getNodePos();
32246
32260
  var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage);
32247
32261
  var dotPos = getNodePos();
@@ -32252,7 +32266,7 @@ var ts;
32252
32266
  break;
32253
32267
  }
32254
32268
  dotPos = getNodePos();
32255
- entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos);
32269
+ entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, allowPrivateIdentifiers)), pos);
32256
32270
  }
32257
32271
  return entity;
32258
32272
  }
@@ -32385,7 +32399,7 @@ var ts;
32385
32399
  }
32386
32400
  // TYPES
32387
32401
  function parseEntityNameOfTypeReference() {
32388
- return parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
32402
+ return parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false, ts.Diagnostics.Type_expected);
32389
32403
  }
32390
32404
  function parseTypeArgumentsOfTypeReference() {
32391
32405
  if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 29 /* LessThanToken */) {
@@ -32518,7 +32532,9 @@ var ts;
32518
32532
  function parseTypeQuery() {
32519
32533
  var pos = getNodePos();
32520
32534
  parseExpected(112 /* TypeOfKeyword */);
32521
- return finishNode(factory.createTypeQueryNode(parseEntityName(/*allowReservedWords*/ true)), pos);
32535
+ var entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true);
32536
+ var typeArguments = tryParseTypeArguments();
32537
+ return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos);
32522
32538
  }
32523
32539
  function parseTypeParameter() {
32524
32540
  var pos = getNodePos();
@@ -34588,20 +34604,30 @@ var ts;
34588
34604
  expression = parsePropertyAccessExpressionRest(pos, expression, questionDotToken);
34589
34605
  continue;
34590
34606
  }
34591
- if (!questionDotToken && token() === 53 /* ExclamationToken */ && !scanner.hasPrecedingLineBreak()) {
34592
- nextToken();
34593
- expression = finishNode(factory.createNonNullExpression(expression), pos);
34594
- continue;
34595
- }
34596
34607
  // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName
34597
34608
  if ((questionDotToken || !inDecoratorContext()) && parseOptional(22 /* OpenBracketToken */)) {
34598
34609
  expression = parseElementAccessExpressionRest(pos, expression, questionDotToken);
34599
34610
  continue;
34600
34611
  }
34601
34612
  if (isTemplateStartOfTaggedTemplate()) {
34602
- expression = parseTaggedTemplateRest(pos, expression, questionDotToken, /*typeArguments*/ undefined);
34613
+ // Absorb type arguments into TemplateExpression when preceding expression is ExpressionWithTypeArguments
34614
+ expression = !questionDotToken && expression.kind === 227 /* ExpressionWithTypeArguments */ ?
34615
+ parseTaggedTemplateRest(pos, expression.expression, questionDotToken, expression.typeArguments) :
34616
+ parseTaggedTemplateRest(pos, expression, questionDotToken, /*typeArguments*/ undefined);
34603
34617
  continue;
34604
34618
  }
34619
+ if (!questionDotToken) {
34620
+ if (token() === 53 /* ExclamationToken */ && !scanner.hasPrecedingLineBreak()) {
34621
+ nextToken();
34622
+ expression = finishNode(factory.createNonNullExpression(expression), pos);
34623
+ continue;
34624
+ }
34625
+ var typeArguments = tryParse(parseTypeArgumentsInExpression);
34626
+ if (typeArguments) {
34627
+ expression = finishNode(factory.createExpressionWithTypeArguments(expression, typeArguments), pos);
34628
+ continue;
34629
+ }
34630
+ }
34605
34631
  return expression;
34606
34632
  }
34607
34633
  }
@@ -34621,38 +34647,30 @@ var ts;
34621
34647
  function parseCallExpressionRest(pos, expression) {
34622
34648
  while (true) {
34623
34649
  expression = parseMemberExpressionRest(pos, expression, /*allowOptionalChain*/ true);
34650
+ var typeArguments = void 0;
34624
34651
  var questionDotToken = parseOptionalToken(28 /* QuestionDotToken */);
34625
- // handle 'foo<<T>()'
34626
- // parse template arguments only in TypeScript files (not in JavaScript files).
34627
- if ((contextFlags & 131072 /* JavaScriptFile */) === 0 && (token() === 29 /* LessThanToken */ || token() === 47 /* LessThanLessThanToken */)) {
34628
- // See if this is the start of a generic invocation. If so, consume it and
34629
- // keep checking for postfix expressions. Otherwise, it's just a '<' that's
34630
- // part of an arithmetic expression. Break out so we consume it higher in the
34631
- // stack.
34632
- var typeArguments = tryParse(parseTypeArgumentsInExpression);
34633
- if (typeArguments) {
34634
- if (isTemplateStartOfTaggedTemplate()) {
34635
- expression = parseTaggedTemplateRest(pos, expression, questionDotToken, typeArguments);
34636
- continue;
34637
- }
34638
- var argumentList = parseArgumentList();
34639
- var callExpr = questionDotToken || tryReparseOptionalChain(expression) ?
34640
- factory.createCallChain(expression, questionDotToken, typeArguments, argumentList) :
34641
- factory.createCallExpression(expression, typeArguments, argumentList);
34642
- expression = finishNode(callExpr, pos);
34652
+ if (questionDotToken) {
34653
+ typeArguments = tryParse(parseTypeArgumentsInExpression);
34654
+ if (isTemplateStartOfTaggedTemplate()) {
34655
+ expression = parseTaggedTemplateRest(pos, expression, questionDotToken, typeArguments);
34643
34656
  continue;
34644
34657
  }
34645
34658
  }
34646
- else if (token() === 20 /* OpenParenToken */) {
34659
+ if (typeArguments || token() === 20 /* OpenParenToken */) {
34660
+ // Absorb type arguments into CallExpression when preceding expression is ExpressionWithTypeArguments
34661
+ if (!questionDotToken && expression.kind === 227 /* ExpressionWithTypeArguments */) {
34662
+ typeArguments = expression.typeArguments;
34663
+ expression = expression.expression;
34664
+ }
34647
34665
  var argumentList = parseArgumentList();
34648
34666
  var callExpr = questionDotToken || tryReparseOptionalChain(expression) ?
34649
- factory.createCallChain(expression, questionDotToken, /*typeArguments*/ undefined, argumentList) :
34650
- factory.createCallExpression(expression, /*typeArguments*/ undefined, argumentList);
34667
+ factory.createCallChain(expression, questionDotToken, typeArguments, argumentList) :
34668
+ factory.createCallExpression(expression, typeArguments, argumentList);
34651
34669
  expression = finishNode(callExpr, pos);
34652
34670
  continue;
34653
34671
  }
34654
34672
  if (questionDotToken) {
34655
- // We failed to parse anything, so report a missing identifier here.
34673
+ // We parsed `?.` but then failed to parse anything, so report a missing identifier here.
34656
34674
  var name = createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics.Identifier_expected);
34657
34675
  expression = finishNode(factory.createPropertyAccessChain(expression, questionDotToken, name), pos);
34658
34676
  }
@@ -34680,21 +34698,25 @@ var ts;
34680
34698
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
34681
34699
  return undefined;
34682
34700
  }
34683
- // If we have a '<', then only parse this as a argument list if the type arguments
34684
- // are complete and we have an open paren. if we don't, rewind and return nothing.
34685
- return typeArguments && canFollowTypeArgumentsInExpression()
34686
- ? typeArguments
34687
- : undefined;
34701
+ // We successfully parsed a type argument list. The next token determines whether we want to
34702
+ // treat it as such. If the type argument list is followed by `(` or a template literal, as in
34703
+ // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
34704
+ // it as a relational expression.
34705
+ return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments : undefined;
34688
34706
  }
34689
34707
  function canFollowTypeArgumentsInExpression() {
34690
34708
  switch (token()) {
34709
+ // These tokens can follow a type argument list in a call expression.
34691
34710
  case 20 /* OpenParenToken */: // foo<x>(
34692
34711
  case 14 /* NoSubstitutionTemplateLiteral */: // foo<T> `...`
34693
34712
  case 15 /* TemplateHead */: // foo<T> `...${100}...`
34694
- // these are the only tokens can legally follow a type argument
34695
- // list. So we definitely want to treat them as type arg lists.
34713
+ // These tokens can't follow in a call expression, nor can they start an
34714
+ // expression. So, consider the type argument list part of an instantiation
34715
+ // expression.
34696
34716
  // falls through
34717
+ case 27 /* CommaToken */: // foo<x>,
34697
34718
  case 24 /* DotToken */: // foo<x>.
34719
+ case 28 /* QuestionDotToken */: // foo<x>?.
34698
34720
  case 21 /* CloseParenToken */: // foo<x>)
34699
34721
  case 23 /* CloseBracketToken */: // foo<x>]
34700
34722
  case 58 /* ColonToken */: // foo<x>:
@@ -34712,20 +34734,10 @@ var ts;
34712
34734
  case 51 /* BarToken */: // foo<x> |
34713
34735
  case 19 /* CloseBraceToken */: // foo<x> }
34714
34736
  case 1 /* EndOfFileToken */: // foo<x>
34715
- // these cases can't legally follow a type arg list. However, they're not legal
34716
- // expressions either. The user is probably in the middle of a generic type. So
34717
- // treat it as such.
34718
34737
  return true;
34719
- case 27 /* CommaToken */: // foo<x>,
34720
- case 18 /* OpenBraceToken */: // foo<x> {
34721
- // We don't want to treat these as type arguments. Otherwise we'll parse this
34722
- // as an invocation expression. Instead, we want to parse out the expression
34723
- // in isolation from the type arguments.
34724
- // falls through
34725
- default:
34726
- // Anything else treat as an expression.
34727
- return false;
34728
34738
  }
34739
+ // Treat anything else as an expression.
34740
+ return false;
34729
34741
  }
34730
34742
  function parsePrimaryExpression() {
34731
34743
  switch (token()) {
@@ -34906,26 +34918,15 @@ var ts;
34906
34918
  return finishNode(factory.createMetaProperty(103 /* NewKeyword */, name), pos);
34907
34919
  }
34908
34920
  var expressionPos = getNodePos();
34909
- var expression = parsePrimaryExpression();
34921
+ var expression = parseMemberExpressionRest(expressionPos, parsePrimaryExpression(), /*allowOptionalChain*/ false);
34910
34922
  var typeArguments;
34911
- while (true) {
34912
- expression = parseMemberExpressionRest(expressionPos, expression, /*allowOptionalChain*/ false);
34913
- typeArguments = tryParse(parseTypeArgumentsInExpression);
34914
- if (isTemplateStartOfTaggedTemplate()) {
34915
- ts.Debug.assert(!!typeArguments, "Expected a type argument list; all plain tagged template starts should be consumed in 'parseMemberExpressionRest'");
34916
- expression = parseTaggedTemplateRest(expressionPos, expression, /*optionalChain*/ undefined, typeArguments);
34917
- typeArguments = undefined;
34918
- }
34919
- break;
34920
- }
34921
- var argumentsArray;
34922
- if (token() === 20 /* OpenParenToken */) {
34923
- argumentsArray = parseArgumentList();
34924
- }
34925
- else if (typeArguments) {
34926
- parseErrorAt(pos, scanner.getStartPos(), ts.Diagnostics.A_new_expression_with_type_arguments_must_always_be_followed_by_a_parenthesized_argument_list);
34923
+ // Absorb type arguments into NewExpression when preceding expression is ExpressionWithTypeArguments
34924
+ if (expression.kind === 227 /* ExpressionWithTypeArguments */) {
34925
+ typeArguments = expression.typeArguments;
34926
+ expression = expression.expression;
34927
34927
  }
34928
- return finishNode(factory.createNewExpression(expression, typeArguments, argumentsArray), pos);
34928
+ var argumentList = token() === 20 /* OpenParenToken */ ? parseArgumentList() : undefined;
34929
+ return finishNode(factory.createNewExpression(expression, typeArguments, argumentList), pos);
34929
34930
  }
34930
34931
  // STATEMENTS
34931
34932
  function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) {
@@ -35089,11 +35090,12 @@ var ts;
35089
35090
  }
35090
35091
  function parseCaseClause() {
35091
35092
  var pos = getNodePos();
35093
+ var hasJSDoc = hasPrecedingJSDocComment();
35092
35094
  parseExpected(82 /* CaseKeyword */);
35093
35095
  var expression = allowInAnd(parseExpression);
35094
35096
  parseExpected(58 /* ColonToken */);
35095
35097
  var statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
35096
- return finishNode(factory.createCaseClause(expression, statements), pos);
35098
+ return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc);
35097
35099
  }
35098
35100
  function parseDefaultClause() {
35099
35101
  var pos = getNodePos();
@@ -36013,6 +36015,9 @@ var ts;
36013
36015
  function parseExpressionWithTypeArguments() {
36014
36016
  var pos = getNodePos();
36015
36017
  var expression = parseLeftHandSideExpressionOrHigher();
36018
+ if (expression.kind === 227 /* ExpressionWithTypeArguments */) {
36019
+ return expression;
36020
+ }
36016
36021
  var typeArguments = tryParseTypeArguments();
36017
36022
  return finishNode(factory.createExpressionWithTypeArguments(expression, typeArguments), pos);
36018
36023
  }
@@ -36256,7 +36261,7 @@ var ts;
36256
36261
  function parseModuleReference() {
36257
36262
  return isExternalModuleReference()
36258
36263
  ? parseExternalModuleReference()
36259
- : parseEntityName(/*allowReservedWords*/ false);
36264
+ : parseEntityName(/*allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36260
36265
  }
36261
36266
  function parseExternalModuleReference() {
36262
36267
  var pos = getNodePos();
@@ -36538,7 +36543,7 @@ var ts;
36538
36543
  var pos = getNodePos();
36539
36544
  var hasBrace = parseOptional(18 /* OpenBraceToken */);
36540
36545
  var p2 = getNodePos();
36541
- var entityName = parseEntityName(/* allowReservedWords*/ false);
36546
+ var entityName = parseEntityName(/* allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36542
36547
  while (token() === 80 /* PrivateIdentifier */) {
36543
36548
  reScanHashToken(); // rescan #id as # id
36544
36549
  nextTokenJSDoc(); // then skip the #
@@ -36981,7 +36986,7 @@ var ts;
36981
36986
  // parseEntityName logs an error for non-identifier, so create a MissingNode ourselves to avoid the error
36982
36987
  var p2 = getNodePos();
36983
36988
  var name = ts.tokenIsIdentifierOrKeyword(token())
36984
- ? parseEntityName(/*allowReservedWords*/ true)
36989
+ ? parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false)
36985
36990
  : undefined;
36986
36991
  if (name) {
36987
36992
  while (token() === 80 /* PrivateIdentifier */) {
@@ -37006,11 +37011,13 @@ var ts;
37006
37011
  && nextTokenJSDoc() === 59 /* AtToken */
37007
37012
  && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc())) {
37008
37013
  var kind = scanner.getTokenValue();
37009
- if (kind === "link" || kind === "linkcode" || kind === "linkplain") {
37014
+ if (isJSDocLinkTag(kind))
37010
37015
  return kind;
37011
- }
37012
37016
  }
37013
37017
  }
37018
+ function isJSDocLinkTag(kind) {
37019
+ return kind === "link" || kind === "linkcode" || kind === "linkplain";
37020
+ }
37014
37021
  function parseUnknownTag(start, tagName, indent, indentText) {
37015
37022
  return finishNode(factory.createJSDocUnknownTag(tagName, parseTrailingTagComments(start, getNodePos(), indent, indentText)), start);
37016
37023
  }
@@ -37116,7 +37123,7 @@ var ts;
37116
37123
  }
37117
37124
  function parseSeeTag(start, tagName, indent, indentText) {
37118
37125
  var isMarkdownOrJSDocLink = token() === 22 /* OpenBracketToken */
37119
- || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && scanner.getTokenValue() === "link"; });
37126
+ || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue()); });
37120
37127
  var nameExpression = isMarkdownOrJSDocLink ? undefined : parseJSDocNameReference();
37121
37128
  var comments = indent !== undefined && indentText !== undefined ? parseTrailingTagComments(start, getNodePos(), indent, indentText) : undefined;
37122
37129
  return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start);
@@ -37983,6 +37990,19 @@ var ts;
37983
37990
  return ts.fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */]);
37984
37991
  }
37985
37992
  ts.isDeclarationFileName = isDeclarationFileName;
37993
+ function parseResolutionMode(mode, pos, end, reportDiagnostic) {
37994
+ if (!mode) {
37995
+ return undefined;
37996
+ }
37997
+ if (mode === "import") {
37998
+ return ts.ModuleKind.ESNext;
37999
+ }
38000
+ if (mode === "require") {
38001
+ return ts.ModuleKind.CommonJS;
38002
+ }
38003
+ reportDiagnostic(pos, end - pos, ts.Diagnostics.resolution_mode_should_be_either_require_or_import);
38004
+ return undefined;
38005
+ }
37986
38006
  /*@internal*/
37987
38007
  function processCommentPragmas(context, sourceText) {
37988
38008
  var pragmas = [];
@@ -38025,12 +38045,13 @@ var ts;
38025
38045
  var typeReferenceDirectives_1 = context.typeReferenceDirectives;
38026
38046
  var libReferenceDirectives_1 = context.libReferenceDirectives;
38027
38047
  ts.forEach(ts.toArray(entryOrList), function (arg) {
38028
- var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path;
38048
+ var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path, res = _a["resolution-mode"];
38029
38049
  if (arg.arguments["no-default-lib"]) {
38030
38050
  context.hasNoDefaultLib = true;
38031
38051
  }
38032
38052
  else if (types) {
38033
- typeReferenceDirectives_1.push({ pos: types.pos, end: types.end, fileName: types.value });
38053
+ var parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
38054
+ typeReferenceDirectives_1.push(__assign({ pos: types.pos, end: types.end, fileName: types.value }, (parsed ? { resolutionMode: parsed } : {})));
38034
38055
  }
38035
38056
  else if (lib) {
38036
38057
  libReferenceDirectives_1.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
@@ -41608,14 +41629,14 @@ var ts;
41608
41629
  * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
41609
41630
  * is assumed to be the same as root directory of the project.
41610
41631
  */
41611
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache) {
41632
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache, resolutionMode) {
41612
41633
  var traceEnabled = isTraceEnabled(options, host);
41613
41634
  if (redirectedReference) {
41614
41635
  options = redirectedReference.commandLine.options;
41615
41636
  }
41616
41637
  var containingDirectory = containingFile ? ts.getDirectoryPath(containingFile) : undefined;
41617
41638
  var perFolderCache = containingDirectory ? cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference) : undefined;
41618
- var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ undefined);
41639
+ var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ resolutionMode);
41619
41640
  if (result) {
41620
41641
  if (traceEnabled) {
41621
41642
  trace(host, ts.Diagnostics.Resolving_type_reference_directive_0_containing_file_1, typeReferenceDirectiveName, containingFile);
@@ -41650,7 +41671,18 @@ var ts;
41650
41671
  }
41651
41672
  var failedLookupLocations = [];
41652
41673
  var features = getDefaultNodeResolutionFeatures(options);
41653
- var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
41674
+ // Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
41675
+ // setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
41676
+ // set in a non-modal module resolution setting here. Do note that our behavior is not particularly well defined when these mode-overriding imports
41677
+ // are present in a non-modal project; while in theory we'd like to either ignore the mode or provide faithful modern resolution, depending on what we feel is best,
41678
+ // in practice, not every cache has the options available to intelligently make the choice to ignore the mode request, and it's unclear how modern "faithful modern
41679
+ // resolution" should be (`node12`? `nodenext`?). As such, witnessing a mode-overriding triple-slash reference in a non-modal module resolution
41680
+ // context should _probably_ be an error - and that should likely be handled by the `Program` (which is what we do).
41681
+ if (resolutionMode === ts.ModuleKind.ESNext && (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext)) {
41682
+ features |= NodeResolutionFeatures.EsmMode;
41683
+ }
41684
+ var conditions = features & NodeResolutionFeatures.Exports ? features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] : [];
41685
+ var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: conditions };
41654
41686
  var resolved = primaryLookup();
41655
41687
  var primary = true;
41656
41688
  if (!resolved) {
@@ -41670,7 +41702,7 @@ var ts;
41670
41702
  };
41671
41703
  }
41672
41704
  result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations };
41673
- perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ undefined, result);
41705
+ perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
41674
41706
  if (traceEnabled)
41675
41707
  traceResult(result);
41676
41708
  return result;
@@ -41721,7 +41753,7 @@ var ts;
41721
41753
  result_4 = searchResult && searchResult.value;
41722
41754
  }
41723
41755
  else {
41724
- var candidate = ts.normalizePathAndParts(ts.combinePaths(initialLocationForSecondaryLookup, typeReferenceDirectiveName)).path;
41756
+ var candidate = normalizePathForCJSResolution(initialLocationForSecondaryLookup, typeReferenceDirectiveName).path;
41725
41757
  result_4 = nodeLoadModuleByRelativeName(Extensions.DtsOnly, candidate, /*onlyRecordFailures*/ false, moduleResolutionState, /*considerPackageJson*/ true);
41726
41758
  }
41727
41759
  return resolvedTypeScriptOnly(result_4);
@@ -41956,7 +41988,11 @@ var ts;
41956
41988
  ts.Debug.assert(keys.length === values.length);
41957
41989
  var map = createModeAwareCache();
41958
41990
  for (var i = 0; i < keys.length; ++i) {
41959
- map.set(keys[i], ts.getModeForResolutionAtIndex(file, i), values[i]);
41991
+ var entry = keys[i];
41992
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
41993
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
41994
+ var mode = !ts.isString(entry) ? entry.resolutionMode || file.impliedNodeFormat : ts.getModeForResolutionAtIndex(file, i);
41995
+ map.set(name, mode, values[i]);
41960
41996
  }
41961
41997
  return map;
41962
41998
  }
@@ -42424,13 +42460,25 @@ var ts;
42424
42460
  return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
42425
42461
  }
42426
42462
  else {
42427
- var _a = ts.normalizePathAndParts(ts.combinePaths(containingDirectory, moduleName)), candidate = _a.path, parts = _a.parts;
42463
+ var _a = normalizePathForCJSResolution(containingDirectory, moduleName), candidate = _a.path, parts = _a.parts;
42428
42464
  var resolved_2 = nodeLoadModuleByRelativeName(extensions, candidate, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
42429
42465
  // Treat explicit "node_modules" import as an external library import.
42430
42466
  return resolved_2 && toSearchResult({ resolved: resolved_2, isExternalLibraryImport: ts.contains(parts, "node_modules") });
42431
42467
  }
42432
42468
  }
42433
42469
  }
42470
+ // If you import from "." inside a containing directory "/foo", the result of `normalizePath`
42471
+ // would be "/foo", but this loses the information that `foo` is a directory and we intended
42472
+ // to look inside of it. The Node CommonJS resolution algorithm doesn't call this out
42473
+ // (https://nodejs.org/api/modules.html#all-together), but it seems that module paths ending
42474
+ // in `.` are actually normalized to `./` before proceeding with the resolution algorithm.
42475
+ function normalizePathForCJSResolution(containingDirectory, moduleName) {
42476
+ var combined = ts.combinePaths(containingDirectory, moduleName);
42477
+ var parts = ts.getPathComponents(combined);
42478
+ var lastPart = ts.lastOrUndefined(parts);
42479
+ var path = lastPart === "." || lastPart === ".." ? ts.ensureTrailingDirectorySeparator(ts.normalizePath(combined)) : ts.normalizePath(combined);
42480
+ return { path: path, parts: parts };
42481
+ }
42434
42482
  function realPath(path, host, traceEnabled) {
42435
42483
  if (!host.realpath) {
42436
42484
  return path;
@@ -42472,7 +42520,13 @@ var ts;
42472
42520
  onlyRecordFailures = true;
42473
42521
  }
42474
42522
  }
42475
- return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
42523
+ // esm mode relative imports shouldn't do any directory lookups (either inside `package.json`
42524
+ // files or implicit `index.js`es). This is a notable depature from cjs norms, where `./foo/pkg`
42525
+ // could have been redirected by `./foo/pkg/package.json` to an arbitrary location!
42526
+ if (!(state.features & NodeResolutionFeatures.EsmMode)) {
42527
+ return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
42528
+ }
42529
+ return undefined;
42476
42530
  }
42477
42531
  /*@internal*/
42478
42532
  ts.nodeModulesPathPart = "/node_modules/";
@@ -42839,7 +42893,16 @@ var ts;
42839
42893
  // Even if extensions is DtsOnly, we can still look up a .ts file as a result of package.json "types"
42840
42894
  var nextExtensions = extensions === Extensions.DtsOnly ? Extensions.TypeScript : extensions;
42841
42895
  // Don't do package.json lookup recursively, because Node.js' package lookup doesn't.
42842
- return nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
42896
+ // Disable `EsmMode` for the resolution of the package path for cjs-mode packages (so the `main` field can omit extensions)
42897
+ // (technically it only emits a deprecation warning in esm packages right now, but that's probably
42898
+ // enough to mean we don't need to support it)
42899
+ var features = state.features;
42900
+ if ((jsonContent === null || jsonContent === void 0 ? void 0 : jsonContent.type) !== "module") {
42901
+ state.features &= ~NodeResolutionFeatures.EsmMode;
42902
+ }
42903
+ var result = nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
42904
+ state.features = features;
42905
+ return result;
42843
42906
  };
42844
42907
  var onlyRecordFailuresForPackageFile = packageFile ? !ts.directoryProbablyExists(ts.getDirectoryPath(packageFile), state.host) : undefined;
42845
42908
  var onlyRecordFailuresForIndex = onlyRecordFailures || !ts.directoryProbablyExists(candidate, state.host);
@@ -43184,6 +43247,14 @@ var ts;
43184
43247
  }
43185
43248
  var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) ||
43186
43249
  loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths);
43250
+ if (!pathAndExtension && packageInfo
43251
+ && packageInfo.packageJsonContent.exports === undefined
43252
+ && packageInfo.packageJsonContent.main === undefined
43253
+ && state.features & NodeResolutionFeatures.EsmMode) {
43254
+ // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume
43255
+ // a default `index.js` entrypoint if no `main` or `exports` are present
43256
+ pathAndExtension = loadModuleFromFile(extensions, ts.combinePaths(candidate, "index.js"), onlyRecordFailures, state);
43257
+ }
43187
43258
  return withPackageId(packageInfo, pathAndExtension);
43188
43259
  };
43189
43260
  if (rest !== "") { // If "rest" is empty, we just did this search above.
@@ -46941,8 +47012,7 @@ var ts;
46941
47012
  IntersectionState[IntersectionState["Source"] = 1] = "Source";
46942
47013
  IntersectionState[IntersectionState["Target"] = 2] = "Target";
46943
47014
  IntersectionState[IntersectionState["PropertyCheck"] = 4] = "PropertyCheck";
46944
- IntersectionState[IntersectionState["UnionIntersectionCheck"] = 8] = "UnionIntersectionCheck";
46945
- IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
47015
+ IntersectionState[IntersectionState["InPropertyCheck"] = 8] = "InPropertyCheck";
46946
47016
  })(IntersectionState || (IntersectionState = {}));
46947
47017
  var RecursionFlags;
46948
47018
  (function (RecursionFlags) {
@@ -50401,8 +50471,15 @@ var ts;
50401
50471
  return res;
50402
50472
  }
50403
50473
  var candidates = ts.mapDefined(symbol.declarations, function (d) {
50404
- if (!ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
50405
- return getSymbolOfNode(d.parent);
50474
+ if (!ts.isAmbientModule(d) && d.parent) {
50475
+ // direct children of a module
50476
+ if (hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
50477
+ return getSymbolOfNode(d.parent);
50478
+ }
50479
+ // export ='d member of an ambient module
50480
+ if (ts.isModuleBlock(d.parent) && d.parent.parent && resolveExternalModuleSymbol(getSymbolOfNode(d.parent.parent)) === symbol) {
50481
+ return getSymbolOfNode(d.parent.parent);
50482
+ }
50406
50483
  }
50407
50484
  if (ts.isClassExpression(d) && ts.isBinaryExpression(d.parent) && d.parent.operatorToken.kind === 63 /* EqualsToken */ && ts.isAccessExpression(d.parent.left) && ts.isEntityNameExpression(d.parent.left.expression)) {
50408
50485
  if (ts.isModuleExportsAccessExpression(d.parent.left) || ts.isExportsIdentifier(d.parent.left.expression)) {
@@ -50949,7 +51026,7 @@ var ts;
50949
51026
  // get symbol of the first identifier of the entityName
50950
51027
  var meaning;
50951
51028
  if (entityName.parent.kind === 180 /* TypeQuery */ ||
50952
- ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent) ||
51029
+ entityName.parent.kind === 227 /* ExpressionWithTypeArguments */ && !ts.isPartOfTypeNode(entityName.parent) ||
50953
51030
  entityName.parent.kind === 161 /* ComputedPropertyName */) {
50954
51031
  // Typeof value
50955
51032
  meaning = 111551 /* Value */ | 1048576 /* ExportValue */;
@@ -51060,7 +51137,7 @@ var ts;
51060
51137
  return flags & 814775659 /* NodeBuilderFlagsMask */;
51061
51138
  }
51062
51139
  function isClassInstanceSide(type) {
51063
- return !!type.symbol && !!(type.symbol.flags & 32 /* Class */) && (type === getDeclaredTypeOfClassOrInterface(type.symbol) || (!!(type.flags & 524288 /* Object */) && !!(ts.getObjectFlags(type) & 16777216 /* IsClassInstanceClone */)));
51140
+ return !!type.symbol && !!(type.symbol.flags & 32 /* Class */) && (type === getDeclaredTypeOfClassOrInterface(type.symbol) || (!!(type.flags & 524288 /* Object */) && !!(ts.getObjectFlags(type) & 33554432 /* IsClassInstanceClone */)));
51064
51141
  }
51065
51142
  function createNodeBuilder() {
51066
51143
  return {
@@ -54989,7 +55066,7 @@ var ts;
54989
55066
  members_4, exportedType.callSignatures, exportedType.constructSignatures, exportedType.indexInfos);
54990
55067
  result.objectFlags |= (ts.getObjectFlags(type) & 8192 /* JSLiteral */); // Propagate JSLiteral flag
54991
55068
  if (result.symbol && result.symbol.flags & 32 /* Class */ && type === getDeclaredTypeOfClassOrInterface(result.symbol)) {
54992
- result.objectFlags |= 16777216 /* IsClassInstanceClone */; // Propagate the knowledge that this type is equivalent to the symbol's class instance type
55069
+ result.objectFlags |= 33554432 /* IsClassInstanceClone */; // Propagate the knowledge that this type is equivalent to the symbol's class instance type
54993
55070
  }
54994
55071
  return result;
54995
55072
  }
@@ -57035,87 +57112,87 @@ var ts;
57035
57112
  * Converts an AnonymousType to a ResolvedType.
57036
57113
  */
57037
57114
  function resolveAnonymousTypeMembers(type) {
57038
- var symbol = getMergedSymbol(type.symbol);
57039
57115
  if (type.target) {
57040
57116
  setStructuredTypeMembers(type, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57041
- var members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
57117
+ var members_6 = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
57042
57118
  var callSignatures = instantiateSignatures(getSignaturesOfType(type.target, 0 /* Call */), type.mapper);
57043
57119
  var constructSignatures = instantiateSignatures(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper);
57044
- var indexInfos = instantiateIndexInfos(getIndexInfosOfType(type.target), type.mapper);
57045
- setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos);
57120
+ var indexInfos_1 = instantiateIndexInfos(getIndexInfosOfType(type.target), type.mapper);
57121
+ setStructuredTypeMembers(type, members_6, callSignatures, constructSignatures, indexInfos_1);
57122
+ return;
57046
57123
  }
57047
- else if (symbol.flags & 2048 /* TypeLiteral */) {
57124
+ var symbol = getMergedSymbol(type.symbol);
57125
+ if (symbol.flags & 2048 /* TypeLiteral */) {
57048
57126
  setStructuredTypeMembers(type, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57049
- var members = getMembersOfSymbol(symbol);
57050
- var callSignatures = getSignaturesOfSymbol(members.get("__call" /* Call */));
57051
- var constructSignatures = getSignaturesOfSymbol(members.get("__new" /* New */));
57052
- var indexInfos = getIndexInfosOfSymbol(symbol);
57053
- setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos);
57127
+ var members_7 = getMembersOfSymbol(symbol);
57128
+ var callSignatures = getSignaturesOfSymbol(members_7.get("__call" /* Call */));
57129
+ var constructSignatures = getSignaturesOfSymbol(members_7.get("__new" /* New */));
57130
+ var indexInfos_2 = getIndexInfosOfSymbol(symbol);
57131
+ setStructuredTypeMembers(type, members_7, callSignatures, constructSignatures, indexInfos_2);
57132
+ return;
57054
57133
  }
57055
- else {
57056
- // Combinations of function, class, enum and module
57057
- var members = emptySymbols;
57058
- var indexInfos = void 0;
57059
- if (symbol.exports) {
57060
- members = getExportsOfSymbol(symbol);
57061
- if (symbol === globalThisSymbol) {
57062
- var varsOnly_1 = new ts.Map();
57063
- members.forEach(function (p) {
57064
- if (!(p.flags & 418 /* BlockScoped */)) {
57065
- varsOnly_1.set(p.escapedName, p);
57066
- }
57067
- });
57068
- members = varsOnly_1;
57069
- }
57134
+ // Combinations of function, class, enum and module
57135
+ var members = emptySymbols;
57136
+ var indexInfos;
57137
+ if (symbol.exports) {
57138
+ members = getExportsOfSymbol(symbol);
57139
+ if (symbol === globalThisSymbol) {
57140
+ var varsOnly_1 = new ts.Map();
57141
+ members.forEach(function (p) {
57142
+ if (!(p.flags & 418 /* BlockScoped */)) {
57143
+ varsOnly_1.set(p.escapedName, p);
57144
+ }
57145
+ });
57146
+ members = varsOnly_1;
57070
57147
  }
57071
- var baseConstructorIndexInfo = void 0;
57072
- setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57073
- if (symbol.flags & 32 /* Class */) {
57074
- var classType = getDeclaredTypeOfClassOrInterface(symbol);
57075
- var baseConstructorType = getBaseConstructorTypeOfClass(classType);
57076
- if (baseConstructorType.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 8650752 /* TypeVariable */)) {
57077
- members = ts.createSymbolTable(getNamedOrIndexSignatureMembers(members));
57078
- addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
57079
- }
57080
- else if (baseConstructorType === anyType) {
57081
- baseConstructorIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false);
57082
- }
57148
+ }
57149
+ var baseConstructorIndexInfo;
57150
+ setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57151
+ if (symbol.flags & 32 /* Class */) {
57152
+ var classType = getDeclaredTypeOfClassOrInterface(symbol);
57153
+ var baseConstructorType = getBaseConstructorTypeOfClass(classType);
57154
+ if (baseConstructorType.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 8650752 /* TypeVariable */)) {
57155
+ members = ts.createSymbolTable(getNamedOrIndexSignatureMembers(members));
57156
+ addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
57083
57157
  }
57084
- var indexSymbol = getIndexSymbolFromSymbolTable(members);
57085
- if (indexSymbol) {
57086
- indexInfos = getIndexInfosOfIndexSymbol(indexSymbol);
57158
+ else if (baseConstructorType === anyType) {
57159
+ baseConstructorIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false);
57087
57160
  }
57088
- else {
57089
- if (baseConstructorIndexInfo) {
57090
- indexInfos = ts.append(indexInfos, baseConstructorIndexInfo);
57091
- }
57092
- if (symbol.flags & 384 /* Enum */ && (getDeclaredTypeOfSymbol(symbol).flags & 32 /* Enum */ ||
57093
- ts.some(type.properties, function (prop) { return !!(getTypeOfSymbol(prop).flags & 296 /* NumberLike */); }))) {
57094
- indexInfos = ts.append(indexInfos, enumNumberIndexInfo);
57095
- }
57161
+ }
57162
+ var indexSymbol = getIndexSymbolFromSymbolTable(members);
57163
+ if (indexSymbol) {
57164
+ indexInfos = getIndexInfosOfIndexSymbol(indexSymbol);
57165
+ }
57166
+ else {
57167
+ if (baseConstructorIndexInfo) {
57168
+ indexInfos = ts.append(indexInfos, baseConstructorIndexInfo);
57096
57169
  }
57097
- setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, indexInfos || ts.emptyArray);
57098
- // We resolve the members before computing the signatures because a signature may use
57099
- // typeof with a qualified name expression that circularly references the type we are
57100
- // in the process of resolving (see issue #6072). The temporarily empty signature list
57101
- // will never be observed because a qualified name can't reference signatures.
57102
- if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) {
57103
- type.callSignatures = getSignaturesOfSymbol(symbol);
57170
+ if (symbol.flags & 384 /* Enum */ && (getDeclaredTypeOfSymbol(symbol).flags & 32 /* Enum */ ||
57171
+ ts.some(type.properties, function (prop) { return !!(getTypeOfSymbol(prop).flags & 296 /* NumberLike */); }))) {
57172
+ indexInfos = ts.append(indexInfos, enumNumberIndexInfo);
57104
57173
  }
57105
- // And likewise for construct signatures for classes
57106
- if (symbol.flags & 32 /* Class */) {
57107
- var classType_1 = getDeclaredTypeOfClassOrInterface(symbol);
57108
- var constructSignatures = symbol.members ? getSignaturesOfSymbol(symbol.members.get("__constructor" /* Constructor */)) : ts.emptyArray;
57109
- if (symbol.flags & 16 /* Function */) {
57110
- constructSignatures = ts.addRange(constructSignatures.slice(), ts.mapDefined(type.callSignatures, function (sig) { return isJSConstructor(sig.declaration) ?
57111
- createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, classType_1, /*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.flags & 39 /* PropagatingFlags */) :
57112
- undefined; }));
57113
- }
57114
- if (!constructSignatures.length) {
57115
- constructSignatures = getDefaultConstructSignatures(classType_1);
57116
- }
57117
- type.constructSignatures = constructSignatures;
57174
+ }
57175
+ setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, indexInfos || ts.emptyArray);
57176
+ // We resolve the members before computing the signatures because a signature may use
57177
+ // typeof with a qualified name expression that circularly references the type we are
57178
+ // in the process of resolving (see issue #6072). The temporarily empty signature list
57179
+ // will never be observed because a qualified name can't reference signatures.
57180
+ if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) {
57181
+ type.callSignatures = getSignaturesOfSymbol(symbol);
57182
+ }
57183
+ // And likewise for construct signatures for classes
57184
+ if (symbol.flags & 32 /* Class */) {
57185
+ var classType_1 = getDeclaredTypeOfClassOrInterface(symbol);
57186
+ var constructSignatures = symbol.members ? getSignaturesOfSymbol(symbol.members.get("__constructor" /* Constructor */)) : ts.emptyArray;
57187
+ if (symbol.flags & 16 /* Function */) {
57188
+ constructSignatures = ts.addRange(constructSignatures.slice(), ts.mapDefined(type.callSignatures, function (sig) { return isJSConstructor(sig.declaration) ?
57189
+ createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, classType_1, /*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.flags & 39 /* PropagatingFlags */) :
57190
+ undefined; }));
57118
57191
  }
57192
+ if (!constructSignatures.length) {
57193
+ constructSignatures = getDefaultConstructSignatures(classType_1);
57194
+ }
57195
+ type.constructSignatures = constructSignatures;
57119
57196
  }
57120
57197
  }
57121
57198
  function replaceIndexedAccess(instantiable, type, replacement) {
@@ -58116,8 +58193,8 @@ var ts;
58116
58193
  var stringIndexInfo;
58117
58194
  var applicableInfo;
58118
58195
  var applicableInfos;
58119
- for (var _i = 0, indexInfos_1 = indexInfos; _i < indexInfos_1.length; _i++) {
58120
- var info = indexInfos_1[_i];
58196
+ for (var _i = 0, indexInfos_3 = indexInfos; _i < indexInfos_3.length; _i++) {
58197
+ var info = indexInfos_3[_i];
58121
58198
  if (info.keyType === stringType) {
58122
58199
  stringIndexInfo = info;
58123
58200
  }
@@ -58656,13 +58733,15 @@ var ts;
58656
58733
  return signature;
58657
58734
  }
58658
58735
  function getOrCreateTypeFromSignature(signature) {
58736
+ var _a;
58659
58737
  // There are two ways to declare a construct signature, one is by declaring a class constructor
58660
58738
  // using the constructor keyword, and the other is declaring a bare construct signature in an
58661
58739
  // object type literal or interface (using the new keyword). Each way of declaring a constructor
58662
58740
  // will result in a different declaration kind.
58663
58741
  if (!signature.isolatedSignatureType) {
58664
- var kind = signature.declaration ? signature.declaration.kind : 0 /* Unknown */;
58665
- var isConstructor = kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58742
+ var kind = (_a = signature.declaration) === null || _a === void 0 ? void 0 : _a.kind;
58743
+ // If declaration is undefined, it is likely to be the signature of the default constructor.
58744
+ var isConstructor = kind === undefined || kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58666
58745
  var type = createObjectType(16 /* Anonymous */);
58667
58746
  type.members = emptySymbols;
58668
58747
  type.properties = ts.emptyArray;
@@ -58688,14 +58767,14 @@ var ts;
58688
58767
  }
58689
58768
  function getIndexInfosOfIndexSymbol(indexSymbol) {
58690
58769
  if (indexSymbol.declarations) {
58691
- var indexInfos_2 = [];
58770
+ var indexInfos_4 = [];
58692
58771
  var _loop_14 = function (declaration) {
58693
58772
  if (declaration.parameters.length === 1) {
58694
58773
  var parameter = declaration.parameters[0];
58695
58774
  if (parameter.type) {
58696
58775
  forEachType(getTypeFromTypeNode(parameter.type), function (keyType) {
58697
- if (isValidIndexKeyType(keyType) && !findIndexInfo(indexInfos_2, keyType)) {
58698
- indexInfos_2.push(createIndexInfo(keyType, declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, ts.hasEffectiveModifier(declaration, 64 /* Readonly */), declaration));
58776
+ if (isValidIndexKeyType(keyType) && !findIndexInfo(indexInfos_4, keyType)) {
58777
+ indexInfos_4.push(createIndexInfo(keyType, declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, ts.hasEffectiveModifier(declaration, 64 /* Readonly */), declaration));
58699
58778
  }
58700
58779
  });
58701
58780
  }
@@ -58705,7 +58784,7 @@ var ts;
58705
58784
  var declaration = _a[_i];
58706
58785
  _loop_14(declaration);
58707
58786
  }
58708
- return indexInfos_2;
58787
+ return indexInfos_4;
58709
58788
  }
58710
58789
  return ts.emptyArray;
58711
58790
  }
@@ -59253,7 +59332,7 @@ var ts;
59253
59332
  // The expression is processed as an identifier expression (section 4.3)
59254
59333
  // or property access expression(section 4.10),
59255
59334
  // the widened type(section 3.9) of which becomes the result.
59256
- var type = ts.isThisIdentifier(node.exprName) ? checkThisExpression(node.exprName) : checkExpression(node.exprName);
59335
+ var type = checkExpressionWithTypeArguments(node);
59257
59336
  links.resolvedType = getRegularTypeOfLiteralType(getWidenedType(type));
59258
59337
  }
59259
59338
  return links.resolvedType;
@@ -59590,7 +59669,7 @@ var ts;
59590
59669
  }
59591
59670
  }
59592
59671
  var fixedLength = properties.length;
59593
- var lengthSymbol = createSymbol(4 /* Property */, "length");
59672
+ var lengthSymbol = createSymbol(4 /* Property */, "length", readonly ? 8 /* Readonly */ : 0);
59594
59673
  if (combinedFlags & 12 /* Variable */) {
59595
59674
  lengthSymbol.type = numberType;
59596
59675
  }
@@ -61957,7 +62036,9 @@ var ts;
61957
62036
  return result;
61958
62037
  }
61959
62038
  function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
61960
- var declaration = type.objectFlags & 4 /* Reference */ ? type.node : type.symbol.declarations[0];
62039
+ var declaration = type.objectFlags & 4 /* Reference */ ? type.node :
62040
+ type.objectFlags & 16777216 /* InstantiationExpressionType */ ? type.node :
62041
+ type.symbol.declarations[0];
61961
62042
  var links = getNodeLinks(declaration);
61962
62043
  var target = type.objectFlags & 4 /* Reference */ ? links.resolvedType :
61963
62044
  type.objectFlags & 64 /* Instantiated */ ? type.target : type;
@@ -61973,8 +62054,8 @@ var ts;
61973
62054
  outerTypeParameters = ts.addRange(outerTypeParameters, templateTagParameters);
61974
62055
  }
61975
62056
  typeParameters = outerTypeParameters || ts.emptyArray;
61976
- var allDeclarations_1 = type.objectFlags & 4 /* Reference */ ? [declaration] : type.symbol.declarations;
61977
- typeParameters = (target.objectFlags & 4 /* Reference */ || target.symbol.flags & 8192 /* Method */ || target.symbol.flags & 2048 /* TypeLiteral */) && !target.aliasTypeArguments ?
62057
+ var allDeclarations_1 = type.objectFlags & (4 /* Reference */ | 16777216 /* InstantiationExpressionType */) ? [declaration] : type.symbol.declarations;
62058
+ typeParameters = (target.objectFlags & (4 /* Reference */ | 16777216 /* InstantiationExpressionType */) || target.symbol.flags & 8192 /* Method */ || target.symbol.flags & 2048 /* TypeLiteral */) && !target.aliasTypeArguments ?
61978
62059
  ts.filter(typeParameters, function (tp) { return ts.some(allDeclarations_1, function (d) { return isTypeParameterPossiblyReferenced(tp, d); }); }) :
61979
62060
  typeParameters;
61980
62061
  links.outerTypeParameters = typeParameters;
@@ -62146,6 +62227,9 @@ var ts;
62146
62227
  mapper = combineTypeMappers(makeUnaryTypeMapper(origTypeParameter, freshTypeParameter), mapper);
62147
62228
  freshTypeParameter.mapper = mapper;
62148
62229
  }
62230
+ if (type.objectFlags & 16777216 /* InstantiationExpressionType */) {
62231
+ result.node = type.node;
62232
+ }
62149
62233
  result.target = type;
62150
62234
  result.mapper = mapper;
62151
62235
  result.aliasSymbol = aliasSymbol || type.aliasSymbol;
@@ -63137,9 +63221,11 @@ var ts;
63137
63221
  isEnumTypeRelatedTo(getParentOfSymbol(source.symbol), getParentOfSymbol(target.symbol), errorReporter))
63138
63222
  return true;
63139
63223
  }
63140
- if (s & 32768 /* Undefined */ && (!strictNullChecks || t & (32768 /* Undefined */ | 16384 /* Void */)))
63224
+ // In non-strictNullChecks mode, `undefined` and `null` are assignable to anything except `never`.
63225
+ // Since unions and intersections may reduce to `never`, we exclude them here.
63226
+ if (s & 32768 /* Undefined */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & (32768 /* Undefined */ | 16384 /* Void */)))
63141
63227
  return true;
63142
- if (s & 65536 /* Null */ && (!strictNullChecks || t & 65536 /* Null */))
63228
+ if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
63143
63229
  return true;
63144
63230
  if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
63145
63231
  return true;
@@ -63228,11 +63314,11 @@ var ts;
63228
63314
  var overflow = false;
63229
63315
  var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
63230
63316
  var lastSkippedInfo;
63231
- var incompatibleStack = [];
63317
+ var incompatibleStack;
63232
63318
  var inPropertyCheck = false;
63233
63319
  ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
63234
63320
  var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
63235
- if (incompatibleStack.length) {
63321
+ if (incompatibleStack) {
63236
63322
  reportIncompatibleStack();
63237
63323
  }
63238
63324
  if (overflow) {
@@ -63289,19 +63375,19 @@ var ts;
63289
63375
  return {
63290
63376
  errorInfo: errorInfo,
63291
63377
  lastSkippedInfo: lastSkippedInfo,
63292
- incompatibleStack: incompatibleStack.slice(),
63378
+ incompatibleStack: incompatibleStack === null || incompatibleStack === void 0 ? void 0 : incompatibleStack.slice(),
63293
63379
  overrideNextErrorInfo: overrideNextErrorInfo,
63294
- relatedInfo: !relatedInfo ? undefined : relatedInfo.slice()
63380
+ relatedInfo: relatedInfo === null || relatedInfo === void 0 ? void 0 : relatedInfo.slice(),
63295
63381
  };
63296
63382
  }
63297
63383
  function reportIncompatibleError(message, arg0, arg1, arg2, arg3) {
63298
63384
  overrideNextErrorInfo++; // Suppress the next relation error
63299
63385
  lastSkippedInfo = undefined; // Reset skipped info cache
63300
- incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
63386
+ (incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
63301
63387
  }
63302
63388
  function reportIncompatibleStack() {
63303
- var stack = incompatibleStack;
63304
- incompatibleStack = [];
63389
+ var stack = incompatibleStack || [];
63390
+ incompatibleStack = undefined;
63305
63391
  var info = lastSkippedInfo;
63306
63392
  lastSkippedInfo = undefined;
63307
63393
  if (stack.length === 1) {
@@ -63407,7 +63493,7 @@ var ts;
63407
63493
  }
63408
63494
  function reportError(message, arg0, arg1, arg2, arg3) {
63409
63495
  ts.Debug.assert(!!errorNode);
63410
- if (incompatibleStack.length)
63496
+ if (incompatibleStack)
63411
63497
  reportIncompatibleStack();
63412
63498
  if (message.elidedInCompatabilityPyramid)
63413
63499
  return;
@@ -63423,7 +63509,7 @@ var ts;
63423
63509
  }
63424
63510
  }
63425
63511
  function reportRelationError(message, source, target) {
63426
- if (incompatibleStack.length)
63512
+ if (incompatibleStack)
63427
63513
  reportIncompatibleStack();
63428
63514
  var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
63429
63515
  var generalizedSource = source;
@@ -63535,7 +63621,9 @@ var ts;
63535
63621
  if (isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)) {
63536
63622
  return -1 /* True */;
63537
63623
  }
63538
- reportErrorResults(originalSource, originalTarget, 0 /* False */, !!(ts.getObjectFlags(originalSource) & 2048 /* JsxAttributes */));
63624
+ if (reportErrors) {
63625
+ reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
63626
+ }
63539
63627
  return 0 /* False */;
63540
63628
  }
63541
63629
  // Normalize the source and target types: Turn fresh literal types into regular literal types,
@@ -63547,7 +63635,12 @@ var ts;
63547
63635
  if (source === target)
63548
63636
  return -1 /* True */;
63549
63637
  if (relation === identityRelation) {
63550
- return isIdenticalTo(source, target, recursionFlags);
63638
+ if (source.flags !== target.flags)
63639
+ return 0 /* False */;
63640
+ if (source.flags & 67358815 /* Singleton */)
63641
+ return -1 /* True */;
63642
+ traceUnionsOrIntersectionsTooLarge(source, target);
63643
+ return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63551
63644
  }
63552
63645
  // We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
63553
63646
  // and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
@@ -63557,163 +63650,130 @@ var ts;
63557
63650
  if (source.flags & 262144 /* TypeParameter */ && getConstraintOfType(source) === target) {
63558
63651
  return -1 /* True */;
63559
63652
  }
63560
- // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
63561
- // If so, reporting the `null` and `undefined` in the type is hardly useful.
63562
- // First, see if we're even relating an object type to a union.
63563
- // Then see if the target is stripped down to a single non-union type.
63564
- // Note
63565
- // * We actually want to remove null and undefined naively here (rather than using getNonNullableType),
63566
- // since we don't want to end up with a worse error like "`Foo` is not assignable to `NonNullable<T>`"
63567
- // when dealing with generics.
63568
- // * We also don't deal with primitive source types, since we already halt elaboration below.
63569
- if (target.flags & 1048576 /* Union */ && source.flags & 524288 /* Object */ &&
63570
- target.types.length <= 3 && maybeTypeOfKind(target, 98304 /* Nullable */)) {
63571
- var nullStrippedTarget = extractTypesOfKind(target, ~98304 /* Nullable */);
63572
- if (!(nullStrippedTarget.flags & (1048576 /* Union */ | 131072 /* Never */))) {
63573
- target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
63574
- }
63575
- if (source === nullStrippedTarget)
63576
- return -1 /* True */;
63653
+ // See if we're relating a definitely non-nullable type to a union that includes null and/or undefined
63654
+ // plus a single non-nullable type. If so, remove null and/or undefined from the target type.
63655
+ if (source.flags & 470302716 /* DefinitelyNonNullable */ && target.flags & 1048576 /* Union */) {
63656
+ var types = target.types;
63657
+ var candidate = types.length === 2 && types[0].flags & 98304 /* Nullable */ ? types[1] :
63658
+ types.length === 3 && types[0].flags & 98304 /* Nullable */ && types[1].flags & 98304 /* Nullable */ ? types[2] :
63659
+ undefined;
63660
+ if (candidate && !(candidate.flags & 98304 /* Nullable */)) {
63661
+ target = getNormalizedType(candidate, /*writing*/ true);
63662
+ if (source === target)
63663
+ return -1 /* True */;
63664
+ }
63577
63665
  }
63578
63666
  if (relation === comparableRelation && !(target.flags & 131072 /* Never */) && isSimpleTypeRelatedTo(target, source, relation) ||
63579
63667
  isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined))
63580
63668
  return -1 /* True */;
63581
- var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63582
- var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63583
- if (isPerformingExcessPropertyChecks) {
63584
- if (hasExcessProperties(source, target, reportErrors)) {
63669
+ if (source.flags & 469499904 /* StructuredOrInstantiable */ || target.flags & 469499904 /* StructuredOrInstantiable */) {
63670
+ var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63671
+ if (isPerformingExcessPropertyChecks) {
63672
+ if (hasExcessProperties(source, target, reportErrors)) {
63673
+ if (reportErrors) {
63674
+ reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63675
+ }
63676
+ return 0 /* False */;
63677
+ }
63678
+ }
63679
+ var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63680
+ source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63681
+ target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63682
+ (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63683
+ var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63684
+ if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63585
63685
  if (reportErrors) {
63586
- reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63686
+ var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63687
+ var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63688
+ var calls = getSignaturesOfType(source, 0 /* Call */);
63689
+ var constructs = getSignaturesOfType(source, 1 /* Construct */);
63690
+ if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63691
+ constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63692
+ reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63693
+ }
63694
+ else {
63695
+ reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63696
+ }
63587
63697
  }
63588
63698
  return 0 /* False */;
63589
63699
  }
63590
- }
63591
- var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63592
- source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63593
- target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63594
- (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63595
- if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63596
- if (reportErrors) {
63597
- var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63598
- var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63599
- var calls = getSignaturesOfType(source, 0 /* Call */);
63600
- var constructs = getSignaturesOfType(source, 1 /* Construct */);
63601
- if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63602
- constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63603
- reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63604
- }
63605
- else {
63606
- reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63607
- }
63700
+ traceUnionsOrIntersectionsTooLarge(source, target);
63701
+ var skipCaching = source.flags & 1048576 /* Union */ && source.types.length < 4 && !(target.flags & 1048576 /* Union */) ||
63702
+ target.flags & 1048576 /* Union */ && target.types.length < 4 && !(source.flags & 469499904 /* StructuredOrInstantiable */);
63703
+ var result_7 = skipCaching ?
63704
+ unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) :
63705
+ recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags);
63706
+ // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63707
+ // an extra property check where the intersection is viewed as a single object. The following are motivating
63708
+ // examples that all should be errors, but aren't without this extra property check:
63709
+ //
63710
+ // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63711
+ //
63712
+ // declare let wrong: { a: { y: string } };
63713
+ // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63714
+ //
63715
+ // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63716
+ // x = y; // Mismatched property in source intersection
63717
+ // }
63718
+ //
63719
+ // We suppress recursive intersection property checks because they can generate lots of work when relating
63720
+ // recursive intersections that are structurally similar but not exactly identical. See #37854.
63721
+ if (result_7 && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63722
+ isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 524288 /* NonInferrableType */); }))) {
63723
+ inPropertyCheck = true;
63724
+ result_7 &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63725
+ inPropertyCheck = false;
63726
+ }
63727
+ if (result_7) {
63728
+ return result_7;
63608
63729
  }
63609
- return 0 /* False */;
63610
- }
63611
- traceUnionsOrIntersectionsTooLarge(source, target);
63612
- var result = 0 /* False */;
63613
- var saveErrorInfo = captureErrorCalculationState();
63614
- if ((source.flags & 1048576 /* Union */ || target.flags & 1048576 /* Union */) && getConstituentCount(source) * getConstituentCount(target) < 4) {
63615
- // We skip caching when source or target is a union with no more than three constituents.
63616
- result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
63617
63730
  }
63618
- else if (source.flags & 3145728 /* UnionOrIntersection */ || target.flags & 3145728 /* UnionOrIntersection */) {
63619
- result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */, recursionFlags);
63731
+ if (reportErrors) {
63732
+ reportErrorResults(originalSource, originalTarget, source, target, headMessage);
63620
63733
  }
63621
- if (!result && !(source.flags & 1048576 /* Union */) && (source.flags & (469499904 /* StructuredOrInstantiable */) || target.flags & 469499904 /* StructuredOrInstantiable */)) {
63622
- if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
63623
- resetErrorInfo(saveErrorInfo);
63734
+ return 0 /* False */;
63735
+ }
63736
+ function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
63737
+ var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63738
+ var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63739
+ source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63740
+ target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63741
+ var maybeSuppress = overrideNextErrorInfo > 0;
63742
+ if (maybeSuppress) {
63743
+ overrideNextErrorInfo--;
63744
+ }
63745
+ if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63746
+ var currentError = errorInfo;
63747
+ tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ true);
63748
+ if (errorInfo !== currentError) {
63749
+ maybeSuppress = !!errorInfo;
63750
+ }
63751
+ }
63752
+ if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63753
+ tryElaborateErrorsForPrimitivesAndObjects(source, target);
63754
+ }
63755
+ else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63756
+ reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63757
+ }
63758
+ else if (ts.getObjectFlags(source) & 2048 /* JsxAttributes */ && target.flags & 2097152 /* Intersection */) {
63759
+ var targetTypes = target.types;
63760
+ var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63761
+ var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63762
+ if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63763
+ (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63764
+ // do not report top error
63765
+ return;
63624
63766
  }
63625
63767
  }
63626
- if (!result && source.flags & (2097152 /* Intersection */ | 262144 /* TypeParameter */)) {
63627
- // The combined constraint of an intersection type is the intersection of the constraints of
63628
- // the constituents. When an intersection type contains instantiable types with union type
63629
- // constraints, there are situations where we need to examine the combined constraint. One is
63630
- // when the target is a union type. Another is when the intersection contains types belonging
63631
- // to one of the disjoint domains. For example, given type variables T and U, each with the
63632
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
63633
- // we need to check this constraint against a union on the target side. Also, given a type
63634
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
63635
- // 'string & number | number & number' which reduces to just 'number'.
63636
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
63637
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
63638
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
63639
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
63640
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
63641
- if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
63642
- if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
63643
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
63644
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
63645
- resetErrorInfo(saveErrorInfo);
63646
- }
63647
- }
63648
- }
63768
+ else {
63769
+ errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63649
63770
  }
63650
- // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63651
- // an extra property check where the intersection is viewed as a single object. The following are motivating
63652
- // examples that all should be errors, but aren't without this extra property check:
63653
- //
63654
- // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63655
- //
63656
- // declare let wrong: { a: { y: string } };
63657
- // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63658
- //
63659
- // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63660
- // x = y; // Mismatched property in source intersection
63661
- // }
63662
- //
63663
- // We suppress recursive intersection property checks because they can generate lots of work when relating
63664
- // recursive intersections that are structurally similar but not exactly identical. See #37854.
63665
- if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63666
- isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 524288 /* NonInferrableType */); }))) {
63667
- inPropertyCheck = true;
63668
- result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63669
- inPropertyCheck = false;
63670
- }
63671
- reportErrorResults(source, target, result, isComparingJsxAttributes);
63672
- return result;
63673
- function reportErrorResults(source, target, result, isComparingJsxAttributes) {
63674
- if (!result && reportErrors) {
63675
- var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63676
- var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63677
- source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63678
- target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63679
- var maybeSuppress = overrideNextErrorInfo > 0;
63680
- if (maybeSuppress) {
63681
- overrideNextErrorInfo--;
63682
- }
63683
- if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63684
- var currentError = errorInfo;
63685
- tryElaborateArrayLikeErrors(source, target, reportErrors);
63686
- if (errorInfo !== currentError) {
63687
- maybeSuppress = !!errorInfo;
63688
- }
63689
- }
63690
- if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63691
- tryElaborateErrorsForPrimitivesAndObjects(source, target);
63692
- }
63693
- else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63694
- reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63695
- }
63696
- else if (isComparingJsxAttributes && target.flags & 2097152 /* Intersection */) {
63697
- var targetTypes = target.types;
63698
- var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63699
- var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63700
- if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63701
- (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63702
- // do not report top error
63703
- return result;
63704
- }
63705
- }
63706
- else {
63707
- errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63708
- }
63709
- if (!headMessage && maybeSuppress) {
63710
- lastSkippedInfo = [source, target];
63711
- // Used by, eg, missing property checking to replace the top-level message with a more informative one
63712
- return result;
63713
- }
63714
- reportRelationError(headMessage, source, target);
63715
- }
63771
+ if (!headMessage && maybeSuppress) {
63772
+ lastSkippedInfo = [source, target];
63773
+ // Used by, eg, missing property checking to replace the top-level message with a more informative one
63774
+ return;
63716
63775
  }
63776
+ reportRelationError(headMessage, source, target);
63717
63777
  }
63718
63778
  function traceUnionsOrIntersectionsTooLarge(source, target) {
63719
63779
  if (!ts.tracing) {
@@ -63740,21 +63800,6 @@ var ts;
63740
63800
  }
63741
63801
  }
63742
63802
  }
63743
- function isIdenticalTo(source, target, recursionFlags) {
63744
- if (source.flags !== target.flags)
63745
- return 0 /* False */;
63746
- if (source.flags & 67358815 /* Singleton */)
63747
- return -1 /* True */;
63748
- traceUnionsOrIntersectionsTooLarge(source, target);
63749
- if (source.flags & 3145728 /* UnionOrIntersection */) {
63750
- var result_7 = eachTypeRelatedToSomeType(source, target);
63751
- if (result_7) {
63752
- result_7 &= eachTypeRelatedToSomeType(target, source);
63753
- }
63754
- return result_7;
63755
- }
63756
- return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63757
- }
63758
63803
  function getTypeOfPropertyInTypes(types, name) {
63759
63804
  var appendPropType = function (propTypes, type) {
63760
63805
  var _a;
@@ -63853,6 +63898,41 @@ var ts;
63853
63898
  function shouldCheckAsExcessProperty(prop, container) {
63854
63899
  return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
63855
63900
  }
63901
+ function unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
63902
+ // Note that these checks are specifically ordered to produce correct results. In particular,
63903
+ // we need to deconstruct unions before intersections (because unions are always at the top),
63904
+ // and we need to handle "each" relations before "some" relations for the same kind of type.
63905
+ if (source.flags & 1048576 /* Union */) {
63906
+ return relation === comparableRelation ?
63907
+ someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState) :
63908
+ eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState);
63909
+ }
63910
+ if (target.flags & 1048576 /* Union */) {
63911
+ return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
63912
+ }
63913
+ if (target.flags & 2097152 /* Intersection */) {
63914
+ return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
63915
+ }
63916
+ // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
63917
+ // constraints of all non-primitive types in the source into a new intersection. We do this because the
63918
+ // intersection may further constrain the constraints of the non-primitive types. For example, given a type
63919
+ // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
63920
+ // appear to be comparable to '2'.
63921
+ if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
63922
+ var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
63923
+ if (constraints !== source.types) {
63924
+ source = getIntersectionType(constraints);
63925
+ if (!(source.flags & 2097152 /* Intersection */)) {
63926
+ return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
63927
+ }
63928
+ }
63929
+ }
63930
+ // Check to see if any constituents of the intersection are immediately related to the target.
63931
+ // Don't report errors though. Elaborating on whether a source constituent is related to the target is
63932
+ // not actually useful and leads to some confusing error messages. Instead, we rely on the caller
63933
+ // checking whether the full intersection viewed as an object is related to the target.
63934
+ return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
63935
+ }
63856
63936
  function eachTypeRelatedToSomeType(source, target) {
63857
63937
  var result = -1 /* True */;
63858
63938
  var sourceTypes = source.types;
@@ -63888,8 +63968,11 @@ var ts;
63888
63968
  }
63889
63969
  }
63890
63970
  if (reportErrors) {
63971
+ // Elaborate only if we can find a best matching type in the target union
63891
63972
  var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
63892
- isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], 2 /* Target */, /*reportErrors*/ true);
63973
+ if (bestMatchingType) {
63974
+ isRelatedTo(source, bestMatchingType, 2 /* Target */, /*reportErrors*/ true);
63975
+ }
63893
63976
  }
63894
63977
  return 0 /* False */;
63895
63978
  }
@@ -64025,7 +64108,7 @@ var ts;
64025
64108
  if (overflow) {
64026
64109
  return 0 /* False */;
64027
64110
  }
64028
- var keyIntersectionState = intersectionState | (inPropertyCheck ? 16 /* InPropertyCheck */ : 0);
64111
+ var keyIntersectionState = intersectionState | (inPropertyCheck ? 8 /* InPropertyCheck */ : 0);
64029
64112
  var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
64030
64113
  var entry = relation.get(id);
64031
64114
  if (entry !== undefined) {
@@ -64093,6 +64176,7 @@ var ts;
64093
64176
  return originalHandler(onlyUnreliable);
64094
64177
  };
64095
64178
  }
64179
+ var result;
64096
64180
  if (expandingFlags === 3 /* Both */) {
64097
64181
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "recursiveTypeRelatedTo_DepthLimit", {
64098
64182
  sourceId: source.id,
@@ -64102,8 +64186,13 @@ var ts;
64102
64186
  depth: sourceDepth,
64103
64187
  targetDepth: targetDepth
64104
64188
  });
64189
+ result = 3 /* Maybe */;
64190
+ }
64191
+ else {
64192
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64193
+ result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState);
64194
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64105
64195
  }
64106
- var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
64107
64196
  if (outofbandVarianceMarkerHandler) {
64108
64197
  outofbandVarianceMarkerHandler = originalHandler;
64109
64198
  }
@@ -64135,98 +64224,97 @@ var ts;
64135
64224
  return result;
64136
64225
  }
64137
64226
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
64138
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64139
- var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState);
64140
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64141
- return result;
64142
- }
64143
- function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState) {
64144
64227
  if (intersectionState & 4 /* PropertyCheck */) {
64145
64228
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
64146
64229
  }
64147
- if (intersectionState & 8 /* UnionIntersectionCheck */) {
64148
- // Note that these checks are specifically ordered to produce correct results. In particular,
64149
- // we need to deconstruct unions before intersections (because unions are always at the top),
64150
- // and we need to handle "each" relations before "some" relations for the same kind of type.
64151
- if (source.flags & 1048576 /* Union */) {
64152
- return relation === comparableRelation ?
64153
- someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */) :
64154
- eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */);
64155
- }
64156
- if (target.flags & 1048576 /* Union */) {
64157
- return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
64158
- }
64159
- if (target.flags & 2097152 /* Intersection */) {
64160
- return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
64161
- }
64162
- // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
64163
- // constraints of all non-primitive types in the source into a new intersection. We do this because the
64164
- // intersection may further constrain the constraints of the non-primitive types. For example, given a type
64165
- // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
64166
- // appear to be comparable to '2'.
64167
- if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
64168
- var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
64169
- if (constraints !== source.types) {
64170
- source = getIntersectionType(constraints);
64171
- if (!(source.flags & 2097152 /* Intersection */)) {
64172
- return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
64173
- }
64230
+ var result;
64231
+ var originalErrorInfo;
64232
+ var varianceCheckFailed = false;
64233
+ var saveErrorInfo = captureErrorCalculationState();
64234
+ var sourceFlags = source.flags;
64235
+ var targetFlags = target.flags;
64236
+ if (relation === identityRelation) {
64237
+ // We've already checked that source.flags and target.flags are identical
64238
+ if (sourceFlags & 3145728 /* UnionOrIntersection */) {
64239
+ var result_8 = eachTypeRelatedToSomeType(source, target);
64240
+ if (result_8) {
64241
+ result_8 &= eachTypeRelatedToSomeType(target, source);
64174
64242
  }
64243
+ return result_8;
64175
64244
  }
64176
- // Check to see if any constituents of the intersection are immediately related to the target.
64177
- //
64178
- // Don't report errors though. Checking whether a constituent is related to the source is not actually
64179
- // useful and leads to some confusing error messages. Instead it is better to let the below checks
64180
- // take care of this, or to not elaborate at all. For instance,
64181
- //
64182
- // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
64183
- //
64184
- // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
64185
- // than to report that 'D' is not assignable to 'A' or 'B'.
64186
- //
64187
- // - For a primitive type or type parameter (such as 'number = A & B') there is no point in
64188
- // breaking the intersection apart.
64189
- return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
64190
- }
64191
- var flags = source.flags & target.flags;
64192
- if (relation === identityRelation && !(flags & 524288 /* Object */)) {
64193
- if (flags & 4194304 /* Index */) {
64245
+ if (sourceFlags & 4194304 /* Index */) {
64194
64246
  return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
64195
64247
  }
64196
- var result_8 = 0 /* False */;
64197
- if (flags & 8388608 /* IndexedAccess */) {
64198
- if (result_8 = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64199
- if (result_8 &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64200
- return result_8;
64248
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64249
+ if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64250
+ if (result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64251
+ return result;
64201
64252
  }
64202
64253
  }
64203
64254
  }
64204
- if (flags & 16777216 /* Conditional */) {
64255
+ if (sourceFlags & 16777216 /* Conditional */) {
64205
64256
  if (source.root.isDistributive === target.root.isDistributive) {
64206
- if (result_8 = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64207
- if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64208
- if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64209
- if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64210
- return result_8;
64257
+ if (result = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64258
+ if (result &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64259
+ if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64260
+ if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64261
+ return result;
64211
64262
  }
64212
64263
  }
64213
64264
  }
64214
64265
  }
64215
64266
  }
64216
64267
  }
64217
- if (flags & 33554432 /* Substitution */) {
64268
+ if (sourceFlags & 33554432 /* Substitution */) {
64218
64269
  return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
64219
64270
  }
64220
- return 0 /* False */;
64271
+ if (!(sourceFlags & 524288 /* Object */)) {
64272
+ return 0 /* False */;
64273
+ }
64274
+ }
64275
+ else if (sourceFlags & 3145728 /* UnionOrIntersection */ || targetFlags & 3145728 /* UnionOrIntersection */) {
64276
+ if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
64277
+ return result;
64278
+ }
64279
+ if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
64280
+ // The combined constraint of an intersection type is the intersection of the constraints of
64281
+ // the constituents. When an intersection type contains instantiable types with union type
64282
+ // constraints, there are situations where we need to examine the combined constraint. One is
64283
+ // when the target is a union type. Another is when the intersection contains types belonging
64284
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
64285
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
64286
+ // we need to check this constraint against a union on the target side. Also, given a type
64287
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
64288
+ // 'string & number | number & number' which reduces to just 'number'.
64289
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
64290
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
64291
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
64292
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
64293
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
64294
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
64295
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
64296
+ if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
64297
+ resetErrorInfo(saveErrorInfo);
64298
+ return result;
64299
+ }
64300
+ }
64301
+ }
64302
+ // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
64303
+ // Source is instantiable (e.g. source has union or intersection constraint).
64304
+ // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
64305
+ // Source is an intersection, target is an object (e.g. { a } & { b } <=> { a, b }).
64306
+ // Source is an intersection, target is a union (e.g. { a } & { b: boolean } <=> { a, b: true } | { a, b: false }).
64307
+ // Source is an intersection, target instantiable (e.g. string & { tag } <=> T["a"] constrained to string & { tag }).
64308
+ if (!(sourceFlags & 465829888 /* Instantiable */ ||
64309
+ sourceFlags & 524288 /* Object */ && targetFlags & 1048576 /* Union */ ||
64310
+ sourceFlags & 2097152 /* Intersection */ && targetFlags & (524288 /* Object */ | 1048576 /* Union */ | 465829888 /* Instantiable */))) {
64311
+ return 0 /* False */;
64312
+ }
64221
64313
  }
64222
- var result;
64223
- var originalErrorInfo;
64224
- var varianceCheckFailed = false;
64225
- var saveErrorInfo = captureErrorCalculationState();
64226
64314
  // We limit alias variance probing to only object and conditional types since their alias behavior
64227
64315
  // is more predictable than other, interned types, which may or may not have an alias depending on
64228
64316
  // the order in which things were checked.
64229
- if (source.flags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64317
+ if (sourceFlags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64230
64318
  source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
64231
64319
  !(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
64232
64320
  var variances = getAliasVariances(source.aliasSymbol);
@@ -64244,7 +64332,7 @@ var ts;
64244
64332
  isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
64245
64333
  return result;
64246
64334
  }
64247
- if (target.flags & 262144 /* TypeParameter */) {
64335
+ if (targetFlags & 262144 /* TypeParameter */) {
64248
64336
  // A source type { [P in Q]: X } is related to a target type T if keyof T is related to Q and X is related to T[Q].
64249
64337
  if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
64250
64338
  if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
@@ -64256,10 +64344,10 @@ var ts;
64256
64344
  }
64257
64345
  }
64258
64346
  }
64259
- else if (target.flags & 4194304 /* Index */) {
64347
+ else if (targetFlags & 4194304 /* Index */) {
64260
64348
  var targetType_1 = target.type;
64261
64349
  // A keyof S is related to a keyof T if T is related to S.
64262
- if (source.flags & 4194304 /* Index */) {
64350
+ if (sourceFlags & 4194304 /* Index */) {
64263
64351
  if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
64264
64352
  return result;
64265
64353
  }
@@ -64310,8 +64398,8 @@ var ts;
64310
64398
  }
64311
64399
  }
64312
64400
  }
64313
- else if (target.flags & 8388608 /* IndexedAccess */) {
64314
- if (source.flags & 8388608 /* IndexedAccess */) {
64401
+ else if (targetFlags & 8388608 /* IndexedAccess */) {
64402
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64315
64403
  // Relate components directly before falling back to constraint relationships
64316
64404
  // A type S[K] is related to a type T[J] if S is related to T and K is related to J.
64317
64405
  if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
@@ -64417,7 +64505,7 @@ var ts;
64417
64505
  }
64418
64506
  }
64419
64507
  }
64420
- else if (target.flags & 16777216 /* Conditional */) {
64508
+ else if (targetFlags & 16777216 /* Conditional */) {
64421
64509
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64422
64510
  // conditional type and bail out with a Ternary.Maybe result.
64423
64511
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
@@ -64442,8 +64530,8 @@ var ts;
64442
64530
  }
64443
64531
  }
64444
64532
  }
64445
- else if (target.flags & 134217728 /* TemplateLiteral */) {
64446
- if (source.flags & 134217728 /* TemplateLiteral */) {
64533
+ else if (targetFlags & 134217728 /* TemplateLiteral */) {
64534
+ if (sourceFlags & 134217728 /* TemplateLiteral */) {
64447
64535
  if (relation === comparableRelation) {
64448
64536
  return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
64449
64537
  }
@@ -64455,11 +64543,11 @@ var ts;
64455
64543
  return -1 /* True */;
64456
64544
  }
64457
64545
  }
64458
- if (source.flags & 8650752 /* TypeVariable */) {
64459
- // IndexedAccess comparisons are handled above in the `target.flags & TypeFlage.IndexedAccess` branch
64460
- if (!(source.flags & 8388608 /* IndexedAccess */ && target.flags & 8388608 /* IndexedAccess */)) {
64546
+ if (sourceFlags & 8650752 /* TypeVariable */) {
64547
+ // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
64548
+ if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
64461
64549
  var constraint = getConstraintOfType(source);
64462
- if (!constraint || (source.flags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64550
+ if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64463
64551
  // A type variable with no constraint is not related to the non-primitive object type.
64464
64552
  if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
64465
64553
  resetErrorInfo(saveErrorInfo);
@@ -64472,7 +64560,7 @@ var ts;
64472
64560
  return result;
64473
64561
  }
64474
64562
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
64475
- else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64563
+ else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64476
64564
  resetErrorInfo(saveErrorInfo);
64477
64565
  return result;
64478
64566
  }
@@ -64489,14 +64577,14 @@ var ts;
64489
64577
  }
64490
64578
  }
64491
64579
  }
64492
- else if (source.flags & 4194304 /* Index */) {
64580
+ else if (sourceFlags & 4194304 /* Index */) {
64493
64581
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
64494
64582
  resetErrorInfo(saveErrorInfo);
64495
64583
  return result;
64496
64584
  }
64497
64585
  }
64498
- else if (source.flags & 134217728 /* TemplateLiteral */ && !(target.flags & 524288 /* Object */)) {
64499
- if (!(target.flags & 134217728 /* TemplateLiteral */)) {
64586
+ else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
64587
+ if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
64500
64588
  var constraint = getBaseConstraintOfType(source);
64501
64589
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
64502
64590
  resetErrorInfo(saveErrorInfo);
@@ -64504,8 +64592,8 @@ var ts;
64504
64592
  }
64505
64593
  }
64506
64594
  }
64507
- else if (source.flags & 268435456 /* StringMapping */) {
64508
- if (target.flags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64595
+ else if (sourceFlags & 268435456 /* StringMapping */) {
64596
+ if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64509
64597
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
64510
64598
  resetErrorInfo(saveErrorInfo);
64511
64599
  return result;
@@ -64519,14 +64607,14 @@ var ts;
64519
64607
  }
64520
64608
  }
64521
64609
  }
64522
- else if (source.flags & 16777216 /* Conditional */) {
64610
+ else if (sourceFlags & 16777216 /* Conditional */) {
64523
64611
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64524
64612
  // conditional type and bail out with a Ternary.Maybe result.
64525
64613
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
64526
64614
  resetErrorInfo(saveErrorInfo);
64527
64615
  return 3 /* Maybe */;
64528
64616
  }
64529
- if (target.flags & 16777216 /* Conditional */) {
64617
+ if (targetFlags & 16777216 /* Conditional */) {
64530
64618
  // Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
64531
64619
  // one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
64532
64620
  // and Y1 is related to Y2.
@@ -64586,15 +64674,21 @@ var ts;
64586
64674
  }
64587
64675
  return 0 /* False */;
64588
64676
  }
64589
- var sourceIsPrimitive = !!(source.flags & 131068 /* Primitive */);
64677
+ var sourceIsPrimitive = !!(sourceFlags & 131068 /* Primitive */);
64590
64678
  if (relation !== identityRelation) {
64591
64679
  source = getApparentType(source);
64680
+ sourceFlags = source.flags;
64592
64681
  }
64593
64682
  else if (isGenericMappedType(source)) {
64594
64683
  return 0 /* False */;
64595
64684
  }
64596
64685
  if (ts.getObjectFlags(source) & 4 /* Reference */ && ts.getObjectFlags(target) & 4 /* Reference */ && source.target === target.target &&
64597
64686
  !isTupleType(source) && !(ts.getObjectFlags(source) & 4096 /* MarkerType */ || ts.getObjectFlags(target) & 4096 /* MarkerType */)) {
64687
+ // When strictNullChecks is disabled, the element type of the empty array literal is undefinedWideningType,
64688
+ // and an empty array literal wouldn't be assignable to a `never[]` without this check.
64689
+ if (isEmptyArrayLiteralType(source)) {
64690
+ return -1 /* True */;
64691
+ }
64598
64692
  // We have type references to the same generic type, and the type references are not marker
64599
64693
  // type references (which are intended by be compared structurally). Obtain the variance
64600
64694
  // information for the type parameters and relate the type arguments accordingly.
@@ -64630,7 +64724,7 @@ var ts;
64630
64724
  // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
64631
64725
  // to X. Failing both of those we want to check if the aggregation of A and B's members structurally
64632
64726
  // relates to X. Thus, we include intersection types on the source side here.
64633
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 524288 /* Object */) {
64727
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 524288 /* Object */) {
64634
64728
  // Report structural errors only if we haven't reported any errors yet
64635
64729
  var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo.errorInfo && !sourceIsPrimitive;
64636
64730
  result = propertiesRelatedTo(source, target, reportStructuralErrors, /*excludedProperties*/ undefined, intersectionState);
@@ -64654,7 +64748,7 @@ var ts;
64654
64748
  // there exists a constituent of T for every combination of the discriminants of S
64655
64749
  // with respect to T. We do not report errors here, as we will use the existing
64656
64750
  // error result from checking each constituent of the union.
64657
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 1048576 /* Union */) {
64751
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 1048576 /* Union */) {
64658
64752
  var objectOnlyTarget = extractTypesOfKind(target, 524288 /* Object */ | 2097152 /* Intersection */ | 33554432 /* Substitution */);
64659
64753
  if (objectOnlyTarget.flags & 1048576 /* Union */) {
64660
64754
  var result_9 = typeRelatedToDiscriminatedType(source, objectOnlyTarget);
@@ -64901,6 +64995,15 @@ var ts;
64901
64995
  }
64902
64996
  return 0 /* False */;
64903
64997
  }
64998
+ // Ensure {readonly a: whatever} is not a subtype of {a: whatever},
64999
+ // while {a: whatever} is a subtype of {readonly a: whatever}.
65000
+ // This ensures the subtype relationship is ordered, and preventing declaration order
65001
+ // from deciding which type "wins" in union subtype reduction.
65002
+ // They're still assignable to one another, since `readonly` doesn't affect assignability.
65003
+ if ((relation === subtypeRelation || relation === strictSubtypeRelation) &&
65004
+ !!(sourcePropFlags & 64 /* Readonly */) && !(targetPropFlags & 64 /* Readonly */)) {
65005
+ return 0 /* False */;
65006
+ }
64904
65007
  // If the target comes from a partial union prop, allow `undefined` in the target type
64905
65008
  var related = isPropertySymbolTypeRelated(sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState);
64906
65009
  if (!related) {
@@ -65169,7 +65272,6 @@ var ts;
65169
65272
  }
65170
65273
  }
65171
65274
  var result = -1 /* True */;
65172
- var saveErrorInfo = captureErrorCalculationState();
65173
65275
  var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
65174
65276
  var sourceObjectFlags = ts.getObjectFlags(source);
65175
65277
  var targetObjectFlags = ts.getObjectFlags(target);
@@ -65210,6 +65312,7 @@ var ts;
65210
65312
  else {
65211
65313
  outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) {
65212
65314
  var t = targetSignatures_1[_i];
65315
+ var saveErrorInfo = captureErrorCalculationState();
65213
65316
  // Only elaborate errors from the first failure
65214
65317
  var shouldElaborateErrors = reportErrors;
65215
65318
  for (var _c = 0, sourceSignatures_1 = sourceSignatures; _c < sourceSignatures_1.length; _c++) {
@@ -65320,8 +65423,8 @@ var ts;
65320
65423
  var indexInfos = getIndexInfosOfType(target);
65321
65424
  var targetHasStringIndex = ts.some(indexInfos, function (info) { return info.keyType === stringType; });
65322
65425
  var result = -1 /* True */;
65323
- for (var _i = 0, indexInfos_3 = indexInfos; _i < indexInfos_3.length; _i++) {
65324
- var targetInfo = indexInfos_3[_i];
65426
+ for (var _i = 0, indexInfos_5 = indexInfos; _i < indexInfos_5.length; _i++) {
65427
+ var targetInfo = indexInfos_5[_i];
65325
65428
  var related = !sourceIsPrimitive && targetHasStringIndex && targetInfo.type.flags & 1 /* Any */ ? -1 /* True */ :
65326
65429
  isGenericMappedType(source) && targetHasStringIndex ? isRelatedTo(getTemplateTypeFromMappedType(source), targetInfo.type, 3 /* Both */, reportErrors) :
65327
65430
  typeRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
@@ -65928,10 +66031,10 @@ var ts;
65928
66031
  if (!(ts.getObjectFlags(type) & 4 /* Reference */) || !(ts.getObjectFlags(type.target) & 3 /* ClassOrInterface */)) {
65929
66032
  return undefined;
65930
66033
  }
65931
- if (ts.getObjectFlags(type) & 33554432 /* IdenticalBaseTypeCalculated */) {
65932
- return ts.getObjectFlags(type) & 67108864 /* IdenticalBaseTypeExists */ ? type.cachedEquivalentBaseType : undefined;
66034
+ if (ts.getObjectFlags(type) & 67108864 /* IdenticalBaseTypeCalculated */) {
66035
+ return ts.getObjectFlags(type) & 134217728 /* IdenticalBaseTypeExists */ ? type.cachedEquivalentBaseType : undefined;
65933
66036
  }
65934
- type.objectFlags |= 33554432 /* IdenticalBaseTypeCalculated */;
66037
+ type.objectFlags |= 67108864 /* IdenticalBaseTypeCalculated */;
65935
66038
  var target = type.target;
65936
66039
  if (ts.getObjectFlags(target) & 1 /* Class */) {
65937
66040
  var baseTypeNode = getBaseTypeNodeOfClass(target);
@@ -65952,7 +66055,7 @@ var ts;
65952
66055
  if (ts.length(getTypeArguments(type)) > ts.length(target.typeParameters)) {
65953
66056
  instantiatedBase = getTypeWithThisArgument(instantiatedBase, ts.last(getTypeArguments(type)));
65954
66057
  }
65955
- type.objectFlags |= 67108864 /* IdenticalBaseTypeExists */;
66058
+ type.objectFlags |= 134217728 /* IdenticalBaseTypeExists */;
65956
66059
  return type.cachedEquivalentBaseType = instantiatedBase;
65957
66060
  }
65958
66061
  function isEmptyLiteralType(type) {
@@ -66616,7 +66719,7 @@ var ts;
66616
66719
  var result = !!(type.flags & 465829888 /* Instantiable */ ||
66617
66720
  type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || ts.forEach(getTypeArguments(type), couldContainTypeVariables)) ||
66618
66721
  objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations ||
66619
- objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 8388608 /* ObjectRestType */)) ||
66722
+ objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 8388608 /* ObjectRestType */ | 16777216 /* InstantiationExpressionType */)) ||
66620
66723
  type.flags & 3145728 /* UnionOrIntersection */ && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && ts.some(type.types, couldContainTypeVariables));
66621
66724
  if (type.flags & 3899393 /* ObjectFlagsType */) {
66622
66725
  type.objectFlags |= 1048576 /* CouldContainTypeVariablesComputed */ | (result ? 2097152 /* CouldContainTypeVariables */ : 0);
@@ -67533,8 +67636,8 @@ var ts;
67533
67636
  var priority = (ts.getObjectFlags(source) & ts.getObjectFlags(target) & 32 /* Mapped */) ? 8 /* HomomorphicMappedType */ : 0;
67534
67637
  var indexInfos = getIndexInfosOfType(target);
67535
67638
  if (isObjectTypeWithInferableIndex(source)) {
67536
- for (var _i = 0, indexInfos_4 = indexInfos; _i < indexInfos_4.length; _i++) {
67537
- var targetInfo = indexInfos_4[_i];
67639
+ for (var _i = 0, indexInfos_6 = indexInfos; _i < indexInfos_6.length; _i++) {
67640
+ var targetInfo = indexInfos_6[_i];
67538
67641
  var propTypes = [];
67539
67642
  for (var _a = 0, _b = getPropertiesOfType(source); _a < _b.length; _a++) {
67540
67643
  var prop = _b[_a];
@@ -67554,8 +67657,8 @@ var ts;
67554
67657
  }
67555
67658
  }
67556
67659
  }
67557
- for (var _e = 0, indexInfos_5 = indexInfos; _e < indexInfos_5.length; _e++) {
67558
- var targetInfo = indexInfos_5[_e];
67660
+ for (var _e = 0, indexInfos_7 = indexInfos; _e < indexInfos_7.length; _e++) {
67661
+ var targetInfo = indexInfos_7[_e];
67559
67662
  var sourceInfo = getApplicableIndexInfo(source, targetInfo.keyType);
67560
67663
  if (sourceInfo) {
67561
67664
  inferWithPriority(sourceInfo.type, targetInfo.type, priority);
@@ -68380,9 +68483,6 @@ var ts;
68380
68483
  getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
68381
68484
  mapType(type, mapper);
68382
68485
  }
68383
- function getConstituentCount(type) {
68384
- return type.flags & 1048576 /* Union */ ? type.types.length : 1;
68385
- }
68386
68486
  function extractTypesOfKind(type, kind) {
68387
68487
  return filterType(type, function (t) { return (t.flags & kind) !== 0; });
68388
68488
  }
@@ -73103,6 +73203,9 @@ var ts;
73103
73203
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
73104
73204
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
73105
73205
  }
73206
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
73207
+ addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
73208
+ }
73106
73209
  }
73107
73210
  else {
73108
73211
  if (isDeprecatedSymbol(prop) && isUncalledFunctionReference(node, prop) && prop.declarations) {
@@ -75719,6 +75822,72 @@ var ts;
75719
75822
  return node.flags & 32 /* OptionalChain */ ? checkNonNullChain(node) :
75720
75823
  getNonNullableType(checkExpression(node.expression));
75721
75824
  }
75825
+ function checkExpressionWithTypeArguments(node) {
75826
+ checkGrammarExpressionWithTypeArguments(node);
75827
+ var exprType = node.kind === 227 /* ExpressionWithTypeArguments */ ? checkExpression(node.expression) :
75828
+ ts.isThisIdentifier(node.exprName) ? checkThisExpression(node.exprName) :
75829
+ checkExpression(node.exprName);
75830
+ var typeArguments = node.typeArguments;
75831
+ if (exprType === silentNeverType || isErrorType(exprType) || !ts.some(typeArguments)) {
75832
+ return exprType;
75833
+ }
75834
+ var hasSomeApplicableSignature = false;
75835
+ var nonApplicableType;
75836
+ var result = getInstantiatedType(exprType);
75837
+ var errorType = hasSomeApplicableSignature ? nonApplicableType : exprType;
75838
+ if (errorType) {
75839
+ diagnostics.add(ts.createDiagnosticForNodeArray(ts.getSourceFileOfNode(node), typeArguments, ts.Diagnostics.Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable, typeToString(errorType)));
75840
+ }
75841
+ return result;
75842
+ function getInstantiatedType(type) {
75843
+ var hasSignatures = false;
75844
+ var hasApplicableSignature = false;
75845
+ var result = getInstantiatedTypePart(type);
75846
+ hasSomeApplicableSignature || (hasSomeApplicableSignature = hasApplicableSignature);
75847
+ if (hasSignatures && !hasApplicableSignature) {
75848
+ nonApplicableType !== null && nonApplicableType !== void 0 ? nonApplicableType : (nonApplicableType = type);
75849
+ }
75850
+ return result;
75851
+ function getInstantiatedTypePart(type) {
75852
+ if (type.flags & 524288 /* Object */) {
75853
+ var resolved = resolveStructuredTypeMembers(type);
75854
+ var callSignatures = getInstantiatedSignatures(resolved.callSignatures);
75855
+ var constructSignatures = getInstantiatedSignatures(resolved.constructSignatures);
75856
+ hasSignatures || (hasSignatures = resolved.callSignatures.length !== 0 || resolved.constructSignatures.length !== 0);
75857
+ hasApplicableSignature || (hasApplicableSignature = callSignatures.length !== 0 || constructSignatures.length !== 0);
75858
+ if (callSignatures !== resolved.callSignatures || constructSignatures !== resolved.constructSignatures) {
75859
+ var result_11 = createAnonymousType(undefined, resolved.members, callSignatures, constructSignatures, resolved.indexInfos);
75860
+ result_11.objectFlags |= 16777216 /* InstantiationExpressionType */;
75861
+ result_11.node = node;
75862
+ return result_11;
75863
+ }
75864
+ }
75865
+ else if (type.flags & 58982400 /* InstantiableNonPrimitive */) {
75866
+ var constraint = getBaseConstraintOfType(type);
75867
+ if (constraint) {
75868
+ var instantiated = getInstantiatedTypePart(constraint);
75869
+ if (instantiated !== constraint) {
75870
+ return instantiated;
75871
+ }
75872
+ }
75873
+ }
75874
+ else if (type.flags & 1048576 /* Union */) {
75875
+ return mapType(type, getInstantiatedType);
75876
+ }
75877
+ else if (type.flags & 2097152 /* Intersection */) {
75878
+ return getIntersectionType(ts.sameMap(type.types, getInstantiatedTypePart));
75879
+ }
75880
+ return type;
75881
+ }
75882
+ }
75883
+ function getInstantiatedSignatures(signatures) {
75884
+ var applicableSignatures = ts.filter(signatures, function (sig) { return !!sig.typeParameters && hasCorrectTypeArgumentArity(sig, typeArguments); });
75885
+ return ts.sameMap(applicableSignatures, function (sig) {
75886
+ var typeArgumentTypes = checkTypeArguments(sig, typeArguments, /*reportErrors*/ true);
75887
+ return typeArgumentTypes ? getSignatureInstantiation(sig, typeArgumentTypes, ts.isInJSFile(sig.declaration)) : sig;
75888
+ });
75889
+ }
75890
+ }
75722
75891
  function checkMetaProperty(node) {
75723
75892
  checkGrammarMetaProperty(node);
75724
75893
  if (node.keywordToken === 103 /* NewKeyword */) {
@@ -76048,21 +76217,22 @@ var ts;
76048
76217
  if (links.type === unknownType) {
76049
76218
  links.type = getTypeFromBindingPattern(declaration.name);
76050
76219
  }
76051
- assignBindingElementTypes(declaration.name);
76220
+ assignBindingElementTypes(declaration.name, links.type);
76052
76221
  }
76053
76222
  }
76054
76223
  }
76055
76224
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76056
76225
  // the destructured type into the contained binding elements.
76057
- function assignBindingElementTypes(pattern) {
76226
+ function assignBindingElementTypes(pattern, parentType) {
76058
76227
  for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
76059
76228
  var element = _a[_i];
76060
76229
  if (!ts.isOmittedExpression(element)) {
76230
+ var type = getBindingElementTypeFromParentType(element, parentType);
76061
76231
  if (element.name.kind === 79 /* Identifier */) {
76062
- getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
76232
+ getSymbolLinks(getSymbolOfNode(element)).type = type;
76063
76233
  }
76064
76234
  else {
76065
- assignBindingElementTypes(element.name);
76235
+ assignBindingElementTypes(element.name, type);
76066
76236
  }
76067
76237
  }
76068
76238
  }
@@ -78234,6 +78404,8 @@ var ts;
78234
78404
  return checkAssertion(node);
78235
78405
  case 229 /* NonNullExpression */:
78236
78406
  return checkNonNullAssertion(node);
78407
+ case 227 /* ExpressionWithTypeArguments */:
78408
+ return checkExpressionWithTypeArguments(node);
78237
78409
  case 230 /* MetaProperty */:
78238
78410
  return checkMetaProperty(node);
78239
78411
  case 214 /* DeleteExpression */:
@@ -79437,12 +79609,12 @@ var ts;
79437
79609
  case 264 /* ImportEqualsDeclaration */:
79438
79610
  case 267 /* NamespaceImport */:
79439
79611
  case 266 /* ImportClause */:
79440
- var result_11 = 0 /* None */;
79612
+ var result_12 = 0 /* None */;
79441
79613
  var target = resolveAlias(getSymbolOfNode(d));
79442
79614
  ts.forEach(target.declarations, function (d) {
79443
- result_11 |= getDeclarationSpaces(d);
79615
+ result_12 |= getDeclarationSpaces(d);
79444
79616
  });
79445
- return result_11;
79617
+ return result_12;
79446
79618
  case 253 /* VariableDeclaration */:
79447
79619
  case 202 /* BindingElement */:
79448
79620
  case 255 /* FunctionDeclaration */:
@@ -79803,28 +79975,24 @@ var ts;
79803
79975
  if (returnType.flags & 1 /* Any */) {
79804
79976
  return;
79805
79977
  }
79978
+ var headMessage;
79806
79979
  var expectedReturnType;
79807
- var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
79808
- var errorInfo;
79809
79980
  switch (node.parent.kind) {
79810
79981
  case 256 /* ClassDeclaration */:
79982
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79811
79983
  var classSymbol = getSymbolOfNode(node.parent);
79812
79984
  var classConstructorType = getTypeOfSymbol(classSymbol);
79813
79985
  expectedReturnType = getUnionType([classConstructorType, voidType]);
79814
79986
  break;
79815
- case 163 /* Parameter */:
79816
- expectedReturnType = voidType;
79817
- errorInfo = ts.chainDiagnosticMessages(
79818
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
79819
- break;
79820
79987
  case 166 /* PropertyDeclaration */:
79988
+ case 163 /* Parameter */:
79989
+ headMessage = ts.Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any;
79821
79990
  expectedReturnType = voidType;
79822
- errorInfo = ts.chainDiagnosticMessages(
79823
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
79824
79991
  break;
79825
79992
  case 168 /* MethodDeclaration */:
79826
79993
  case 171 /* GetAccessor */:
79827
79994
  case 172 /* SetAccessor */:
79995
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79828
79996
  var methodType = getTypeOfNode(node.parent);
79829
79997
  var descriptorType = createTypedPropertyDescriptorType(methodType);
79830
79998
  expectedReturnType = getUnionType([descriptorType, voidType]);
@@ -79832,7 +80000,7 @@ var ts;
79832
80000
  default:
79833
80001
  return ts.Debug.fail();
79834
80002
  }
79835
- checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, function () { return errorInfo; });
80003
+ checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage);
79836
80004
  }
79837
80005
  /**
79838
80006
  * If a TypeNode can be resolved to a value symbol imported from an external module, it is
@@ -82005,8 +82173,8 @@ var ts;
82005
82173
  }
82006
82174
  }
82007
82175
  if (indexInfos.length > 1) {
82008
- for (var _d = 0, indexInfos_6 = indexInfos; _d < indexInfos_6.length; _d++) {
82009
- var info = indexInfos_6[_d];
82176
+ for (var _d = 0, indexInfos_8 = indexInfos; _d < indexInfos_8.length; _d++) {
82177
+ var info = indexInfos_8[_d];
82010
82178
  checkIndexConstraintForIndexSignature(type, info);
82011
82179
  }
82012
82180
  }
@@ -82032,8 +82200,8 @@ var ts;
82032
82200
  error(errorNode, ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, symbolToString(prop), typeToString(propType), typeToString(info.keyType), typeToString(info.type));
82033
82201
  }
82034
82202
  };
82035
- for (var _i = 0, indexInfos_7 = indexInfos; _i < indexInfos_7.length; _i++) {
82036
- var info = indexInfos_7[_i];
82203
+ for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
82204
+ var info = indexInfos_9[_i];
82037
82205
  _loop_27(info);
82038
82206
  }
82039
82207
  }
@@ -82055,8 +82223,8 @@ var ts;
82055
82223
  error(errorNode, ts.Diagnostics._0_index_type_1_is_not_assignable_to_2_index_type_3, typeToString(checkInfo.keyType), typeToString(checkInfo.type), typeToString(info.keyType), typeToString(info.type));
82056
82224
  }
82057
82225
  };
82058
- for (var _i = 0, indexInfos_8 = indexInfos; _i < indexInfos_8.length; _i++) {
82059
- var info = indexInfos_8[_i];
82226
+ for (var _i = 0, indexInfos_10 = indexInfos; _i < indexInfos_10.length; _i++) {
82227
+ var info = indexInfos_10[_i];
82060
82228
  _loop_28(info);
82061
82229
  }
82062
82230
  }
@@ -85380,7 +85548,7 @@ var ts;
85380
85548
  if (resolvedTypeReferenceDirectives) {
85381
85549
  // populate reverse mapping: file path -> type reference directive that was resolved to this file
85382
85550
  fileToDirective = new ts.Map();
85383
- resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key) {
85551
+ resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key, mode) {
85384
85552
  if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
85385
85553
  return;
85386
85554
  }
@@ -85388,7 +85556,7 @@ var ts;
85388
85556
  if (file) {
85389
85557
  // Add the transitive closure of path references loaded by this file (as long as they are not)
85390
85558
  // part of an existing type reference.
85391
- addReferencedFilesToTypeDirective(file, key);
85559
+ addReferencedFilesToTypeDirective(file, key, mode);
85392
85560
  }
85393
85561
  });
85394
85562
  }
@@ -85582,16 +85750,16 @@ var ts;
85582
85750
  }
85583
85751
  return false;
85584
85752
  }
85585
- function addReferencedFilesToTypeDirective(file, key) {
85753
+ function addReferencedFilesToTypeDirective(file, key, mode) {
85586
85754
  if (fileToDirective.has(file.path))
85587
85755
  return;
85588
- fileToDirective.set(file.path, key);
85756
+ fileToDirective.set(file.path, [key, mode]);
85589
85757
  for (var _i = 0, _a = file.referencedFiles; _i < _a.length; _i++) {
85590
- var fileName = _a[_i].fileName;
85758
+ var _b = _a[_i], fileName = _b.fileName, resolutionMode = _b.resolutionMode;
85591
85759
  var resolvedFile = ts.resolveTripleslashReference(fileName, file.fileName);
85592
85760
  var referencedFile = host.getSourceFile(resolvedFile);
85593
85761
  if (referencedFile) {
85594
- addReferencedFilesToTypeDirective(referencedFile, key);
85762
+ addReferencedFilesToTypeDirective(referencedFile, key, resolutionMode || file.impliedNodeFormat);
85595
85763
  }
85596
85764
  }
85597
85765
  }
@@ -87296,28 +87464,27 @@ var ts;
87296
87464
  }
87297
87465
  function findMostOverlappyType(source, unionTarget) {
87298
87466
  var bestMatch;
87299
- var matchingCount = 0;
87300
- for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87301
- var target = _a[_i];
87302
- var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87303
- if (overlap.flags & 4194304 /* Index */) {
87304
- // perfect overlap of keys
87305
- bestMatch = target;
87306
- matchingCount = Infinity;
87307
- }
87308
- else if (overlap.flags & 1048576 /* Union */) {
87309
- // We only want to account for literal types otherwise.
87310
- // If we have a union of index types, it seems likely that we
87311
- // needed to elaborate between two generic mapped types anyway.
87312
- var len = ts.length(ts.filter(overlap.types, isUnitType));
87313
- if (len >= matchingCount) {
87314
- bestMatch = target;
87315
- matchingCount = len;
87316
- }
87317
- }
87318
- else if (isUnitType(overlap) && 1 >= matchingCount) {
87319
- bestMatch = target;
87320
- matchingCount = 1;
87467
+ if (!(source.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87468
+ var matchingCount = 0;
87469
+ for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87470
+ var target = _a[_i];
87471
+ if (!(target.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87472
+ var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87473
+ if (overlap.flags & 4194304 /* Index */) {
87474
+ // perfect overlap of keys
87475
+ return target;
87476
+ }
87477
+ else if (isUnitType(overlap) || overlap.flags & 1048576 /* Union */) {
87478
+ // We only want to account for literal types otherwise.
87479
+ // If we have a union of index types, it seems likely that we
87480
+ // needed to elaborate between two generic mapped types anyway.
87481
+ var len = overlap.flags & 1048576 /* Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
87482
+ if (len >= matchingCount) {
87483
+ bestMatch = target;
87484
+ matchingCount = len;
87485
+ }
87486
+ }
87487
+ }
87321
87488
  }
87322
87489
  }
87323
87490
  return bestMatch;
@@ -87690,7 +87857,7 @@ var ts;
87690
87857
  return factory.updateConstructorTypeNode(node, nodesVisitor(node.modifiers, visitor, ts.isModifier), nodesVisitor(node.typeParameters, visitor, ts.isTypeParameterDeclaration), nodesVisitor(node.parameters, visitor, ts.isParameterDeclaration), nodeVisitor(node.type, visitor, ts.isTypeNode));
87691
87858
  case 180 /* TypeQuery */:
87692
87859
  ts.Debug.type(node);
87693
- return factory.updateTypeQueryNode(node, nodeVisitor(node.exprName, visitor, ts.isEntityName));
87860
+ return factory.updateTypeQueryNode(node, nodeVisitor(node.exprName, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode));
87694
87861
  case 181 /* TypeLiteral */:
87695
87862
  ts.Debug.type(node);
87696
87863
  return factory.updateTypeLiteralNode(node, nodesVisitor(node.members, visitor, ts.isTypeElement));
@@ -90582,8 +90749,8 @@ var ts;
90582
90749
  function generateClassElementDecorationExpressions(node, isStatic) {
90583
90750
  var members = getDecoratedClassElements(node, isStatic);
90584
90751
  var expressions;
90585
- for (var _i = 0, members_6 = members; _i < members_6.length; _i++) {
90586
- var member = members_6[_i];
90752
+ for (var _i = 0, members_8 = members; _i < members_8.length; _i++) {
90753
+ var member = members_8[_i];
90587
90754
  var expression = generateClassElementDecorationExpression(node, member);
90588
90755
  if (expression) {
90589
90756
  if (!expressions) {
@@ -95928,8 +96095,8 @@ var ts;
95928
96095
  function convertJsxChildrenToChildrenPropAssignment(children) {
95929
96096
  var nonWhitespaceChildren = ts.getSemanticJsxChildren(children);
95930
96097
  if (ts.length(nonWhitespaceChildren) === 1 && !nonWhitespaceChildren[0].dotDotDotToken) {
95931
- var result_12 = transformJsxChildToExpression(nonWhitespaceChildren[0]);
95932
- return result_12 && factory.createPropertyAssignment("children", result_12);
96098
+ var result_13 = transformJsxChildToExpression(nonWhitespaceChildren[0]);
96099
+ return result_13 && factory.createPropertyAssignment("children", result_13);
95933
96100
  }
95934
96101
  var result = ts.mapDefined(children, transformJsxChildToExpression);
95935
96102
  return ts.length(result) ? factory.createPropertyAssignment("children", factory.createArrayLiteralExpression(result)) : undefined;
@@ -106360,7 +106527,7 @@ var ts;
106360
106527
  var sourceFile = ts.createUnparsedSourceFile(prepend, "dts", stripInternal);
106361
106528
  hasNoDefaultLib_1 = hasNoDefaultLib_1 || !!sourceFile.hasNoDefaultLib;
106362
106529
  collectReferences(sourceFile, refs);
106363
- recordTypeReferenceDirectivesIfNecessary(sourceFile.typeReferenceDirectives);
106530
+ recordTypeReferenceDirectivesIfNecessary(ts.map(sourceFile.typeReferenceDirectives, function (ref) { return [ref.fileName, ref.resolutionMode]; }));
106364
106531
  collectLibs(sourceFile, libs);
106365
106532
  return sourceFile;
106366
106533
  }
@@ -106415,9 +106582,10 @@ var ts;
106415
106582
  return ts.map(ts.arrayFrom(libs.keys()), function (lib) { return ({ fileName: lib, pos: -1, end: -1 }); });
106416
106583
  }
106417
106584
  function getFileReferencesForUsedTypeReferences() {
106418
- return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForTypeName) : [];
106585
+ return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
106419
106586
  }
106420
- function getFileReferenceForTypeName(typeName) {
106587
+ function getFileReferenceForSpecifierModeTuple(_a) {
106588
+ var typeName = _a[0], mode = _a[1];
106421
106589
  // Elide type references for which we have imports
106422
106590
  if (emittedImports) {
106423
106591
  for (var _i = 0, emittedImports_1 = emittedImports; _i < emittedImports_1.length; _i++) {
@@ -106433,7 +106601,7 @@ var ts;
106433
106601
  }
106434
106602
  }
106435
106603
  }
106436
- return { fileName: typeName, pos: -1, end: -1 };
106604
+ return __assign({ fileName: typeName, pos: -1, end: -1 }, (mode ? { resolutionMode: mode } : undefined));
106437
106605
  }
106438
106606
  function mapReferencesIntoArray(references, outputFilePath) {
106439
106607
  return function (file) {
@@ -106453,7 +106621,7 @@ var ts;
106453
106621
  // If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
106454
106622
  // via a non-relative name, emit a type reference directive to that non-relative name, rather than
106455
106623
  // a relative path to the declaration file
106456
- recordTypeReferenceDirectivesIfNecessary([specifier]);
106624
+ recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]);
106457
106625
  return;
106458
106626
  }
106459
106627
  var fileName = ts.getRelativePathToDirectoryOrUrl(outputFilePath, declFileName, host.getCurrentDirectory(), host.getCanonicalFileName,
@@ -109566,6 +109734,8 @@ var ts;
109566
109734
  return emitAsExpression(node);
109567
109735
  case 229 /* NonNullExpression */:
109568
109736
  return emitNonNullExpression(node);
109737
+ case 227 /* ExpressionWithTypeArguments */:
109738
+ return emitExpressionWithTypeArguments(node);
109569
109739
  case 230 /* MetaProperty */:
109570
109740
  return emitMetaProperty(node);
109571
109741
  case 231 /* SyntheticExpression */:
@@ -110010,6 +110180,7 @@ var ts;
110010
110180
  writeKeyword("typeof");
110011
110181
  writeSpace();
110012
110182
  emit(node.exprName);
110183
+ emitTypeArguments(node, node.typeArguments);
110013
110184
  }
110014
110185
  function emitTypeLiteral(node) {
110015
110186
  writePunctuation("{");
@@ -111565,9 +111736,12 @@ var ts;
111565
111736
  for (var _d = 0, types_24 = types; _d < types_24.length; _d++) {
111566
111737
  var directive = types_24[_d];
111567
111738
  var pos = writer.getTextPos();
111568
- writeComment("/// <reference types=\"" + directive.fileName + "\" />");
111739
+ var resolutionMode = directive.resolutionMode && directive.resolutionMode !== (currentSourceFile === null || currentSourceFile === void 0 ? void 0 : currentSourceFile.impliedNodeFormat)
111740
+ ? "resolution-mode=\"" + (directive.resolutionMode === ts.ModuleKind.ESNext ? "import" : "require") + "\""
111741
+ : "";
111742
+ writeComment("/// <reference types=\"" + directive.fileName + "\" " + resolutionMode + "/>");
111569
111743
  if (bundleFileInfo)
111570
- bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: "type" /* Type */, data: directive.fileName });
111744
+ bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: !directive.resolutionMode ? "type" /* Type */ : directive.resolutionMode === ts.ModuleKind.ESNext ? "type-import" /* TypeResolutionModeImport */ : "type-require" /* TypeResolutionModeRequire */, data: directive.fileName });
111571
111745
  writeLine();
111572
111746
  }
111573
111747
  for (var _e = 0, libs_1 = libs; _e < libs_1.length; _e++) {
@@ -114174,7 +114348,7 @@ var ts;
114174
114348
  }
114175
114349
  ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
114176
114350
  /* @internal */
114177
- function loadWithLocalCache(names, containingFile, redirectedReference, loader) {
114351
+ function loadWithTypeDirectiveCache(names, containingFile, redirectedReference, containingFileMode, loader) {
114178
114352
  if (names.length === 0) {
114179
114353
  return [];
114180
114354
  }
@@ -114183,19 +114357,28 @@ var ts;
114183
114357
  for (var _i = 0, names_2 = names; _i < names_2.length; _i++) {
114184
114358
  var name = names_2[_i];
114185
114359
  var result = void 0;
114186
- if (cache.has(name)) {
114187
- result = cache.get(name);
114360
+ var mode = getModeForFileReference(name, containingFileMode);
114361
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
114362
+ var strName = ts.isString(name) ? name : name.fileName.toLowerCase();
114363
+ var cacheKey = mode !== undefined ? mode + "|" + strName : strName;
114364
+ if (cache.has(cacheKey)) {
114365
+ result = cache.get(cacheKey);
114188
114366
  }
114189
114367
  else {
114190
- cache.set(name, result = loader(name, containingFile, redirectedReference));
114368
+ cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
114191
114369
  }
114192
114370
  resolutions.push(result);
114193
114371
  }
114194
114372
  return resolutions;
114195
114373
  }
114196
- ts.loadWithLocalCache = loadWithLocalCache;
114374
+ ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache;
114197
114375
  ;
114198
114376
  /* @internal */
114377
+ function getModeForFileReference(ref, containingFileMode) {
114378
+ return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
114379
+ }
114380
+ ts.getModeForFileReference = getModeForFileReference;
114381
+ /* @internal */
114199
114382
  function getModeForResolutionAtIndex(file, index) {
114200
114383
  if (file.impliedNodeFormat === undefined)
114201
114384
  return undefined;
@@ -114298,7 +114481,7 @@ var ts;
114298
114481
  var _d, _e, _f, _g;
114299
114482
  var file = ts.Debug.checkDefined(getSourceFileByPath(ref.file));
114300
114483
  var kind = ref.kind, index = ref.index;
114301
- var pos, end, packageId;
114484
+ var pos, end, packageId, resolutionMode;
114302
114485
  switch (kind) {
114303
114486
  case ts.FileIncludeKind.Import:
114304
114487
  var importLiteral = getModuleNameStringLiteralAt(file, index);
@@ -114312,8 +114495,8 @@ var ts;
114312
114495
  (_a = file.referencedFiles[index], pos = _a.pos, end = _a.end);
114313
114496
  break;
114314
114497
  case ts.FileIncludeKind.TypeReferenceDirective:
114315
- (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end);
114316
- packageId = (_g = (_f = file.resolvedTypeReferenceDirectiveNames) === null || _f === void 0 ? void 0 : _f.get(ts.toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), file.impliedNodeFormat)) === null || _g === void 0 ? void 0 : _g.packageId;
114498
+ (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end, resolutionMode = _b.resolutionMode);
114499
+ packageId = (_g = (_f = file.resolvedTypeReferenceDirectiveNames) === null || _f === void 0 ? void 0 : _f.get(ts.toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), resolutionMode || file.impliedNodeFormat)) === null || _g === void 0 ? void 0 : _g.packageId;
114317
114500
  break;
114318
114501
  case ts.FileIncludeKind.LibReferenceDirective:
114319
114502
  (_c = file.libReferenceDirectives[index], pos = _c.pos, end = _c.end);
@@ -114557,7 +114740,7 @@ var ts;
114557
114740
  var fileReasons = ts.createMultiMap();
114558
114741
  var cachedBindAndCheckDiagnosticsForFile = {};
114559
114742
  var cachedDeclarationDiagnosticsForFile = {};
114560
- var resolvedTypeReferenceDirectives = new ts.Map();
114743
+ var resolvedTypeReferenceDirectives = ts.createModeAwareCache();
114561
114744
  var fileProcessingDiagnostics;
114562
114745
  // The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
114563
114746
  // This works as imported modules are discovered recursively in a depth first manner, specifically:
@@ -114610,12 +114793,12 @@ var ts;
114610
114793
  }
114611
114794
  var actualResolveTypeReferenceDirectiveNamesWorker;
114612
114795
  if (host.resolveTypeReferenceDirectives) {
114613
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options); };
114796
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference, containingFileMode) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options, containingFileMode); };
114614
114797
  }
114615
114798
  else {
114616
114799
  typeReferenceDirectiveResolutionCache = ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
114617
- var loader_2 = function (typesRef, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114618
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference) { return loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_2); };
114800
+ var loader_2 = function (typesRef, containingFile, redirectedReference, resolutionMode) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114801
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference, containingFileMode) { return loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_2); };
114619
114802
  }
114620
114803
  // Map from a stringified PackageId to the source file with that id.
114621
114804
  // Only one source file may have a given packageId. Others become redirects (see createRedirectSourceFile).
@@ -114712,7 +114895,8 @@ var ts;
114712
114895
  var containingFilename = ts.combinePaths(containingDirectory, ts.inferredTypesContainingFile);
114713
114896
  var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
114714
114897
  for (var i = 0; i < typeReferences.length; i++) {
114715
- processTypeReferenceDirective(typeReferences[i], resolutions[i], { kind: ts.FileIncludeKind.AutomaticTypeDirectiveFile, typeReference: typeReferences[i], packageId: (_c = resolutions[i]) === null || _c === void 0 ? void 0 : _c.packageId });
114898
+ // under node12/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
114899
+ processTypeReferenceDirective(typeReferences[i], /*mode*/ undefined, resolutions[i], { kind: ts.FileIncludeKind.AutomaticTypeDirectiveFile, typeReference: typeReferences[i], packageId: (_c = resolutions[i]) === null || _c === void 0 ? void 0 : _c.packageId });
114716
114900
  }
114717
114901
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
114718
114902
  }
@@ -114872,9 +115056,10 @@ var ts;
114872
115056
  return [];
114873
115057
  var containingFileName = !ts.isString(containingFile) ? ts.getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory) : containingFile;
114874
115058
  var redirectedReference = !ts.isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
115059
+ var containingFileMode = !ts.isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
114875
115060
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName: containingFileName });
114876
115061
  ts.performance.mark("beforeResolveTypeReference");
114877
- var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference);
115062
+ var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
114878
115063
  ts.performance.mark("afterResolveTypeReference");
114879
115064
  ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
114880
115065
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
@@ -114969,15 +115154,15 @@ var ts;
114969
115154
  // which per above occurred during the current program creation.
114970
115155
  // Since we assume the filesystem does not change during program creation,
114971
115156
  // it is safe to reuse resolutions from the earlier call.
114972
- var result_13 = [];
115157
+ var result_14 = [];
114973
115158
  var i = 0;
114974
115159
  for (var _i = 0, moduleNames_1 = moduleNames; _i < moduleNames_1.length; _i++) {
114975
115160
  var moduleName = moduleNames_1[_i];
114976
115161
  var resolvedModule = file.resolvedModules.get(moduleName, getModeForResolutionAtIndex(file, i));
114977
115162
  i++;
114978
- result_13.push(resolvedModule);
115163
+ result_14.push(resolvedModule);
114979
115164
  }
114980
- return result_13;
115165
+ return result_14;
114981
115166
  }
114982
115167
  // At this point, we know at least one of the following hold:
114983
115168
  // - file has local declarations for ambient modules
@@ -115266,8 +115451,7 @@ var ts;
115266
115451
  else {
115267
115452
  newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
115268
115453
  }
115269
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
115270
- var typesReferenceDirectives = ts.map(newSourceFile.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
115454
+ var typesReferenceDirectives = newSourceFile.typeReferenceDirectives;
115271
115455
  var typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
115272
115456
  // ensure that types resolutions are still correct
115273
115457
  var typeReferenceResolutionsChanged = ts.hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, ts.typeDirectiveIsEqualTo);
@@ -116346,8 +116530,7 @@ var ts;
116346
116530
  });
116347
116531
  }
116348
116532
  function processTypeReferenceDirectives(file) {
116349
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
116350
- var typeDirectives = ts.map(file.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
116533
+ var typeDirectives = file.typeReferenceDirectives;
116351
116534
  if (!typeDirectives) {
116352
116535
  return;
116353
116536
  }
@@ -116358,17 +116541,21 @@ var ts;
116358
116541
  // store resolved type directive on the file
116359
116542
  var fileName = ts.toFileNameLowerCase(ref.fileName);
116360
116543
  ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
116361
- processTypeReferenceDirective(fileName, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116544
+ var mode = ref.resolutionMode || file.impliedNodeFormat;
116545
+ if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
116546
+ programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext));
116547
+ }
116548
+ processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116362
116549
  }
116363
116550
  }
116364
- function processTypeReferenceDirective(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116551
+ function processTypeReferenceDirective(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116365
116552
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "processTypeReferenceDirective", { directive: typeReferenceDirective, hasResolved: !!resolveModuleNamesReusingOldState, refKind: reason.kind, refPath: isReferencedFile(reason) ? reason.file : undefined });
116366
- processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason);
116553
+ processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason);
116367
116554
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116368
116555
  }
116369
- function processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116556
+ function processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116370
116557
  // If we already found this library as a primary reference - nothing to do
116371
- var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective);
116558
+ var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective, mode);
116372
116559
  if (previousResolution && previousResolution.primary) {
116373
116560
  return;
116374
116561
  }
@@ -116407,7 +116594,7 @@ var ts;
116407
116594
  addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_find_type_definition_file_for_0, [typeReferenceDirective]);
116408
116595
  }
116409
116596
  if (saveResolution) {
116410
- resolvedTypeReferenceDirectives.set(typeReferenceDirective, resolvedTypeReferenceDirective);
116597
+ resolvedTypeReferenceDirectives.set(typeReferenceDirective, mode, resolvedTypeReferenceDirective);
116411
116598
  }
116412
116599
  }
116413
116600
  function pathForLibFile(libFileName) {
@@ -119225,9 +119412,9 @@ var ts;
119225
119412
  });
119226
119413
  hasChangedAutomaticTypeDirectiveNames = false;
119227
119414
  }
119228
- function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference) {
119415
+ function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference, _containingSourceFile, mode) {
119229
119416
  var _a;
119230
- var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference);
119417
+ var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
119231
119418
  // return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
119232
119419
  if (!resolutionHost.getGlobalCache) {
119233
119420
  return primaryResult;
@@ -119248,12 +119435,12 @@ var ts;
119248
119435
  // Default return the result from the first pass
119249
119436
  return primaryResult;
119250
119437
  }
119251
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {
119252
- return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache);
119438
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, _containingSourceFile, resolutionMode) {
119439
+ return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
119253
119440
  }
119254
119441
  function resolveNamesWithLocalCache(_a) {
119255
119442
  var _b, _c, _d;
119256
- var names = _a.names, containingFile = _a.containingFile, redirectedReference = _a.redirectedReference, cache = _a.cache, perDirectoryCacheWithRedirects = _a.perDirectoryCacheWithRedirects, loader = _a.loader, getResolutionWithResolvedFileName = _a.getResolutionWithResolvedFileName, shouldRetryResolution = _a.shouldRetryResolution, reusedNames = _a.reusedNames, logChanges = _a.logChanges, containingSourceFile = _a.containingSourceFile;
119443
+ var names = _a.names, containingFile = _a.containingFile, redirectedReference = _a.redirectedReference, cache = _a.cache, perDirectoryCacheWithRedirects = _a.perDirectoryCacheWithRedirects, loader = _a.loader, getResolutionWithResolvedFileName = _a.getResolutionWithResolvedFileName, shouldRetryResolution = _a.shouldRetryResolution, reusedNames = _a.reusedNames, logChanges = _a.logChanges, containingSourceFile = _a.containingSourceFile, containingSourceFileMode = _a.containingSourceFileMode;
119257
119444
  var path = resolutionHost.toPath(containingFile);
119258
119445
  var resolutionsInFile = cache.get(path) || cache.set(path, ts.createModeAwareCache()).get(path);
119259
119446
  var dirPath = ts.getDirectoryPath(path);
@@ -119275,8 +119462,15 @@ var ts;
119275
119462
  var seenNamesInFile = ts.createModeAwareCache();
119276
119463
  var i = 0;
119277
119464
  for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
119278
- var name = names_4[_i];
119279
- var mode = containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119465
+ var entry = names_4[_i];
119466
+ var name = ts.isString(entry) ? entry : entry.fileName.toLowerCase();
119467
+ // Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
119468
+ // they require calculating the mode for a given import from it's position in the resolution table, since a given
119469
+ // import's syntax may override the file's default mode.
119470
+ // Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
119471
+ // a default file mode override if applicable.
119472
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, containingSourceFileMode) :
119473
+ containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119280
119474
  i++;
119281
119475
  var resolution = resolutionsInFile.get(name, mode);
119282
119476
  // Resolution is valid if it is present and not invalidated
@@ -119305,7 +119499,7 @@ var ts;
119305
119499
  }
119306
119500
  }
119307
119501
  else {
119308
- resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile);
119502
+ resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
119309
119503
  perDirectoryResolution.set(name, mode, resolution);
119310
119504
  if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
119311
119505
  resolutionHost.onDiscoveredSymlink();
@@ -119369,7 +119563,7 @@ var ts;
119369
119563
  return oldResult.resolvedFileName === newResult.resolvedFileName;
119370
119564
  }
119371
119565
  }
119372
- function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference) {
119566
+ function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode) {
119373
119567
  return resolveNamesWithLocalCache({
119374
119568
  names: typeDirectiveNames,
119375
119569
  containingFile: containingFile,
@@ -119379,6 +119573,7 @@ var ts;
119379
119573
  loader: resolveTypeReferenceDirective,
119380
119574
  getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
119381
119575
  shouldRetryResolution: function (resolution) { return resolution.resolvedTypeReferenceDirective === undefined; },
119576
+ containingSourceFileMode: containingFileMode
119382
119577
  });
119383
119578
  }
119384
119579
  function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile) {
@@ -120085,9 +120280,9 @@ var ts;
120085
120280
  if (!preferSymlinks) {
120086
120281
  // Symlinks inside ignored paths are already filtered out of the symlink cache,
120087
120282
  // so we only need to remove them from the realpath filenames.
120088
- var result_14 = ts.forEach(targets, function (p) { return !(shouldFilterIgnoredPaths && ts.containsIgnoredPath(p)) && cb(p, referenceRedirect === p); });
120089
- if (result_14)
120090
- return result_14;
120283
+ var result_15 = ts.forEach(targets, function (p) { return !(shouldFilterIgnoredPaths && ts.containsIgnoredPath(p)) && cb(p, referenceRedirect === p); });
120284
+ if (result_15)
120285
+ return result_15;
120091
120286
  }
120092
120287
  var symlinkedDirectories = (_a = host.getSymlinkCache) === null || _a === void 0 ? void 0 : _a.call(host).getSymlinkedDirectoriesByRealpath();
120093
120288
  var fullImportedFileName = ts.getNormalizedAbsolutePath(importedFileName, cwd);
@@ -120107,10 +120302,10 @@ var ts;
120107
120302
  for (var _i = 0, symlinkDirectories_1 = symlinkDirectories; _i < symlinkDirectories_1.length; _i++) {
120108
120303
  var symlinkDirectory = symlinkDirectories_1[_i];
120109
120304
  var option = ts.resolvePath(symlinkDirectory, relative);
120110
- var result_15 = cb(option, target === referenceRedirect);
120305
+ var result_16 = cb(option, target === referenceRedirect);
120111
120306
  shouldFilterIgnoredPaths = true; // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
120112
- if (result_15)
120113
- return result_15;
120307
+ if (result_16)
120308
+ return result_16;
120114
120309
  }
120115
120310
  });
120116
120311
  });
@@ -121287,7 +121482,7 @@ var ts;
121287
121482
  }
121288
121483
  return host.resolveTypeReferenceDirectives.apply(host, args);
121289
121484
  }) :
121290
- (function (typeDirectiveNames, containingFile, redirectedReference) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference); });
121485
+ (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
121291
121486
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
121292
121487
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
121293
121488
  synchronizeProgram();
@@ -122023,9 +122218,9 @@ var ts;
122023
122218
  compilerHost.getModuleResolutionCache = function () { return moduleResolutionCache; };
122024
122219
  }
122025
122220
  if (!compilerHost.resolveTypeReferenceDirectives) {
122026
- var loader_4 = function (moduleName, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; };
122027
- compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference) {
122028
- return ts.loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_4);
122221
+ var loader_4 = function (moduleName, containingFile, redirectedReference, containingFileMode) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective; };
122222
+ compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
122223
+ return ts.loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_4);
122029
122224
  };
122030
122225
  }
122031
122226
  var _a = ts.createWatchFactory(hostWithWatch, options), watchFile = _a.watchFile, watchDirectory = _a.watchDirectory, writeLog = _a.writeLog;
@@ -123951,7 +124146,7 @@ var ts;
123951
124146
  case 199 /* ImportType */:
123952
124147
  return !node.parent.isTypeOf;
123953
124148
  case 227 /* ExpressionWithTypeArguments */:
123954
- return !ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent);
124149
+ return ts.isPartOfTypeNode(node.parent);
123955
124150
  }
123956
124151
  return false;
123957
124152
  }
@@ -126934,6 +127129,10 @@ var ts;
126934
127129
  return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
126935
127130
  }
126936
127131
  ts.getFormatCodeSettingsForWriting = getFormatCodeSettingsForWriting;
127132
+ function jsxModeNeedsExplicitImport(jsx) {
127133
+ return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
127134
+ }
127135
+ ts.jsxModeNeedsExplicitImport = jsxModeNeedsExplicitImport;
126937
127136
  // #endregion
126938
127137
  })(ts || (ts = {}));
126939
127138
  /*@internal*/
@@ -128878,9 +129077,18 @@ var ts;
128878
129077
  return getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, scriptPath);
128879
129078
  }
128880
129079
  }
129080
+ function isEmitResolutionKindUsingNodeModules(compilerOptions) {
129081
+ return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeJs ||
129082
+ ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node12 ||
129083
+ ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext;
129084
+ }
129085
+ function isEmitModuleResolutionRespectingExportMaps(compilerOptions) {
129086
+ return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node12 ||
129087
+ ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext;
129088
+ }
128881
129089
  function getSupportedExtensionsForModuleResolution(compilerOptions) {
128882
129090
  var extensions = ts.getSupportedExtensions(compilerOptions);
128883
- return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeJs ?
129091
+ return isEmitResolutionKindUsingNodeModules(compilerOptions) ?
128884
129092
  ts.getSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, extensions) :
128885
129093
  extensions;
128886
129094
  }
@@ -129043,7 +129251,7 @@ var ts;
129043
129251
  result.push(nameAndKind(ambientName, "external module name" /* externalModuleName */, /*extension*/ undefined));
129044
129252
  }
129045
129253
  getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, fragmentDirectory, extensionOptions, result);
129046
- if (ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeJs) {
129254
+ if (isEmitResolutionKindUsingNodeModules(compilerOptions)) {
129047
129255
  // If looking for a global package name, don't just include everything in `node_modules` because that includes dependencies' own dependencies.
129048
129256
  // (But do if we didn't find anything, e.g. 'package.json' missing.)
129049
129257
  var foundGlobal = false;
@@ -129060,12 +129268,68 @@ var ts;
129060
129268
  }
129061
129269
  }
129062
129270
  if (!foundGlobal) {
129063
- ts.forEachAncestorDirectory(scriptPath, function (ancestor) {
129271
+ var ancestorLookup = function (ancestor) {
129064
129272
  var nodeModules = ts.combinePaths(ancestor, "node_modules");
129065
129273
  if (ts.tryDirectoryExists(host, nodeModules)) {
129066
129274
  getCompletionEntriesForDirectoryFragment(fragment, nodeModules, extensionOptions, host, /*exclude*/ undefined, result);
129067
129275
  }
129068
- });
129276
+ };
129277
+ if (fragmentDirectory && isEmitModuleResolutionRespectingExportMaps(compilerOptions)) {
129278
+ var nodeModulesDirectoryLookup_1 = ancestorLookup;
129279
+ ancestorLookup = function (ancestor) {
129280
+ var components = ts.getPathComponents(fragment);
129281
+ components.shift(); // shift off empty root
129282
+ var packagePath = components.shift();
129283
+ if (!packagePath) {
129284
+ return nodeModulesDirectoryLookup_1(ancestor);
129285
+ }
129286
+ if (ts.startsWith(packagePath, "@")) {
129287
+ var subName = components.shift();
129288
+ if (!subName) {
129289
+ return nodeModulesDirectoryLookup_1(ancestor);
129290
+ }
129291
+ packagePath = ts.combinePaths(packagePath, subName);
129292
+ }
129293
+ var packageFile = ts.combinePaths(ancestor, "node_modules", packagePath, "package.json");
129294
+ if (ts.tryFileExists(host, packageFile)) {
129295
+ var packageJson = ts.readJson(packageFile, host);
129296
+ var exports = packageJson.exports;
129297
+ if (exports) {
129298
+ if (typeof exports !== "object" || exports === null) { // eslint-disable-line no-null/no-null
129299
+ return; // null exports or entrypoint only, no sub-modules available
129300
+ }
129301
+ var keys = ts.getOwnKeys(exports);
129302
+ var fragmentSubpath_1 = components.join("/");
129303
+ var processedKeys = ts.mapDefined(keys, function (k) {
129304
+ if (k === ".")
129305
+ return undefined;
129306
+ if (!ts.startsWith(k, "./"))
129307
+ return undefined;
129308
+ var subpath = k.substring(2);
129309
+ if (!ts.startsWith(subpath, fragmentSubpath_1))
129310
+ return undefined;
129311
+ // subpath is a valid export (barring conditions, which we don't currently check here)
129312
+ if (!ts.stringContains(subpath, "*")) {
129313
+ return subpath;
129314
+ }
129315
+ // pattern export - only return everything up to the `*`, so the user can autocomplete, then
129316
+ // keep filling in the pattern (we could speculatively return a list of options by hitting disk,
129317
+ // but conditions will make that somewhat awkward, as each condition may have a different set of possible
129318
+ // options for the `*`.
129319
+ return subpath.slice(0, subpath.indexOf("*"));
129320
+ });
129321
+ ts.forEach(processedKeys, function (k) {
129322
+ if (k) {
129323
+ result.push(nameAndKind(k, "external module name" /* externalModuleName */, /*extension*/ undefined));
129324
+ }
129325
+ });
129326
+ return;
129327
+ }
129328
+ }
129329
+ return nodeModulesDirectoryLookup_1(ancestor);
129330
+ };
129331
+ }
129332
+ ts.forEachAncestorDirectory(scriptPath, ancestorLookup);
129069
129333
  }
129070
129334
  }
129071
129335
  return result;
@@ -130507,14 +130771,15 @@ var ts;
130507
130771
  if (tag.tagName.pos <= position && position <= tag.tagName.end) {
130508
130772
  return { kind: 1 /* JsDocTagName */ };
130509
130773
  }
130510
- if (isTagWithTypeExpression(tag) && tag.typeExpression && tag.typeExpression.kind === 307 /* JSDocTypeExpression */) {
130774
+ var typeExpression = tryGetTypeExpressionFromTag(tag);
130775
+ if (typeExpression) {
130511
130776
  currentToken = ts.getTokenAtPosition(sourceFile, position);
130512
130777
  if (!currentToken ||
130513
130778
  (!ts.isDeclarationName(currentToken) &&
130514
130779
  (currentToken.parent.kind !== 345 /* JSDocPropertyTag */ ||
130515
130780
  currentToken.parent.name !== currentToken))) {
130516
130781
  // Use as type location if inside tag's type expression
130517
- insideJsDocTagTypeExpression = isCurrentlyEditingNode(tag.typeExpression);
130782
+ insideJsDocTagTypeExpression = isCurrentlyEditingNode(typeExpression);
130518
130783
  }
130519
130784
  }
130520
130785
  if (!insideJsDocTagTypeExpression && ts.isJSDocParameterTag(tag) && (ts.nodeIsMissing(tag.name) || tag.name.pos <= position && position <= tag.name.end)) {
@@ -130771,10 +131036,19 @@ var ts;
130771
131036
  case 341 /* JSDocTypeTag */:
130772
131037
  case 343 /* JSDocTypedefTag */:
130773
131038
  return true;
131039
+ case 342 /* JSDocTemplateTag */:
131040
+ return !!tag.constraint;
130774
131041
  default:
130775
131042
  return false;
130776
131043
  }
130777
131044
  }
131045
+ function tryGetTypeExpressionFromTag(tag) {
131046
+ if (isTagWithTypeExpression(tag)) {
131047
+ var typeExpression = ts.isJSDocTemplateTag(tag) ? tag.constraint : tag.typeExpression;
131048
+ return typeExpression && typeExpression.kind === 307 /* JSDocTypeExpression */ ? typeExpression : undefined;
131049
+ }
131050
+ return undefined;
131051
+ }
130778
131052
  function getTypeScriptMemberSymbols() {
130779
131053
  // Right of dot member completion list
130780
131054
  completionKind = 2 /* PropertyAccess */;
@@ -133530,7 +133804,7 @@ var ts;
133530
133804
  }
133531
133805
  for (var _c = 0, _d = referencingFile.typeReferenceDirectives; _c < _d.length; _c++) {
133532
133806
  var ref = _d[_c];
133533
- var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName);
133807
+ var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName, ref.resolutionMode || referencingFile.impliedNodeFormat);
133534
133808
  if (referenced !== undefined && referenced.resolvedFileName === searchSourceFile.fileName) {
133535
133809
  refs.push({ kind: "reference", referencingFile: referencingFile, ref: ref });
133536
133810
  }
@@ -136752,7 +137026,7 @@ var ts;
136752
137026
  }
136753
137027
  var typeReferenceDirective = findReferenceInPosition(sourceFile.typeReferenceDirectives, position);
136754
137028
  if (typeReferenceDirective) {
136755
- var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName);
137029
+ var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName, typeReferenceDirective.resolutionMode || sourceFile.impliedNodeFormat);
136756
137030
  var file = reference && program.getSourceFile(reference.resolvedFileName); // TODO:GH#18217
136757
137031
  return file && { reference: typeReferenceDirective, fileName: file.fileName, file: file, unverified: false };
136758
137032
  }
@@ -138558,6 +138832,7 @@ var ts;
138558
138832
  return oldImports;
138559
138833
  }
138560
138834
  var typeChecker = program.getTypeChecker();
138835
+ var compilerOptions = program.getCompilerOptions();
138561
138836
  var jsxNamespace = typeChecker.getJsxNamespace(sourceFile);
138562
138837
  var jsxFragmentFactory = typeChecker.getJsxFragmentFactory(sourceFile);
138563
138838
  var jsxElementsPresent = !!(sourceFile.transformFlags & 2 /* ContainsJsx */);
@@ -138614,7 +138889,7 @@ var ts;
138614
138889
  return usedImports;
138615
138890
  function isDeclarationUsed(identifier) {
138616
138891
  // The JSX factory symbol is always used if JSX elements are present - even if they are not allowed.
138617
- return jsxElementsPresent && (identifier.text === jsxNamespace || jsxFragmentFactory && identifier.text === jsxFragmentFactory) ||
138892
+ return jsxElementsPresent && (identifier.text === jsxNamespace || jsxFragmentFactory && identifier.text === jsxFragmentFactory) && ts.jsxModeNeedsExplicitImport(compilerOptions.jsx) ||
138618
138893
  ts.FindAllReferences.Core.isSymbolReferencedInFile(identifier, typeChecker, sourceFile);
138619
138894
  }
138620
138895
  }
@@ -150305,12 +150580,9 @@ var ts;
150305
150580
  return undefined;
150306
150581
  return { kind: 4 /* PromoteTypeOnly */, typeOnlyAliasDeclaration: typeOnlyAliasDeclaration };
150307
150582
  }
150308
- function jsxModeNeedsExplicitImport(jsx) {
150309
- return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
150310
- }
150311
150583
  function getSymbolName(sourceFile, checker, symbolToken, compilerOptions) {
150312
150584
  var parent = symbolToken.parent;
150313
- if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
150585
+ if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && ts.jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
150314
150586
  var jsxNamespace = checker.getJsxNamespace(sourceFile);
150315
150587
  if (needsJsxNamespaceFix(jsxNamespace, symbolToken, checker)) {
150316
150588
  return jsxNamespace;
@@ -156817,7 +157089,7 @@ var ts;
156817
157089
  // cannot find either start or end node
156818
157090
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
156819
157091
  }
156820
- if (ts.isJSDoc(start)) {
157092
+ if (start.flags & 4194304 /* JSDoc */) {
156821
157093
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractJSDoc)] };
156822
157094
  }
156823
157095
  if (start.parent !== end.parent) {
@@ -163576,7 +163848,7 @@ var ts;
163576
163848
  if ("getTypeReferenceDirectiveResolutionsForFile" in this.shimHost) {
163577
163849
  this.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
163578
163850
  var typeDirectivesForFile = JSON.parse(_this.shimHost.getTypeReferenceDirectiveResolutionsForFile(containingFile)); // TODO: GH#18217
163579
- return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, name); });
163851
+ return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, ts.isString(name) ? name : name.fileName.toLowerCase()); });
163580
163852
  };
163581
163853
  }
163582
163854
  }
@@ -166275,8 +166547,8 @@ var ts;
166275
166547
  Project.prototype.getResolvedModuleWithFailedLookupLocationsFromCache = function (moduleName, containingFile, resolutionMode) {
166276
166548
  return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode);
166277
166549
  };
166278
- Project.prototype.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile, redirectedReference) {
166279
- return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference);
166550
+ Project.prototype.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
166551
+ return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode);
166280
166552
  };
166281
166553
  Project.prototype.directoryExists = function (path) {
166282
166554
  return this.directoryStructureHost.directoryExists(path); // TODO: GH#18217