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/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220706";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220709";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -2250,7 +2250,7 @@ var ts;
2250
2250
  * and 1 insertion/deletion at 3 characters)
2251
2251
  */
2252
2252
  function getSpellingSuggestion(name, candidates, getName) {
2253
- var maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
2253
+ var maximumLengthDifference = Math.max(2, Math.floor(name.length * 0.34));
2254
2254
  var bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
2255
2255
  var bestCandidate;
2256
2256
  for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
@@ -2979,6 +2979,22 @@ var ts;
2979
2979
  return formatEnum(flags, ts.FlowFlags, /*isFlags*/ true);
2980
2980
  }
2981
2981
  Debug.formatFlowFlags = formatFlowFlags;
2982
+ function formatRelationComparisonResult(result) {
2983
+ return formatEnum(result, ts.RelationComparisonResult, /*isFlags*/ true);
2984
+ }
2985
+ Debug.formatRelationComparisonResult = formatRelationComparisonResult;
2986
+ function formatCheckMode(mode) {
2987
+ return formatEnum(mode, ts.CheckMode, /*isFlags*/ true);
2988
+ }
2989
+ Debug.formatCheckMode = formatCheckMode;
2990
+ function formatSignatureCheckMode(mode) {
2991
+ return formatEnum(mode, ts.SignatureCheckMode, /*isFlags*/ true);
2992
+ }
2993
+ Debug.formatSignatureCheckMode = formatSignatureCheckMode;
2994
+ function formatTypeFacts(facts) {
2995
+ return formatEnum(facts, ts.TypeFacts, /*isFlags*/ true);
2996
+ }
2997
+ Debug.formatTypeFacts = formatTypeFacts;
2982
2998
  var isDebugInfoEnabled = false;
2983
2999
  var extendedDebugModule;
2984
3000
  function extendedDebug() {
@@ -9218,6 +9234,7 @@ var ts;
9218
9234
  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'."),
9219
9235
  _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?"),
9220
9236
  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."),
9237
+ 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."),
9221
9238
  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}'."),
9222
9239
  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}'."),
9223
9240
  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}'."),
@@ -19716,7 +19733,8 @@ var ts;
19716
19733
  function getDeclarationModifierFlagsFromSymbol(s, isWrite) {
19717
19734
  if (isWrite === void 0) { isWrite = false; }
19718
19735
  if (s.valueDeclaration) {
19719
- var declaration = (isWrite && s.declarations && ts.find(s.declarations, function (d) { return d.kind === 173 /* SetAccessor */; })) || s.valueDeclaration;
19736
+ var declaration = (isWrite && s.declarations && ts.find(s.declarations, ts.isSetAccessorDeclaration))
19737
+ || (s.flags & 32768 /* GetAccessor */ && ts.find(s.declarations, ts.isGetAccessorDeclaration)) || s.valueDeclaration;
19720
19738
  var flags = ts.getCombinedModifierFlags(declaration);
19721
19739
  return s.parent && s.parent.flags & 32 /* Class */ ? flags : flags & ~28 /* AccessibilityModifier */;
19722
19740
  }
@@ -20391,7 +20409,7 @@ var ts;
20391
20409
  // Excludes declaration files - they still require an explicit `export {}` or the like
20392
20410
  // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
20393
20411
  // that aren't esm-mode (meaning not in a `type: module` scope).
20394
- return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) && !file.isDeclarationFile ? true : undefined;
20412
+ return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */]))) && !file.isDeclarationFile ? true : undefined;
20395
20413
  }
20396
20414
  function getSetExternalModuleIndicator(options) {
20397
20415
  // TODO: Should this callback be cached?
@@ -20414,10 +20432,7 @@ var ts;
20414
20432
  if (options.jsx === 4 /* ReactJSX */ || options.jsx === 5 /* ReactJSXDev */) {
20415
20433
  checks.push(isFileModuleFromUsingJSXTag);
20416
20434
  }
20417
- var moduleKind = getEmitModuleKind(options);
20418
- if (moduleKind === ts.ModuleKind.Node16 || moduleKind === ts.ModuleKind.NodeNext) {
20419
- checks.push(isFileForcedToBeModuleByFormat);
20420
- }
20435
+ checks.push(isFileForcedToBeModuleByFormat);
20421
20436
  var combined_1 = ts.or.apply(void 0, checks);
20422
20437
  var callback = function (file) { return void (file.externalModuleIndicator = combined_1(file)); };
20423
20438
  return callback;
@@ -34137,10 +34152,10 @@ var ts;
34137
34152
  var hasJSDoc = hasPrecedingJSDocComment();
34138
34153
  var modifiers = parseModifiers();
34139
34154
  if (parseContextualModifier(136 /* GetKeyword */)) {
34140
- return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 172 /* GetAccessor */);
34155
+ return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 172 /* GetAccessor */, 4 /* Type */);
34141
34156
  }
34142
34157
  if (parseContextualModifier(149 /* SetKeyword */)) {
34143
- return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 173 /* SetAccessor */);
34158
+ return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 173 /* SetAccessor */, 4 /* Type */);
34144
34159
  }
34145
34160
  if (isIndexSignature()) {
34146
34161
  return parseIndexSignatureDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers);
@@ -36186,10 +36201,10 @@ var ts;
36186
36201
  var decorators = parseDecorators();
36187
36202
  var modifiers = parseModifiers();
36188
36203
  if (parseContextualModifier(136 /* GetKeyword */)) {
36189
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */);
36204
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */, 0 /* None */);
36190
36205
  }
36191
36206
  if (parseContextualModifier(149 /* SetKeyword */)) {
36192
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */);
36207
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */, 0 /* None */);
36193
36208
  }
36194
36209
  var asteriskToken = parseOptionalToken(41 /* AsteriskToken */);
36195
36210
  var tokenIsIdentifier = isIdentifier();
@@ -36881,9 +36896,15 @@ var ts;
36881
36896
  return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === 10 /* StringLiteral */);
36882
36897
  }
36883
36898
  function parseFunctionBlockOrSemicolon(flags, diagnosticMessage) {
36884
- if (token() !== 18 /* OpenBraceToken */ && canParseSemicolon()) {
36885
- parseSemicolon();
36886
- return;
36899
+ if (token() !== 18 /* OpenBraceToken */) {
36900
+ if (flags & 4 /* Type */) {
36901
+ parseTypeMemberSemicolon();
36902
+ return;
36903
+ }
36904
+ if (canParseSemicolon()) {
36905
+ parseSemicolon();
36906
+ return;
36907
+ }
36887
36908
  }
36888
36909
  return parseFunctionBlock(flags, diagnosticMessage);
36889
36910
  }
@@ -37087,12 +37108,12 @@ var ts;
37087
37108
  }
37088
37109
  return parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken);
37089
37110
  }
37090
- function parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, kind) {
37111
+ function parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, kind, flags) {
37091
37112
  var name = parsePropertyName();
37092
37113
  var typeParameters = parseTypeParameters();
37093
37114
  var parameters = parseParameters(0 /* None */);
37094
37115
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
37095
- var body = parseFunctionBlockOrSemicolon(0 /* None */);
37116
+ var body = parseFunctionBlockOrSemicolon(flags);
37096
37117
  var node = kind === 172 /* GetAccessor */
37097
37118
  ? factory.createGetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, type, body)
37098
37119
  : factory.createSetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, body);
@@ -37279,10 +37300,10 @@ var ts;
37279
37300
  return parseClassStaticBlockDeclaration(pos, hasJSDoc, decorators, modifiers);
37280
37301
  }
37281
37302
  if (parseContextualModifier(136 /* GetKeyword */)) {
37282
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */);
37303
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */, 0 /* None */);
37283
37304
  }
37284
37305
  if (parseContextualModifier(149 /* SetKeyword */)) {
37285
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */);
37306
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */, 0 /* None */);
37286
37307
  }
37287
37308
  if (token() === 134 /* ConstructorKeyword */ || token() === 10 /* StringLiteral */) {
37288
37309
  var constructorDeclaration = tryParseConstructorDeclaration(pos, hasJSDoc, decorators, modifiers);
@@ -44593,6 +44614,7 @@ var ts;
44593
44614
  return toSearchResult(/*value*/ undefined);
44594
44615
  }
44595
44616
  /**
44617
+ * @internal
44596
44618
  * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 -
44597
44619
  * "longest" has some nuance as to what "longest" means in the presence of pattern trailers
44598
44620
  */
@@ -44615,6 +44637,7 @@ var ts;
44615
44637
  return 1;
44616
44638
  return 0;
44617
44639
  }
44640
+ ts.comparePatternKeys = comparePatternKeys;
44618
44641
  function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) {
44619
44642
  var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports);
44620
44643
  if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) {
@@ -48686,7 +48709,7 @@ var ts;
48686
48709
  // Masks
48687
48710
  TypeFacts[TypeFacts["OrFactsMask"] = 8256] = "OrFactsMask";
48688
48711
  TypeFacts[TypeFacts["AndFactsMask"] = 134209471] = "AndFactsMask";
48689
- })(TypeFacts || (TypeFacts = {}));
48712
+ })(TypeFacts = ts.TypeFacts || (ts.TypeFacts = {}));
48690
48713
  var typeofNEFacts = new ts.Map(ts.getEntries({
48691
48714
  string: 256 /* TypeofNEString */,
48692
48715
  number: 512 /* TypeofNENumber */,
@@ -48721,7 +48744,7 @@ var ts;
48721
48744
  CheckMode[CheckMode["RestBindingElement"] = 64] = "RestBindingElement";
48722
48745
  // e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
48723
48746
  // we need to preserve generic types instead of substituting them for constraints
48724
- })(CheckMode || (CheckMode = {}));
48747
+ })(CheckMode = ts.CheckMode || (ts.CheckMode = {}));
48725
48748
  var SignatureCheckMode;
48726
48749
  (function (SignatureCheckMode) {
48727
48750
  SignatureCheckMode[SignatureCheckMode["BivariantCallback"] = 1] = "BivariantCallback";
@@ -48729,7 +48752,7 @@ var ts;
48729
48752
  SignatureCheckMode[SignatureCheckMode["IgnoreReturnTypes"] = 4] = "IgnoreReturnTypes";
48730
48753
  SignatureCheckMode[SignatureCheckMode["StrictArity"] = 8] = "StrictArity";
48731
48754
  SignatureCheckMode[SignatureCheckMode["Callback"] = 3] = "Callback";
48732
- })(SignatureCheckMode || (SignatureCheckMode = {}));
48755
+ })(SignatureCheckMode = ts.SignatureCheckMode || (ts.SignatureCheckMode = {}));
48733
48756
  var IntersectionState;
48734
48757
  (function (IntersectionState) {
48735
48758
  IntersectionState[IntersectionState["None"] = 0] = "None";
@@ -49081,7 +49104,7 @@ var ts;
49081
49104
  },
49082
49105
  getContextualTypeForObjectLiteralElement: function (nodeIn) {
49083
49106
  var node = ts.getParseTreeNode(nodeIn, ts.isObjectLiteralElementLike);
49084
- return node ? getContextualTypeForObjectLiteralElement(node) : undefined;
49107
+ return node ? getContextualTypeForObjectLiteralElement(node, /*contextFlags*/ undefined) : undefined;
49085
49108
  },
49086
49109
  getContextualTypeForArgumentAtIndex: function (nodeIn, argIndex) {
49087
49110
  var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
@@ -49089,7 +49112,7 @@ var ts;
49089
49112
  },
49090
49113
  getContextualTypeForJsxAttribute: function (nodeIn) {
49091
49114
  var node = ts.getParseTreeNode(nodeIn, ts.isJsxAttributeLike);
49092
- return node && getContextualTypeForJsxAttribute(node);
49115
+ return node && getContextualTypeForJsxAttribute(node, /*contextFlags*/ undefined);
49093
49116
  },
49094
49117
  isContextSensitive: isContextSensitive,
49095
49118
  getTypeOfPropertyOfContextualType: getTypeOfPropertyOfContextualType,
@@ -50421,6 +50444,7 @@ var ts;
50421
50444
  if (ctor && ctor.locals) {
50422
50445
  if (lookup(ctor.locals, name, meaning & 111551 /* Value */)) {
50423
50446
  // Remember the property node, it will be used later to report appropriate error
50447
+ ts.Debug.assertNode(location, ts.isPropertyDeclaration);
50424
50448
  propertyWithInvalidInitializer = location;
50425
50449
  }
50426
50450
  }
@@ -50610,11 +50634,27 @@ var ts;
50610
50634
  }
