typescript 4.8.0-dev.20220706 → 4.8.0-dev.20220709

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
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220706";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220709";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -2065,7 +2065,7 @@ var ts;
2065
2065
  * and 1 insertion/deletion at 3 characters)
2066
2066
  */
2067
2067
  function getSpellingSuggestion(name, candidates, getName) {
2068
- var maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
2068
+ var maximumLengthDifference = Math.max(2, Math.floor(name.length * 0.34));
2069
2069
  var bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
2070
2070
  var bestCandidate;
2071
2071
  for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
@@ -2794,6 +2794,22 @@ var ts;
2794
2794
  return formatEnum(flags, ts.FlowFlags, /*isFlags*/ true);
2795
2795
  }
2796
2796
  Debug.formatFlowFlags = formatFlowFlags;
2797
+ function formatRelationComparisonResult(result) {
2798
+ return formatEnum(result, ts.RelationComparisonResult, /*isFlags*/ true);
2799
+ }
2800
+ Debug.formatRelationComparisonResult = formatRelationComparisonResult;
2801
+ function formatCheckMode(mode) {
2802
+ return formatEnum(mode, ts.CheckMode, /*isFlags*/ true);
2803
+ }
2804
+ Debug.formatCheckMode = formatCheckMode;
2805
+ function formatSignatureCheckMode(mode) {
2806
+ return formatEnum(mode, ts.SignatureCheckMode, /*isFlags*/ true);
2807
+ }
2808
+ Debug.formatSignatureCheckMode = formatSignatureCheckMode;
2809
+ function formatTypeFacts(facts) {
2810
+ return formatEnum(facts, ts.TypeFacts, /*isFlags*/ true);
2811
+ }
2812
+ Debug.formatTypeFacts = formatTypeFacts;
2797
2813
  var isDebugInfoEnabled = false;
2798
2814
  var extendedDebugModule;
2799
2815
  function extendedDebug() {
@@ -9033,6 +9049,7 @@ var ts;
9033
9049
  The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."),
9034
9050
  _0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation: diag(2842, ts.DiagnosticCategory.Error, "_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation_2842", "'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?"),
9035
9051
  We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here: diag(2843, ts.DiagnosticCategory.Error, "We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here_2843", "We can only write a type for '{0}' by adding a type for the entire parameter here."),
9052
+ Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2844, ts.DiagnosticCategory.Error, "Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2844", "Type of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
9036
9053
  Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
9037
9054
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
9038
9055
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -19531,7 +19548,8 @@ var ts;
19531
19548
  function getDeclarationModifierFlagsFromSymbol(s, isWrite) {
19532
19549
  if (isWrite === void 0) { isWrite = false; }
19533
19550
  if (s.valueDeclaration) {
19534
- var declaration = (isWrite && s.declarations && ts.find(s.declarations, function (d) { return d.kind === 173 /* SetAccessor */; })) || s.valueDeclaration;
19551
+ var declaration = (isWrite && s.declarations && ts.find(s.declarations, ts.isSetAccessorDeclaration))
19552
+ || (s.flags & 32768 /* GetAccessor */ && ts.find(s.declarations, ts.isGetAccessorDeclaration)) || s.valueDeclaration;
19535
19553
  var flags = ts.getCombinedModifierFlags(declaration);
19536
19554
  return s.parent && s.parent.flags & 32 /* Class */ ? flags : flags & ~28 /* AccessibilityModifier */;
19537
19555
  }
@@ -20206,7 +20224,7 @@ var ts;
20206
20224
  // Excludes declaration files - they still require an explicit `export {}` or the like
20207
20225
  // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
20208
20226
  // that aren't esm-mode (meaning not in a `type: module` scope).
20209
- return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) && !file.isDeclarationFile ? true : undefined;
20227
+ return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */]))) && !file.isDeclarationFile ? true : undefined;
20210
20228
  }
20211
20229
  function getSetExternalModuleIndicator(options) {
20212
20230
  // TODO: Should this callback be cached?
@@ -20229,10 +20247,7 @@ var ts;
20229
20247
  if (options.jsx === 4 /* ReactJSX */ || options.jsx === 5 /* ReactJSXDev */) {
20230
20248
  checks.push(isFileModuleFromUsingJSXTag);
20231
20249
  }
20232
- var moduleKind = getEmitModuleKind(options);
20233
- if (moduleKind === ts.ModuleKind.Node16 || moduleKind === ts.ModuleKind.NodeNext) {
20234
- checks.push(isFileForcedToBeModuleByFormat);
20235
- }
20250
+ checks.push(isFileForcedToBeModuleByFormat);
20236
20251
  var combined_1 = ts.or.apply(void 0, checks);
20237
20252
  var callback = function (file) { return void (file.externalModuleIndicator = combined_1(file)); };
20238
20253
  return callback;
@@ -33952,10 +33967,10 @@ var ts;
33952
33967
  var hasJSDoc = hasPrecedingJSDocComment();
33953
33968
  var modifiers = parseModifiers();
33954
33969
  if (parseContextualModifier(136 /* GetKeyword */)) {
33955
- return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 172 /* GetAccessor */);
33970
+ return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 172 /* GetAccessor */, 4 /* Type */);
33956
33971
  }
33957
33972
  if (parseContextualModifier(149 /* SetKeyword */)) {
33958
- return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 173 /* SetAccessor */);
33973
+ return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 173 /* SetAccessor */, 4 /* Type */);
33959
33974
  }
33960
33975
  if (isIndexSignature()) {
33961
33976
  return parseIndexSignatureDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers);
@@ -36001,10 +36016,10 @@ var ts;
36001
36016
  var decorators = parseDecorators();
36002
36017
  var modifiers = parseModifiers();
36003
36018
  if (parseContextualModifier(136 /* GetKeyword */)) {
36004
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */);
36019
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */, 0 /* None */);
36005
36020
  }
36006
36021
  if (parseContextualModifier(149 /* SetKeyword */)) {
36007
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */);
36022
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */, 0 /* None */);
36008
36023
  }
36009
36024
  var asteriskToken = parseOptionalToken(41 /* AsteriskToken */);
36010
36025
  var tokenIsIdentifier = isIdentifier();
@@ -36696,9 +36711,15 @@ var ts;
36696
36711
  return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === 10 /* StringLiteral */);
36697
36712
  }
36698
36713
  function parseFunctionBlockOrSemicolon(flags, diagnosticMessage) {
36699
- if (token() !== 18 /* OpenBraceToken */ && canParseSemicolon()) {
36700
- parseSemicolon();
36701
- return;
36714
+ if (token() !== 18 /* OpenBraceToken */) {
36715
+ if (flags & 4 /* Type */) {
36716
+ parseTypeMemberSemicolon();
36717
+ return;
36718
+ }
36719
+ if (canParseSemicolon()) {
36720
+ parseSemicolon();
36721
+ return;
36722
+ }
36702
36723
  }
36703
36724
  return parseFunctionBlock(flags, diagnosticMessage);
36704
36725
  }
@@ -36902,12 +36923,12 @@ var ts;
36902
36923
  }
36903
36924
  return parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken);
36904
36925
  }
36905
- function parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, kind) {
36926
+ function parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, kind, flags) {
36906
36927
  var name = parsePropertyName();
36907
36928
  var typeParameters = parseTypeParameters();
36908
36929
  var parameters = parseParameters(0 /* None */);
36909
36930
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
36910
- var body = parseFunctionBlockOrSemicolon(0 /* None */);
36931
+ var body = parseFunctionBlockOrSemicolon(flags);
36911
36932
  var node = kind === 172 /* GetAccessor */
36912
36933
  ? factory.createGetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, type, body)
36913
36934
  : factory.createSetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, body);
@@ -37094,10 +37115,10 @@ var ts;
37094
37115
  return parseClassStaticBlockDeclaration(pos, hasJSDoc, decorators, modifiers);
37095
37116
  }
37096
37117
  if (parseContextualModifier(136 /* GetKeyword */)) {
37097
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */);
37118
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */, 0 /* None */);
37098
37119
  }
37099
37120
  if (parseContextualModifier(149 /* SetKeyword */)) {
37100
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */);
37121
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */, 0 /* None */);
37101
37122
  }
37102
37123
  if (token() === 134 /* ConstructorKeyword */ || token() === 10 /* StringLiteral */) {
37103
37124
  var constructorDeclaration = tryParseConstructorDeclaration(pos, hasJSDoc, decorators, modifiers);
@@ -44408,6 +44429,7 @@ var ts;
44408
44429
  return toSearchResult(/*value*/ undefined);
44409
44430
  }
44410
44431
  /**
44432
+ * @internal
44411
44433
  * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 -
44412
44434
  * "longest" has some nuance as to what "longest" means in the presence of pattern trailers
44413
44435
  */
@@ -44430,6 +44452,7 @@ var ts;
44430
44452
  return 1;
44431
44453
  return 0;
44432
44454
  }
44455
+ ts.comparePatternKeys = comparePatternKeys;
44433
44456
  function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) {
44434
44457
  var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports);
44435
44458
  if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) {
@@ -48501,7 +48524,7 @@ var ts;
48501
48524
  // Masks
48502
48525
  TypeFacts[TypeFacts["OrFactsMask"] = 8256] = "OrFactsMask";
48503
48526
  TypeFacts[TypeFacts["AndFactsMask"] = 134209471] = "AndFactsMask";
48504
- })(TypeFacts || (TypeFacts = {}));
48527
+ })(TypeFacts = ts.TypeFacts || (ts.TypeFacts = {}));
48505
48528
  var typeofNEFacts = new ts.Map(ts.getEntries({
48506
48529
  string: 256 /* TypeofNEString */,
48507
48530
  number: 512 /* TypeofNENumber */,
@@ -48536,7 +48559,7 @@ var ts;
48536
48559
  CheckMode[CheckMode["RestBindingElement"] = 64] = "RestBindingElement";
48537
48560
  // e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
48538
48561
  // we need to preserve generic types instead of substituting them for constraints
48539
- })(CheckMode || (CheckMode = {}));
48562
+ })(CheckMode = ts.CheckMode || (ts.CheckMode = {}));
48540
48563
  var SignatureCheckMode;
48541
48564
  (function (SignatureCheckMode) {
48542
48565
  SignatureCheckMode[SignatureCheckMode["BivariantCallback"] = 1] = "BivariantCallback";
@@ -48544,7 +48567,7 @@ var ts;
48544
48567
  SignatureCheckMode[SignatureCheckMode["IgnoreReturnTypes"] = 4] = "IgnoreReturnTypes";
48545
48568
  SignatureCheckMode[SignatureCheckMode["StrictArity"] = 8] = "StrictArity";
48546
48569
  SignatureCheckMode[SignatureCheckMode["Callback"] = 3] = "Callback";
48547
- })(SignatureCheckMode || (SignatureCheckMode = {}));
48570
+ })(SignatureCheckMode = ts.SignatureCheckMode || (ts.SignatureCheckMode = {}));
48548
48571
  var IntersectionState;
48549
48572
  (function (IntersectionState) {
48550
48573
  IntersectionState[IntersectionState["None"] = 0] = "None";
@@ -48896,7 +48919,7 @@ var ts;
48896
48919
  },
48897
48920
  getContextualTypeForObjectLiteralElement: function (nodeIn) {
48898
48921
  var node = ts.getParseTreeNode(nodeIn, ts.isObjectLiteralElementLike);
48899
- return node ? getContextualTypeForObjectLiteralElement(node) : undefined;
48922
+ return node ? getContextualTypeForObjectLiteralElement(node, /*contextFlags*/ undefined) : undefined;
48900
48923
  },
48901
48924
  getContextualTypeForArgumentAtIndex: function (nodeIn, argIndex) {
48902
48925
  var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
@@ -48904,7 +48927,7 @@ var ts;
48904
48927
  },
48905
48928
  getContextualTypeForJsxAttribute: function (nodeIn) {
48906
48929
  var node = ts.getParseTreeNode(nodeIn, ts.isJsxAttributeLike);
48907
- return node && getContextualTypeForJsxAttribute(node);
48930
+ return node && getContextualTypeForJsxAttribute(node, /*contextFlags*/ undefined);
48908
48931
  },
48909
48932
  isContextSensitive: isContextSensitive,
48910
48933
  getTypeOfPropertyOfContextualType: getTypeOfPropertyOfContextualType,
@@ -50236,6 +50259,7 @@ var ts;
50236
50259
  if (ctor && ctor.locals) {
50237
50260
  if (lookup(ctor.locals, name, meaning & 111551 /* Value */)) {
50238
50261
  // Remember the property node, it will be used later to report appropriate error
50262
+ ts.Debug.assertNode(location, ts.isPropertyDeclaration);
50239
50263
  propertyWithInvalidInitializer = location;
50240
50264
  }
50241
50265
  }
@@ -50425,11 +50449,27 @@ var ts;
50425
50449
  }
