typescript 4.8.0-dev.20220728 → 4.8.0-dev.20220729

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.
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220728";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220729";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -1904,6 +1904,10 @@ var ts;
1904
1904
  /** Does nothing. */
1905
1905
  function noop(_) { }
1906
1906
  ts.noop = noop;
1907
+ ts.noopPush = {
1908
+ push: noop,
1909
+ length: 0
1910
+ };
1907
1911
  /** Do nothing and return false */
1908
1912
  function returnFalse() {
1909
1913
  return false;
@@ -8985,6 +8989,7 @@ var ts;
8985
8989
  Cannot_create_an_instance_of_an_abstract_class: diag(2511, ts.DiagnosticCategory.Error, "Cannot_create_an_instance_of_an_abstract_class_2511", "Cannot create an instance of an abstract class."),
8986
8990
  Overload_signatures_must_all_be_abstract_or_non_abstract: diag(2512, ts.DiagnosticCategory.Error, "Overload_signatures_must_all_be_abstract_or_non_abstract_2512", "Overload signatures must all be abstract or non-abstract."),
8987
8991
  Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression: diag(2513, ts.DiagnosticCategory.Error, "Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression_2513", "Abstract method '{0}' in class '{1}' cannot be accessed via super expression."),
8992
+ A_tuple_type_cannot_be_indexed_with_a_negative_value: diag(2514, ts.DiagnosticCategory.Error, "A_tuple_type_cannot_be_indexed_with_a_negative_value_2514", "A tuple type cannot be indexed with a negative value."),
8988
8993
  Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: diag(2515, ts.DiagnosticCategory.Error, "Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2_2515", "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'."),
8989
8994
  All_declarations_of_an_abstract_method_must_be_consecutive: diag(2516, ts.DiagnosticCategory.Error, "All_declarations_of_an_abstract_method_must_be_consecutive_2516", "All declarations of an abstract method must be consecutive."),
8990
8995
  Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: diag(2517, ts.DiagnosticCategory.Error, "Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type_2517", "Cannot assign an abstract constructor type to a non-abstract constructor type."),
@@ -43339,18 +43344,7 @@ var ts;
43339
43344
  * Does not try `@types/${packageName}` - use a second pass if needed.
43340
43345
  */
43341
43346
  function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
43342
- var moduleResolutionState = {
43343
- compilerOptions: options,
43344
- host: host,
43345
- traceEnabled: isTraceEnabled(options, host),
43346
- failedLookupLocations: [],
43347
- affectingLocations: [],
43348
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
43349
- conditions: ts.emptyArray,
43350
- features: NodeResolutionFeatures.None,
43351
- requestContainingDirectory: containingDirectory,
43352
- reportDiagnostic: ts.noop
43353
- };
43347
+ var moduleResolutionState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
43354
43348
  return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
43355
43349
  if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
43356
43350
  var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
@@ -44310,18 +44304,9 @@ var ts;
44310
44304
  var entrypoints;
44311
44305
  var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
44312
44306
  var features = getDefaultNodeResolutionFeatures(options);
44313
- var requireState = {
44314
- compilerOptions: options,
44315
- host: host,
44316
- traceEnabled: isTraceEnabled(options, host),
44317
- failedLookupLocations: [],
44318
- affectingLocations: [],
44319
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
44320
- conditions: ["node", "require", "types"],
44321
- features: features,
44322
- requestContainingDirectory: packageJsonInfo.packageDirectory,
44323
- reportDiagnostic: ts.noop
44324
- };
44307
+ var requireState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
44308
+ requireState.conditions = ["node", "require", "types"];
44309
+ requireState.requestContainingDirectory = packageJsonInfo.packageDirectory;
44325
44310
  var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
44326
44311
  /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
44327
44312
  entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
@@ -44394,23 +44379,27 @@ var ts;
44394
44379
  }
44395
44380
  }
44396
44381
  }
44397
- /**
44398
- * A function for locating the package.json scope for a given path
44399
- */
44400
44382
  /*@internal*/