50611
50635
  }
50612
50636
  }
50637
+ // The invalid initializer error is needed in two situation:
50638
+ // 1. When result is undefined, after checking for a missing "this."
50639
+ // 2. When result is defined
50640
+ function checkAndReportErrorForInvalidInitializer() {
50641
+ if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
50642
+ // We have a match, but the reference occurred within a property initializer and the identifier also binds
50643
+ // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
50644
+ // with ESNext+useDefineForClassFields because the scope semantics are different.
50645
+ error(errorLocation, errorLocation && propertyWithInvalidInitializer.type && ts.textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos)
50646
+ ? ts.Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor
50647
+ : ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyWithInvalidInitializer.name), diagnosticName(nameArg));
50648
+ return true;
50649
+ }
50650
+ return false;
50651
+ }
50613
50652
  if (!result) {
50614
50653
  if (nameNotFoundMessage) {
50615
50654
  addLazyDiagnostic(function () {
50616
50655
  if (!errorLocation ||
50617
50656
  !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
50657
+ !checkAndReportErrorForInvalidInitializer() &&
50618
50658
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
50619
50659
  !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
50620
50660
  !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
@@ -50622,7 +50662,16 @@ var ts;
50622
50662
  !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
50623
50663
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
50624
50664
  var suggestion = void 0;
50625
- if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
50665
+ var suggestedLib = void 0;
50666
+ // Report missing lib first
50667
+ if (nameArg) {
50668
+ suggestedLib = getSuggestedLibForNonExistentName(nameArg);
50669
+ if (suggestedLib) {
50670
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), suggestedLib);
50671
+ }
50672
+ }
50673
+ // then spelling suggestions
50674
+ if (!suggestedLib && getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
50626
50675
  suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
50627
50676
  var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
50628
50677
  if (isGlobalScopeAugmentationDeclaration) {
@@ -50641,16 +50690,9 @@ var ts;
50641
50690
  }
50642
50691
  }
50643
50692
  }
50644
- if (!suggestion) {
50645
- if (nameArg) {
50646
- var lib = getSuggestedLibForNonExistentName(nameArg);
50647
- if (lib) {
50648
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), lib);
50649
- }
50650
- else {
50651
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
50652
- }
50653
- }
50693
+ // And then fall back to unspecified "not found"
50694
+ if (!suggestion && !suggestedLib && nameArg) {
50695
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
50654
50696
  }
50655
50697
  suggestionCount++;
50656
50698
  }
@@ -50658,12 +50700,7 @@ var ts;
50658
50700
  }
50659
50701
  return undefined;
50660
50702
  }
50661
- if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
50662
- // We have a match, but the reference occurred within a property initializer and the identifier also binds
50663
- // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
50664
- // with ESNext+useDefineForClassFields because the scope semantics are different.
50665
- var propertyName = propertyWithInvalidInitializer.name;
50666
- error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), diagnosticName(nameArg));
50703
+ else if (checkAndReportErrorForInvalidInitializer()) {
50667
50704
  return undefined;
50668
50705
  }
50669
50706
  // Perform extra checks only if error reporting was requested
@@ -52812,13 +52849,25 @@ var ts;
52812
52849
  && isDeclarationVisible(declaration.parent)) {
52813
52850
  return addVisibleAlias(declaration, declaration);
52814
52851
  }
52815
- 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
52816
- && ts.isVariableDeclaration(declaration.parent.parent)
52817
- && ((_b = declaration.parent.parent.parent) === null || _b === void 0 ? void 0 : _b.parent) && ts.isVariableStatement(declaration.parent.parent.parent.parent)
52818
- && !ts.hasSyntacticModifier(declaration.parent.parent.parent.parent, 1 /* Export */)
52819
- && declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
52820
- && isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
52821
- return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
52852
+ else if (ts.isBindingElement(declaration)) {
52853
+ 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
52854
+ && ts.isVariableDeclaration(declaration.parent.parent)
52855
+ && ((_b = declaration.parent.parent.parent) === null || _b === void 0 ? void 0 : _b.parent) && ts.isVariableStatement(declaration.parent.parent.parent.parent)
52856
+ && !ts.hasSyntacticModifier(declaration.parent.parent.parent.parent, 1 /* Export */)
52857
+ && declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
52858
+ && isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
52859
+ return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
52860
+ }
52861
+ else if (symbol.flags & 2 /* BlockScopedVariable */) {
52862
+ var variableStatement = ts.findAncestor(declaration, ts.isVariableStatement);
52863
+ if (ts.hasSyntacticModifier(variableStatement, 1 /* Export */)) {
52864
+ return true;
52865
+ }
52866
+ if (!isDeclarationVisible(variableStatement.parent)) {
52867
+ return false;
52868
+ }
52869
+ return addVisibleAlias(declaration, variableStatement);
52870
+ }
52822
52871
  }
52823
52872
  // Declaration is not visible
52824
52873
  return false;
@@ -53339,6 +53388,10 @@ var ts;
53339
53388
  }
53340
53389
  return typeToTypeNodeHelper(type, context);
53341
53390
  }
53391
+ function isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) {
53392
+ return isMappedTypeWithKeyofConstraintDeclaration(type)
53393
+ && !(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */);
53394
+ }
53342
53395
  function createMappedTypeNodeFromType(type) {
53343
53396
  ts.Debug.assert(!!(type.flags & 524288 /* Object */));
53344
53397
  var readonlyToken = type.declaration.readonlyToken ? ts.factory.createToken(type.declaration.readonlyToken.kind) : undefined;
@@ -53348,7 +53401,7 @@ var ts;
53348
53401
  if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
53349
53402
  // We have a { [P in keyof T]: X }
53350
53403
  // We do this to ensure we retain the toplevel keyof-ness of the type which may be lost due to keyof distribution during `getConstraintTypeFromMappedType`
53351
- if (!(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53404
+ if (isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53352
53405
  var newParam = createTypeParameter(createSymbol(262144 /* TypeParameter */, "T"));
53353
53406
  var name = typeParameterToName(newParam, context);
53354
53407
  newTypeVariable = ts.factory.createTypeReferenceNode(name);
@@ -53364,11 +53417,12 @@ var ts;
53364
53417
  var mappedTypeNode = ts.factory.createMappedTypeNode(readonlyToken, typeParameterNode, nameTypeNode, questionToken, templateTypeNode, /*members*/ undefined);
53365
53418
  context.approximateLength += 10;
53366
53419
  var result = ts.setEmitFlags(mappedTypeNode, 1 /* SingleLine */);
53367
- if (isMappedTypeWithKeyofConstraintDeclaration(type) && !(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53420
+ if (isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53368
53421
  // homomorphic mapped type with a non-homomorphic naive inlining
53369
53422
  // wrap it with a conditional like `SomeModifiersType extends infer U ? {..the mapped type...} : never` to ensure the resulting
53370
53423
  // type stays homomorphic
53371
- 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 */));
53424
+ var originalConstraint = instantiateType(getConstraintOfTypeParameter(getTypeFromTypeNode(type.declaration.typeParameter.constraint.type)) || unknownType, type.mapper);
53425
+ 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 */));
53372
53426
  }
53373
53427
  return result;
53374
53428
  }
@@ -62513,19 +62567,22 @@ var ts;
62513
62567
  * to reduce the resulting type if possible (since only intersections with conflicting literal-typed properties are reducible).
62514
62568
  */
62515
62569
  function isPossiblyReducibleByInstantiation(type) {
62516
- return ts.some(type.types, function (t) {
62517
- var uniqueFilled = getUniqueLiteralFilledInstantiation(t);
62518
- return getReducedType(uniqueFilled) !== uniqueFilled;
62519
- });
62570
+ var uniqueFilled = getUniqueLiteralFilledInstantiation(type);
62571
+ return getReducedType(uniqueFilled) !== uniqueFilled;
62572
+ }
62573
+ function shouldDeferIndexType(type) {
62574
+ return !!(type.flags & 58982400 /* InstantiableNonPrimitive */ ||
62575
+ isGenericTupleType(type) ||
62576
+ isGenericMappedType(type) && !hasDistributiveNameType(type) ||
62577
+ type.flags & 1048576 /* Union */ && ts.some(type.types, isPossiblyReducibleByInstantiation) ||
62578
+ type.flags & 2097152 /* Intersection */ && maybeTypeOfKind(type, 465829888 /* Instantiable */) && ts.some(type.types, isEmptyAnonymousObjectType));
62520
62579
  }
62521
62580
  function getIndexType(type, stringsOnly, noIndexSignatures) {
62522
62581
  if (stringsOnly === void 0) { stringsOnly = keyofStringsOnly; }
62523
62582
  type = getReducedType(type);
62524
- return type.flags & 1048576 /* Union */ ? isPossiblyReducibleByInstantiation(type)
62525
- ? getIndexTypeForGenericType(type, stringsOnly)
62526
- : getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62527
- type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62528
- type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericTupleType(type) || isGenericMappedType(type) && !hasDistributiveNameType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
62583
+ return shouldDeferIndexType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
62584
+ type.flags & 1048576 /* Union */ ? getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62585
+ type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62529
62586
  ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) :
62530
62587
  type === wildcardType ? wildcardType :
62531
62588
  type.flags & 2 /* Unknown */ ? neverType :
@@ -66318,13 +66375,20 @@ var ts;
66318
66375
  return result;
66319
66376
  }
66320
66377
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66378
+ var saveErrorInfo = captureErrorCalculationState();
66379
+ var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66380
+ if (result) {
66381
+ resetErrorInfo(saveErrorInfo);
66382
+ }
66383
+ return result;
66384
+ }
66385
+ function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo) {
66321
66386
  if (intersectionState & 4 /* PropertyCheck */) {
66322
66387
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
66323
66388
  }
66324
66389
  var result;
66325
66390
  var originalErrorInfo;
66326
66391
  var varianceCheckFailed = false;
66327
- var saveErrorInfo = captureErrorCalculationState();
66328
66392
  var sourceFlags = source.flags;
66329
66393
  var targetFlags = target.flags;
66330
66394
  if (relation === identityRelation) {
@@ -66388,7 +66452,6 @@ var ts;
66388
66452
  if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66389
66453
  // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66390
66454
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66391
- resetErrorInfo(saveErrorInfo);
66392
66455
  return result;
66393
66456
  }
66394
66457
  }
@@ -66513,7 +66576,6 @@ var ts;
66513
66576
  result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, reportErrors);
66514
66577
  }
66515
66578
  if (result) {
66516
- resetErrorInfo(saveErrorInfo);
66517
66579
  return result;
66518
66580
  }
66519
66581
  if (reportErrors) {
@@ -66616,7 +66678,6 @@ var ts;
66616
66678
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
66617
66679
  // conditional type and bail out with a Ternary.Maybe result.
66618
66680
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
66619
- resetErrorInfo(saveErrorInfo);
66620
66681
  return 3 /* Maybe */;
66621
66682
  }
66622
66683
  var c = target;
@@ -66631,7 +66692,6 @@ var ts;
66631
66692
  if (result = skipTrue ? -1 /* True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false)) {
66632
66693
  result &= skipFalse ? -1 /* True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false);
66633
66694
  if (result) {
66634
- resetErrorInfo(saveErrorInfo);
66635
66695
  return result;
66636
66696
  }
66637
66697
  }
@@ -66663,12 +66723,10 @@ var ts;
66663
66723
  var constraint = getConstraintOfType(source) || unknownType;
66664
66724
  // 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
66665
66725
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66666
- resetErrorInfo(saveErrorInfo);
66667
66726
  return result;
66668
66727
  }
66669
66728
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
66670
66729
  else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && constraint !== unknownType && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
66671
- resetErrorInfo(saveErrorInfo);
66672
66730
  return result;
66673
66731
  }
66674
66732
  if (isMappedTypeGenericIndexedAccess(source)) {
@@ -66677,7 +66735,6 @@ var ts;
66677
66735
  var indexConstraint = getConstraintOfType(source.indexType);
66678
66736
  if (indexConstraint) {
66679
66737
  if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
66680
- resetErrorInfo(saveErrorInfo);
66681
66738
  return result;
66682
66739
  }
66683
66740
  }
@@ -66686,7 +66743,6 @@ var ts;
66686
66743
  }
66687
66744
  else if (sourceFlags & 4194304 /* Index */) {
66688
66745
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
66689
- resetErrorInfo(saveErrorInfo);
66690
66746
  return result;
66691
66747
  }