50426
50450
  }
50427
50451
  }
50452
+ // The invalid initializer error is needed in two situation:
50453
+ // 1. When result is undefined, after checking for a missing "this."
50454
+ // 2. When result is defined
50455
+ function checkAndReportErrorForInvalidInitializer() {
50456
+ if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
50457
+ // We have a match, but the reference occurred within a property initializer and the identifier also binds
50458
+ // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
50459
+ // with ESNext+useDefineForClassFields because the scope semantics are different.
50460
+ error(errorLocation, errorLocation && propertyWithInvalidInitializer.type && ts.textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos)
50461
+ ? ts.Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor
50462
+ : ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyWithInvalidInitializer.name), diagnosticName(nameArg));
50463
+ return true;
50464
+ }
50465
+ return false;
50466
+ }
50428
50467
  if (!result) {
50429
50468
  if (nameNotFoundMessage) {
50430
50469
  addLazyDiagnostic(function () {
50431
50470
  if (!errorLocation ||
50432
50471
  !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
50472
+ !checkAndReportErrorForInvalidInitializer() &&
50433
50473
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
50434
50474
  !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
50435
50475
  !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
@@ -50437,7 +50477,16 @@ var ts;
50437
50477
  !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
50438
50478
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
50439
50479
  var suggestion = void 0;
50440
- if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
50480
+ var suggestedLib = void 0;
50481
+ // Report missing lib first
50482
+ if (nameArg) {
50483
+ suggestedLib = getSuggestedLibForNonExistentName(nameArg);
50484
+ if (suggestedLib) {
50485
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), suggestedLib);
50486
+ }
50487
+ }
50488
+ // then spelling suggestions
50489
+ if (!suggestedLib && getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
50441
50490
  suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
50442
50491
  var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
50443
50492
  if (isGlobalScopeAugmentationDeclaration) {
@@ -50456,16 +50505,9 @@ var ts;
50456
50505
  }
50457
50506
  }
50458
50507
  }
50459
- if (!suggestion) {
50460
- if (nameArg) {
50461
- var lib = getSuggestedLibForNonExistentName(nameArg);
50462
- if (lib) {
50463
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), lib);
50464
- }
50465
- else {
50466
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
50467
- }
50468
- }
50508
+ // And then fall back to unspecified "not found"
50509
+ if (!suggestion && !suggestedLib && nameArg) {
50510
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
50469
50511
  }
50470
50512
  suggestionCount++;
50471
50513
  }
@@ -50473,12 +50515,7 @@ var ts;
50473
50515
  }
50474
50516
  return undefined;
50475
50517
  }
50476
- if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
50477
- // We have a match, but the reference occurred within a property initializer and the identifier also binds
50478
- // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
50479
- // with ESNext+useDefineForClassFields because the scope semantics are different.
50480
- var propertyName = propertyWithInvalidInitializer.name;
50481
- error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), diagnosticName(nameArg));
50518
+ else if (checkAndReportErrorForInvalidInitializer()) {
50482
50519
  return undefined;
50483
50520
  }
50484
50521
  // Perform extra checks only if error reporting was requested
@@ -52627,13 +52664,25 @@ var ts;
52627
52664
  && isDeclarationVisible(declaration.parent)) {
52628
52665
  return addVisibleAlias(declaration, declaration);
52629
52666
  }
52630
- else if (symbol.flags & 2097152 /* Alias */ && ts.isBindingElement(declaration) && ts.isInJSFile(declaration) && ((_a = declaration.parent) === null || _a === void 0 ? void 0 : _a.parent) // exported import-like top-level JS require statement
52631
- && ts.isVariableDeclaration(declaration.parent.parent)
52632
- && ((_b = declaration.parent.parent.parent) === null || _b === void 0 ? void 0 : _b.parent) && ts.isVariableStatement(declaration.parent.parent.parent.parent)
52633
- && !ts.hasSyntacticModifier(declaration.parent.parent.parent.parent, 1 /* Export */)
52634
- && declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
52635
- && isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
52636
- return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
52667
+ else if (ts.isBindingElement(declaration)) {
52668
+ if (symbol.flags & 2097152 /* Alias */ && ts.isInJSFile(declaration) && ((_a = declaration.parent) === null || _a === void 0 ? void 0 : _a.parent) // exported import-like top-level JS require statement
52669
+ && ts.isVariableDeclaration(declaration.parent.parent)
52670
+ && ((_b = declaration.parent.parent.parent) === null || _b === void 0 ? void 0 : _b.parent) && ts.isVariableStatement(declaration.parent.parent.parent.parent)
52671
+ && !ts.hasSyntacticModifier(declaration.parent.parent.parent.parent, 1 /* Export */)
52672
+ && declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
52673
+ && isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
52674
+ return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
52675
+ }
52676
+ else if (symbol.flags & 2 /* BlockScopedVariable */) {
52677
+ var variableStatement = ts.findAncestor(declaration, ts.isVariableStatement);
52678
+ if (ts.hasSyntacticModifier(variableStatement, 1 /* Export */)) {
52679
+ return true;
52680
+ }
52681
+ if (!isDeclarationVisible(variableStatement.parent)) {
52682
+ return false;
52683
+ }
52684
+ return addVisibleAlias(declaration, variableStatement);
52685
+ }
52637
52686
  }
52638
52687
  // Declaration is not visible
52639
52688
  return false;
@@ -53154,6 +53203,10 @@ var ts;
53154
53203
  }
53155
53204
  return typeToTypeNodeHelper(type, context);
53156
53205
  }
53206
+ function isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) {
53207
+ return isMappedTypeWithKeyofConstraintDeclaration(type)
53208
+ && !(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */);
53209
+ }
53157
53210
  function createMappedTypeNodeFromType(type) {
53158
53211
  ts.Debug.assert(!!(type.flags & 524288 /* Object */));
53159
53212
  var readonlyToken = type.declaration.readonlyToken ? ts.factory.createToken(type.declaration.readonlyToken.kind) : undefined;
@@ -53163,7 +53216,7 @@ var ts;
53163
53216
  if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
53164
53217
  // We have a { [P in keyof T]: X }
53165
53218
  // We do this to ensure we retain the toplevel keyof-ness of the type which may be lost due to keyof distribution during `getConstraintTypeFromMappedType`
53166
- if (!(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53219
+ if (isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53167
53220
  var newParam = createTypeParameter(createSymbol(262144 /* TypeParameter */, "T"));
53168
53221
  var name = typeParameterToName(newParam, context);
53169
53222
  newTypeVariable = ts.factory.createTypeReferenceNode(name);
@@ -53179,11 +53232,12 @@ var ts;
53179
53232
  var mappedTypeNode = ts.factory.createMappedTypeNode(readonlyToken, typeParameterNode, nameTypeNode, questionToken, templateTypeNode, /*members*/ undefined);
53180
53233
  context.approximateLength += 10;
53181
53234
  var result = ts.setEmitFlags(mappedTypeNode, 1 /* SingleLine */);
53182
- if (isMappedTypeWithKeyofConstraintDeclaration(type) && !(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53235
+ if (isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53183
53236
  // homomorphic mapped type with a non-homomorphic naive inlining
53184
53237
  // wrap it with a conditional like `SomeModifiersType extends infer U ? {..the mapped type...} : never` to ensure the resulting
53185
53238
  // type stays homomorphic
53186
- return ts.factory.createConditionalTypeNode(typeToTypeNodeHelper(getModifiersTypeFromMappedType(type), context), ts.factory.createInferTypeNode(ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, ts.factory.cloneNode(newTypeVariable.typeName))), result, ts.factory.createKeywordTypeNode(143 /* NeverKeyword */));
53239
+ var originalConstraint = instantiateType(getConstraintOfTypeParameter(getTypeFromTypeNode(type.declaration.typeParameter.constraint.type)) || unknownType, type.mapper);
53240
+ return ts.factory.createConditionalTypeNode(typeToTypeNodeHelper(getModifiersTypeFromMappedType(type), context), ts.factory.createInferTypeNode(ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, ts.factory.cloneNode(newTypeVariable.typeName), originalConstraint.flags & 2 /* Unknown */ ? undefined : typeToTypeNodeHelper(originalConstraint, context))), result, ts.factory.createKeywordTypeNode(143 /* NeverKeyword */));
53187
53241
  }
53188
53242
  return result;
53189
53243
  }
@@ -62328,19 +62382,22 @@ var ts;
62328
62382
  * to reduce the resulting type if possible (since only intersections with conflicting literal-typed properties are reducible).
62329
62383
  */
62330
62384
  function isPossiblyReducibleByInstantiation(type) {
62331
- return ts.some(type.types, function (t) {
62332
- var uniqueFilled = getUniqueLiteralFilledInstantiation(t);
62333
- return getReducedType(uniqueFilled) !== uniqueFilled;
62334
- });
62385
+ var uniqueFilled = getUniqueLiteralFilledInstantiation(type);
62386
+ return getReducedType(uniqueFilled) !== uniqueFilled;
62387
+ }
62388
+ function shouldDeferIndexType(type) {
62389
+ return !!(type.flags & 58982400 /* InstantiableNonPrimitive */ ||
62390
+ isGenericTupleType(type) ||
62391
+ isGenericMappedType(type) && !hasDistributiveNameType(type) ||
62392
+ type.flags & 1048576 /* Union */ && ts.some(type.types, isPossiblyReducibleByInstantiation) ||
62393
+ type.flags & 2097152 /* Intersection */ && maybeTypeOfKind(type, 465829888 /* Instantiable */) && ts.some(type.types, isEmptyAnonymousObjectType));
62335
62394
  }
62336
62395
  function getIndexType(type, stringsOnly, noIndexSignatures) {
62337
62396
  if (stringsOnly === void 0) { stringsOnly = keyofStringsOnly; }
62338
62397
  type = getReducedType(type);
62339
- return type.flags & 1048576 /* Union */ ? isPossiblyReducibleByInstantiation(type)
62340
- ? getIndexTypeForGenericType(type, stringsOnly)
62341
- : getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62342
- type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62343
- type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericTupleType(type) || isGenericMappedType(type) && !hasDistributiveNameType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
62398
+ return shouldDeferIndexType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
62399
+ type.flags & 1048576 /* Union */ ? getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62400
+ type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62344
62401
  ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) :
62345
62402
  type === wildcardType ? wildcardType :
62346
62403
  type.flags & 2 /* Unknown */ ? neverType :
@@ -66133,13 +66190,20 @@ var ts;
66133
66190
  return result;
66134
66191
  }
66135
66192
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66193
+ var saveErrorInfo = captureErrorCalculationState();
66194
+ var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66195
+ if (result) {
66196
+ resetErrorInfo(saveErrorInfo);
66197
+ }
66198
+ return result;
66199
+ }
66200
+ function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo) {
66136
66201
  if (intersectionState & 4 /* PropertyCheck */) {
66137
66202
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
66138
66203
  }
66139
66204
  var result;
66140
66205
  var originalErrorInfo;
66141
66206
  var varianceCheckFailed = false;
66142
- var saveErrorInfo = captureErrorCalculationState();
66143
66207
  var sourceFlags = source.flags;
66144
66208
  var targetFlags = target.flags;
66145
66209
  if (relation === identityRelation) {
@@ -66203,7 +66267,6 @@ var ts;
66203
66267
  if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66204
66268
  // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66205
66269
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66206
- resetErrorInfo(saveErrorInfo);
66207
66270
  return result;
66208
66271
  }
66209
66272
  }
@@ -66328,7 +66391,6 @@ var ts;
66328
66391
  result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, reportErrors);
66329
66392
  }
66330
66393
  if (result) {
66331
- resetErrorInfo(saveErrorInfo);
66332
66394
  return result;
66333
66395
  }
66334
66396
  if (reportErrors) {
@@ -66431,7 +66493,6 @@ var ts;
66431
66493
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
66432
66494
  // conditional type and bail out with a Ternary.Maybe result.
66433
66495
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
66434
- resetErrorInfo(saveErrorInfo);
66435
66496
  return 3 /* Maybe */;
66436
66497
  }
66437
66498
  var c = target;