44401
- function getPackageScopeForPath(fileName, packageJsonInfoCache, host, options) {
44402
- var state = {
44383
+ function getTemporaryModuleResolutionState(packageJsonInfoCache, host, options) {
44384
+ return {
44403
44385
  host: host,
44404
44386
  compilerOptions: options,
44405
44387
  traceEnabled: isTraceEnabled(options, host),
44406
- failedLookupLocations: [],
44407
- affectingLocations: [],
44388
+ failedLookupLocations: ts.noopPush,
44389
+ affectingLocations: ts.noopPush,
44408
44390
  packageJsonInfoCache: packageJsonInfoCache,
44409
- features: 0,
44410
- conditions: [],
44391
+ features: NodeResolutionFeatures.None,
44392
+ conditions: ts.emptyArray,
44411
44393
  requestContainingDirectory: undefined,
44412
44394
  reportDiagnostic: ts.noop
44413
44395
  };
44396
+ }
44397
+ ts.getTemporaryModuleResolutionState = getTemporaryModuleResolutionState;
44398
+ /**
44399
+ * A function for locating the package.json scope for a given path
44400
+ */
44401
+ /*@internal*/
44402
+ function getPackageScopeForPath(fileName, state) {
44414
44403
  var parts = ts.getPathComponents(fileName);
44415
44404
  parts.pop();
44416
44405
  while (parts.length > 0) {
@@ -44581,7 +44570,7 @@ var ts;
44581
44570
  var _a, _b;
44582
44571
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44583
44572
  var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames));
44584
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44573
+ var scope = getPackageScopeForPath(directoryPath, state);
44585
44574
  if (!scope || !scope.packageJsonContent.exports) {
44586
44575
  return undefined;
44587
44576
  }
@@ -44640,7 +44629,7 @@ var ts;
44640
44629
  }
44641
44630
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44642
44631
  var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames));
44643
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44632
+ var scope = getPackageScopeForPath(directoryPath, state);
44644
44633
  if (!scope) {
44645
44634
  if (state.traceEnabled) {
44646
44635
  trace(state.host, ts.Diagnostics.Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve, directoryPath);
@@ -53100,6 +53089,12 @@ var ts;
53100
53089
  return context.truncating = context.approximateLength > ((context.flags & 1 /* NoTruncation */) ? ts.noTruncationMaximumTruncationLength : ts.defaultMaximumTruncationLength);
53101
53090
  }
53102
53091
  function typeToTypeNodeHelper(type, context) {
53092
+ var savedFlags = context.flags;
53093
+ var typeNode = typeToTypeNodeWorker(type, context);
53094
+ context.flags = savedFlags;
53095
+ return typeNode;
53096
+ }
53097
+ function typeToTypeNodeWorker(type, context) {
53103
53098
  if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
53104
53099
  cancellationToken.throwIfCancellationRequested();
53105
53100
  }
@@ -62838,21 +62833,28 @@ var ts;
62838
62833
  getFlowTypeOfReference(accessExpression, propType) :
62839
62834
  propType;
62840
62835
  }
62841
- if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
62836
+ if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName)) {
62837
+ var index = +propName;
62842
62838
  if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
62843
62839
  var indexNode = getIndexNodeForAccessExpression(accessNode);
62844
62840
  if (isTupleType(objectType)) {
62841
+ if (index < 0) {
62842
+ error(indexNode, ts.Diagnostics.A_tuple_type_cannot_be_indexed_with_a_negative_value);
62843
+ return undefinedType;
62844
+ }
62845
62845
  error(indexNode, ts.Diagnostics.Tuple_type_0_of_length_1_has_no_element_at_index_2, typeToString(objectType), getTypeReferenceArity(objectType), ts.unescapeLeadingUnderscores(propName));
62846
62846
  }
62847
62847
  else {
62848
62848
  error(indexNode, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.unescapeLeadingUnderscores(propName), typeToString(objectType));
62849
62849
  }
62850
62850
  }
62851
- errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62852
- return mapType(objectType, function (t) {
62853
- var restType = getRestTypeOfTupleType(t) || undefinedType;
62854
- return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62855
- });
62851
+ if (index >= 0) {
62852
+ errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62853
+ return mapType(objectType, function (t) {
62854
+ var restType = getRestTypeOfTupleType(t) || undefinedType;
62855
+ return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62856
+ });
62857
+ }
62856
62858
  }
62857
62859
  }