66692
66748
  }
@@ -66694,7 +66750,6 @@ var ts;
66694
66750
  if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
66695
66751
  var constraint = getBaseConstraintOfType(source);
66696
66752
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
66697
- resetErrorInfo(saveErrorInfo);
66698
66753
  return result;
66699
66754
  }
66700
66755
  }
@@ -66705,14 +66760,12 @@ var ts;
66705
66760
  return 0 /* False */;
66706
66761
  }
66707
66762
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
66708
- resetErrorInfo(saveErrorInfo);
66709
66763
  return result;
66710
66764
  }
66711
66765
  }
66712
66766
  else {
66713
66767
  var constraint = getBaseConstraintOfType(source);
66714
66768
  if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
66715
- resetErrorInfo(saveErrorInfo);
66716
66769
  return result;
66717
66770
  }
66718
66771
  }
@@ -66721,7 +66774,6 @@ var ts;
66721
66774
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
66722
66775
  // conditional type and bail out with a Ternary.Maybe result.
66723
66776
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
66724
- resetErrorInfo(saveErrorInfo);
66725
66777
  return 3 /* Maybe */;
66726
66778
  }
66727
66779
  if (targetFlags & 16777216 /* Conditional */) {
@@ -66744,7 +66796,6 @@ var ts;
66744
66796
  result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, reportErrors);
66745
66797
  }
66746
66798
  if (result) {
66747
- resetErrorInfo(saveErrorInfo);
66748
66799
  return result;
66749
66800
  }
66750
66801
  }
@@ -66755,7 +66806,6 @@ var ts;
66755
66806
  var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
66756
66807
  if (distributiveConstraint) {
66757
66808
  if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
66758
- resetErrorInfo(saveErrorInfo);
66759
66809
  return result;
66760
66810
  }
66761
66811
  }
@@ -66765,7 +66815,6 @@ var ts;
66765
66815
  var defaultConstraint = getDefaultConstraintOfConditionalType(source);
66766
66816
  if (defaultConstraint) {
66767
66817
  if (result = isRelatedTo(defaultConstraint, target, 1 /* Source */, reportErrors)) {
66768
- resetErrorInfo(saveErrorInfo);
66769
66818
  return result;
66770
66819
  }
66771
66820
  }
@@ -66778,7 +66827,6 @@ var ts;
66778
66827
  if (isGenericMappedType(target)) {
66779
66828
  if (isGenericMappedType(source)) {
66780
66829
  if (result = mappedTypeRelatedTo(source, target, reportErrors)) {
66781
- resetErrorInfo(saveErrorInfo);
66782
66830
  return result;
66783
66831
  }
66784
66832
  }
@@ -70124,6 +70172,15 @@ var ts;
70124
70172
  var key = getFlowCacheKey(node.expression, declaredType, initialType, flowContainer);
70125
70173
  return key && key + "." + propName;
70126
70174
  }
70175
+ break;
70176
+ case 201 /* ObjectBindingPattern */:
70177
+ case 202 /* ArrayBindingPattern */:
70178
+ case 256 /* FunctionDeclaration */:
70179
+ case 213 /* FunctionExpression */:
70180
+ case 214 /* ArrowFunction */:
70181
+ case 169 /* MethodDeclaration */:
70182
+ // Handle pseudo-references originating in getNarrowedTypeOfSymbol.
70183
+ return getNodeId(node) + "#" + getTypeId(declaredType);
70127
70184
  }
70128
70185
  return undefined;
70129
70186
  }
@@ -72299,7 +72356,7 @@ var ts;
72299
72356
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
72300
72357
  (checkMode && checkMode & 64 /* RestBindingElement */ ?
72301
72358
  getContextualType(node, 8 /* SkipBindingPatterns */)
72302
- : getContextualType(node));
72359
+ : getContextualType(node, /*contextFlags*/ undefined));
72303
72360
  return contextualType && !isGenericType(contextualType);
72304
72361
  }
72305
72362
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -73163,7 +73220,7 @@ var ts;
73163
73220
  // We have an object literal method. Check if the containing object literal has a contextual type
73164
73221
  // that includes a ThisType<T>. If so, T is the contextual type for 'this'. We continue looking in
73165
73222
  // any directly enclosing object literals.
73166
- var contextualType = getApparentTypeOfContextualType(containingLiteral);
73223
+ var contextualType = getApparentTypeOfContextualType(containingLiteral, /*contextFlags*/ undefined);
73167
73224
  var literal = containingLiteral;
73168
73225
  var type = contextualType;
73169
73226
  while (type) {
@@ -73175,7 +73232,7 @@ var ts;
73175
73232
  break;
73176
73233
  }
73177
73234
  literal = literal.parent.parent;
73178
- type = getApparentTypeOfContextualType(literal);
73235
+ type = getApparentTypeOfContextualType(literal, /*contextFlags*/ undefined);
73179
73236
  }
73180
73237
  // There was no contextual ThisType<T> for the containing object literal, so the contextual type
73181
73238
  // for 'this' is the non-null form of the contextual type for the containing object literal or
@@ -73232,7 +73289,7 @@ var ts;
73232
73289
  tryGetTypeAtPosition(contextualSignature, index);
73233
73290
  }
73234
73291
  }
73235
- function getContextualTypeForVariableLikeDeclaration(declaration) {
73292
+ function getContextualTypeForVariableLikeDeclaration(declaration, contextFlags) {
73236
73293
  var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
73237
73294
  if (typeNode) {
73238
73295
  return getTypeFromTypeNode(typeNode);
@@ -73241,18 +73298,18 @@ var ts;
73241
73298
  case 164 /* Parameter */:
73242
73299
  return getContextuallyTypedParameterType(declaration);
73243
73300
  case 203 /* BindingElement */:
73244
- return getContextualTypeForBindingElement(declaration);
73301
+ return getContextualTypeForBindingElement(declaration, contextFlags);
73245
73302
  case 167 /* PropertyDeclaration */:
73246
73303
  if (ts.isStatic(declaration)) {
73247
- return getContextualTypeForStaticPropertyDeclaration(declaration);
73304
+ return getContextualTypeForStaticPropertyDeclaration(declaration, contextFlags);
73248
73305
  }
73249
73306
  // By default, do nothing and return undefined - only the above cases have context implied by a parent
73250
73307
  }
73251
73308
  }
73252
- function getContextualTypeForBindingElement(declaration) {
73309
+ function getContextualTypeForBindingElement(declaration, contextFlags) {
73253
73310
  var parent = declaration.parent.parent;
73254
73311
  var name = declaration.propertyName || declaration.name;
73255
- var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
73312
+ var parentType = getContextualTypeForVariableLikeDeclaration(parent, contextFlags) ||
73256
73313
  parent.kind !== 203 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */);
73257
73314
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
73258
73315
  return undefined;
@@ -73268,8 +73325,8 @@ var ts;
73268
73325
  return getTypeOfPropertyOfType(parentType, text);
73269
73326
  }
73270
73327
  }