@@ -66446,7 +66507,6 @@ var ts;
66446
66507
  if (result = skipTrue ? -1 /* True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false)) {
66447
66508
  result &= skipFalse ? -1 /* True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false);
66448
66509
  if (result) {
66449
- resetErrorInfo(saveErrorInfo);
66450
66510
  return result;
66451
66511
  }
66452
66512
  }
@@ -66478,12 +66538,10 @@ var ts;
66478
66538
  var constraint = getConstraintOfType(source) || unknownType;
66479
66539
  // hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
66480
66540
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66481
- resetErrorInfo(saveErrorInfo);
66482
66541
  return result;
66483
66542
  }
66484
66543
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
66485
66544
  else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && constraint !== unknownType && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
66486
- resetErrorInfo(saveErrorInfo);
66487
66545
  return result;
66488
66546
  }
66489
66547
  if (isMappedTypeGenericIndexedAccess(source)) {
@@ -66492,7 +66550,6 @@ var ts;
66492
66550
  var indexConstraint = getConstraintOfType(source.indexType);
66493
66551
  if (indexConstraint) {
66494
66552
  if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
66495
- resetErrorInfo(saveErrorInfo);
66496
66553
  return result;
66497
66554
  }
66498
66555
  }
@@ -66501,7 +66558,6 @@ var ts;
66501
66558
  }
66502
66559
  else if (sourceFlags & 4194304 /* Index */) {
66503
66560
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
66504
- resetErrorInfo(saveErrorInfo);
66505
66561
  return result;
66506
66562
  }
66507
66563
  }
@@ -66509,7 +66565,6 @@ var ts;
66509
66565
  if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
66510
66566
  var constraint = getBaseConstraintOfType(source);
66511
66567
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
66512
- resetErrorInfo(saveErrorInfo);
66513
66568
  return result;
66514
66569
  }
66515
66570
  }
@@ -66520,14 +66575,12 @@ var ts;
66520
66575
  return 0 /* False */;
66521
66576
  }
66522
66577
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
66523
- resetErrorInfo(saveErrorInfo);
66524
66578
  return result;
66525
66579
  }
66526
66580
  }
66527
66581
  else {
66528
66582
  var constraint = getBaseConstraintOfType(source);
66529
66583
  if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
66530
- resetErrorInfo(saveErrorInfo);
66531
66584
  return result;
66532
66585
  }
66533
66586
  }
@@ -66536,7 +66589,6 @@ var ts;
66536
66589
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
66537
66590
  // conditional type and bail out with a Ternary.Maybe result.
66538
66591
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
66539
- resetErrorInfo(saveErrorInfo);
66540
66592
  return 3 /* Maybe */;
66541
66593
  }
66542
66594
  if (targetFlags & 16777216 /* Conditional */) {
@@ -66559,7 +66611,6 @@ var ts;
66559
66611
  result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, reportErrors);
66560
66612
  }
66561
66613
  if (result) {
66562
- resetErrorInfo(saveErrorInfo);
66563
66614
  return result;
66564
66615
  }
66565
66616
  }
@@ -66570,7 +66621,6 @@ var ts;
66570
66621
  var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
66571
66622
  if (distributiveConstraint) {
66572
66623
  if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
66573
- resetErrorInfo(saveErrorInfo);
66574
66624
  return result;
66575
66625
  }
66576
66626
  }
@@ -66580,7 +66630,6 @@ var ts;
66580
66630
  var defaultConstraint = getDefaultConstraintOfConditionalType(source);
66581
66631
  if (defaultConstraint) {
66582
66632
  if (result = isRelatedTo(defaultConstraint, target, 1 /* Source */, reportErrors)) {
66583
- resetErrorInfo(saveErrorInfo);
66584
66633
  return result;
66585
66634
  }
66586
66635
  }
@@ -66593,7 +66642,6 @@ var ts;
66593
66642
  if (isGenericMappedType(target)) {
66594
66643
  if (isGenericMappedType(source)) {
66595
66644
  if (result = mappedTypeRelatedTo(source, target, reportErrors)) {
66596
- resetErrorInfo(saveErrorInfo);
66597
66645
  return result;
66598
66646
  }
66599
66647
  }
@@ -69939,6 +69987,15 @@ var ts;
69939
69987
  var key = getFlowCacheKey(node.expression, declaredType, initialType, flowContainer);
69940
69988
  return key && key + "." + propName;
69941
69989
  }
69990
+ break;
69991
+ case 201 /* ObjectBindingPattern */:
69992
+ case 202 /* ArrayBindingPattern */:
69993
+ case 256 /* FunctionDeclaration */:
69994
+ case 213 /* FunctionExpression */:
69995
+ case 214 /* ArrowFunction */:
69996
+ case 169 /* MethodDeclaration */:
69997
+ // Handle pseudo-references originating in getNarrowedTypeOfSymbol.
69998
+ return getNodeId(node) + "#" + getTypeId(declaredType);
69942
69999
  }
69943
70000
  return undefined;
69944
70001
  }
@@ -72114,7 +72171,7 @@ var ts;
72114
72171
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
72115
72172
  (checkMode && checkMode & 64 /* RestBindingElement */ ?
72116
72173
  getContextualType(node, 8 /* SkipBindingPatterns */)
72117
- : getContextualType(node));
72174
+ : getContextualType(node, /*contextFlags*/ undefined));
72118
72175
  return contextualType && !isGenericType(contextualType);
72119
72176
  }
72120
72177
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -72978,7 +73035,7 @@ var ts;
72978
73035
  // We have an object literal method. Check if the containing object literal has a contextual type
72979
73036
  // that includes a ThisType<T>. If so, T is the contextual type for 'this'. We continue looking in
72980
73037
  // any directly enclosing object literals.
72981
- var contextualType = getApparentTypeOfContextualType(containingLiteral);
73038
+ var contextualType = getApparentTypeOfContextualType(containingLiteral, /*contextFlags*/ undefined);
72982
73039
  var literal = containingLiteral;
72983
73040
  var type = contextualType;
72984
73041
  while (type) {
@@ -72990,7 +73047,7 @@ var ts;
72990
73047
  break;
72991
73048
  }
72992
73049
  literal = literal.parent.parent;
72993
- type = getApparentTypeOfContextualType(literal);
73050
+ type = getApparentTypeOfContextualType(literal, /*contextFlags*/ undefined);
72994
73051
  }
72995
73052
  // There was no contextual ThisType<T> for the containing object literal, so the contextual type
72996
73053
  // for 'this' is the non-null form of the contextual type for the containing object literal or
@@ -73047,7 +73104,7 @@ var ts;
73047
73104
  tryGetTypeAtPosition(contextualSignature, index);
73048
73105
  }
73049
73106
  }
73050
- function getContextualTypeForVariableLikeDeclaration(declaration) {
73107
+ function getContextualTypeForVariableLikeDeclaration(declaration, contextFlags) {
73051
73108
  var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
73052
73109
  if (typeNode) {
73053
73110
  return getTypeFromTypeNode(typeNode);
@@ -73056,18 +73113,18 @@ var ts;
73056
73113
  case 164 /* Parameter */:
73057
73114
  return getContextuallyTypedParameterType(declaration);
73058
73115
  case 203 /* BindingElement */:
73059
- return getContextualTypeForBindingElement(declaration);
73116
+ return getContextualTypeForBindingElement(declaration, contextFlags);
73060
73117
  case 167 /* PropertyDeclaration */:
73061
73118
  if (ts.isStatic(declaration)) {
73062
- return getContextualTypeForStaticPropertyDeclaration(declaration);
73119
+ return getContextualTypeForStaticPropertyDeclaration(declaration, contextFlags);
73063
73120
  }
73064
73121
  // By default, do nothing and return undefined - only the above cases have context implied by a parent
73065
73122
  }
73066
73123
  }
73067
- function getContextualTypeForBindingElement(declaration) {
73124
+ function getContextualTypeForBindingElement(declaration, contextFlags) {
73068
73125
  var parent = declaration.parent.parent;
73069
73126
  var name = declaration.propertyName || declaration.name;
73070
- var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
73127
+ var parentType = getContextualTypeForVariableLikeDeclaration(parent, contextFlags) ||
73071
73128
  parent.kind !== 203 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */);
73072
73129
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
73073
73130
  return undefined;
@@ -73083,8 +73140,8 @@ var ts;
73083
73140
  return getTypeOfPropertyOfType(parentType, text);
73084
73141
  }
73085
73142
  }