62858
62860
  if (!(indexType.flags & 98304 /* Nullable */) && isTypeAssignableToKind(indexType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */)) {
@@ -117863,7 +117865,7 @@ var ts;
117863
117865
  return undefined;
117864
117866
  }
117865
117867
  function lookupFromPackageJson() {
117866
- var scope = ts.getPackageScopeForPath(fileName, packageJsonInfoCache, host, options);
117868
+ var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117867
117869
  return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117868
117870
  }
117869
117871
  }
@@ -149245,6 +149247,7 @@ var ts;
149245
149247
  var options = _a.options, getRules = _a.getRules, host = _a.host;
149246
149248
  // formatting context is used by rules provider
149247
149249
  var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options);
149250
+ var previousRangeTriviaEnd;
149248
149251
  var previousRange;
149249
149252
  var previousParent;
149250
149253
  var previousRangeStartLine;
@@ -149273,10 +149276,30 @@ var ts;
149273
149276
  }
149274
149277
  }
149275
149278
  if (previousRange && formattingScanner.getStartPos() >= originalRange.end) {
149279
+ // Formatting edits happen by looking at pairs of contiguous tokens (see `processPair`),
149280
+ // typically inserting or deleting whitespace between them. The recursive `processNode`
149281
+ // logic above bails out as soon as it encounters a token that is beyond the end of the
149282
+ // range we're supposed to format (or if we reach the end of the file). But this potentially
149283
+ // leaves out an edit that would occur *inside* the requested range but cannot be discovered
149284
+ // without looking at one token *beyond* the end of the range: consider the line `x = { }`
149285
+ // with a selection from the beginning of the line to the space inside the curly braces,
149286
+ // inclusive. We would expect a format-selection would delete the space (if rules apply),
149287
+ // but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
149288
+ // just before getting there. This block handles this trailing edit.
149276
149289
  var tokenInfo = formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() :
149277
149290
  formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token :
149278
149291
  undefined;
149279
- if (tokenInfo) {
149292
+ if (tokenInfo && tokenInfo.pos === previousRangeTriviaEnd) {
149293
+ // We need to check that tokenInfo and previousRange are contiguous: the `originalRange`
149294
+ // may have ended in the middle of a token, which means we will have stopped formatting
149295
+ // on that token, leaving `previousRange` pointing to the token before it, but already
149296
+ // having moved the formatting scanner (where we just got `tokenInfo`) to the next token.
149297
+ // If this happens, our supposed pair [previousRange, tokenInfo] actually straddles the
149298
+ // token that intersects the end of the range we're supposed to format, so the pair will
149299
+ // produce bogus edits if we try to `processPair`. Recall that the point of this logic is
149300
+ // to perform a trailing edit at the end of the selection range: but there can be no valid
149301
+ // edit in the middle of a token where the range ended, so if we have a non-contiguous
149302
+ // pair here, we're already done and we can ignore it.
149280
149303
  var parent = ((_b = ts.findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)) === null || _b === void 0 ? void 0 : _b.parent) || previousParent;
149281
149304
  processPair(tokenInfo, sourceFile.getLineAndCharacterOfPosition(tokenInfo.pos).line, parent, previousRange, previousRangeStartLine, previousParent, parent,
149282
149305
  /*dynamicIndentation*/ undefined);
@@ -149634,6 +149657,7 @@ var ts;
149634
149657
  }
149635
149658
  }
149636
149659
  if (currentTokenInfo.trailingTrivia) {
149660
+ previousRangeTriviaEnd = ts.last(currentTokenInfo.trailingTrivia).end;
149637
149661
  processTrivia(currentTokenInfo.trailingTrivia, parent, childContextNode, dynamicIndentation);
149638
149662
  }
149639
149663
  if (indentToken) {
@@ -149704,6 +149728,7 @@ var ts;
149704
149728
  }
149705
149729
  }
149706
149730
  previousRange = range;
149731
+ previousRangeTriviaEnd = range.end;
149707
149732
  previousParent = parent;
149708
149733
  previousRangeStartLine = rangeStart.line;
149709
149734
  return lineAction;
@@ -178634,7 +178659,7 @@ var ts;
178634
178659
  var packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex);