73271
- function getContextualTypeForStaticPropertyDeclaration(declaration) {
73272
- var parentType = ts.isExpression(declaration.parent) && getContextualType(declaration.parent);
73328
+ function getContextualTypeForStaticPropertyDeclaration(declaration, contextFlags) {
73329
+ var parentType = ts.isExpression(declaration.parent) && getContextualType(declaration.parent, contextFlags);
73273
73330
  if (!parentType)
73274
73331
  return undefined;
73275
73332
  return getTypeOfPropertyOfContextualType(parentType, getSymbolOfNode(declaration).escapedName);
@@ -73285,7 +73342,7 @@ var ts;
73285
73342
  function getContextualTypeForInitializerExpression(node, contextFlags) {
73286
73343
  var declaration = node.parent;
73287
73344
  if (ts.hasInitializer(declaration) && node === declaration.initializer) {
73288
- var result = getContextualTypeForVariableLikeDeclaration(declaration);
73345
+ var result = getContextualTypeForVariableLikeDeclaration(declaration, contextFlags);
73289
73346
  if (result) {
73290
73347
  return result;
73291
73348
  }
@@ -73295,10 +73352,10 @@ var ts;
73295
73352
  }
73296
73353
  return undefined;
73297
73354
  }
73298
- function getContextualTypeForReturnExpression(node) {
73355
+ function getContextualTypeForReturnExpression(node, contextFlags) {
73299
73356
  var func = ts.getContainingFunction(node);
73300
73357
  if (func) {
73301
- var contextualReturnType = getContextualReturnType(func);
73358
+ var contextualReturnType = getContextualReturnType(func, contextFlags);
73302
73359
  if (contextualReturnType) {
73303
73360
  var functionFlags = ts.getFunctionFlags(func);
73304
73361
  if (functionFlags & 1 /* Generator */) { // Generator or AsyncGenerator function
@@ -73328,11 +73385,11 @@ var ts;
73328
73385
  }
73329
73386
  return undefined;
73330
73387
  }
73331
- function getContextualTypeForYieldOperand(node) {
73388
+ function getContextualTypeForYieldOperand(node, contextFlags) {
73332
73389
  var func = ts.getContainingFunction(node);
73333
73390
  if (func) {
73334
73391
  var functionFlags = ts.getFunctionFlags(func);
73335
- var contextualReturnType = getContextualReturnType(func);
73392
+ var contextualReturnType = getContextualReturnType(func, contextFlags);
73336
73393
  if (contextualReturnType) {
73337
73394
  return node.asteriskToken
73338
73395
  ? contextualReturnType
@@ -73356,14 +73413,14 @@ var ts;
73356
73413
  }
73357
73414
  function getContextualIterationType(kind, functionDecl) {
73358
73415
  var isAsync = !!(ts.getFunctionFlags(functionDecl) & 2 /* Async */);
73359
- var contextualReturnType = getContextualReturnType(functionDecl);
73416
+ var contextualReturnType = getContextualReturnType(functionDecl, /*contextFlags*/ undefined);
73360
73417
  if (contextualReturnType) {
73361
73418
  return getIterationTypeOfGeneratorFunctionReturnType(kind, contextualReturnType, isAsync)
73362
73419
  || undefined;
73363
73420
  }
73364
73421
  return undefined;
73365
73422
  }
73366
- function getContextualReturnType(functionDecl) {
73423
+ function getContextualReturnType(functionDecl, contextFlags) {
73367
73424
  // If the containing function has a return type annotation, is a constructor, or is a get accessor whose
73368
73425
  // corresponding set accessor has a type annotation, return statements in the function are contextually typed
73369
73426
  var returnType = getReturnTypeFromAnnotation(functionDecl);
@@ -73378,7 +73435,7 @@ var ts;
73378
73435
  }
73379
73436
  var iife = ts.getImmediatelyInvokedFunctionExpression(functionDecl);
73380
73437
  if (iife) {
73381
- return getContextualType(iife);
73438
+ return getContextualType(iife, contextFlags);
73382
73439
  }
73383
73440
  return undefined;
73384
73441
  }
@@ -73631,7 +73688,7 @@ var ts;
73631
73688
  }
73632
73689
  function getContextualTypeForObjectLiteralElement(element, contextFlags) {
73633
73690
  var objectLiteral = element.parent;
73634
- var propertyAssignmentType = ts.isPropertyAssignment(element) && getContextualTypeForVariableLikeDeclaration(element);
73691
+ var propertyAssignmentType = ts.isPropertyAssignment(element) && getContextualTypeForVariableLikeDeclaration(element, contextFlags);
73635
73692
  if (propertyAssignmentType) {
73636
73693
  return propertyAssignmentType;
73637
73694
  }
@@ -73826,9 +73883,9 @@ var ts;
73826
73883
  return getContextualTypeForInitializerExpression(node, contextFlags);
73827
73884
  case 214 /* ArrowFunction */:
73828
73885
  case 247 /* ReturnStatement */:
73829
- return getContextualTypeForReturnExpression(node);
73886
+ return getContextualTypeForReturnExpression(node, contextFlags);
73830
73887
  case 224 /* YieldExpression */:
73831
- return getContextualTypeForYieldOperand(parent);
73888
+ return getContextualTypeForYieldOperand(parent, contextFlags);
73832
73889
  case 218 /* AwaitExpression */:
73833
73890
  return getContextualTypeForAwaitOperand(parent, contextFlags);
73834
73891
  case 208 /* CallExpression */:
@@ -73876,7 +73933,7 @@ var ts;
73876
73933
  }
73877
73934
  return undefined;
73878
73935
  function tryFindWhenConstTypeReference(node) {
73879
- return getContextualType(node);
73936
+ return getContextualType(node, contextFlags);
73880
73937
  }
73881
73938
  }
73882
73939
  function getInferenceContext(node) {
@@ -74178,7 +74235,7 @@ var ts;
74178
74235
  var elementCount = elements.length;
74179
74236
  var elementTypes = [];
74180
74237
  var elementFlags = [];
74181
- var contextualType = getApparentTypeOfContextualType(node);
74238
+ var contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
74182
74239
  var inDestructuringPattern = ts.isAssignmentTarget(node);
74183
74240
  var inConstContext = isConstContext(node);
74184
74241
  var hasOmittedExpression = false;
@@ -74349,7 +74406,7 @@ var ts;
74349
74406
  var propertiesTable = ts.createSymbolTable();
74350
74407
  var propertiesArray = [];
74351
74408
  var spread = emptyObjectType;
74352
- var contextualType = getApparentTypeOfContextualType(node);
74409
+ var contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
74353
74410
  var contextualTypeHasPattern = contextualType && contextualType.pattern &&
74354
74411
  (contextualType.pattern.kind === 201 /* ObjectBindingPattern */ || contextualType.pattern.kind === 205 /* ObjectLiteralExpression */);
74355
74412
  var inConstContext = isConstContext(node);
@@ -74688,7 +74745,7 @@ var ts;
74688
74745
  if (explicitlySpecifyChildrenAttribute) {
74689
74746
  error(attributes, ts.Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName));
74690
74747
  }
74691
- var contextualType = getApparentTypeOfContextualType(openingLikeElement.attributes);
74748
+ var contextualType = getApparentTypeOfContextualType(openingLikeElement.attributes, /*contextFlags*/ undefined);
74692
74749
  var childrenContextualType = contextualType && getTypeOfPropertyOfContextualType(contextualType, jsxChildrenPropertyName);
74693
74750
  // 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
74694
74751
  var childrenPropSymbol = createSymbol(4 /* Property */, jsxChildrenPropertyName);
@@ -78528,17 +78585,6 @@ var ts;
78528
78585
  }
78529
78586
  }
78530
78587
  }
78531
- var restType = getEffectiveRestType(context);
78532
- if (restType && restType.flags & 262144 /* TypeParameter */) {
78533
- // The contextual signature has a generic rest parameter. We first instantiate the contextual
78534
- // signature (without fixing type parameters) and assign types to contextually typed parameters.
78535
- var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
78536
- assignContextualParameterTypes(signature, instantiatedContext);
78537
- // We then infer from a tuple type representing the parameters that correspond to the contextual
78538
- // rest parameter.
78539
- var restPos = getParameterCount(context) - 1;
78540
- inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
78541
- }
78542
78588
  }
78543
78589
  function assignContextualParameterTypes(signature, context) {
78544
78590
  if (context.typeParameters) {
@@ -78731,7 +78777,7 @@ var ts;
78731
78777
  var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
78732
78778
  var contextualType = !contextualSignature ? undefined :
78733
78779
  contextualSignature === getSignatureFromDeclaration(func) ? isGenerator ? undefined : returnType :
78734
- instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func);
78780
+ instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func, /*contextFlags*/ undefined);
78735
78781
  if (isGenerator) {
78736
78782
  yieldType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(yieldType, contextualType, 0 /* Yield */, isAsync);
78737
78783
  returnType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(returnType, contextualType, 1 /* Return */, isAsync);
@@ -78802,7 +78848,7 @@ var ts;
78802
78848
  nextType = iterationTypes && iterationTypes.nextType;
78803
78849
  }
78804
78850
  else {
78805
- nextType = getContextualType(yieldExpression);
78851
+ nextType = getContextualType(yieldExpression, /*contextFlags*/ undefined);
78806
78852
  }
78807
78853
  if (nextType)
78808
78854
  ts.pushIfUnique(nextTypes, nextType);
@@ -79011,11 +79057,16 @@ var ts;
79011
79057
  if (isContextSensitive(node)) {
79012
79058
  if (contextualSignature) {
79013
79059
  var inferenceContext = getInferenceContext(node);
79060
+ var instantiatedContextualSignature = void 0;
79014
79061
  if (checkMode && checkMode & 2 /* Inferential */) {
79015
79062
  inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
79063
+ var restType = getEffectiveRestType(contextualSignature);
79064
+ if (restType && restType.flags & 262144 /* TypeParameter */) {
79065
+ instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext.nonFixingMapper);
79066
+ }
79016
79067
  }
79017
- var instantiatedContextualSignature = inferenceContext ?
79018
- instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
79068
+ instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ?
79069
+ instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature);
79019
79070
  assignContextualParameterTypes(signature, instantiatedContextualSignature);
79020
79071
  }
79021
79072
  else {
@@ -80257,7 +80308,7 @@ var ts;
80257
80308
  type = anyType;
80258
80309
  addLazyDiagnostic(function () {
80259
80310
  if (noImplicitAny && !ts.expressionResultIsUnused(node)) {
80260
- var contextualType = getContextualType(node);
80311
+ var contextualType = getContextualType(node, /*contextFlags*/ undefined);
80261
80312
  if (!contextualType || isTypeAny(contextualType)) {
80262
80313
  error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
80263
80314
  }
@@ -80298,7 +80349,7 @@ var ts;
80298
80349
  texts.push(span.literal.text);
80299
80350
  types.push(isTypeAssignableTo(type, templateConstraintType) ? type : stringType);
80300
80351
  }
80301
- return isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
80352
+ return isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node, /*contextFlags*/ undefined) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
80302
80353
  }
80303
80354
  function isTemplateLiteralContextualType(type) {
80304
80355
  return !!(type.flags & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */) ||
@@ -80326,7 +80377,7 @@ var ts;
80326
80377
  // We strip literal freshness when an appropriate contextual type is present such that contextually typed
80327
80378
  // literals always preserve their literal types (otherwise they might widen during type inference). An alternative
80328
80379
  // here would be to not mark contextually typed literals as fresh in the first place.
80329
- var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
80380
+ var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, /*contextFlags*/ undefined)) ?
80330
80381
  getRegularTypeOfLiteralType(type) : type;
80331
80382
  return result;
80332
80383
  }
@@ -80441,7 +80492,7 @@ var ts;
80441
80492
  var type = checkExpression(node, checkMode, forceTuple);
80442
80493
  return isConstContext(node) || ts.isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) :
80443
80494
  isTypeAssertion(node) ? type :
80444
- getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node) : contextualType, node));
80495
+ getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node, /*contextFlags*/ undefined) : contextualType, node, /*contextFlags*/ undefined));
80445
80496
  }
80446
80497
  function checkPropertyAssignment(node, checkMode) {
80447
80498
  // Do not use hasDynamicName here, because that returns false for well known symbols.
@@ -132962,6 +133013,26 @@ var ts;
132962
133013
  (function (Completions) {
132963
133014
  var StringCompletions;
132964
133015
  (function (StringCompletions) {
133016
+ var _a;
133017
+ var kindPrecedence = (_a = {},
133018
+ _a["directory" /* directory */] = 0,
133019
+ _a["script" /* scriptElement */] = 1,
133020
+ _a["external module name" /* externalModuleName */] = 2,
133021
+ _a);
133022
+ function createNameAndKindSet() {
133023
+ var map = new ts.Map();
133024
+ function add(value) {
133025
+ var existing = map.get(value.name);
133026
+ if (!existing || kindPrecedence[existing.kind] < kindPrecedence[value.kind]) {
133027
+ map.set(value.name, value);
133028
+ }
133029
+ }
133030
+ return {
133031
+ add: add,
133032
+ has: map.has.bind(map),
133033
+ values: map.values.bind(map),
133034
+ };
133035
+ }
132965
133036
  function getStringLiteralCompletions(sourceFile, position, contextToken, options, host, program, log, preferences) {
132966
133037
  if (ts.isInReferenceComment(sourceFile, position)) {
132967
133038
  var entries = getTripleSlashReferenceCompletion(sourceFile, position, options, host);
@@ -133243,11 +133314,12 @@ var ts;
133243
133314
  }
133244
133315
  function getStringLiteralCompletionsFromModuleNamesWorker(sourceFile, node, compilerOptions, host, typeChecker, preferences) {
133245
133316
  var literalValue = ts.normalizeSlashes(node.text);
133317
+ var mode = ts.isStringLiteralLike(node) ? ts.getModeForUsageLocation(sourceFile, node) : undefined;
133246
133318
  var scriptPath = sourceFile.path;
133247
133319
  var scriptDirectory = ts.getDirectoryPath(scriptPath);
133248
133320
  return isPathRelativeToScript(literalValue) || !compilerOptions.baseUrl && (ts.isRootedDiskPath(literalValue) || ts.isUrl(literalValue))
133249
133321
  ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, getIncludeExtensionOption())
133250
- : getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, compilerOptions, host, typeChecker);
133322
+ : getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, mode, compilerOptions, host, getIncludeExtensionOption(), typeChecker);
133251
133323
  function getIncludeExtensionOption() {
133252
133324
  var mode = ts.isStringLiteralLike(node) ? ts.getModeForUsageLocation(sourceFile, node) : undefined;
133253
133325
  return preferences.importModuleSpecifierEnding === "js" || mode === ts.ModuleKind.ESNext ? 2 /* ModuleSpecifierCompletion */ : 0 /* Exclude */;
@@ -133263,7 +133335,7 @@ var ts;
133263
133335
  return getCompletionEntriesForDirectoryFragmentWithRootDirs(compilerOptions.rootDirs, literalValue, scriptDirectory, extensionOptions, compilerOptions, host, scriptPath);
133264
133336
  }
133265
133337
  else {
133266
- return getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, scriptPath);
133338
+ return ts.arrayFrom(getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, scriptPath).values());
133267
133339
  }
133268
133340
  }
133269
133341
  function isEmitResolutionKindUsingNodeModules(compilerOptions) {
@@ -133299,7 +133371,7 @@ var ts;
133299
133371
  var basePath = compilerOptions.project || host.getCurrentDirectory();
133300
133372
  var ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames());
133301
133373
  var baseDirectories = getBaseDirectoriesFromRootDirs(rootDirs, basePath, scriptDirectory, ignoreCase);
133302
- return ts.flatMap(baseDirectories, function (baseDirectory) { return getCompletionEntriesForDirectoryFragment(fragment, baseDirectory, extensionOptions, host, exclude); });
133374
+ return ts.flatMap(baseDirectories, function (baseDirectory) { return ts.arrayFrom(getCompletionEntriesForDirectoryFragment(fragment, baseDirectory, extensionOptions, host, exclude).values()); });
133303
133375
  }
133304
133376
  var IncludeExtensionsOption;