73086
- function getContextualTypeForStaticPropertyDeclaration(declaration) {
73087
- var parentType = ts.isExpression(declaration.parent) && getContextualType(declaration.parent);
73143
+ function getContextualTypeForStaticPropertyDeclaration(declaration, contextFlags) {
73144
+ var parentType = ts.isExpression(declaration.parent) && getContextualType(declaration.parent, contextFlags);
73088
73145
  if (!parentType)
73089
73146
  return undefined;
73090
73147
  return getTypeOfPropertyOfContextualType(parentType, getSymbolOfNode(declaration).escapedName);
@@ -73100,7 +73157,7 @@ var ts;
73100
73157
  function getContextualTypeForInitializerExpression(node, contextFlags) {
73101
73158
  var declaration = node.parent;
73102
73159
  if (ts.hasInitializer(declaration) && node === declaration.initializer) {
73103
- var result = getContextualTypeForVariableLikeDeclaration(declaration);
73160
+ var result = getContextualTypeForVariableLikeDeclaration(declaration, contextFlags);
73104
73161
  if (result) {
73105
73162
  return result;
73106
73163
  }
@@ -73110,10 +73167,10 @@ var ts;
73110
73167
  }
73111
73168
  return undefined;
73112
73169
  }
73113
- function getContextualTypeForReturnExpression(node) {
73170
+ function getContextualTypeForReturnExpression(node, contextFlags) {
73114
73171
  var func = ts.getContainingFunction(node);
73115
73172
  if (func) {
73116
- var contextualReturnType = getContextualReturnType(func);
73173
+ var contextualReturnType = getContextualReturnType(func, contextFlags);
73117
73174
  if (contextualReturnType) {
73118
73175
  var functionFlags = ts.getFunctionFlags(func);
73119
73176
  if (functionFlags & 1 /* Generator */) { // Generator or AsyncGenerator function
@@ -73143,11 +73200,11 @@ var ts;
73143
73200
  }
73144
73201
  return undefined;
73145
73202
  }
73146
- function getContextualTypeForYieldOperand(node) {
73203
+ function getContextualTypeForYieldOperand(node, contextFlags) {
73147
73204
  var func = ts.getContainingFunction(node);
73148
73205
  if (func) {
73149
73206
  var functionFlags = ts.getFunctionFlags(func);
73150
- var contextualReturnType = getContextualReturnType(func);
73207
+ var contextualReturnType = getContextualReturnType(func, contextFlags);
73151
73208
  if (contextualReturnType) {
73152
73209
  return node.asteriskToken
73153
73210
  ? contextualReturnType
@@ -73171,14 +73228,14 @@ var ts;
73171
73228
  }
73172
73229
  function getContextualIterationType(kind, functionDecl) {
73173
73230
  var isAsync = !!(ts.getFunctionFlags(functionDecl) & 2 /* Async */);
73174
- var contextualReturnType = getContextualReturnType(functionDecl);
73231
+ var contextualReturnType = getContextualReturnType(functionDecl, /*contextFlags*/ undefined);
73175
73232
  if (contextualReturnType) {
73176
73233
  return getIterationTypeOfGeneratorFunctionReturnType(kind, contextualReturnType, isAsync)
73177
73234
  || undefined;
73178
73235
  }
73179
73236
  return undefined;
73180
73237
  }
73181
- function getContextualReturnType(functionDecl) {
73238
+ function getContextualReturnType(functionDecl, contextFlags) {
73182
73239
  // If the containing function has a return type annotation, is a constructor, or is a get accessor whose
73183
73240
  // corresponding set accessor has a type annotation, return statements in the function are contextually typed
73184
73241
  var returnType = getReturnTypeFromAnnotation(functionDecl);
@@ -73193,7 +73250,7 @@ var ts;
73193
73250
  }
73194
73251
  var iife = ts.getImmediatelyInvokedFunctionExpression(functionDecl);
73195
73252
  if (iife) {
73196
- return getContextualType(iife);
73253
+ return getContextualType(iife, contextFlags);
73197
73254
  }
73198
73255
  return undefined;
73199
73256
  }
@@ -73446,7 +73503,7 @@ var ts;
73446
73503
  }
73447
73504
  function getContextualTypeForObjectLiteralElement(element, contextFlags) {
73448
73505
  var objectLiteral = element.parent;
73449
- var propertyAssignmentType = ts.isPropertyAssignment(element) && getContextualTypeForVariableLikeDeclaration(element);
73506
+ var propertyAssignmentType = ts.isPropertyAssignment(element) && getContextualTypeForVariableLikeDeclaration(element, contextFlags);
73450
73507
  if (propertyAssignmentType) {
73451
73508
  return propertyAssignmentType;
73452
73509
  }
@@ -73641,9 +73698,9 @@ var ts;
73641
73698
  return getContextualTypeForInitializerExpression(node, contextFlags);
73642
73699
  case 214 /* ArrowFunction */:
73643
73700
  case 247 /* ReturnStatement */:
73644
- return getContextualTypeForReturnExpression(node);
73701
+ return getContextualTypeForReturnExpression(node, contextFlags);
73645
73702
  case 224 /* YieldExpression */:
73646
- return getContextualTypeForYieldOperand(parent);
73703
+ return getContextualTypeForYieldOperand(parent, contextFlags);
73647
73704
  case 218 /* AwaitExpression */:
73648
73705
  return getContextualTypeForAwaitOperand(parent, contextFlags);
73649
73706
  case 208 /* CallExpression */:
@@ -73691,7 +73748,7 @@ var ts;
73691
73748
  }
73692
73749
  return undefined;
73693
73750
  function tryFindWhenConstTypeReference(node) {
73694
- return getContextualType(node);
73751
+ return getContextualType(node, contextFlags);
73695
73752
  }
73696
73753
  }
73697
73754
  function getInferenceContext(node) {
@@ -73993,7 +74050,7 @@ var ts;
73993
74050
  var elementCount = elements.length;
73994
74051
  var elementTypes = [];
73995
74052
  var elementFlags = [];
73996
- var contextualType = getApparentTypeOfContextualType(node);
74053
+ var contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
73997
74054
  var inDestructuringPattern = ts.isAssignmentTarget(node);
73998
74055
  var inConstContext = isConstContext(node);
73999
74056
  var hasOmittedExpression = false;
@@ -74164,7 +74221,7 @@ var ts;
74164
74221
  var propertiesTable = ts.createSymbolTable();
74165
74222
  var propertiesArray = [];
74166
74223
  var spread = emptyObjectType;
74167
- var contextualType = getApparentTypeOfContextualType(node);
74224
+ var contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
74168
74225
  var contextualTypeHasPattern = contextualType && contextualType.pattern &&
74169
74226
  (contextualType.pattern.kind === 201 /* ObjectBindingPattern */ || contextualType.pattern.kind === 205 /* ObjectLiteralExpression */);
74170
74227
  var inConstContext = isConstContext(node);
@@ -74503,7 +74560,7 @@ var ts;
74503
74560
  if (explicitlySpecifyChildrenAttribute) {
74504
74561
  error(attributes, ts.Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName));
74505
74562
  }
74506
- var contextualType = getApparentTypeOfContextualType(openingLikeElement.attributes);
74563
+ var contextualType = getApparentTypeOfContextualType(openingLikeElement.attributes, /*contextFlags*/ undefined);
74507
74564
  var childrenContextualType = contextualType && getTypeOfPropertyOfContextualType(contextualType, jsxChildrenPropertyName);
74508
74565
  // If there are children in the body of JSX element, create dummy attribute "children" with the union of children types so that it will pass the attribute checking process
74509
74566
  var childrenPropSymbol = createSymbol(4 /* Property */, jsxChildrenPropertyName);
@@ -78343,17 +78400,6 @@ var ts;
78343
78400
  }
78344
78401
  }
78345
78402
  }
78346
- var restType = getEffectiveRestType(context);
78347
- if (restType && restType.flags & 262144 /* TypeParameter */) {
78348
- // The contextual signature has a generic rest parameter. We first instantiate the contextual
78349
- // signature (without fixing type parameters) and assign types to contextually typed parameters.
78350
- var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
78351
- assignContextualParameterTypes(signature, instantiatedContext);
78352
- // We then infer from a tuple type representing the parameters that correspond to the contextual
78353
- // rest parameter.
78354
- var restPos = getParameterCount(context) - 1;
78355
- inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
78356
- }
78357
78403
  }
78358
78404
  function assignContextualParameterTypes(signature, context) {
78359
78405
  if (context.typeParameters) {
@@ -78546,7 +78592,7 @@ var ts;
78546
78592
  var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
78547
78593
  var contextualType = !contextualSignature ? undefined :
78548
78594
  contextualSignature === getSignatureFromDeclaration(func) ? isGenerator ? undefined : returnType :
78549
- instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func);
78595
+ instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func, /*contextFlags*/ undefined);
78550
78596
  if (isGenerator) {
78551
78597
  yieldType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(yieldType, contextualType, 0 /* Yield */, isAsync);
78552
78598
  returnType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(returnType, contextualType, 1 /* Return */, isAsync);
@@ -78617,7 +78663,7 @@ var ts;
78617
78663
  nextType = iterationTypes && iterationTypes.nextType;
78618
78664
  }
78619
78665
  else {
78620
- nextType = getContextualType(yieldExpression);
78666
+ nextType = getContextualType(yieldExpression, /*contextFlags*/ undefined);
78621
78667
  }
78622
78668
  if (nextType)
78623
78669
  ts.pushIfUnique(nextTypes, nextType);
@@ -78826,11 +78872,16 @@ var ts;
78826
78872
  if (isContextSensitive(node)) {
78827
78873
  if (contextualSignature) {
78828
78874
  var inferenceContext = getInferenceContext(node);
78875
+ var instantiatedContextualSignature = void 0;
78829
78876
  if (checkMode && checkMode & 2 /* Inferential */) {
78830
78877
  inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
78878
+ var restType = getEffectiveRestType(contextualSignature);
78879
+ if (restType && restType.flags & 262144 /* TypeParameter */) {
78880
+ instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext.nonFixingMapper);
78881
+ }
78831
78882
  }
78832
- var instantiatedContextualSignature = inferenceContext ?
78833
- instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
78883
+ instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ?
78884
+ instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature);
78834
78885
  assignContextualParameterTypes(signature, instantiatedContextualSignature);
78835
78886
  }
78836
78887
  else {
@@ -80072,7 +80123,7 @@ var ts;
80072
80123
  type = anyType;
80073
80124
  addLazyDiagnostic(function () {
80074
80125
  if (noImplicitAny && !ts.expressionResultIsUnused(node)) {
80075
- var contextualType = getContextualType(node);
80126
+ var contextualType = getContextualType(node, /*contextFlags*/ undefined);
80076
80127
  if (!contextualType || isTypeAny(contextualType)) {
80077
80128
  error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
80078
80129
  }
@@ -80113,7 +80164,7 @@ var ts;
80113
80164
  texts.push(span.literal.text);
80114
80165
  types.push(isTypeAssignableTo(type, templateConstraintType) ? type : stringType);
80115
80166
  }
80116
- return isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
80167
+ return isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node, /*contextFlags*/ undefined) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
80117
80168
  }
80118
80169
  function isTemplateLiteralContextualType(type) {
80119
80170
  return !!(type.flags & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */) ||
@@ -80141,7 +80192,7 @@ var ts;
80141
80192
  // We strip literal freshness when an appropriate contextual type is present such that contextually typed
80142
80193
  // literals always preserve their literal types (otherwise they might widen during type inference). An alternative
80143
80194
  // here would be to not mark contextually typed literals as fresh in the first place.
80144
- var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
80195
+ var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, /*contextFlags*/ undefined)) ?
80145
80196
  getRegularTypeOfLiteralType(type) : type;
80146
80197
  return result;
80147
80198
  }
@@ -80256,7 +80307,7 @@ var ts;
80256
80307
  var type = checkExpression(node, checkMode, forceTuple);
80257
80308
  return isConstContext(node) || ts.isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) :
80258
80309
  isTypeAssertion(node) ? type :
80259
- getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node) : contextualType, node));
80310
+ getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node, /*contextFlags*/ undefined) : contextualType, node, /*contextFlags*/ undefined));
80260
80311
  }
80261
80312
  function checkPropertyAssignment(node, checkMode) {
80262
80313
  // Do not use hasDynamicName here, because that returns false for well known symbols.
@@ -132358,6 +132409,26 @@ var ts;
132358
132409
  (function (Completions) {
132359
132410
  var StringCompletions;
132360
132411
  (function (StringCompletions) {
132412
+ var _a;
132413
+ var kindPrecedence = (_a = {},
132414
+ _a["directory" /* directory */] = 0,
132415
+ _a["script" /* scriptElement */] = 1,
132416
+ _a["external module name" /* externalModuleName */] = 2,
132417
+ _a);
132418
+ function createNameAndKindSet() {
132419
+ var map = new ts.Map();
132420
+ function add(value) {
132421
+ var existing = map.get(value.name);
132422
+ if (!existing || kindPrecedence[existing.kind] < kindPrecedence[value.kind]) {
132423
+ map.set(value.name, value);
132424
+ }
132425
+ }
132426
+ return {
132427
+ add: add,
132428
+ has: map.has.bind(map),
132429
+ values: map.values.bind(map),
132430
+ };
132431
+ }
132361
132432
  function getStringLiteralCompletions(sourceFile, position, contextToken, options, host, program, log, preferences) {
132362
132433
  if (ts.isInReferenceComment(sourceFile, position)) {
132363
132434
  var entries = getTripleSlashReferenceCompletion(sourceFile, position, options, host);
@@ -132639,11 +132710,12 @@ var ts;
132639
132710
  }
132640
132711
  function getStringLiteralCompletionsFromModuleNamesWorker(sourceFile, node, compilerOptions, host, typeChecker, preferences) {
132641
132712
  var literalValue = ts.normalizeSlashes(node.text);
132713
+ var mode = ts.isStringLiteralLike(node) ? ts.getModeForUsageLocation(sourceFile, node) : undefined;
132642
132714
  var scriptPath = sourceFile.path;
132643
132715
  var scriptDirectory = ts.getDirectoryPath(scriptPath);
132644
132716
  return isPathRelativeToScript(literalValue) || !compilerOptions.baseUrl && (ts.isRootedDiskPath(literalValue) || ts.isUrl(literalValue))
132645
132717
  ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, getIncludeExtensionOption())
132646
- : getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, compilerOptions, host, typeChecker);
132718
+ : getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, mode, compilerOptions, host, getIncludeExtensionOption(), typeChecker);
132647
132719
  function getIncludeExtensionOption() {
132648
132720
  var mode = ts.isStringLiteralLike(node) ? ts.getModeForUsageLocation(sourceFile, node) : undefined;
132649
132721
  return preferences.importModuleSpecifierEnding === "js" || mode === ts.ModuleKind.ESNext ? 2 /* ModuleSpecifierCompletion */ : 0 /* Exclude */;
@@ -132659,7 +132731,7 @@ var ts;
132659
132731
  return getCompletionEntriesForDirectoryFragmentWithRootDirs(compilerOptions.rootDirs, literalValue, scriptDirectory, extensionOptions, compilerOptions, host, scriptPath);
132660
132732
  }
132661
132733
  else {
132662
- return getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, scriptPath);
132734
+ return ts.arrayFrom(getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, scriptPath).values());
132663
132735
  }
132664
132736
  }
132665
132737
  function isEmitResolutionKindUsingNodeModules(compilerOptions) {
@@ -132695,7 +132767,7 @@ var ts;
132695
132767
  var basePath = compilerOptions.project || host.getCurrentDirectory();
132696
132768
  var ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames());
132697
132769
  var baseDirectories = getBaseDirectoriesFromRootDirs(rootDirs, basePath, scriptDirectory, ignoreCase);
132698
- return ts.flatMap(baseDirectories, function (baseDirectory) { return getCompletionEntriesForDirectoryFragment(fragment, baseDirectory, extensionOptions, host, exclude); });
132770
+ return ts.flatMap(baseDirectories, function (baseDirectory) { return ts.arrayFrom(getCompletionEntriesForDirectoryFragment(fragment, baseDirectory, extensionOptions, host, exclude).values()); });
132699
132771
  }
132700
132772
  var IncludeExtensionsOption;