178635
178660
  var packageJsonCache = (_a = project.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache();
178636
178661
  var compilerOptions = project.getCompilationSettings();
178637
- var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), packageJsonCache, project, compilerOptions);
178662
+ var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), ts.getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions));
178638
178663
  if (!packageJson)
178639
178664
  return undefined;
178640
178665
  // Use fake options instead of actual compiler options to avoid following export map if the project uses node16 or nodenext -
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.20220728";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220729";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -1895,6 +1895,10 @@ var ts;
1895
1895
  /** Does nothing. */
1896
1896
  function noop(_) { }
1897
1897
  ts.noop = noop;
1898
+ ts.noopPush = {
1899
+ push: noop,
1900
+ length: 0
1901
+ };
1898
1902
  /** Do nothing and return false */
1899
1903
  function returnFalse() {
1900
1904
  return false;
@@ -8976,6 +8980,7 @@ var ts;
8976
8980
  Cannot_create_an_instance_of_an_abstract_class: diag(2511, ts.DiagnosticCategory.Error, "Cannot_create_an_instance_of_an_abstract_class_2511", "Cannot create an instance of an abstract class."),
8977
8981
  Overload_signatures_must_all_be_abstract_or_non_abstract: diag(2512, ts.DiagnosticCategory.Error, "Overload_signatures_must_all_be_abstract_or_non_abstract_2512", "Overload signatures must all be abstract or non-abstract."),
8978
8982
  Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression: diag(2513, ts.DiagnosticCategory.Error, "Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression_2513", "Abstract method '{0}' in class '{1}' cannot be accessed via super expression."),
8983
+ A_tuple_type_cannot_be_indexed_with_a_negative_value: diag(2514, ts.DiagnosticCategory.Error, "A_tuple_type_cannot_be_indexed_with_a_negative_value_2514", "A tuple type cannot be indexed with a negative value."),
8979
8984
  Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: diag(2515, ts.DiagnosticCategory.Error, "Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2_2515", "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'."),
8980
8985
  All_declarations_of_an_abstract_method_must_be_consecutive: diag(2516, ts.DiagnosticCategory.Error, "All_declarations_of_an_abstract_method_must_be_consecutive_2516", "All declarations of an abstract method must be consecutive."),
8981
8986
  Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: diag(2517, ts.DiagnosticCategory.Error, "Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type_2517", "Cannot assign an abstract constructor type to a non-abstract constructor type."),
@@ -43330,18 +43335,7 @@ var ts;
43330
43335
  * Does not try `@types/${packageName}` - use a second pass if needed.
43331
43336
  */
43332
43337
  function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
43333
- var moduleResolutionState = {
43334
- compilerOptions: options,
43335
- host: host,
43336
- traceEnabled: isTraceEnabled(options, host),
43337
- failedLookupLocations: [],
43338
- affectingLocations: [],
43339
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
43340
- conditions: ts.emptyArray,
43341
- features: NodeResolutionFeatures.None,
43342
- requestContainingDirectory: containingDirectory,
43343
- reportDiagnostic: ts.noop
43344
- };
43338
+ var moduleResolutionState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
43345
43339
  return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
43346
43340
  if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
43347
43341
  var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
@@ -44301,18 +44295,9 @@ var ts;
44301
44295
  var entrypoints;
44302
44296
  var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
44303
44297
  var features = getDefaultNodeResolutionFeatures(options);
44304
- var requireState = {
44305
- compilerOptions: options,
44306
- host: host,
44307
- traceEnabled: isTraceEnabled(options, host),
44308
- failedLookupLocations: [],
44309
- affectingLocations: [],
44310
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
44311
- conditions: ["node", "require", "types"],
44312
- features: features,
44313
- requestContainingDirectory: packageJsonInfo.packageDirectory,
44314
- reportDiagnostic: ts.noop
44315
- };
44298
+ var requireState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
44299
+ requireState.conditions = ["node", "require", "types"];
44300
+ requireState.requestContainingDirectory = packageJsonInfo.packageDirectory;
44316
44301
  var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
44317
44302
  /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
44318
44303
  entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
@@ -44385,23 +44370,27 @@ var ts;
44385
44370
  }
44386
44371
  }
44387
44372
  }
44388
- /**
44389
- * A function for locating the package.json scope for a given path
44390
- */
44391
44373
  /*@internal*/