133305
133377
  (function (IncludeExtensionsOption) {
@@ -133310,10 +133382,9 @@ var ts;
133310
133382
  /**
133311
133383
  * Given a path ending at a directory, gets the completions for the path, and filters for those entries containing the basename.
133312
133384
  */
133313
- function getCompletionEntriesForDirectoryFragment(fragment, scriptPath, _a, host, exclude, result) {
133314
- var _b;
133315
- var extensions = _a.extensions, includeExtensionsOption = _a.includeExtensionsOption;
133316
- if (result === void 0) { result = []; }
133385
+ function getCompletionEntriesForDirectoryFragment(fragment, scriptPath, extensionOptions, host, exclude, result) {
133386
+ var _a;
133387
+ if (result === void 0) { result = createNameAndKindSet(); }
133317
133388
  if (fragment === undefined) {
133318
133389
  fragment = "";
133319
133390
  }
@@ -133337,11 +133408,11 @@ var ts;
133337
133408
  var packageJson = ts.readJson(packageJsonPath, host);
133338
133409
  var typesVersions = packageJson.typesVersions;
133339
133410
  if (typeof typesVersions === "object") {
133340
- var versionPaths = (_b = ts.getPackageJsonTypesVersionsPaths(typesVersions)) === null || _b === void 0 ? void 0 : _b.paths;
133411
+ var versionPaths = (_a = ts.getPackageJsonTypesVersionsPaths(typesVersions)) === null || _a === void 0 ? void 0 : _a.paths;
133341
133412
  if (versionPaths) {
133342
133413
  var packageDirectory = ts.getDirectoryPath(packageJsonPath);
133343
133414
  var pathInPackage = absolutePath.slice(ts.ensureTrailingDirectorySeparator(packageDirectory).length);
133344
- if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensions, versionPaths, host)) {
133415
+ if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensionOptions, host, versionPaths)) {
133345
133416
  // A true result means one of the `versionPaths` was matched, which will block relative resolution
133346
133417
  // to files and folders from here. All reachable paths given the pattern match are already added.
133347
133418
  return result;
@@ -133353,39 +133424,17 @@ var ts;
133353
133424
  if (!ts.tryDirectoryExists(host, baseDirectory))
133354
133425
  return result;
133355
133426
  // Enumerate the available files if possible
133356
- var files = ts.tryReadDirectory(host, baseDirectory, extensions, /*exclude*/ undefined, /*include*/ ["./*"]);
133427
+ var files = ts.tryReadDirectory(host, baseDirectory, extensionOptions.extensions, /*exclude*/ undefined, /*include*/ ["./*"]);
133357
133428
  if (files) {
133358
- /**
133359
- * Multiple file entries might map to the same truncated name once we remove extensions
133360
- * (happens iff includeExtensionsOption === includeExtensionsOption.Exclude) so we use a set-like data structure. Eg:
133361
- *
133362
- * both foo.ts and foo.tsx become foo
133363
- */
133364
- var foundFiles = new ts.Map(); // maps file to its extension
133365
133429
  for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
133366
133430
  var filePath = files_1[_i];
133367
133431
  filePath = ts.normalizePath(filePath);
133368
133432
  if (exclude && ts.comparePaths(filePath, exclude, scriptPath, ignoreCase) === 0 /* EqualTo */) {
133369
133433
  continue;
133370
133434
  }
133371
- var foundFileName = void 0;
133372
- var outputExtension = ts.moduleSpecifiers.tryGetJSExtensionForFile(filePath, host.getCompilationSettings());
133373
- if (includeExtensionsOption === 0 /* Exclude */ && !ts.fileExtensionIsOneOf(filePath, [".json" /* Json */, ".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */])) {
133374
- foundFileName = ts.removeFileExtension(ts.getBaseFileName(filePath));
133375
- foundFiles.set(foundFileName, ts.tryGetExtensionFromPath(filePath));
133376
- }
133377
- else if ((ts.fileExtensionIsOneOf(filePath, [".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */]) || includeExtensionsOption === 2 /* ModuleSpecifierCompletion */) && outputExtension) {
133378
- foundFileName = ts.changeExtension(ts.getBaseFileName(filePath), outputExtension);
133379
- foundFiles.set(foundFileName, outputExtension);
133380
- }
133381
- else {
133382
- foundFileName = ts.getBaseFileName(filePath);
133383
- foundFiles.set(foundFileName, ts.tryGetExtensionFromPath(filePath));
133384
- }
133435
+ var _b = getFilenameWithExtensionOption(ts.getBaseFileName(filePath), host.getCompilationSettings(), extensionOptions.includeExtensionsOption), name = _b.name, extension = _b.extension;
133436
+ result.add(nameAndKind(name, "script" /* scriptElement */, extension));
133385
133437
  }
133386
- foundFiles.forEach(function (ext, foundFile) {
133387
- result.push(nameAndKind(foundFile, "script" /* scriptElement */, ext));
133388
- });
133389
133438
  }
133390
133439
  // If possible, get folder completion as well
133391
133440
  var directories = ts.tryGetDirectories(host, baseDirectory);
@@ -133394,27 +133443,52 @@ var ts;
133394
133443
  var directory = directories_1[_c];
133395
133444
  var directoryName = ts.getBaseFileName(ts.normalizePath(directory));
133396
133445
  if (directoryName !== "@types") {
133397
- result.push(directoryResult(directoryName));
133446
+ result.add(directoryResult(directoryName));
133398
133447
  }
133399
133448
  }
133400
133449
  }
133401
133450
  return result;
133402
133451
  }
133452
+ function getFilenameWithExtensionOption(name, compilerOptions, includeExtensionsOption) {
133453
+ var outputExtension = ts.moduleSpecifiers.tryGetJSExtensionForFile(name, compilerOptions);
133454
+ if (includeExtensionsOption === 0 /* Exclude */ && !ts.fileExtensionIsOneOf(name, [".json" /* Json */, ".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */])) {
133455
+ return { name: ts.removeFileExtension(name), extension: ts.tryGetExtensionFromPath(name) };
133456
+ }
133457
+ else if ((ts.fileExtensionIsOneOf(name, [".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */]) || includeExtensionsOption === 2 /* ModuleSpecifierCompletion */) && outputExtension) {
133458
+ return { name: ts.changeExtension(name, outputExtension), extension: outputExtension };
133459
+ }
133460
+ else {
133461
+ return { name: name, extension: ts.tryGetExtensionFromPath(name) };
133462
+ }
133463
+ }
133403
133464
  /** @returns whether `fragment` was a match for any `paths` (which should indicate whether any other path completions should be offered) */
133404
- function addCompletionEntriesFromPaths(result, fragment, baseDirectory, fileExtensions, paths, host) {
133405
- var _a;
133465
+ function addCompletionEntriesFromPaths(result, fragment, baseDirectory, extensionOptions, host, paths) {
133466
+ var getPatternsForKey = function (key) { return paths[key]; };
133467
+ var comparePaths = function (a, b) {
133468
+ var patternA = ts.tryParsePattern(a);
133469
+ var patternB = ts.tryParsePattern(b);
133470
+ var lengthA = typeof patternA === "object" ? patternA.prefix.length : a.length;
133471
+ var lengthB = typeof patternB === "object" ? patternB.prefix.length : b.length;
133472
+ return ts.compareValues(lengthB, lengthA);
133473
+ };
133474
+ return addCompletionEntriesFromPathsOrExports(result, fragment, baseDirectory, extensionOptions, host, ts.getOwnKeys(paths), getPatternsForKey, comparePaths);
133475
+ }
133476
+ /** @returns whether `fragment` was a match for any `paths` (which should indicate whether any other path completions should be offered) */
133477
+ function addCompletionEntriesFromPathsOrExports(result, fragment, baseDirectory, extensionOptions, host, keys, getPatternsForKey, comparePaths) {
133406
133478
  var pathResults = [];
133407
- var matchedPathPrefixLength = -1;
133408
- for (var path in paths) {
133409
- if (!ts.hasProperty(paths, path))
133479
+ var matchedPath;
133480
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
133481
+ var key = keys_1[_i];
133482
+ if (key === ".")
133410
133483
  continue;
133411
- var patterns = paths[path];
133484
+ var keyWithoutLeadingDotSlash = key.replace(/^\.\//, ""); // remove leading "./"
133485
+ var patterns = getPatternsForKey(key);
133412
133486
  if (patterns) {
133413
- var pathPattern = ts.tryParsePattern(path);
133487
+ var pathPattern = ts.tryParsePattern(keyWithoutLeadingDotSlash);
133414
133488
  if (!pathPattern)
133415
133489
  continue;
133416
133490
  var isMatch = typeof pathPattern === "object" && ts.isPatternMatch(pathPattern, fragment);
133417
- var isLongestMatch = isMatch && (matchedPathPrefixLength === undefined || pathPattern.prefix.length > matchedPathPrefixLength);
133491
+ var isLongestMatch = isMatch && (matchedPath === undefined || comparePaths(key, matchedPath) === -1 /* LessThan */);
133418
133492
  if (isLongestMatch) {
133419
133493
  // If this is a higher priority match than anything we've seen so far, previous results from matches are invalid, e.g.
133420
133494
  // for `import {} from "some-package/|"` with a typesVersions:
@@ -133427,13 +133501,13 @@ var ts;
133427
133501
  // added by the '*' match, after typing `"some-package/foo/|"` we would get file results from both
133428
133502
  // ./dist/foo and ./foo, when only the latter will actually be resolvable.
133429
133503
  // See pathCompletionsTypesVersionsWildcard6.ts.
133430
- matchedPathPrefixLength = pathPattern.prefix.length;
133504
+ matchedPath = key;
133431
133505
  pathResults = pathResults.filter(function (r) { return !r.matchedPattern; });
133432
133506
  }
133433
- if (typeof pathPattern === "string" || matchedPathPrefixLength === undefined || pathPattern.prefix.length >= matchedPathPrefixLength) {
133507
+ if (typeof pathPattern === "string" || matchedPath === undefined || comparePaths(key, matchedPath) !== 1 /* GreaterThan */) {
133434
133508
  pathResults.push({
133435
133509
  matchedPattern: isMatch,
133436
- results: getCompletionsForPathMapping(path, patterns, fragment, baseDirectory, fileExtensions, host)
133510
+ results: getCompletionsForPathMapping(keyWithoutLeadingDotSlash, patterns, fragment, baseDirectory, extensionOptions, host)
133437
133511
  .map(function (_a) {
133438
133512
  var name = _a.name, kind = _a.kind, extension = _a.extension;
133439
133513
  return nameAndKind(name, kind, extension);
@@ -133442,10 +133516,8 @@ var ts;
133442
133516
  }
133443
133517
  }
133444
133518
  }
133445
- var equatePaths = ((_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host)) ? ts.equateStringsCaseSensitive : ts.equateStringsCaseInsensitive;
133446
- var equateResults = function (a, b) { return equatePaths(a.name, b.name); };
133447
- pathResults.forEach(function (pathResult) { return pathResult.results.forEach(function (pathResult) { return ts.pushIfUnique(result, pathResult, equateResults); }); });
133448
- return matchedPathPrefixLength > -1;
133519
+ pathResults.forEach(function (pathResult) { return pathResult.results.forEach(function (r) { return result.add(r); }); });
133520
+ return matchedPath !== undefined;
133449
133521
  }
133450
133522
  /**
133451
133523
  * Check all of the declared modules and those in node modules. Possible sources of modules:
@@ -133454,22 +133526,22 @@ var ts;
133454
133526
  * Modules from node_modules (i.e. those listed in package.json)
133455
133527
  * This includes all files that are found in node_modules/moduleName/ with acceptable file extensions
133456
133528
  */
133457
- function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, compilerOptions, host, typeChecker) {
133529
+ function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, compilerOptions, host, includeExtensionsOption, typeChecker) {
133458
133530
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths;
133459
- var result = [];
133460
- var extensionOptions = getExtensionOptions(compilerOptions);
133531
+ var result = createNameAndKindSet();
133532
+ var extensionOptions = getExtensionOptions(compilerOptions, includeExtensionsOption);
133461
133533
  if (baseUrl) {
133462
133534
  var projectDir = compilerOptions.project || host.getCurrentDirectory();
133463
133535
  var absolute = ts.normalizePath(ts.combinePaths(projectDir, baseUrl));
133464
133536
  getCompletionEntriesForDirectoryFragment(fragment, absolute, extensionOptions, host, /*exclude*/ undefined, result);
133465
133537
  if (paths) {
133466
- addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions.extensions, paths, host);
133538
+ addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions, host, paths);
133467
133539
  }
133468
133540
  }
133469
133541
  var fragmentDirectory = getFragmentDirectory(fragment);
133470
133542
  for (var _i = 0, _a = getAmbientModuleCompletions(fragment, fragmentDirectory, typeChecker); _i < _a.length; _i++) {
133471
133543
  var ambientName = _a[_i];
133472
- result.push(nameAndKind(ambientName, "external module name" /* externalModuleName */, /*extension*/ undefined));
133544
+ result.add(nameAndKind(ambientName, "external module name" /* externalModuleName */, /*extension*/ undefined));
133473
133545
  }
133474
133546
  getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, fragmentDirectory, extensionOptions, result);
133475
133547
  if (isEmitResolutionKindUsingNodeModules(compilerOptions)) {
@@ -133477,15 +133549,13 @@ var ts;
133477
133549
  // (But do if we didn't find anything, e.g. 'package.json' missing.)
133478
133550
  var foundGlobal = false;
133479
133551
  if (fragmentDirectory === undefined) {
133480
- var _loop_3 = function (moduleName) {
133481
- if (!result.some(function (entry) { return entry.name === moduleName; })) {
133482
- foundGlobal = true;
133483
- result.push(nameAndKind(moduleName, "external module name" /* externalModuleName */, /*extension*/ undefined));
133484
- }
133485
- };
133486
133552
  for (var _b = 0, _c = enumerateNodeModulesVisibleToScript(host, scriptPath); _b < _c.length; _b++) {
133487
133553
  var moduleName = _c[_b];
133488
- _loop_3(moduleName);
133554
+ var moduleResult = nameAndKind(moduleName, "external module name" /* externalModuleName */, /*extension*/ undefined);
133555
+ if (!result.has(moduleResult.name)) {
133556
+ foundGlobal = true;
133557
+ result.add(moduleResult);
133558
+ }
133489
133559
  }
133490
133560
  }
133491
133561
  if (!foundGlobal) {
@@ -133511,39 +133581,19 @@ var ts;
133511
133581
  }
133512
133582
  packagePath = ts.combinePaths(packagePath, subName);
133513
133583
  }
133514
- var packageFile = ts.combinePaths(ancestor, "node_modules", packagePath, "package.json");
133584
+ var packageDirectory = ts.combinePaths(ancestor, "node_modules", packagePath);
133585
+ var packageFile = ts.combinePaths(packageDirectory, "package.json");
133515
133586
  if (ts.tryFileExists(host, packageFile)) {
133516
133587
  var packageJson = ts.readJson(packageFile, host);
133517
- var exports = packageJson.exports;
133518
- if (exports) {
133519
- if (typeof exports !== "object" || exports === null) { // eslint-disable-line no-null/no-null
133588
+ var exports_1 = packageJson.exports;
133589
+ if (exports_1) {
133590
+ if (typeof exports_1 !== "object" || exports_1 === null) { // eslint-disable-line no-null/no-null
133520
133591
  return; // null exports or entrypoint only, no sub-modules available
133521
133592
  }
133522
- var keys = ts.getOwnKeys(exports);
133523
- var fragmentSubpath_1 = components.join("/");
133524
- var processedKeys = ts.mapDefined(keys, function (k) {
133525
- if (k === ".")
133526
- return undefined;
133527
- if (!ts.startsWith(k, "./"))
133528
- return undefined;
133529
- var subpath = k.substring(2);
133530
- if (!ts.startsWith(subpath, fragmentSubpath_1))
133531
- return undefined;
133532
- // subpath is a valid export (barring conditions, which we don't currently check here)
133533
- if (!ts.stringContains(subpath, "*")) {
133534
- return subpath;
133535
- }
133536
- // pattern export - only return everything up to the `*`, so the user can autocomplete, then
133537
- // keep filling in the pattern (we could speculatively return a list of options by hitting disk,
133538
- // but conditions will make that somewhat awkward, as each condition may have a different set of possible
133539
- // options for the `*`.
133540
- return subpath.slice(0, subpath.indexOf("*"));
133541
- });
133542
- ts.forEach(processedKeys, function (k) {
133543
- if (k) {
133544
- result.push(nameAndKind(k, "external module name" /* externalModuleName */, /*extension*/ undefined));
133545
- }
133546
- });
133593
+ var keys = ts.getOwnKeys(exports_1);
133594
+ var fragmentSubpath = components.join("/") + (components.length && ts.hasTrailingDirectorySeparator(fragment) ? "/" : "");
133595
+ var conditions_1 = mode === ts.ModuleKind.ESNext ? ["node", "import", "types"] : ["node", "require", "types"];
133596
+ addCompletionEntriesFromPathsOrExports(result, fragmentSubpath, packageDirectory, extensionOptions, host, keys, function (key) { return ts.singleElementArray(getPatternFromFirstMatchingCondition(exports_1[key], conditions_1)); }, ts.comparePatternKeys);
133547
133597
  return;
133548
133598
  }
133549
133599
  }
@@ -133553,31 +133603,44 @@ var ts;
133553
133603
  ts.forEachAncestorDirectory(scriptPath, ancestorLookup);
133554
133604
  }
133555
133605
  }
133556
- return result;
133606
+ return ts.arrayFrom(result.values());
133607
+ }
133608
+ function getPatternFromFirstMatchingCondition(target, conditions) {
133609
+ if (typeof target === "string") {
133610
+ return target;
133611
+ }
133612
+ if (target && typeof target === "object" && !ts.isArray(target)) {
133613
+ for (var condition in target) {
133614
+ if (condition === "default" || conditions.indexOf(condition) > -1 || ts.isApplicableVersionedTypesKey(conditions, condition)) {
133615
+ var pattern = target[condition];
133616
+ return getPatternFromFirstMatchingCondition(pattern, conditions);
133617
+ }
133618
+ }
133619
+ }
133557
133620
  }
133558
133621
  function getFragmentDirectory(fragment) {
133559
133622
  return containsSlash(fragment) ? ts.hasTrailingDirectorySeparator(fragment) ? fragment : ts.getDirectoryPath(fragment) : undefined;
133560
133623
  }
133561
- function getCompletionsForPathMapping(path, patterns, fragment, baseUrl, fileExtensions, host) {
133624
+ function getCompletionsForPathMapping(path, patterns, fragment, packageDirectory, extensionOptions, host) {
133562
133625
  if (!ts.endsWith(path, "*")) {
133563
133626
  // For a path mapping "foo": ["/x/y/z.ts"], add "foo" itself as a completion.
133564
- return !ts.stringContains(path, "*") ? justPathMappingName(path) : ts.emptyArray;
133627
+ return !ts.stringContains(path, "*") ? justPathMappingName(path, "script" /* scriptElement */) : ts.emptyArray;
133565
133628
  }
133566
133629
  var pathPrefix = path.slice(0, path.length - 1);
133567
133630
  var remainingFragment = ts.tryRemovePrefix(fragment, pathPrefix);
133568
133631
  if (remainingFragment === undefined) {
133569
133632
  var starIsFullPathComponent = path[path.length - 2] === "/";
133570
- 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) {
133633
+ 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) {
133571
133634
  var name = _a.name, rest = __rest(_a, ["name"]);
133572
133635
  return (__assign({ name: pathPrefix + name }, rest));
133573
133636
  }); });
133574
133637
  }
133575
- return ts.flatMap(patterns, function (pattern) { return getModulesForPathsPattern(remainingFragment, baseUrl, pattern, fileExtensions, host); });
133576
- function justPathMappingName(name) {
133577
- return ts.startsWith(name, fragment) ? [directoryResult(ts.removeTrailingDirectorySeparator(name))] : ts.emptyArray;
133638
+ return ts.flatMap(patterns, function (pattern) { return getModulesForPathsPattern(remainingFragment, packageDirectory, pattern, extensionOptions, host); });
133639
+ function justPathMappingName(name, kind) {
133640
+ return ts.startsWith(name, fragment) ? [{ name: ts.removeTrailingDirectorySeparator(name), kind: kind, extension: undefined }] : ts.emptyArray;
133578
133641
  }
133579
133642
  }
133580
- function getModulesForPathsPattern(fragment, baseUrl, pattern, fileExtensions, host) {
133643
+ function getModulesForPathsPattern(fragment, packageDirectory, pattern, extensionOptions, host) {
133581
133644
  if (!host.readDirectory) {
133582
133645
  return undefined;
133583
133646
  }
@@ -133596,21 +133659,33 @@ var ts;
133596
133659
  var expandedPrefixDirectory = fragmentHasPath ? ts.combinePaths(normalizedPrefixDirectory, normalizedPrefixBase + fragmentDirectory) : normalizedPrefixDirectory;
133597
133660
  var normalizedSuffix = ts.normalizePath(parsed.suffix);
133598
133661
  // Need to normalize after combining: If we combinePaths("a", "../b"), we want "b" and not "a/../b".
133599
- var baseDirectory = ts.normalizePath(ts.combinePaths(baseUrl, expandedPrefixDirectory));
133662
+ var baseDirectory = ts.normalizePath(ts.combinePaths(packageDirectory, expandedPrefixDirectory));
133600
133663
  var completePrefix = fragmentHasPath ? baseDirectory : ts.ensureTrailingDirectorySeparator(baseDirectory) + normalizedPrefixBase;
133601
- // If we have a suffix, then we need to read the directory all the way down. We could create a glob
133602
- // that encodes the suffix, but we would have to escape the character "?" which readDirectory
133603
- // doesn't support. For now, this is safer but slower
133604
- var includeGlob = normalizedSuffix ? "**/*" : "./*";
133605
- var matches = ts.mapDefined(ts.tryReadDirectory(host, baseDirectory, fileExtensions, /*exclude*/ undefined, [includeGlob]), function (match) {
133606
- var extension = ts.tryGetExtensionFromPath(match);
133607
- var name = trimPrefixAndSuffix(match);
133608
- return name === undefined ? undefined : nameAndKind(ts.removeFileExtension(name), "script" /* scriptElement */, extension);
133609
- });
133610
- var directories = ts.mapDefined(ts.tryGetDirectories(host, baseDirectory).map(function (d) { return ts.combinePaths(baseDirectory, d); }), function (dir) {
133611
- var name = trimPrefixAndSuffix(dir);
133612
- return name === undefined ? undefined : directoryResult(name);
133664
+ // If we have a suffix, then we read the directory all the way down to avoid returning completions for
133665
+ // directories that don't contain files that would match the suffix. A previous comment here was concerned
133666
+ // about the case where `normalizedSuffix` includes a `?` character, which should be interpreted literally,
133667
+ // but will match any single character as part of the `include` pattern in `tryReadDirectory`. This is not
133668
+ // a problem, because (in the extremely unusual circumstance where the suffix has a `?` in it) a `?`
133669
+ // interpreted as "any character" can only return *too many* results as compared to the literal
133670
+ // interpretation, so we can filter those superfluous results out via `trimPrefixAndSuffix` as we've always
133671
+ // done.
133672
+ var includeGlob = normalizedSuffix ? "**/*" + normalizedSuffix : "./*";
133673
+ var matches = ts.mapDefined(ts.tryReadDirectory(host, baseDirectory, extensionOptions.extensions, /*exclude*/ undefined, [includeGlob]), function (match) {
133674
+ var trimmedWithPattern = trimPrefixAndSuffix(match);
133675
+ if (trimmedWithPattern) {
133676
+ if (containsSlash(trimmedWithPattern)) {
133677
+ return directoryResult(ts.getPathComponents(removeLeadingDirectorySeparator(trimmedWithPattern))[1]);
133678
+ }
133679
+ var _a = getFilenameWithExtensionOption(trimmedWithPattern, host.getCompilationSettings(), extensionOptions.includeExtensionsOption), name = _a.name, extension = _a.extension;
133680
+ return nameAndKind(name, "script" /* scriptElement */, extension);
133681
+ }
133613
133682
  });
133683
+ // If we had a suffix, we already recursively searched for all possible files that could match
133684
+ // it and returned the directories leading to those files. Otherwise, assume any directory could
133685
+ // have something valid to import.
133686
+ var directories = normalizedSuffix
133687
+ ? ts.emptyArray
133688
+ : ts.mapDefined(ts.tryGetDirectories(host, baseDirectory), function (dir) { return dir === "node_modules" ? undefined : directoryResult(dir); });
133614
133689
  return __spreadArray(__spreadArray([], matches, true), directories, true);
133615
133690
  function trimPrefixAndSuffix(path) {
133616
133691
  var inner = withoutStartAndEnd(ts.normalizePath(path), completePrefix, normalizedSuffix);
@@ -133653,10 +133728,10 @@ var ts;
133653
133728
  var names = kind === "path" ? getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getExtensionOptions(compilerOptions, 1 /* Include */), host, sourceFile.path)
133654
133729
  : kind === "types" ? getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, getFragmentDirectory(toComplete), getExtensionOptions(compilerOptions))
133655
133730
  : ts.Debug.fail();
133656
- return addReplacementSpans(toComplete, range.pos + prefix.length, names);
133731
+ return addReplacementSpans(toComplete, range.pos + prefix.length, ts.arrayFrom(names.values()));
133657
133732
  }
133658
133733
  function getCompletionEntriesFromTypings(host, options, scriptPath, fragmentDirectory, extensionOptions, result) {
133659
- if (result === void 0) { result = []; }
133734
+ if (result === void 0) { result = createNameAndKindSet(); }
133660
133735
  // Check for typings specified in compiler options
133661
133736
  var seen = new ts.Map();
133662
133737
  var typeRoots = ts.tryAndIgnoreErrors(function () { return ts.getEffectiveTypeRoots(options, host); }) || ts.emptyArray;
@@ -133681,7 +133756,7 @@ var ts;
133681
133756
  continue;
133682
133757
  if (fragmentDirectory === undefined) {
133683
133758
  if (!seen.has(packageName)) {
133684
- result.push(nameAndKind(packageName, "external module name" /* externalModuleName */, /*extension*/ undefined));
133759
+ result.add(nameAndKind(packageName, "external module name" /* externalModuleName */, /*extension*/ undefined));
133685
133760
  seen.set(packageName, true);
133686
133761
  }
133687
133762
  }
@@ -139282,7 +139357,7 @@ var ts;
139282
139357
  result = references;
139283
139358
  continue;
139284
139359
  }
139285
- var _loop_4 = function (entry) {
139360
+ var _loop_3 = function (entry) {
139286
139361
  if (!entry.definition || entry.definition.type !== 0 /* Symbol */) {
139287
139362
  result.push(entry);
139288
139363
  return "continue";
@@ -139314,7 +139389,7 @@ var ts;
139314
139389
  };
139315
139390
  for (var _b = 0, references_2 = references; _b < references_2.length; _b++) {
139316
139391
  var entry = references_2[_b];
139317
- _loop_4(entry);
139392
+ _loop_3(entry);
139318
139393
  }
139319
139394
  }
139320
139395
  return result;
@@ -140895,8 +140970,8 @@ var ts;
140895
140970
  var declarations;
140896
140971
  if (symbol && symbol.declarations) {
140897
140972
  var indices = ts.indicesOf(symbol.declarations);
140898
- var keys_1 = ts.map(symbol.declarations, function (decl) { return ({ file: decl.getSourceFile().fileName, pos: decl.pos }); });
140899
- indices.sort(function (a, b) { return ts.compareStringsCaseSensitive(keys_1[a].file, keys_1[b].file) || keys_1[a].pos - keys_1[b].pos; });
140973
+ var keys_2 = ts.map(symbol.declarations, function (decl) { return ({ file: decl.getSourceFile().fileName, pos: decl.pos }); });
140974
+ indices.sort(function (a, b) { return ts.compareStringsCaseSensitive(keys_2[a].file, keys_2[b].file) || keys_2[a].pos - keys_2[b].pos; });
140900
140975
  var sortedDeclarations = ts.map(indices, function (i) { return symbol.declarations[i]; });
140901
140976
  var lastDecl = void 0;
140902
140977
  for (var _i = 0, sortedDeclarations_1 = sortedDeclarations; _i < sortedDeclarations_1.length; _i++) {
@@ -141344,7 +141419,7 @@ var ts;
141344
141419
  }
141345
141420
  function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
141346
141421
  var allFiles = program.getSourceFiles();
141347
- var _loop_5 = function (sourceFile) {
141422
+ var _loop_4 = function (sourceFile) {
141348
141423
  var newFromOld = oldToNew(sourceFile.fileName);
141349
141424
  var newImportFromPath = newFromOld !== null && newFromOld !== void 0 ? newFromOld : sourceFile.fileName;
141350
141425
  var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -141376,7 +141451,7 @@ var ts;
141376
141451
  };
141377
141452
  for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
141378
141453
  var sourceFile = allFiles_1[_i];
141379
- _loop_5(sourceFile);
141454
+ _loop_4(sourceFile);
141380
141455
  }
141381
141456
  }
141382
141457
  function combineNormal(pathA, pathB) {
@@ -142400,7 +142475,7 @@ var ts;
142400
142475
  if (!patternMatcher)
142401
142476
  return ts.emptyArray;
142402
142477
  var rawItems = [];
142403
- var _loop_6 = function (sourceFile) {
142478
+ var _loop_5 = function (sourceFile) {
142404
142479
  cancellationToken.throwIfCancellationRequested();
142405
142480
  if (excludeDtsFiles && sourceFile.isDeclarationFile) {
142406
142481
  return "continue";
@@ -142412,7 +142487,7 @@ var ts;
142412
142487
  // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
142413
142488
  for (var _i = 0, sourceFiles_4 = sourceFiles; _i < sourceFiles_4.length; _i++) {
142414
142489
  var sourceFile = sourceFiles_4[_i];
142415
- _loop_6(sourceFile);
142490
+ _loop_5(sourceFile);
142416
142491
  }
142417
142492
  rawItems.sort(compareNavigateToItems);
142418
142493
  return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -144475,13 +144550,13 @@ var ts;
144475
144550
  // Assumes 'value' is already lowercase.
144476
144551
  function indexOfIgnoringCase(str, value) {
144477
144552
  var n = str.length - value.length;
144478
- var _loop_7 = function (start) {
144553
+ var _loop_6 = function (start) {
144479
144554
  if (every(value, function (valueChar, i) { return toLowerCase(str.charCodeAt(i + start)) === valueChar; })) {
144480
144555
  return { value: start };
144481
144556
  }
144482
144557
  };
144483
144558
  for (var start = 0; start <= n; start++) {
144484
- var state_3 = _loop_7(start);
144559
+ var state_3 = _loop_6(start);
144485
144560
  if (typeof state_3 === "object")
144486
144561
  return state_3.value;
144487
144562
  }
@@ -145948,7 +146023,7 @@ var ts;
145948
146023
  return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
145949
146024
  }
145950
146025
  function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
145951
- var _loop_8 = function (n) {
146026
+ var _loop_7 = function (n) {
145952
146027
  // If the node is not a subspan of its parent, this is a big problem.
145953
146028
  // There have been crashes that might be caused by this violation.
145954
146029
  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); });
@@ -145958,7 +146033,7 @@ var ts;
145958
146033
  }
145959
146034
  };
145960
146035
  for (var n = node; !ts.isSourceFile(n) && (isManuallyInvoked || !ts.isBlock(n)); n = n.parent) {
145961
- var state_4 = _loop_8(n);
146036
+ var state_4 = _loop_7(n);
145962
146037
  if (typeof state_4 === "object")
145963
146038
  return state_4.value;
145964
146039
  }
@@ -147571,7 +147646,7 @@ var ts;
147571
147646
  commandLineOptionsStringToEnum = commandLineOptionsStringToEnum ||
147572
147647
  ts.filter(ts.optionDeclarations, function (o) { return typeof o.type === "object" && !ts.forEachEntry(o.type, function (v) { return typeof v !== "number"; }); });
147573
147648
  options = ts.cloneCompilerOptions(options);
147574
- var _loop_9 = function (opt) {
147649
+ var _loop_8 = function (opt) {
147575
147650
  if (!ts.hasProperty(options, opt.name)) {
147576
147651
  return "continue";
147577
147652
  }
@@ -147590,7 +147665,7 @@ var ts;
147590
147665
  };
147591
147666
  for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) {
147592
147667
  var opt = commandLineOptionsStringToEnum_1[_i];
147593
- _loop_9(opt);
147668
+ _loop_8(opt);
147594
147669
  }
147595
147670
  return options;
147596
147671
  }
@@ -151355,7 +151430,7 @@ var ts;
151355
151430
  ChangeTracker.prototype.finishDeleteDeclarations = function () {
151356
151431
  var _this = this;
151357
151432
  var deletedNodesInLists = new ts.Set(); // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
151358
- var _loop_10 = function (sourceFile, node) {
151433
+ var _loop_9 = function (sourceFile, node) {
151359
151434
  if (!this_1.deletedNodes.some(function (d) { return d.sourceFile === sourceFile && ts.rangeContainsRangeExclusive(d.node, node); })) {
151360
151435
  if (ts.isArray(node)) {
151361
151436
  this_1.deleteRange(sourceFile, ts.rangeOfTypeParameters(sourceFile, node));
@@ -151368,7 +151443,7 @@ var ts;
151368
151443
  var this_1 = this;
151369
151444
  for (var _i = 0, _a = this.deletedNodes; _i < _a.length; _i++) {
151370
151445
  var _b = _a[_i], sourceFile = _b.sourceFile, node = _b.node;
151371
- _loop_10(sourceFile, node);
151446
+ _loop_9(sourceFile, node);
151372
151447
  }
151373
151448
  deletedNodesInLists.forEach(function (node) {
151374
151449
  var sourceFile = node.getSourceFile();
@@ -151456,14 +151531,14 @@ var ts;
151456
151531
  // order changes by start position
151457
151532
  // 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.
151458
151533
  var normalized = ts.stableSort(changesInFile, function (a, b) { return (a.range.pos - b.range.pos) || (a.range.end - b.range.end); });
151459
- var _loop_11 = function (i) {
151534
+ var _loop_10 = function (i) {
151460
151535
  ts.Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos, "Changes overlap", function () {
151461
151536
  return JSON.stringify(normalized[i].range) + " and " + JSON.stringify(normalized[i + 1].range);
151462
151537
  });
151463
151538
  };
151464
151539
  // verify that change intervals do not overlap, except possibly at end points.
151465
151540
  for (var i = 0; i < normalized.length - 1; i++) {
151466
- _loop_11(i);
151541
+ _loop_10(i);
151467
151542
  }
151468
151543
  var textChanges = ts.mapDefined(normalized, function (c) {
151469
151544
  var span = ts.createTextSpanFromRange(c.range);
@@ -152371,7 +152446,7 @@ var ts;
152371
152446
  }
152372
152447
  var isCompleteFix = identifiers.isCompleteFix;
152373
152448
  var initializers;
152374
- var _loop_12 = function (identifier) {
152449
+ var _loop_11 = function (identifier) {
152375
152450
  var symbol = checker.getSymbolAtLocation(identifier);
152376
152451
  if (!symbol) {
152377
152452
  return "continue";
@@ -152404,7 +152479,7 @@ var ts;
152404
152479
  };
152405
152480
  for (var _i = 0, _a = identifiers.identifiers; _i < _a.length; _i++) {
152406
152481
  var identifier = _a[_i];
152407
- _loop_12(identifier);
152482
+ _loop_11(identifier);
152408
152483
  }
152409
152484
  return initializers && {
152410
152485
  initializers: initializers,
@@ -153289,7 +153364,7 @@ var ts;
153289
153364
  }
153290
153365
  var pos = ts.skipTrivia(sourceFile.text, ts.moveRangePastModifiers(functionToConvert).pos);
153291
153366
  changes.insertModifierAt(sourceFile, pos, 131 /* AsyncKeyword */, { suffix: " " });
153292
- var _loop_13 = function (returnStatement) {
153367
+ var _loop_12 = function (returnStatement) {
153293
153368
  ts.forEachChild(returnStatement, function visit(node) {
153294
153369
  if (ts.isCallExpression(node)) {
153295
153370
  var newNodes = transformExpression(node, node, transformer, /*hasContinuation*/ false);
@@ -153311,7 +153386,7 @@ var ts;
153311
153386
  };
153312
153387
  for (var _i = 0, returnStatements_1 = returnStatements; _i < returnStatements_1.length; _i++) {
153313
153388
  var returnStatement = returnStatements_1[_i];
153314
- var state_5 = _loop_13(returnStatement);
153389
+ var state_5 = _loop_12(returnStatement);
153315
153390
  if (typeof state_5 === "object")
153316
153391
  return state_5.value;
153317
153392
  }
@@ -156646,7 +156721,7 @@ var ts;
156646
156721
  });
156647
156722
  typeDeclToMembers.forEach(function (infos, declaration) {
156648
156723
  var supers = ts.isTypeLiteralNode(declaration) ? undefined : codefix.getAllSupers(declaration, checker);
156649
- var _loop_14 = function (info) {
156724
+ var _loop_13 = function (info) {
156650
156725
  // If some superclass added this property, don't add it again.
156651
156726
  if (supers === null || supers === void 0 ? void 0 : supers.some(function (superClassOrInterface) {
156652
156727
  var superInfos = typeDeclToMembers.get(superClassOrInterface);
@@ -156673,7 +156748,7 @@ var ts;
156673
156748
  };
156674
156749
  for (var _i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
156675
156750
  var info = infos_1[_i];
156676
- _loop_14(info);
156751
+ _loop_13(info);
156677
156752
  }
156678
156753
  });
156679
156754
  }));
@@ -159447,7 +159522,7 @@ var ts;
159447
159522
  function getSignatureFromCalls(calls) {
159448
159523
  var parameters = [];
159449
159524
  var length = Math.max.apply(Math, calls.map(function (c) { return c.argumentTypes.length; }));
159450
- var _loop_15 = function (i) {
159525
+ var _loop_14 = function (i) {
159451
159526
  var symbol = checker.createSymbol(1 /* FunctionScopedVariable */, ts.escapeLeadingUnderscores("arg" + i));
159452
159527
  symbol.type = combineTypes(calls.map(function (call) { return call.argumentTypes[i] || checker.getUndefinedType(); }));
159453
159528
  if (calls.some(function (call) { return call.argumentTypes[i] === undefined; })) {
@@ -159456,7 +159531,7 @@ var ts;
159456
159531
  parameters.push(symbol);
159457
159532
  };
159458
159533
  for (var i = 0; i < length; i++) {
159459
- _loop_15(i);
159534
+ _loop_14(i);
159460
159535
  }
159461
159536
  var returnType = combineFromUsage(combineUsages(calls.map(function (call) { return call.return_; })));
159462
159537
  return checker.createSignature(/*declaration*/ undefined, /*typeParameters*/ undefined, /*thisParameter*/ undefined, parameters, returnType, /*typePredicate*/ undefined, length, 0 /* None */);
@@ -161432,7 +161507,7 @@ var ts;
161432
161507
  // Imports that need to be kept as named imports in the refactored code, to avoid changing the semantics.
161433
161508
  // 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 }`.
161434
161509
  var neededNamedImports = new ts.Set();
161435
- var _loop_16 = function (element) {
161510
+ var _loop_15 = function (element) {
161436
161511
  var propertyName = (element.propertyName || element.name).text;
161437
161512
  ts.FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, function (id) {
161438
161513
  var access = ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(namespaceImportName), propertyName);
@@ -161449,7 +161524,7 @@ var ts;
161449
161524
  };
161450
161525
  for (var _i = 0, _a = toConvert.elements; _i < _a.length; _i++) {
161451
161526
  var element = _a[_i];
161452
- _loop_16(element);
161527
+ _loop_15(element);
161453
161528
  }
161454
161529
  changes.replaceNode(sourceFile, toConvert, shouldUseDefault
161455
161530
  ? ts.factory.createIdentifier(namespaceImportName)
@@ -163340,7 +163415,7 @@ var ts;
163340
163415
  : ts.getEnclosingBlockScopeContainer(scopes[0]);
163341
163416
  ts.forEachChild(containingLexicalScopeOfExtraction, checkForUsedDeclarations);
163342
163417
  }
163343
- var _loop_17 = function (i) {
163418
+ var _loop_16 = function (i) {
163344
163419
  var scopeUsages = usagesPerScope[i];
163345
163420
  // Special case: in the innermost scope, all usages are available.
163346
163421
  // (The computed value reflects the value at the top-level of the scope, but the
@@ -163383,7 +163458,7 @@ var ts;
163383
163458
  }
163384
163459
  };
163385
163460
  for (var i = 0; i < scopes.length; i++) {
163386
- _loop_17(i);
163461
+ _loop_16(i);
163387
163462
  }
163388
163463
  return { target: target, usagesPerScope: usagesPerScope, functionErrorsPerScope: functionErrorsPerScope, constantErrorsPerScope: constantErrorsPerScope, exposedVariableDeclarations: exposedVariableDeclarations };
163389
163464
  function isInGenericContext(node) {
@@ -164084,10 +164159,10 @@ var ts;
164084
164159
  }
164085
164160
  function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
164086
164161
  var checker = program.getTypeChecker();
164087
- var _loop_18 = function (sourceFile) {
164162
+ var _loop_17 = function (sourceFile) {
164088
164163
  if (sourceFile === oldFile)
164089
164164
  return "continue";
164090
- var _loop_19 = function (statement) {
164165
+ var _loop_18 = function (statement) {
164091
164166
  forEachImportInStatement(statement, function (importNode) {
164092
164167
  if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
164093
164168
  return;
@@ -164109,12 +164184,12 @@ var ts;
164109
164184
  };
164110
164185
  for (var _b = 0, _c = sourceFile.statements; _b < _c.length; _b++) {
164111
164186
  var statement = _c[_b];
164112
- _loop_19(statement);
164187
+ _loop_18(statement);
164113
164188
  }
164114
164189
  };
164115
164190
  for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
164116
164191
  var sourceFile = _a[_i];
164117
- _loop_18(sourceFile);
164192
+ _loop_17(sourceFile);
164118
164193
  }
164119
164194
  }
164120
164195
  function getNamespaceLikeImport(node) {
@@ -165477,7 +165552,7 @@ var ts;
165477
165552
  var templateSpans = [];
165478
165553
  var templateHead = ts.factory.createTemplateHead(headText, rawHeadText);
165479
165554
  copyCommentFromStringLiterals(headIndexes, templateHead);
165480
- var _loop_20 = function (i) {
165555
+ var _loop_19 = function (i) {
165481
165556
  var currentNode = getExpressionFromParenthesesOrExpression(nodes[i]);
165482
165557
  copyOperatorComments(i, currentNode);
165483
165558
  var _c = concatConsecutiveString(i + 1, nodes), newIndex = _c[0], subsequentText = _c[1], rawSubsequentText = _c[2], stringIndexes = _c[3];
@@ -165506,7 +165581,7 @@ var ts;
165506
165581
  };
165507
165582
  var out_i_1;
165508
165583
  for (var i = begin; i < nodes.length; i++) {
165509
- _loop_20(i);
165584
+ _loop_19(i);
165510
165585
  i = out_i_1;
165511
165586
  }
165512
165587
  return ts.factory.createTemplateExpression(templateHead, templateSpans);
@@ -166118,20 +166193,25 @@ var ts;
166118
166193
  return this.documentationComment;
166119
166194
  };
166120
166195
  SymbolObject.prototype.getContextualDocumentationComment = function (context, checker) {
166121
- switch (context === null || context === void 0 ? void 0 : context.kind) {
166122
- case 172 /* GetAccessor */:
166196
+ if (context) {
166197
+ if (ts.isGetAccessor(context)) {
166123
166198
  if (!this.contextualGetAccessorDocumentationComment) {
166124
166199
  this.contextualGetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isGetAccessor), checker);
166125
166200
  }
166126
- return this.contextualGetAccessorDocumentationComment;
166127
- case 173 /* SetAccessor */:
166201
+ if (ts.length(this.contextualGetAccessorDocumentationComment)) {
166202
+ return this.contextualGetAccessorDocumentationComment;
166203
+ }
166204
+ }
166205
+ if (ts.isSetAccessor(context)) {
166128
166206
  if (!this.contextualSetAccessorDocumentationComment) {
166129
166207
  this.contextualSetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isSetAccessor), checker);
166130
166208
  }
166131
- return this.contextualSetAccessorDocumentationComment;
166132
- default:
166133
- return this.getDocumentationComment(checker);
166209
+ if (ts.length(this.contextualSetAccessorDocumentationComment)) {
166210
+ return this.contextualSetAccessorDocumentationComment;
166211
+ }
166212
+ }
166134
166213
  }
166214
+ return this.getDocumentationComment(checker);
166135
166215
  };
166136
166216
  SymbolObject.prototype.getJsDocTags = function (checker) {
166137
166217
  if (this.tags === undefined) {
@@ -166140,20 +166220,25 @@ var ts;
166140
166220
  return this.tags;
166141
166221
  };
166142
166222
  SymbolObject.prototype.getContextualJsDocTags = function (context, checker) {
166143
- switch (context === null || context === void 0 ? void 0 : context.kind) {
166144
- case 172 /* GetAccessor */:
166223
+ if (context) {
166224
+ if (ts.isGetAccessor(context)) {
166145
166225
  if (!this.contextualGetAccessorTags) {
166146
166226
  this.contextualGetAccessorTags = getJsDocTagsOfDeclarations(ts.filter(this.declarations, ts.isGetAccessor), checker);
166147
166227
  }
166148
- return this.contextualGetAccessorTags;
166149
- case 173 /* SetAccessor */:
166228
+ if (ts.length(this.contextualGetAccessorTags)) {
166229
+ return this.contextualGetAccessorTags;
166230
+ }
166231
+ }
166232
+ if (ts.isSetAccessor(context)) {
166150
166233
  if (!this.contextualSetAccessorTags) {
166151
166234
  this.contextualSetAccessorTags = getJsDocTagsOfDeclarations(ts.filter(this.declarations, ts.isSetAccessor), checker);
166152
166235
  }
166153
- return this.contextualSetAccessorTags;
166154
- default:
166155
- return this.getJsDocTags(checker);
166236
+ if (ts.length(this.contextualSetAccessorTags)) {
166237
+ return this.contextualSetAccessorTags;
166238
+ }
166239
+ }
166156
166240
  }
166241
+ return this.getJsDocTags(checker);
166157
166242
  };
166158
166243
  return SymbolObject;
166159
166244
  }());
@@ -166342,7 +166427,7 @@ var ts;
166342
166427
  var tags = ts.JsDoc.getJsDocTagsFromDeclarations(declarations, checker);
166343
166428
  if (checker && (tags.length === 0 || declarations.some(hasJSDocInheritDocTag))) {
166344
166429
  var seenSymbols_1 = new ts.Set();
166345
- var _loop_21 = function (declaration) {
166430
+ var _loop_20 = function (declaration) {
166346
166431
  var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) {
166347
166432
  var _a;
166348
166433
  if (!seenSymbols_1.has(symbol)) {
@@ -166359,7 +166444,7 @@ var ts;
166359
166444
  };
166360
166445
  for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
166361
166446
  var declaration = declarations_7[_i];
166362
- _loop_21(declaration);
166447
+ _loop_20(declaration);
166363
166448
  }
166364
166449
  }
166365
166450
  return tags;
@@ -166370,7 +166455,7 @@ var ts;
166370
166455
  var doc = ts.JsDoc.getJsDocCommentsFromDeclarations(declarations, checker);
166371
166456
  if (checker && (doc.length === 0 || declarations.some(hasJSDocInheritDocTag))) {
166372
166457
  var seenSymbols_2 = new ts.Set();
166373
- var _loop_22 = function (declaration) {
166458
+ var _loop_21 = function (declaration) {
166374
166459
  var inheritedDocs = findBaseOfDeclaration(checker, declaration, function (symbol) {
166375
166460
  if (!seenSymbols_2.has(symbol)) {
166376
166461
  seenSymbols_2.add(symbol);
@@ -166386,7 +166471,7 @@ var ts;
166386
166471
  };
166387
166472
  for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
166388
166473
  var declaration = declarations_8[_i];
166389
- _loop_22(declaration);
166474
+ _loop_21(declaration);
166390
166475
  }
166391
166476
  }
166392
166477
  return doc;
@@ -166904,7 +166989,10 @@ var ts;
166904
166989
  program = undefined; // TODO: GH#18217
166905
166990
  lastTypesRootVersion = typeRootsVersion;
166906
166991
  }
166907
- var rootFileNames = host.getScriptFileNames();
166992
+ // This array is retained by the program and will be used to determine if the program is up to date,
166993
+ // so we need to make a copy in case the host mutates the underlying array - otherwise it would look
166994
+ // like every program always has the host's current list of root files.
166995
+ var rootFileNames = host.getScriptFileNames().slice();
166908
166996
  // Get a fresh cache of the host information
166909
166997
  var newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();
166910
166998
  var hasInvalidatedResolution = host.hasInvalidatedResolution || ts.returnFalse;