132701
132773
  (function (IncludeExtensionsOption) {
@@ -132706,10 +132778,9 @@ var ts;
132706
132778
  /**
132707
132779
  * Given a path ending at a directory, gets the completions for the path, and filters for those entries containing the basename.
132708
132780
  */
132709
- function getCompletionEntriesForDirectoryFragment(fragment, scriptPath, _a, host, exclude, result) {
132710
- var _b;
132711
- var extensions = _a.extensions, includeExtensionsOption = _a.includeExtensionsOption;
132712
- if (result === void 0) { result = []; }
132781
+ function getCompletionEntriesForDirectoryFragment(fragment, scriptPath, extensionOptions, host, exclude, result) {
132782
+ var _a;
132783
+ if (result === void 0) { result = createNameAndKindSet(); }
132713
132784
  if (fragment === undefined) {
132714
132785
  fragment = "";
132715
132786
  }
@@ -132733,11 +132804,11 @@ var ts;
132733
132804
  var packageJson = ts.readJson(packageJsonPath, host);
132734
132805
  var typesVersions = packageJson.typesVersions;
132735
132806
  if (typeof typesVersions === "object") {
132736
- var versionPaths = (_b = ts.getPackageJsonTypesVersionsPaths(typesVersions)) === null || _b === void 0 ? void 0 : _b.paths;
132807
+ var versionPaths = (_a = ts.getPackageJsonTypesVersionsPaths(typesVersions)) === null || _a === void 0 ? void 0 : _a.paths;
132737
132808
  if (versionPaths) {
132738
132809
  var packageDirectory = ts.getDirectoryPath(packageJsonPath);
132739
132810
  var pathInPackage = absolutePath.slice(ts.ensureTrailingDirectorySeparator(packageDirectory).length);
132740
- if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensions, versionPaths, host)) {
132811
+ if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensionOptions, host, versionPaths)) {
132741
132812
  // A true result means one of the `versionPaths` was matched, which will block relative resolution
132742
132813
  // to files and folders from here. All reachable paths given the pattern match are already added.
132743
132814
  return result;
@@ -132749,39 +132820,17 @@ var ts;
132749
132820
  if (!ts.tryDirectoryExists(host, baseDirectory))
132750
132821
  return result;
132751
132822
  // Enumerate the available files if possible
132752
- var files = ts.tryReadDirectory(host, baseDirectory, extensions, /*exclude*/ undefined, /*include*/ ["./*"]);
132823
+ var files = ts.tryReadDirectory(host, baseDirectory, extensionOptions.extensions, /*exclude*/ undefined, /*include*/ ["./*"]);
132753
132824
  if (files) {
132754
- /**
132755
- * Multiple file entries might map to the same truncated name once we remove extensions
132756
- * (happens iff includeExtensionsOption === includeExtensionsOption.Exclude) so we use a set-like data structure. Eg:
132757
- *
132758
- * both foo.ts and foo.tsx become foo
132759
- */
132760
- var foundFiles = new ts.Map(); // maps file to its extension
132761
132825
  for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
132762
132826
  var filePath = files_1[_i];
132763
132827
  filePath = ts.normalizePath(filePath);
132764
132828
  if (exclude && ts.comparePaths(filePath, exclude, scriptPath, ignoreCase) === 0 /* EqualTo */) {
132765
132829
  continue;
132766
132830
  }
132767
- var foundFileName = void 0;
132768
- var outputExtension = ts.moduleSpecifiers.tryGetJSExtensionForFile(filePath, host.getCompilationSettings());
132769
- if (includeExtensionsOption === 0 /* Exclude */ && !ts.fileExtensionIsOneOf(filePath, [".json" /* Json */, ".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */])) {
132770
- foundFileName = ts.removeFileExtension(ts.getBaseFileName(filePath));
132771
- foundFiles.set(foundFileName, ts.tryGetExtensionFromPath(filePath));
132772
- }
132773
- else if ((ts.fileExtensionIsOneOf(filePath, [".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */]) || includeExtensionsOption === 2 /* ModuleSpecifierCompletion */) && outputExtension) {
132774
- foundFileName = ts.changeExtension(ts.getBaseFileName(filePath), outputExtension);
132775
- foundFiles.set(foundFileName, outputExtension);
132776
- }
132777
- else {
132778
- foundFileName = ts.getBaseFileName(filePath);
132779
- foundFiles.set(foundFileName, ts.tryGetExtensionFromPath(filePath));
132780
- }
132831
+ var _b = getFilenameWithExtensionOption(ts.getBaseFileName(filePath), host.getCompilationSettings(), extensionOptions.includeExtensionsOption), name = _b.name, extension = _b.extension;
132832
+ result.add(nameAndKind(name, "script" /* scriptElement */, extension));
132781
132833
  }
132782
- foundFiles.forEach(function (ext, foundFile) {
132783
- result.push(nameAndKind(foundFile, "script" /* scriptElement */, ext));
132784
- });
132785
132834
  }
132786
132835
  // If possible, get folder completion as well
132787
132836
  var directories = ts.tryGetDirectories(host, baseDirectory);
@@ -132790,27 +132839,52 @@ var ts;
132790
132839
  var directory = directories_1[_c];
132791
132840
  var directoryName = ts.getBaseFileName(ts.normalizePath(directory));
132792
132841
  if (directoryName !== "@types") {
132793
- result.push(directoryResult(directoryName));
132842
+ result.add(directoryResult(directoryName));
132794
132843
  }
132795
132844
  }
132796
132845
  }
132797
132846
  return result;
132798
132847
  }
132848
+ function getFilenameWithExtensionOption(name, compilerOptions, includeExtensionsOption) {
132849
+ var outputExtension = ts.moduleSpecifiers.tryGetJSExtensionForFile(name, compilerOptions);
132850
+ if (includeExtensionsOption === 0 /* Exclude */ && !ts.fileExtensionIsOneOf(name, [".json" /* Json */, ".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */])) {
132851
+ return { name: ts.removeFileExtension(name), extension: ts.tryGetExtensionFromPath(name) };
132852
+ }
132853
+ else if ((ts.fileExtensionIsOneOf(name, [".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */]) || includeExtensionsOption === 2 /* ModuleSpecifierCompletion */) && outputExtension) {
132854
+ return { name: ts.changeExtension(name, outputExtension), extension: outputExtension };
132855
+ }
132856
+ else {
132857
+ return { name: name, extension: ts.tryGetExtensionFromPath(name) };
132858
+ }
132859
+ }
132799
132860
  /** @returns whether `fragment` was a match for any `paths` (which should indicate whether any other path completions should be offered) */
132800
- function addCompletionEntriesFromPaths(result, fragment, baseDirectory, fileExtensions, paths, host) {
132801
- var _a;
132861
+ function addCompletionEntriesFromPaths(result, fragment, baseDirectory, extensionOptions, host, paths) {
132862
+ var getPatternsForKey = function (key) { return paths[key]; };
132863
+ var comparePaths = function (a, b) {
132864
+ var patternA = ts.tryParsePattern(a);
132865
+ var patternB = ts.tryParsePattern(b);
132866
+ var lengthA = typeof patternA === "object" ? patternA.prefix.length : a.length;
132867
+ var lengthB = typeof patternB === "object" ? patternB.prefix.length : b.length;
132868
+ return ts.compareValues(lengthB, lengthA);
132869
+ };
132870
+ return addCompletionEntriesFromPathsOrExports(result, fragment, baseDirectory, extensionOptions, host, ts.getOwnKeys(paths), getPatternsForKey, comparePaths);
132871
+ }
132872
+ /** @returns whether `fragment` was a match for any `paths` (which should indicate whether any other path completions should be offered) */
132873
+ function addCompletionEntriesFromPathsOrExports(result, fragment, baseDirectory, extensionOptions, host, keys, getPatternsForKey, comparePaths) {
132802
132874
  var pathResults = [];
132803
- var matchedPathPrefixLength = -1;
132804
- for (var path in paths) {
132805
- if (!ts.hasProperty(paths, path))
132875
+ var matchedPath;
132876
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
132877
+ var key = keys_1[_i];
132878
+ if (key === ".")
132806
132879
  continue;
132807
- var patterns = paths[path];
132880
+ var keyWithoutLeadingDotSlash = key.replace(/^\.\//, ""); // remove leading "./"
132881
+ var patterns = getPatternsForKey(key);
132808
132882
  if (patterns) {
132809
- var pathPattern = ts.tryParsePattern(path);
132883
+ var pathPattern = ts.tryParsePattern(keyWithoutLeadingDotSlash);
132810
132884
  if (!pathPattern)
132811
132885
  continue;
132812
132886
  var isMatch = typeof pathPattern === "object" && ts.isPatternMatch(pathPattern, fragment);
132813
- var isLongestMatch = isMatch && (matchedPathPrefixLength === undefined || pathPattern.prefix.length > matchedPathPrefixLength);
132887
+ var isLongestMatch = isMatch && (matchedPath === undefined || comparePaths(key, matchedPath) === -1 /* LessThan */);
132814
132888
  if (isLongestMatch) {
132815
132889
  // If this is a higher priority match than anything we've seen so far, previous results from matches are invalid, e.g.
132816
132890
  // for `import {} from "some-package/|"` with a typesVersions:
@@ -132823,13 +132897,13 @@ var ts;
132823
132897
  // added by the '*' match, after typing `"some-package/foo/|"` we would get file results from both
132824
132898
  // ./dist/foo and ./foo, when only the latter will actually be resolvable.
132825
132899
  // See pathCompletionsTypesVersionsWildcard6.ts.
132826
- matchedPathPrefixLength = pathPattern.prefix.length;
132900
+ matchedPath = key;
132827
132901
  pathResults = pathResults.filter(function (r) { return !r.matchedPattern; });
132828
132902
  }
132829
- if (typeof pathPattern === "string" || matchedPathPrefixLength === undefined || pathPattern.prefix.length >= matchedPathPrefixLength) {
132903
+ if (typeof pathPattern === "string" || matchedPath === undefined || comparePaths(key, matchedPath) !== 1 /* GreaterThan */) {
132830
132904
  pathResults.push({
132831
132905
  matchedPattern: isMatch,
132832
- results: getCompletionsForPathMapping(path, patterns, fragment, baseDirectory, fileExtensions, host)
132906
+ results: getCompletionsForPathMapping(keyWithoutLeadingDotSlash, patterns, fragment, baseDirectory, extensionOptions, host)
132833
132907
  .map(function (_a) {
132834
132908
  var name = _a.name, kind = _a.kind, extension = _a.extension;
132835
132909
  return nameAndKind(name, kind, extension);
@@ -132838,10 +132912,8 @@ var ts;
132838
132912
  }
132839
132913
  }
132840
132914
  }
132841
- var equatePaths = ((_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host)) ? ts.equateStringsCaseSensitive : ts.equateStringsCaseInsensitive;
132842
- var equateResults = function (a, b) { return equatePaths(a.name, b.name); };
132843
- pathResults.forEach(function (pathResult) { return pathResult.results.forEach(function (pathResult) { return ts.pushIfUnique(result, pathResult, equateResults); }); });
132844
- return matchedPathPrefixLength > -1;
132915
+ pathResults.forEach(function (pathResult) { return pathResult.results.forEach(function (r) { return result.add(r); }); });
132916
+ return matchedPath !== undefined;
132845
132917
  }
132846
132918
  /**
132847
132919
  * Check all of the declared modules and those in node modules. Possible sources of modules:
@@ -132850,22 +132922,22 @@ var ts;
132850
132922
  * Modules from node_modules (i.e. those listed in package.json)
132851
132923
  * This includes all files that are found in node_modules/moduleName/ with acceptable file extensions
132852
132924
  */
132853
- function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, compilerOptions, host, typeChecker) {
132925
+ function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, compilerOptions, host, includeExtensionsOption, typeChecker) {
132854
132926
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths;
132855
- var result = [];
132856
- var extensionOptions = getExtensionOptions(compilerOptions);
132927
+ var result = createNameAndKindSet();
132928
+ var extensionOptions = getExtensionOptions(compilerOptions, includeExtensionsOption);
132857
132929
  if (baseUrl) {
132858
132930
  var projectDir = compilerOptions.project || host.getCurrentDirectory();
132859
132931
  var absolute = ts.normalizePath(ts.combinePaths(projectDir, baseUrl));
132860
132932
  getCompletionEntriesForDirectoryFragment(fragment, absolute, extensionOptions, host, /*exclude*/ undefined, result);
132861
132933
  if (paths) {
132862
- addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions.extensions, paths, host);
132934
+ addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions, host, paths);
132863
132935
  }
132864
132936
  }
132865
132937
  var fragmentDirectory = getFragmentDirectory(fragment);
132866
132938
  for (var _i = 0, _a = getAmbientModuleCompletions(fragment, fragmentDirectory, typeChecker); _i < _a.length; _i++) {
132867
132939
  var ambientName = _a[_i];
132868
- result.push(nameAndKind(ambientName, "external module name" /* externalModuleName */, /*extension*/ undefined));
132940
+ result.add(nameAndKind(ambientName, "external module name" /* externalModuleName */, /*extension*/ undefined));
132869
132941
  }
132870
132942
  getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, fragmentDirectory, extensionOptions, result);
132871
132943
  if (isEmitResolutionKindUsingNodeModules(compilerOptions)) {
@@ -132873,15 +132945,13 @@ var ts;
132873
132945
  // (But do if we didn't find anything, e.g. 'package.json' missing.)
132874
132946
  var foundGlobal = false;
132875
132947
  if (fragmentDirectory === undefined) {
132876
- var _loop_3 = function (moduleName) {
132877
- if (!result.some(function (entry) { return entry.name === moduleName; })) {
132878
- foundGlobal = true;
132879
- result.push(nameAndKind(moduleName, "external module name" /* externalModuleName */, /*extension*/ undefined));
132880
- }
132881
- };
132882
132948
  for (var _b = 0, _c = enumerateNodeModulesVisibleToScript(host, scriptPath); _b < _c.length; _b++) {
132883
132949
  var moduleName = _c[_b];
132884
- _loop_3(moduleName);
132950
+ var moduleResult = nameAndKind(moduleName, "external module name" /* externalModuleName */, /*extension*/ undefined);
132951
+ if (!result.has(moduleResult.name)) {
132952
+ foundGlobal = true;
132953
+ result.add(moduleResult);
132954
+ }
132885
132955
  }
132886
132956
  }
132887
132957
  if (!foundGlobal) {
@@ -132907,39 +132977,19 @@ var ts;
132907
132977
  }
132908
132978
  packagePath = ts.combinePaths(packagePath, subName);
132909
132979
  }
132910
- var packageFile = ts.combinePaths(ancestor, "node_modules", packagePath, "package.json");
132980
+ var packageDirectory = ts.combinePaths(ancestor, "node_modules", packagePath);
132981
+ var packageFile = ts.combinePaths(packageDirectory, "package.json");
132911
132982
  if (ts.tryFileExists(host, packageFile)) {
132912
132983
  var packageJson = ts.readJson(packageFile, host);
132913
- var exports = packageJson.exports;
132914
- if (exports) {
132915
- if (typeof exports !== "object" || exports === null) { // eslint-disable-line no-null/no-null
132984
+ var exports_1 = packageJson.exports;
132985
+ if (exports_1) {
132986
+ if (typeof exports_1 !== "object" || exports_1 === null) { // eslint-disable-line no-null/no-null
132916
132987
  return; // null exports or entrypoint only, no sub-modules available
132917
132988
  }
132918
- var keys = ts.getOwnKeys(exports);
132919
- var fragmentSubpath_1 = components.join("/");
132920
- var processedKeys = ts.mapDefined(keys, function (k) {
132921
- if (k === ".")
132922
- return undefined;
132923
- if (!ts.startsWith(k, "./"))
132924
- return undefined;
132925
- var subpath = k.substring(2);
132926
- if (!ts.startsWith(subpath, fragmentSubpath_1))
132927
- return undefined;
132928
- // subpath is a valid export (barring conditions, which we don't currently check here)
132929
- if (!ts.stringContains(subpath, "*")) {
132930
- return subpath;
132931
- }
132932
- // pattern export - only return everything up to the `*`, so the user can autocomplete, then
132933
- // keep filling in the pattern (we could speculatively return a list of options by hitting disk,
132934
- // but conditions will make that somewhat awkward, as each condition may have a different set of possible
132935
- // options for the `*`.
132936
- return subpath.slice(0, subpath.indexOf("*"));
132937
- });
132938
- ts.forEach(processedKeys, function (k) {
132939
- if (k) {
132940
- result.push(nameAndKind(k, "external module name" /* externalModuleName */, /*extension*/ undefined));
132941
- }
132942
- });
132989
+ var keys = ts.getOwnKeys(exports_1);
132990
+ var fragmentSubpath = components.join("/") + (components.length && ts.hasTrailingDirectorySeparator(fragment) ? "/" : "");
132991
+ var conditions_1 = mode === ts.ModuleKind.ESNext ? ["node", "import", "types"] : ["node", "require", "types"];
132992
+ addCompletionEntriesFromPathsOrExports(result, fragmentSubpath, packageDirectory, extensionOptions, host, keys, function (key) { return ts.singleElementArray(getPatternFromFirstMatchingCondition(exports_1[key], conditions_1)); }, ts.comparePatternKeys);
132943
132993
  return;
132944
132994
  }
132945
132995
  }
@@ -132949,31 +132999,44 @@ var ts;
132949
132999
  ts.forEachAncestorDirectory(scriptPath, ancestorLookup);
132950
133000
  }
132951
133001
  }
132952
- return result;
133002
+ return ts.arrayFrom(result.values());
133003
+ }
133004
+ function getPatternFromFirstMatchingCondition(target, conditions) {
133005
+ if (typeof target === "string") {
133006
+ return target;
133007
+ }
133008
+ if (target && typeof target === "object" && !ts.isArray(target)) {
133009
+ for (var condition in target) {
133010
+ if (condition === "default" || conditions.indexOf(condition) > -1 || ts.isApplicableVersionedTypesKey(conditions, condition)) {
133011
+ var pattern = target[condition];
133012
+ return getPatternFromFirstMatchingCondition(pattern, conditions);
133013
+ }
133014
+ }
133015
+ }
132953
133016
  }
132954
133017
  function getFragmentDirectory(fragment) {
132955
133018
  return containsSlash(fragment) ? ts.hasTrailingDirectorySeparator(fragment) ? fragment : ts.getDirectoryPath(fragment) : undefined;
132956
133019
  }
132957
- function getCompletionsForPathMapping(path, patterns, fragment, baseUrl, fileExtensions, host) {
133020
+ function getCompletionsForPathMapping(path, patterns, fragment, packageDirectory, extensionOptions, host) {
132958
133021
  if (!ts.endsWith(path, "*")) {
132959
133022
  // For a path mapping "foo": ["/x/y/z.ts"], add "foo" itself as a completion.
132960
- return !ts.stringContains(path, "*") ? justPathMappingName(path) : ts.emptyArray;
133023
+ return !ts.stringContains(path, "*") ? justPathMappingName(path, "script" /* scriptElement */) : ts.emptyArray;
132961
133024
  }
132962
133025
  var pathPrefix = path.slice(0, path.length - 1);
132963
133026
  var remainingFragment = ts.tryRemovePrefix(fragment, pathPrefix);
132964
133027
  if (remainingFragment === undefined) {
132965
133028
  var starIsFullPathComponent = path[path.length - 2] === "/";
132966
- return starIsFullPathComponent ? justPathMappingName(pathPrefix) : ts.flatMap(patterns, function (pattern) { var _a; return (_a = getModulesForPathsPattern("", baseUrl, pattern, fileExtensions, host)) === null || _a === void 0 ? void 0 : _a.map(function (_a) {
133029
+ return starIsFullPathComponent ? justPathMappingName(pathPrefix, "directory" /* directory */) : ts.flatMap(patterns, function (pattern) { var _a; return (_a = getModulesForPathsPattern("", packageDirectory, pattern, extensionOptions, host)) === null || _a === void 0 ? void 0 : _a.map(function (_a) {
132967
133030
  var name = _a.name, rest = __rest(_a, ["name"]);
132968
133031
  return (__assign({ name: pathPrefix + name }, rest));
132969
133032
  }); });
132970
133033
  }
132971
- return ts.flatMap(patterns, function (pattern) { return getModulesForPathsPattern(remainingFragment, baseUrl, pattern, fileExtensions, host); });
132972
- function justPathMappingName(name) {
132973
- return ts.startsWith(name, fragment) ? [directoryResult(ts.removeTrailingDirectorySeparator(name))] : ts.emptyArray;
133034
+ return ts.flatMap(patterns, function (pattern) { return getModulesForPathsPattern(remainingFragment, packageDirectory, pattern, extensionOptions, host); });
133035
+ function justPathMappingName(name, kind) {
133036
+ return ts.startsWith(name, fragment) ? [{ name: ts.removeTrailingDirectorySeparator(name), kind: kind, extension: undefined }] : ts.emptyArray;
132974
133037
  }
132975
133038
  }
132976
- function getModulesForPathsPattern(fragment, baseUrl, pattern, fileExtensions, host) {
133039
+ function getModulesForPathsPattern(fragment, packageDirectory, pattern, extensionOptions, host) {
132977
133040
  if (!host.readDirectory) {
132978
133041
  return undefined;
132979
133042
  }
@@ -132992,21 +133055,33 @@ var ts;
132992
133055
  var expandedPrefixDirectory = fragmentHasPath ? ts.combinePaths(normalizedPrefixDirectory, normalizedPrefixBase + fragmentDirectory) : normalizedPrefixDirectory;
132993
133056
  var normalizedSuffix = ts.normalizePath(parsed.suffix);
132994
133057
  // Need to normalize after combining: If we combinePaths("a", "../b"), we want "b" and not "a/../b".
132995
- var baseDirectory = ts.normalizePath(ts.combinePaths(baseUrl, expandedPrefixDirectory));
133058
+ var baseDirectory = ts.normalizePath(ts.combinePaths(packageDirectory, expandedPrefixDirectory));
132996
133059
  var completePrefix = fragmentHasPath ? baseDirectory : ts.ensureTrailingDirectorySeparator(baseDirectory) + normalizedPrefixBase;
132997
- // If we have a suffix, then we need to read the directory all the way down. We could create a glob
132998
- // that encodes the suffix, but we would have to escape the character "?" which readDirectory
132999
- // doesn't support. For now, this is safer but slower
133000
- var includeGlob = normalizedSuffix ? "**/*" : "./*";
133001
- var matches = ts.mapDefined(ts.tryReadDirectory(host, baseDirectory, fileExtensions, /*exclude*/ undefined, [includeGlob]), function (match) {
133002
- var extension = ts.tryGetExtensionFromPath(match);
133003
- var name = trimPrefixAndSuffix(match);
133004
- return name === undefined ? undefined : nameAndKind(ts.removeFileExtension(name), "script" /* scriptElement */, extension);
133005
- });
133006
- var directories = ts.mapDefined(ts.tryGetDirectories(host, baseDirectory).map(function (d) { return ts.combinePaths(baseDirectory, d); }), function (dir) {
133007
- var name = trimPrefixAndSuffix(dir);
133008
- return name === undefined ? undefined : directoryResult(name);
133060
+ // If we have a suffix, then we read the directory all the way down to avoid returning completions for
133061
+ // directories that don't contain files that would match the suffix. A previous comment here was concerned
133062
+ // about the case where `normalizedSuffix` includes a `?` character, which should be interpreted literally,
133063
+ // but will match any single character as part of the `include` pattern in `tryReadDirectory`. This is not
133064
+ // a problem, because (in the extremely unusual circumstance where the suffix has a `?` in it) a `?`
133065
+ // interpreted as "any character" can only return *too many* results as compared to the literal
133066
+ // interpretation, so we can filter those superfluous results out via `trimPrefixAndSuffix` as we've always
133067
+ // done.
133068
+ var includeGlob = normalizedSuffix ? "**/*" + normalizedSuffix : "./*";
133069
+ var matches = ts.mapDefined(ts.tryReadDirectory(host, baseDirectory, extensionOptions.extensions, /*exclude*/ undefined, [includeGlob]), function (match) {
133070
+ var trimmedWithPattern = trimPrefixAndSuffix(match);
133071
+ if (trimmedWithPattern) {
133072
+ if (containsSlash(trimmedWithPattern)) {
133073
+ return directoryResult(ts.getPathComponents(removeLeadingDirectorySeparator(trimmedWithPattern))[1]);
133074
+ }
133075
+ var _a = getFilenameWithExtensionOption(trimmedWithPattern, host.getCompilationSettings(), extensionOptions.includeExtensionsOption), name = _a.name, extension = _a.extension;
133076
+ return nameAndKind(name, "script" /* scriptElement */, extension);
133077
+ }
133009
133078
  });
133079
+ // If we had a suffix, we already recursively searched for all possible files that could match
133080
+ // it and returned the directories leading to those files. Otherwise, assume any directory could
133081
+ // have something valid to import.
133082
+ var directories = normalizedSuffix
133083
+ ? ts.emptyArray
133084
+ : ts.mapDefined(ts.tryGetDirectories(host, baseDirectory), function (dir) { return dir === "node_modules" ? undefined : directoryResult(dir); });
133010
133085
  return __spreadArray(__spreadArray([], matches, true), directories, true);
133011
133086
  function trimPrefixAndSuffix(path) {
133012
133087
  var inner = withoutStartAndEnd(ts.normalizePath(path), completePrefix, normalizedSuffix);
@@ -133049,10 +133124,10 @@ var ts;
133049
133124
  var names = kind === "path" ? getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getExtensionOptions(compilerOptions, 1 /* Include */), host, sourceFile.path)
133050
133125
  : kind === "types" ? getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, getFragmentDirectory(toComplete), getExtensionOptions(compilerOptions))
133051
133126
  : ts.Debug.fail();
133052
- return addReplacementSpans(toComplete, range.pos + prefix.length, names);
133127
+ return addReplacementSpans(toComplete, range.pos + prefix.length, ts.arrayFrom(names.values()));
133053
133128
  }
133054
133129
  function getCompletionEntriesFromTypings(host, options, scriptPath, fragmentDirectory, extensionOptions, result) {
133055
- if (result === void 0) { result = []; }
133130
+ if (result === void 0) { result = createNameAndKindSet(); }
133056
133131
  // Check for typings specified in compiler options
133057
133132
  var seen = new ts.Map();
133058
133133
  var typeRoots = ts.tryAndIgnoreErrors(function () { return ts.getEffectiveTypeRoots(options, host); }) || ts.emptyArray;
@@ -133077,7 +133152,7 @@ var ts;
133077
133152
  continue;
133078
133153
  if (fragmentDirectory === undefined) {
133079
133154
  if (!seen.has(packageName)) {
133080
- result.push(nameAndKind(packageName, "external module name" /* externalModuleName */, /*extension*/ undefined));
133155
+ result.add(nameAndKind(packageName, "external module name" /* externalModuleName */, /*extension*/ undefined));
133081
133156
  seen.set(packageName, true);
133082
133157
  }
133083
133158
  }
@@ -138678,7 +138753,7 @@ var ts;
138678
138753
  result = references;
138679
138754
  continue;
138680
138755
  }
138681
- var _loop_4 = function (entry) {
138756
+ var _loop_3 = function (entry) {
138682
138757
  if (!entry.definition || entry.definition.type !== 0 /* Symbol */) {
138683
138758
  result.push(entry);
138684
138759
  return "continue";
@@ -138710,7 +138785,7 @@ var ts;
138710
138785
  };
138711
138786
  for (var _b = 0, references_2 = references; _b < references_2.length; _b++) {
138712
138787
  var entry = references_2[_b];
138713
- _loop_4(entry);
138788
+ _loop_3(entry);
138714
138789
  }
138715
138790
  }
138716
138791
  return result;
@@ -140291,8 +140366,8 @@ var ts;
140291
140366
  var declarations;
140292
140367
  if (symbol && symbol.declarations) {
140293
140368
  var indices = ts.indicesOf(symbol.declarations);
140294
- var keys_1 = ts.map(symbol.declarations, function (decl) { return ({ file: decl.getSourceFile().fileName, pos: decl.pos }); });
140295
- indices.sort(function (a, b) { return ts.compareStringsCaseSensitive(keys_1[a].file, keys_1[b].file) || keys_1[a].pos - keys_1[b].pos; });
140369
+ var keys_2 = ts.map(symbol.declarations, function (decl) { return ({ file: decl.getSourceFile().fileName, pos: decl.pos }); });
140370
+ indices.sort(function (a, b) { return ts.compareStringsCaseSensitive(keys_2[a].file, keys_2[b].file) || keys_2[a].pos - keys_2[b].pos; });
140296
140371
  var sortedDeclarations = ts.map(indices, function (i) { return symbol.declarations[i]; });
140297
140372
  var lastDecl = void 0;
140298
140373
  for (var _i = 0, sortedDeclarations_1 = sortedDeclarations; _i < sortedDeclarations_1.length; _i++) {
@@ -140740,7 +140815,7 @@ var ts;
140740
140815
  }
140741
140816
  function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
140742
140817
  var allFiles = program.getSourceFiles();
140743
- var _loop_5 = function (sourceFile) {
140818
+ var _loop_4 = function (sourceFile) {
140744
140819
  var newFromOld = oldToNew(sourceFile.fileName);
140745
140820
  var newImportFromPath = newFromOld !== null && newFromOld !== void 0 ? newFromOld : sourceFile.fileName;
140746
140821
  var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -140772,7 +140847,7 @@ var ts;
140772
140847
  };
140773
140848
  for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
140774
140849
  var sourceFile = allFiles_1[_i];
140775
- _loop_5(sourceFile);
140850
+ _loop_4(sourceFile);
140776
140851
  }
140777
140852
  }
140778
140853
  function combineNormal(pathA, pathB) {
@@ -141796,7 +141871,7 @@ var ts;
141796
141871
  if (!patternMatcher)
141797
141872
  return ts.emptyArray;
141798
141873
  var rawItems = [];
141799
- var _loop_6 = function (sourceFile) {
141874
+ var _loop_5 = function (sourceFile) {
141800
141875
  cancellationToken.throwIfCancellationRequested();
141801
141876
  if (excludeDtsFiles && sourceFile.isDeclarationFile) {
141802
141877
  return "continue";
@@ -141808,7 +141883,7 @@ var ts;
141808
141883
  // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
141809
141884
  for (var _i = 0, sourceFiles_4 = sourceFiles; _i < sourceFiles_4.length; _i++) {
141810
141885
  var sourceFile = sourceFiles_4[_i];
141811
- _loop_6(sourceFile);
141886
+ _loop_5(sourceFile);
141812
141887
  }
141813
141888
  rawItems.sort(compareNavigateToItems);
141814
141889
  return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -143871,13 +143946,13 @@ var ts;
143871
143946
  // Assumes 'value' is already lowercase.
143872
143947
  function indexOfIgnoringCase(str, value) {
143873
143948
  var n = str.length - value.length;
143874
- var _loop_7 = function (start) {
143949
+ var _loop_6 = function (start) {
143875
143950
  if (every(value, function (valueChar, i) { return toLowerCase(str.charCodeAt(i + start)) === valueChar; })) {
143876
143951
  return { value: start };
143877
143952
  }
143878
143953
  };
143879
143954
  for (var start = 0; start <= n; start++) {
143880
- var state_3 = _loop_7(start);
143955
+ var state_3 = _loop_6(start);
143881
143956
  if (typeof state_3 === "object")
143882
143957
  return state_3.value;
143883
143958
  }
@@ -145344,7 +145419,7 @@ var ts;
145344
145419
  return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
145345
145420
  }
145346
145421
  function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
145347
- var _loop_8 = function (n) {
145422
+ var _loop_7 = function (n) {
145348
145423
  // If the node is not a subspan of its parent, this is a big problem.
145349
145424
  // There have been crashes that might be caused by this violation.
145350
145425
  ts.Debug.assert(ts.rangeContainsRange(n.parent, n), "Not a subspan", function () { return "Child: " + ts.Debug.formatSyntaxKind(n.kind) + ", parent: " + ts.Debug.formatSyntaxKind(n.parent.kind); });
@@ -145354,7 +145429,7 @@ var ts;
145354
145429
  }
145355
145430
  };
145356
145431
  for (var n = node; !ts.isSourceFile(n) && (isManuallyInvoked || !ts.isBlock(n)); n = n.parent) {
145357
- var state_4 = _loop_8(n);
145432
+ var state_4 = _loop_7(n);
145358
145433
  if (typeof state_4 === "object")
145359
145434
  return state_4.value;
145360
145435
  }
@@ -146967,7 +147042,7 @@ var ts;
146967
147042
  commandLineOptionsStringToEnum = commandLineOptionsStringToEnum ||
146968
147043
  ts.filter(ts.optionDeclarations, function (o) { return typeof o.type === "object" && !ts.forEachEntry(o.type, function (v) { return typeof v !== "number"; }); });
146969
147044
  options = ts.cloneCompilerOptions(options);
146970
- var _loop_9 = function (opt) {
147045
+ var _loop_8 = function (opt) {
146971
147046
  if (!ts.hasProperty(options, opt.name)) {
146972
147047
  return "continue";
146973
147048
  }
@@ -146986,7 +147061,7 @@ var ts;
146986
147061
  };
146987
147062
  for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) {
146988
147063
  var opt = commandLineOptionsStringToEnum_1[_i];
146989
- _loop_9(opt);
147064
+ _loop_8(opt);
146990
147065
  }
146991
147066
  return options;
146992
147067
  }
@@ -150751,7 +150826,7 @@ var ts;
150751
150826
  ChangeTracker.prototype.finishDeleteDeclarations = function () {
150752
150827
  var _this = this;
150753
150828
  var deletedNodesInLists = new ts.Set(); // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
150754
- var _loop_10 = function (sourceFile, node) {
150829
+ var _loop_9 = function (sourceFile, node) {
150755
150830
  if (!this_1.deletedNodes.some(function (d) { return d.sourceFile === sourceFile && ts.rangeContainsRangeExclusive(d.node, node); })) {
150756
150831
  if (ts.isArray(node)) {
150757
150832
  this_1.deleteRange(sourceFile, ts.rangeOfTypeParameters(sourceFile, node));
@@ -150764,7 +150839,7 @@ var ts;
150764
150839
  var this_1 = this;
150765
150840
  for (var _i = 0, _a = this.deletedNodes; _i < _a.length; _i++) {
150766
150841
  var _b = _a[_i], sourceFile = _b.sourceFile, node = _b.node;
150767
- _loop_10(sourceFile, node);
150842
+ _loop_9(sourceFile, node);
150768
150843
  }
150769
150844
  deletedNodesInLists.forEach(function (node) {
150770
150845
  var sourceFile = node.getSourceFile();
@@ -150852,14 +150927,14 @@ var ts;
150852
150927
  // order changes by start position
150853
150928
  // If the start position is the same, put the shorter range first, since an empty range (x, x) may precede (x, y) but not vice-versa.
150854
150929
  var normalized = ts.stableSort(changesInFile, function (a, b) { return (a.range.pos - b.range.pos) || (a.range.end - b.range.end); });
150855
- var _loop_11 = function (i) {
150930
+ var _loop_10 = function (i) {
150856
150931
  ts.Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos, "Changes overlap", function () {
150857
150932
  return JSON.stringify(normalized[i].range) + " and " + JSON.stringify(normalized[i + 1].range);
150858
150933
  });
150859
150934
  };
150860
150935
  // verify that change intervals do not overlap, except possibly at end points.
150861
150936
  for (var i = 0; i < normalized.length - 1; i++) {
150862
- _loop_11(i);
150937
+ _loop_10(i);
150863
150938
  }
150864
150939
  var textChanges = ts.mapDefined(normalized, function (c) {
150865
150940
  var span = ts.createTextSpanFromRange(c.range);
@@ -151767,7 +151842,7 @@ var ts;
151767
151842
  }
151768
151843
  var isCompleteFix = identifiers.isCompleteFix;
151769
151844
  var initializers;
151770
- var _loop_12 = function (identifier) {
151845
+ var _loop_11 = function (identifier) {
151771
151846
  var symbol = checker.getSymbolAtLocation(identifier);
151772
151847
  if (!symbol) {
151773
151848
  return "continue";
@@ -151800,7 +151875,7 @@ var ts;
151800
151875
  };
151801
151876
  for (var _i = 0, _a = identifiers.identifiers; _i < _a.length; _i++) {
151802
151877
  var identifier = _a[_i];
151803
- _loop_12(identifier);
151878
+ _loop_11(identifier);
151804
151879
  }
151805
151880
  return initializers && {
151806
151881
  initializers: initializers,
@@ -152685,7 +152760,7 @@ var ts;
152685
152760
  }
152686
152761
  var pos = ts.skipTrivia(sourceFile.text, ts.moveRangePastModifiers(functionToConvert).pos);
152687
152762
  changes.insertModifierAt(sourceFile, pos, 131 /* AsyncKeyword */, { suffix: " " });
152688
- var _loop_13 = function (returnStatement) {
152763
+ var _loop_12 = function (returnStatement) {
152689
152764
  ts.forEachChild(returnStatement, function visit(node) {
152690
152765
  if (ts.isCallExpression(node)) {
152691
152766
  var newNodes = transformExpression(node, node, transformer, /*hasContinuation*/ false);
@@ -152707,7 +152782,7 @@ var ts;
152707
152782
  };
152708
152783
  for (var _i = 0, returnStatements_1 = returnStatements; _i < returnStatements_1.length; _i++) {
152709
152784
  var returnStatement = returnStatements_1[_i];
152710
- var state_5 = _loop_13(returnStatement);
152785
+ var state_5 = _loop_12(returnStatement);
152711
152786
  if (typeof state_5 === "object")
152712
152787
  return state_5.value;
152713
152788
  }
@@ -156042,7 +156117,7 @@ var ts;
156042
156117
  });
156043
156118
  typeDeclToMembers.forEach(function (infos, declaration) {
156044
156119
  var supers = ts.isTypeLiteralNode(declaration) ? undefined : codefix.getAllSupers(declaration, checker);
156045
- var _loop_14 = function (info) {
156120
+ var _loop_13 = function (info) {
156046
156121
  // If some superclass added this property, don't add it again.
156047
156122
  if (supers === null || supers === void 0 ? void 0 : supers.some(function (superClassOrInterface) {
156048
156123
  var superInfos = typeDeclToMembers.get(superClassOrInterface);
@@ -156069,7 +156144,7 @@ var ts;
156069
156144
  };
156070
156145
  for (var _i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
156071
156146
  var info = infos_1[_i];
156072
- _loop_14(info);
156147
+ _loop_13(info);
156073
156148
  }
156074
156149
  });
156075
156150
  }));
@@ -158843,7 +158918,7 @@ var ts;
158843
158918
  function getSignatureFromCalls(calls) {
158844
158919
  var parameters = [];
158845
158920
  var length = Math.max.apply(Math, calls.map(function (c) { return c.argumentTypes.length; }));
158846
- var _loop_15 = function (i) {
158921
+ var _loop_14 = function (i) {
158847
158922
  var symbol = checker.createSymbol(1 /* FunctionScopedVariable */, ts.escapeLeadingUnderscores("arg" + i));
158848
158923
  symbol.type = combineTypes(calls.map(function (call) { return call.argumentTypes[i] || checker.getUndefinedType(); }));
158849
158924
  if (calls.some(function (call) { return call.argumentTypes[i] === undefined; })) {
@@ -158852,7 +158927,7 @@ var ts;
158852
158927
  parameters.push(symbol);
158853
158928
  };
158854
158929
  for (var i = 0; i < length; i++) {
158855
- _loop_15(i);
158930
+ _loop_14(i);
158856
158931
  }
158857
158932
  var returnType = combineFromUsage(combineUsages(calls.map(function (call) { return call.return_; })));
158858
158933
  return checker.createSignature(/*declaration*/ undefined, /*typeParameters*/ undefined, /*thisParameter*/ undefined, parameters, returnType, /*typePredicate*/ undefined, length, 0 /* None */);
@@ -160828,7 +160903,7 @@ var ts;
160828
160903
  // Imports that need to be kept as named imports in the refactored code, to avoid changing the semantics.
160829
160904
  // More specifically, those are named imports that appear in named exports in the original code, e.g. `a` in `import { a } from "m"; export { a }`.
160830
160905
  var neededNamedImports = new ts.Set();
160831
- var _loop_16 = function (element) {
160906
+ var _loop_15 = function (element) {
160832
160907
  var propertyName = (element.propertyName || element.name).text;
160833
160908
  ts.FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, function (id) {
160834
160909
  var access = ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(namespaceImportName), propertyName);
@@ -160845,7 +160920,7 @@ var ts;
160845
160920
  };
160846
160921
  for (var _i = 0, _a = toConvert.elements; _i < _a.length; _i++) {
160847
160922
  var element = _a[_i];
160848
- _loop_16(element);
160923
+ _loop_15(element);
160849
160924
  }
160850
160925
  changes.replaceNode(sourceFile, toConvert, shouldUseDefault
160851
160926
  ? ts.factory.createIdentifier(namespaceImportName)
@@ -162736,7 +162811,7 @@ var ts;
162736
162811
  : ts.getEnclosingBlockScopeContainer(scopes[0]);
162737
162812
  ts.forEachChild(containingLexicalScopeOfExtraction, checkForUsedDeclarations);
162738
162813
  }
162739
- var _loop_17 = function (i) {
162814
+ var _loop_16 = function (i) {
162740
162815
  var scopeUsages = usagesPerScope[i];
162741
162816
  // Special case: in the innermost scope, all usages are available.
162742
162817
  // (The computed value reflects the value at the top-level of the scope, but the
@@ -162779,7 +162854,7 @@ var ts;
162779
162854
  }
162780
162855
  };
162781
162856
  for (var i = 0; i < scopes.length; i++) {
162782
- _loop_17(i);
162857
+ _loop_16(i);
162783
162858
  }
162784
162859
  return { target: target, usagesPerScope: usagesPerScope, functionErrorsPerScope: functionErrorsPerScope, constantErrorsPerScope: constantErrorsPerScope, exposedVariableDeclarations: exposedVariableDeclarations };
162785
162860
  function isInGenericContext(node) {
@@ -163480,10 +163555,10 @@ var ts;
163480
163555
  }
163481
163556
  function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
163482
163557
  var checker = program.getTypeChecker();
163483
- var _loop_18 = function (sourceFile) {
163558
+ var _loop_17 = function (sourceFile) {
163484
163559
  if (sourceFile === oldFile)
163485
163560
  return "continue";
163486
- var _loop_19 = function (statement) {
163561
+ var _loop_18 = function (statement) {
163487
163562
  forEachImportInStatement(statement, function (importNode) {
163488
163563
  if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
163489
163564
  return;
@@ -163505,12 +163580,12 @@ var ts;
163505
163580
  };
163506
163581
  for (var _b = 0, _c = sourceFile.statements; _b < _c.length; _b++) {
163507
163582
  var statement = _c[_b];
163508
- _loop_19(statement);
163583
+ _loop_18(statement);
163509
163584
  }
163510
163585
  };
163511
163586
  for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
163512
163587
  var sourceFile = _a[_i];
163513
- _loop_18(sourceFile);
163588
+ _loop_17(sourceFile);
163514
163589
  }
163515
163590
  }
163516
163591
  function getNamespaceLikeImport(node) {
@@ -164873,7 +164948,7 @@ var ts;
164873
164948
  var templateSpans = [];
164874
164949
  var templateHead = ts.factory.createTemplateHead(headText, rawHeadText);
164875
164950
  copyCommentFromStringLiterals(headIndexes, templateHead);
164876
- var _loop_20 = function (i) {
164951
+ var _loop_19 = function (i) {
164877
164952
  var currentNode = getExpressionFromParenthesesOrExpression(nodes[i]);
164878
164953
  copyOperatorComments(i, currentNode);
164879
164954
  var _c = concatConsecutiveString(i + 1, nodes), newIndex = _c[0], subsequentText = _c[1], rawSubsequentText = _c[2], stringIndexes = _c[3];
@@ -164902,7 +164977,7 @@ var ts;
164902
164977
  };
164903
164978
  var out_i_1;
164904
164979
  for (var i = begin; i < nodes.length; i++) {
164905
- _loop_20(i);
164980
+ _loop_19(i);
164906
164981
  i = out_i_1;
164907
164982
  }
164908
164983
  return ts.factory.createTemplateExpression(templateHead, templateSpans);
@@ -165514,20 +165589,25 @@ var ts;
165514
165589
  return this.documentationComment;
165515
165590
  };
165516
165591
  SymbolObject.prototype.getContextualDocumentationComment = function (context, checker) {
165517
- switch (context === null || context === void 0 ? void 0 : context.kind) {
165518
- case 172 /* GetAccessor */:
165592
+ if (context) {
165593
+ if (ts.isGetAccessor(context)) {
165519
165594
  if (!this.contextualGetAccessorDocumentationComment) {
165520
165595
  this.contextualGetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isGetAccessor), checker);
165521
165596
  }
165522
- return this.contextualGetAccessorDocumentationComment;
165523
- case 173 /* SetAccessor */:
165597
+ if (ts.length(this.contextualGetAccessorDocumentationComment)) {
165598
+ return this.contextualGetAccessorDocumentationComment;
165599
+ }
165600
+ }
165601
+ if (ts.isSetAccessor(context)) {
165524
165602
  if (!this.contextualSetAccessorDocumentationComment) {
165525
165603
  this.contextualSetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isSetAccessor), checker);
165526
165604
  }
165527
- return this.contextualSetAccessorDocumentationComment;
165528
- default:
165529
- return this.getDocumentationComment(checker);
165605
+ if (ts.length(this.contextualSetAccessorDocumentationComment)) {
165606
+ return this.contextualSetAccessorDocumentationComment;
165607
+ }
165608
+ }
165530
165609
  }
165610
+ return this.getDocumentationComment(checker);
165531
165611
  };
165532
165612
  SymbolObject.prototype.getJsDocTags = function (checker) {
165533
165613
  if (this.tags === undefined) {
@@ -165536,20 +165616,25 @@ var ts;
165536
165616
  return this.tags;
165537
165617
  };
165538
165618
  SymbolObject.prototype.getContextualJsDocTags = function (context, checker) {
165539
- switch (context === null || context === void 0 ? void 0 : context.kind) {
165540
- case 172 /* GetAccessor */:
165619
+ if (context) {
165620
+ if (ts.isGetAccessor(context)) {
165541
165621
  if (!this.contextualGetAccessorTags) {
165542
165622
  this.contextualGetAccessorTags = getJsDocTagsOfDeclarations(ts.filter(this.declarations, ts.isGetAccessor), checker);
165543
165623
  }
165544
- return this.contextualGetAccessorTags;
165545
- case 173 /* SetAccessor */:
165624
+ if (ts.length(this.contextualGetAccessorTags)) {
165625
+ return this.contextualGetAccessorTags;
165626
+ }
165627
+ }
165628
+ if (ts.isSetAccessor(context)) {
165546
165629
  if (!this.contextualSetAccessorTags) {
165547
165630
  this.contextualSetAccessorTags = getJsDocTagsOfDeclarations(ts.filter(this.declarations, ts.isSetAccessor), checker);
165548
165631
  }
165549
- return this.contextualSetAccessorTags;
165550
- default:
165551
- return this.getJsDocTags(checker);
165632
+ if (ts.length(this.contextualSetAccessorTags)) {
165633
+ return this.contextualSetAccessorTags;
165634
+ }
165635
+ }
165552
165636
  }
165637
+ return this.getJsDocTags(checker);
165553
165638
  };
165554
165639
  return SymbolObject;
165555
165640
  }());
@@ -165738,7 +165823,7 @@ var ts;
165738
165823
  var tags = ts.JsDoc.getJsDocTagsFromDeclarations(declarations, checker);
165739
165824
  if (checker && (tags.length === 0 || declarations.some(hasJSDocInheritDocTag))) {
165740
165825
  var seenSymbols_1 = new ts.Set();
165741
- var _loop_21 = function (declaration) {
165826
+ var _loop_20 = function (declaration) {
165742
165827
  var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) {
165743
165828
  var _a;
165744
165829
  if (!seenSymbols_1.has(symbol)) {
@@ -165755,7 +165840,7 @@ var ts;
165755
165840
  };
165756
165841
  for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
165757
165842
  var declaration = declarations_7[_i];
165758
- _loop_21(declaration);
165843
+ _loop_20(declaration);
165759
165844
  }
165760
165845
  }
165761
165846
  return tags;
@@ -165766,7 +165851,7 @@ var ts;
165766
165851
  var doc = ts.JsDoc.getJsDocCommentsFromDeclarations(declarations, checker);
165767
165852
  if (checker && (doc.length === 0 || declarations.some(hasJSDocInheritDocTag))) {
165768
165853
  var seenSymbols_2 = new ts.Set();
165769
- var _loop_22 = function (declaration) {
165854
+ var _loop_21 = function (declaration) {
165770
165855
  var inheritedDocs = findBaseOfDeclaration(checker, declaration, function (symbol) {
165771
165856
  if (!seenSymbols_2.has(symbol)) {
165772
165857
  seenSymbols_2.add(symbol);
@@ -165782,7 +165867,7 @@ var ts;
165782
165867
  };
165783
165868
  for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
165784
165869
  var declaration = declarations_8[_i];
165785
- _loop_22(declaration);
165870
+ _loop_21(declaration);
165786
165871
  }
165787
165872
  }
165788
165873
  return doc;
@@ -166300,7 +166385,10 @@ var ts;
166300
166385
  program = undefined; // TODO: GH#18217
166301
166386
  lastTypesRootVersion = typeRootsVersion;
166302
166387
  }
166303
- var rootFileNames = host.getScriptFileNames();
166388
+ // This array is retained by the program and will be used to determine if the program is up to date,
166389
+ // so we need to make a copy in case the host mutates the underlying array - otherwise it would look
166390
+ // like every program always has the host's current list of root files.
166391
+ var rootFileNames = host.getScriptFileNames().slice();
166304
166392
  // Get a fresh cache of the host information
166305
166393
  var newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();
166306
166394
  var hasInvalidatedResolution = host.hasInvalidatedResolution || ts.returnFalse;