44392
- function getPackageScopeForPath(fileName, packageJsonInfoCache, host, options) {
44393
- var state = {
44374
+ function getTemporaryModuleResolutionState(packageJsonInfoCache, host, options) {
44375
+ return {
44394
44376
  host: host,
44395
44377
  compilerOptions: options,
44396
44378
  traceEnabled: isTraceEnabled(options, host),
44397
- failedLookupLocations: [],
44398
- affectingLocations: [],
44379
+ failedLookupLocations: ts.noopPush,
44380
+ affectingLocations: ts.noopPush,
44399
44381
  packageJsonInfoCache: packageJsonInfoCache,
44400
- features: 0,
44401
- conditions: [],
44382
+ features: NodeResolutionFeatures.None,
44383
+ conditions: ts.emptyArray,
44402
44384
  requestContainingDirectory: undefined,
44403
44385
  reportDiagnostic: ts.noop
44404
44386
  };
44387
+ }
44388
+ ts.getTemporaryModuleResolutionState = getTemporaryModuleResolutionState;
44389
+ /**
44390
+ * A function for locating the package.json scope for a given path
44391
+ */
44392
+ /*@internal*/
44393
+ function getPackageScopeForPath(fileName, state) {
44405
44394
  var parts = ts.getPathComponents(fileName);
44406
44395
  parts.pop();
44407
44396
  while (parts.length > 0) {
@@ -44572,7 +44561,7 @@ var ts;
44572
44561
  var _a, _b;
44573
44562
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44574
44563
  var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames));
44575
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44564
+ var scope = getPackageScopeForPath(directoryPath, state);
44576
44565
  if (!scope || !scope.packageJsonContent.exports) {
44577
44566
  return undefined;
44578
44567
  }
@@ -44631,7 +44620,7 @@ var ts;
44631
44620
  }
44632
44621
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44633
44622
  var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames));
44634
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44623
+ var scope = getPackageScopeForPath(directoryPath, state);
44635
44624
  if (!scope) {
44636
44625
  if (state.traceEnabled) {
44637
44626
  trace(state.host, ts.Diagnostics.Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve, directoryPath);
@@ -53091,6 +53080,12 @@ var ts;
53091
53080
  return context.truncating = context.approximateLength > ((context.flags & 1 /* NoTruncation */) ? ts.noTruncationMaximumTruncationLength : ts.defaultMaximumTruncationLength);
53092
53081
  }
53093
53082
  function typeToTypeNodeHelper(type, context) {
53083
+ var savedFlags = context.flags;
53084
+ var typeNode = typeToTypeNodeWorker(type, context);
53085
+ context.flags = savedFlags;
53086
+ return typeNode;
53087
+ }
53088
+ function typeToTypeNodeWorker(type, context) {
53094
53089
  if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
53095
53090
  cancellationToken.throwIfCancellationRequested();
53096
53091
  }
@@ -62829,21 +62824,28 @@ var ts;
62829
62824
  getFlowTypeOfReference(accessExpression, propType) :
62830
62825
  propType;
62831
62826
  }
62832
- if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
62827
+ if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName)) {
62828
+ var index = +propName;
62833
62829
  if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
62834
62830
  var indexNode = getIndexNodeForAccessExpression(accessNode);
62835
62831
  if (isTupleType(objectType)) {
62832
+ if (index < 0) {
62833
+ error(indexNode, ts.Diagnostics.A_tuple_type_cannot_be_indexed_with_a_negative_value);
62834
+ return undefinedType;
62835
+ }
62836
62836
  error(indexNode, ts.Diagnostics.Tuple_type_0_of_length_1_has_no_element_at_index_2, typeToString(objectType), getTypeReferenceArity(objectType), ts.unescapeLeadingUnderscores(propName));
62837
62837
  }
62838
62838
  else {
62839
62839
  error(indexNode, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.unescapeLeadingUnderscores(propName), typeToString(objectType));
62840
62840
  }
62841
62841
  }
62842
- errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62843
- return mapType(objectType, function (t) {
62844
- var restType = getRestTypeOfTupleType(t) || undefinedType;
62845
- return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62846
- });
62842
+ if (index >= 0) {
62843
+ errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62844
+ return mapType(objectType, function (t) {
62845
+ var restType = getRestTypeOfTupleType(t) || undefinedType;
62846
+ return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62847
+ });
62848
+ }
62847
62849
  }
62848
62850
  }
62849
62851
  if (!(indexType.flags & 98304 /* Nullable */) && isTypeAssignableToKind(indexType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */)) {
@@ -117854,7 +117856,7 @@ var ts;
117854
117856
  return undefined;
117855
117857
  }
117856
117858
  function lookupFromPackageJson() {
117857
- var scope = ts.getPackageScopeForPath(fileName, packageJsonInfoCache, host, options);
117859
+ var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117858
117860
  return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117859
117861
  }
117860
117862
  }
@@ -149236,6 +149238,7 @@ var ts;
149236
149238
  var options = _a.options, getRules = _a.getRules, host = _a.host;
149237
149239
  // formatting context is used by rules provider
149238
149240
  var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options);
149241
+ var previousRangeTriviaEnd;
149239
149242
  var previousRange;
149240
149243
  var previousParent;
149241
149244
  var previousRangeStartLine;
@@ -149264,10 +149267,30 @@ var ts;
149264
149267
  }
149265
149268
  }
149266
149269
  if (previousRange && formattingScanner.getStartPos() >= originalRange.end) {
149270
+ // Formatting edits happen by looking at pairs of contiguous tokens (see `processPair`),
149271
+ // typically inserting or deleting whitespace between them. The recursive `processNode`
149272
+ // logic above bails out as soon as it encounters a token that is beyond the end of the
149273
+ // range we're supposed to format (or if we reach the end of the file). But this potentially
149274
+ // leaves out an edit that would occur *inside* the requested range but cannot be discovered
149275
+ // without looking at one token *beyond* the end of the range: consider the line `x = { }`
149276
+ // with a selection from the beginning of the line to the space inside the curly braces,
149277
+ // inclusive. We would expect a format-selection would delete the space (if rules apply),
149278
+ // but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
149279
+ // just before getting there. This block handles this trailing edit.
149267
149280
  var tokenInfo = formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() :
149268
149281
  formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token :
149269
149282
  undefined;
149270
- if (tokenInfo) {
149283
+ if (tokenInfo && tokenInfo.pos === previousRangeTriviaEnd) {
149284
+ // We need to check that tokenInfo and previousRange are contiguous: the `originalRange`
149285
+ // may have ended in the middle of a token, which means we will have stopped formatting
149286
+ // on that token, leaving `previousRange` pointing to the token before it, but already
149287
+ // having moved the formatting scanner (where we just got `tokenInfo`) to the next token.
149288
+ // If this happens, our supposed pair [previousRange, tokenInfo] actually straddles the
149289
+ // token that intersects the end of the range we're supposed to format, so the pair will
149290
+ // produce bogus edits if we try to `processPair`. Recall that the point of this logic is
149291
+ // to perform a trailing edit at the end of the selection range: but there can be no valid
149292
+ // edit in the middle of a token where the range ended, so if we have a non-contiguous
149293
+ // pair here, we're already done and we can ignore it.
149271
149294
  var parent = ((_b = ts.findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)) === null || _b === void 0 ? void 0 : _b.parent) || previousParent;
149272
149295
  processPair(tokenInfo, sourceFile.getLineAndCharacterOfPosition(tokenInfo.pos).line, parent, previousRange, previousRangeStartLine, previousParent, parent,
149273
149296
  /*dynamicIndentation*/ undefined);
@@ -149625,6 +149648,7 @@ var ts;
149625
149648
  }
149626
149649
  }
149627
149650
  if (currentTokenInfo.trailingTrivia) {
149651
+ previousRangeTriviaEnd = ts.last(currentTokenInfo.trailingTrivia).end;
149628
149652
  processTrivia(currentTokenInfo.trailingTrivia, parent, childContextNode, dynamicIndentation);
149629
149653
  }
149630
149654
  if (indentToken) {
@@ -149695,6 +149719,7 @@ var ts;
149695
149719
  }
149696
149720
  }
149697
149721
  previousRange = range;
149722
+ previousRangeTriviaEnd = range.end;
149698
149723
  previousParent = parent;
149699
149724
  previousRangeStartLine = rangeStart.line;
149700
149725
  return lineAction;