typescript 4.6.0-dev.20220116 → 4.6.0-dev.20220120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220116";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220120";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -6810,11 +6810,15 @@ var ts;
6810
6810
  ts.getFileWatcherEventKind = getFileWatcherEventKind;
6811
6811
  /*@internal*/
6812
6812
  ts.ignoredPaths = ["/node_modules/.", "/.git", "/.#"];
6813
+ var curSysLog = ts.noop; // eslint-disable-line prefer-const
6813
6814
  /*@internal*/
6814
- ts.sysLog = ts.noop; // eslint-disable-line prefer-const
6815
+ function sysLog(s) {
6816
+ return curSysLog(s);
6817
+ }
6818
+ ts.sysLog = sysLog;
6815
6819
  /*@internal*/
6816
6820
  function setSysLog(logger) {
6817
- ts.sysLog = logger;
6821
+ curSysLog = logger;
6818
6822
  }
6819
6823
  ts.setSysLog = setSysLog;
6820
6824
  /**
@@ -6949,7 +6953,7 @@ var ts;
6949
6953
  }
6950
6954
  function onTimerToUpdateChildWatches() {
6951
6955
  timerToUpdateChildWatches = undefined;
6952
- ts.sysLog("sysLog:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size);
6956
+ sysLog("sysLog:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size);
6953
6957
  var start = ts.timestamp();
6954
6958
  var invokeMap = new ts.Map();
6955
6959
  while (!timerToUpdateChildWatches && cacheToUpdateChildWatches.size) {
@@ -6962,7 +6966,7 @@ var ts;
6962
6966
  var hasChanges = updateChildWatches(dirName, dirPath, options);
6963
6967
  invokeCallbacks(dirPath, invokeMap, hasChanges ? undefined : fileNames);
6964
6968
  }
6965
- ts.sysLog("sysLog:: invokingWatchers:: Elapsed:: " + (ts.timestamp() - start) + "ms:: " + cacheToUpdateChildWatches.size);
6969
+ sysLog("sysLog:: invokingWatchers:: Elapsed:: " + (ts.timestamp() - start) + "ms:: " + cacheToUpdateChildWatches.size);
6966
6970
  callbackCache.forEach(function (callbacks, rootDirName) {
6967
6971
  var existing = invokeMap.get(rootDirName);
6968
6972
  if (existing) {
@@ -6978,7 +6982,7 @@ var ts;
6978
6982
  }
6979
6983
  });
6980
6984
  var elapsed = ts.timestamp() - start;
6981
- ts.sysLog("sysLog:: Elapsed:: " + elapsed + "ms:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size + " " + timerToUpdateChildWatches);
6985
+ sysLog("sysLog:: Elapsed:: " + elapsed + "ms:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size + " " + timerToUpdateChildWatches);
6982
6986
  }
6983
6987
  function removeChildWatches(parentWatcher) {
6984
6988
  if (!parentWatcher)
@@ -7565,7 +7569,7 @@ var ts;
7565
7569
  * @param createWatcher
7566
7570
  */
7567
7571
  function invokeCallbackAndUpdateWatcher(createWatcher) {
7568
- ts.sysLog("sysLog:: " + fileOrDirectory + ":: Changing watcher to " + (createWatcher === watchPresentFileSystemEntry ? "Present" : "Missing") + "FileSystemEntryWatcher");
7572
+ sysLog("sysLog:: " + fileOrDirectory + ":: Changing watcher to " + (createWatcher === watchPresentFileSystemEntry ? "Present" : "Missing") + "FileSystemEntryWatcher");
7569
7573
  // Call the callback for current directory
7570
7574
  callback("rename", "");
7571
7575
  // If watcher is not closed, update it
@@ -7590,7 +7594,7 @@ var ts;
7590
7594
  }
7591
7595
  }
7592
7596
  if (hitSystemWatcherLimit) {
7593
- ts.sysLog("sysLog:: " + fileOrDirectory + ":: Defaulting to fsWatchFile");
7597
+ sysLog("sysLog:: " + fileOrDirectory + ":: Defaulting to fsWatchFile");
7594
7598
  return watchPresentFileSystemEntryWithFsWatchFile();
7595
7599
  }
7596
7600
  try {
@@ -7606,7 +7610,7 @@ var ts;
7606
7610
  // Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point
7607
7611
  // so instead of throwing error, use fs.watchFile
7608
7612
  hitSystemWatcherLimit || (hitSystemWatcherLimit = e.code === "ENOSPC");
7609
- ts.sysLog("sysLog:: " + fileOrDirectory + ":: Changing to fsWatchFile");
7613
+ sysLog("sysLog:: " + fileOrDirectory + ":: Changing to fsWatchFile");
7610
7614
  return watchPresentFileSystemEntryWithFsWatchFile();
7611
7615
  }
7612
7616
  }
@@ -8205,6 +8209,7 @@ var ts;
8205
8209
  Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"),
8206
8210
  The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output: diag(1470, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output_1470", "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output."),
8207
8211
  Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead: diag(1471, ts.DiagnosticCategory.Error, "Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_c_1471", "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead."),
8212
+ catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8208
8213
  The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
8209
8214
  The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
8210
8215
  Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
@@ -9085,7 +9090,7 @@ var ts;
9085
9090
  Completeness: diag(6257, ts.DiagnosticCategory.Message, "Completeness_6257", "Completeness"),
9086
9091
  _0_should_be_set_inside_the_compilerOptions_object_of_the_config_json_file: diag(6258, ts.DiagnosticCategory.Error, "_0_should_be_set_inside_the_compilerOptions_object_of_the_config_json_file_6258", "'{0}' should be set inside the 'compilerOptions' object of the config json file"),
9087
9092
  Found_1_error_in_1: diag(6259, ts.DiagnosticCategory.Message, "Found_1_error_in_1_6259", "Found 1 error in {1}"),
9088
- Found_0_errors_in_1_file: diag(6260, ts.DiagnosticCategory.Message, "Found_0_errors_in_1_file_6260", "Found {0} errors in 1 file."),
9093
+ Found_0_errors_in_the_same_file_starting_at_Colon_1: diag(6260, ts.DiagnosticCategory.Message, "Found_0_errors_in_the_same_file_starting_at_Colon_1_6260", "Found {0} errors in the same file, starting at: {1}"),
9089
9094
  Found_0_errors_in_1_files: diag(6261, ts.DiagnosticCategory.Message, "Found_0_errors_in_1_files_6261", "Found {0} errors in {1} files."),
9090
9095
  Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve: diag(6270, ts.DiagnosticCategory.Message, "Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve_6270", "Directory '{0}' has no containing package.json scope. Imports will not resolve."),
9091
9096
  Import_specifier_0_does_not_exist_in_package_json_scope_at_path_1: diag(6271, ts.DiagnosticCategory.Message, "Import_specifier_0_does_not_exist_in_package_json_scope_at_path_1_6271", "Import specifier '{0}' does not exist in package.json scope at path '{1}'."),
@@ -15858,7 +15863,7 @@ var ts;
15858
15863
  }
15859
15864
  ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
15860
15865
  function getExternalModuleRequireArgument(node) {
15861
- return isRequireVariableDeclaration(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
15866
+ return isVariableDeclarationInitializedToBareOrAccessedRequire(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
15862
15867
  }
15863
15868
  ts.getExternalModuleRequireArgument = getExternalModuleRequireArgument;
15864
15869
  function isInternalModuleImportEqualsDeclaration(node) {
@@ -15916,17 +15921,29 @@ var ts;
15916
15921
  * Returns true if the node is a VariableDeclaration initialized to a require call (see `isRequireCall`).
15917
15922
  * This function does not test if the node is in a JavaScript file or not.
15918
15923
  */
15919
- function isRequireVariableDeclaration(node) {
15924
+ function isVariableDeclarationInitializedToRequire(node) {
15925
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ false);
15926
+ }
15927
+ ts.isVariableDeclarationInitializedToRequire = isVariableDeclarationInitializedToRequire;
15928
+ /**
15929
+ * Like {@link isVariableDeclarationInitializedToRequire} but allows things like `require("...").foo.bar` or `require("...")["baz"]`.
15930
+ */
15931
+ function isVariableDeclarationInitializedToBareOrAccessedRequire(node) {
15932
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ true);
15933
+ }
15934
+ ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire;
15935
+ function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
15920
15936
  if (node.kind === 202 /* BindingElement */) {
15921
15937
  node = node.parent.parent;
15922
15938
  }
15923
- return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostAccessExpression(node.initializer), /*requireStringLiteralLikeArgument*/ true);
15939
+ return ts.isVariableDeclaration(node) &&
15940
+ !!node.initializer &&
15941
+ isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true);
15924
15942
  }
15925
- ts.isRequireVariableDeclaration = isRequireVariableDeclaration;
15926
15943
  function isRequireVariableStatement(node) {
15927
15944
  return ts.isVariableStatement(node)
15928
15945
  && node.declarationList.declarations.length > 0
15929
- && ts.every(node.declarationList.declarations, function (decl) { return isRequireVariableDeclaration(decl); });
15946
+ && ts.every(node.declarationList.declarations, function (decl) { return isVariableDeclarationInitializedToRequire(decl); });
15930
15947
  }
15931
15948
  ts.isRequireVariableStatement = isRequireVariableStatement;
15932
15949
  function isSingleOrDoubleQuote(charCode) {
@@ -19413,7 +19430,7 @@ var ts;
19413
19430
  getSourceMapSourceConstructor: function () { return SourceMapSource; },
19414
19431
  };
19415
19432
  function setObjectAllocator(alloc) {
19416
- ts.objectAllocator = alloc;
19433
+ Object.assign(ts.objectAllocator, alloc);
19417
19434
  }
19418
19435
  ts.setObjectAllocator = setObjectAllocator;
19419
19436
  function formatStringFromArgs(text, args, baseIndex) {
@@ -19421,13 +19438,22 @@ var ts;
19421
19438
  return text.replace(/{(\d+)}/g, function (_match, index) { return "" + ts.Debug.checkDefined(args[+index + baseIndex]); });
19422
19439
  }
19423
19440
  ts.formatStringFromArgs = formatStringFromArgs;
19441
+ var localizedDiagnosticMessages;
19424
19442
  /* @internal */
19425
19443
  function setLocalizedDiagnosticMessages(messages) {
19426
- ts.localizedDiagnosticMessages = messages;
19444
+ localizedDiagnosticMessages = messages;
19427
19445
  }
19428
19446
  ts.setLocalizedDiagnosticMessages = setLocalizedDiagnosticMessages;
19447
+ /* @internal */
19448
+ // If the localized messages json is unset, and if given function use it to set the json
19449
+ function maybeSetLocalizedDiagnosticMessages(getMessages) {
19450
+ if (!localizedDiagnosticMessages && getMessages) {
19451
+ localizedDiagnosticMessages = getMessages();
19452
+ }
19453
+ }
19454
+ ts.maybeSetLocalizedDiagnosticMessages = maybeSetLocalizedDiagnosticMessages;
19429
19455
  function getLocaleSpecificMessage(message) {
19430
- return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message.key] || message.message;
19456
+ return localizedDiagnosticMessages && localizedDiagnosticMessages[message.key] || message.message;
19431
19457
  }
19432
19458
  ts.getLocaleSpecificMessage = getLocaleSpecificMessage;
19433
19459
  function createDetachedDiagnostic(fileName, start, length, message) {
@@ -35036,7 +35062,7 @@ var ts;
35036
35062
  // one out no matter what.
35037
35063
  var finallyBlock;
35038
35064
  if (!catchClause || token() === 96 /* FinallyKeyword */) {
35039
- parseExpected(96 /* FinallyKeyword */);
35065
+ parseExpected(96 /* FinallyKeyword */, ts.Diagnostics.catch_or_finally_expected);
35040
35066
  finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
35041
35067
  }
35042
35068
  return withJSDoc(finishNode(factory.createTryStatement(tryBlock, catchClause, finallyBlock), pos), hasJSDoc);
@@ -44497,7 +44523,7 @@ var ts;
44497
44523
  maybeBindExpressionFlowIfCall(node.expression);
44498
44524
  }
44499
44525
  function maybeBindExpressionFlowIfCall(node) {
44500
- // A top level or LHS of comma expression call expression with a dotted function name and at least one argument
44526
+ // A top level or comma expression call expression with a dotted function name and at least one argument
44501
44527
  // is potentially an assertion and is therefore included in the control flow.
44502
44528
  if (node.kind === 207 /* CallExpression */) {
44503
44529
  var call = node;
@@ -44665,22 +44691,27 @@ var ts;
44665
44691
  }
44666
44692
  return state;
44667
44693
  }
44668
- function onLeft(left, state, _node) {
44694
+ function onLeft(left, state, node) {
44669
44695
  if (!state.skip) {
44670
- return maybeBind(left);
44696
+ var maybeBound = maybeBind(left);
44697
+ if (node.operatorToken.kind === 27 /* CommaToken */) {
44698
+ maybeBindExpressionFlowIfCall(left);
44699
+ }
44700
+ return maybeBound;
44671
44701
  }
44672
44702
  }
44673
- function onOperator(operatorToken, state, node) {
44703
+ function onOperator(operatorToken, state, _node) {
44674
44704
  if (!state.skip) {
44675
- if (operatorToken.kind === 27 /* CommaToken */) {
44676
- maybeBindExpressionFlowIfCall(node.left);
44677
- }
44678
44705
  bind(operatorToken);
44679
44706
  }
44680
44707
  }
44681
- function onRight(right, state, _node) {
44708
+ function onRight(right, state, node) {
44682
44709
  if (!state.skip) {
44683
- return maybeBind(right);
44710
+ var maybeBound = maybeBind(right);
44711
+ if (node.operatorToken.kind === 27 /* CommaToken */) {
44712
+ maybeBindExpressionFlowIfCall(right);
44713
+ }
44714
+ return maybeBound;
44684
44715
  }
44685
44716
  }
44686
44717
  function onExit(node, state) {
@@ -46243,7 +46274,7 @@ var ts;
46243
46274
  checkStrictModeEvalOrArguments(node, node.name);
46244
46275
  }
46245
46276
  if (!ts.isBindingPattern(node.name)) {
46246
- if (ts.isInJSFile(node) && ts.isRequireVariableDeclaration(node) && !ts.getJSDocTypeTag(node)) {
46277
+ if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node)) {
46247
46278
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
46248
46279
  }
46249
46280
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -49026,7 +49057,7 @@ var ts;
49026
49057
  && isAliasableOrJsExpression(node.parent.right)
49027
49058
  || node.kind === 295 /* ShorthandPropertyAssignment */
49028
49059
  || node.kind === 294 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
49029
- || ts.isRequireVariableDeclaration(node);
49060
+ || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
49030
49061
  }
49031
49062
  function isAliasableOrJsExpression(e) {
49032
49063
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50957,6 +50988,7 @@ var ts;
50957
50988
  getCommonSourceDirectory: !!host.getCommonSourceDirectory ? function () { return host.getCommonSourceDirectory(); } : function () { return ""; },
50958
50989
  getCurrentDirectory: function () { return host.getCurrentDirectory(); },
50959
50990
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache),
50991
+ getPackageJsonInfoCache: function () { var _a; return (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host); },
50960
50992
  useCaseSensitiveFileNames: ts.maybeBind(host, host.useCaseSensitiveFileNames),
50961
50993
  redirectTargetsMap: host.redirectTargetsMap,
50962
50994
  getProjectReferenceRedirect: function (fileName) { return host.getProjectReferenceRedirect(fileName); },
@@ -80584,7 +80616,7 @@ var ts;
80584
80616
  }
80585
80617
  // For a commonjs `const x = require`, validate the alias and exit
80586
80618
  var symbol = getSymbolOfNode(node);
80587
- if (symbol.flags & 2097152 /* Alias */ && ts.isRequireVariableDeclaration(node)) {
80619
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
80588
80620
  checkAliasSymbol(node);
80589
80621
  return;
80590
80622
  }
@@ -95529,10 +95561,19 @@ var ts;
95529
95561
  var _a;
95530
95562
  var nonWhitespaceChildren = ts.getSemanticJsxChildren(children);
95531
95563
  var isStaticChildren = ts.length(nonWhitespaceChildren) > 1 || !!((_a = nonWhitespaceChildren[0]) === null || _a === void 0 ? void 0 : _a.dotDotDotToken);
95532
- var args = [tagName, objectProperties, !keyAttr ? factory.createVoidZero() : transformJsxAttributeInitializer(keyAttr.initializer)];
95564
+ var args = [tagName, objectProperties];
95565
+ // function jsx(type, config, maybeKey) {}
95566
+ // "maybeKey" is optional. It is acceptable to use "_jsx" without a third argument
95567
+ if (keyAttr) {
95568
+ args.push(transformJsxAttributeInitializer(keyAttr.initializer));
95569
+ }
95533
95570
  if (compilerOptions.jsx === 5 /* ReactJSXDev */) {
95534
95571
  var originalFile = ts.getOriginalNode(currentSourceFile);
95535
95572
  if (originalFile && ts.isSourceFile(originalFile)) {
95573
+ // "maybeKey" has to be replaced with "void 0" to not break the jsxDEV signature
95574
+ if (keyAttr === undefined) {
95575
+ args.push(factory.createVoidZero());
95576
+ }
95536
95577
  // isStaticChildren development flag
95537
95578
  args.push(isStaticChildren ? factory.createTrue() : factory.createFalse());
95538
95579
  // __source development flag
@@ -119397,11 +119438,12 @@ var ts;
119397
119438
  };
119398
119439
  }
119399
119440
  function isFormatRequiringExtensions(compilerOptions, importingSourceFileName, host) {
119441
+ var _a;
119400
119442
  if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node12
119401
119443
  && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) {
119402
119444
  return false;
119403
119445
  }
119404
- return ts.getImpliedNodeFormatForFile(importingSourceFileName, /*packageJsonInfoCache*/ undefined, getModuleResolutionHost(host), compilerOptions) !== ts.ModuleKind.CommonJS;
119446
+ return ts.getImpliedNodeFormatForFile(importingSourceFileName, (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host), getModuleResolutionHost(host), compilerOptions) !== ts.ModuleKind.CommonJS;
119405
119447
  }
119406
119448
  function getModuleResolutionHost(host) {
119407
119449
  var _a;
@@ -119961,11 +120003,13 @@ var ts;
119961
120003
  // For classic resolution, only allow importing from node_modules/@types, not other node_modules
119962
120004
  return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Classic && packageName === nodeModulesDirectoryName ? undefined : packageName;
119963
120005
  function tryDirectoryWithPackageJson(packageRootIndex) {
120006
+ var _a, _b;
119964
120007
  var packageRootPath = path.substring(0, packageRootIndex);
119965
120008
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
119966
120009
  var moduleFileToTry = path;
119967
- if (host.fileExists(packageJsonPath)) {
119968
- var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
120010
+ var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
120011
+ if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
120012
+ var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
119969
120013
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
119970
120014
  // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
119971
120015
  // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
@@ -120265,22 +120309,31 @@ var ts;
120265
120309
  ts.Diagnostics.Found_0_errors_Watching_for_file_changes;
120266
120310
  }
120267
120311
  ts.getWatchErrorSummaryDiagnosticMessage = getWatchErrorSummaryDiagnosticMessage;
120312
+ function prettyPathForFileError(error, cwd) {
120313
+ var line = ts.formatColorAndReset(":" + error.line, ts.ForegroundColorEscapeSequences.Grey);
120314
+ if (ts.pathIsAbsolute(error.fileName) && ts.pathIsAbsolute(cwd)) {
120315
+ return ts.getRelativePathFromDirectory(cwd, error.fileName, /* ignoreCase */ false) + line;
120316
+ }
120317
+ return error.fileName + line;
120318
+ }
120268
120319
  function getErrorSummaryText(errorCount, filesInError, newLine, host) {
120269
120320
  if (errorCount === 0)
120270
120321
  return "";
120271
120322
  var nonNilFiles = filesInError.filter(function (fileInError) { return fileInError !== undefined; });
120272
120323
  var distinctFileNamesWithLines = nonNilFiles.map(function (fileInError) { return fileInError.fileName + ":" + fileInError.line; })
120273
120324
  .filter(function (value, index, self) { return self.indexOf(value) === index; });
120325
+ var firstFileReference = nonNilFiles[0] && prettyPathForFileError(nonNilFiles[0], host.getCurrentDirectory());
120274
120326
  var d = errorCount === 1 ?
120275
120327
  ts.createCompilerDiagnostic(filesInError[0] !== undefined ?
120276
120328
  ts.Diagnostics.Found_1_error_in_1 :
120277
- ts.Diagnostics.Found_1_error, errorCount, distinctFileNamesWithLines[0]) :
120329
+ ts.Diagnostics.Found_1_error, errorCount, firstFileReference) :
120278
120330
  ts.createCompilerDiagnostic(distinctFileNamesWithLines.length === 0 ?
120279
120331
  ts.Diagnostics.Found_0_errors :
120280
120332
  distinctFileNamesWithLines.length === 1 ?
120281
- ts.Diagnostics.Found_0_errors_in_1_file :
120282
- ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length);
120283
- return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "");
120333
+ ts.Diagnostics.Found_0_errors_in_the_same_file_starting_at_Colon_1 :
120334
+ ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length === 1 ? firstFileReference : distinctFileNamesWithLines.length);
120335
+ var suffix = distinctFileNamesWithLines.length > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "";
120336
+ return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + suffix;
120284
120337
  }
120285
120338
  ts.getErrorSummaryText = getErrorSummaryText;
120286
120339
  function createTabularErrorsDisplay(filesInError, host) {
@@ -120302,8 +120355,8 @@ var ts;
120302
120355
  var leftPadding = errorCountDigitsLength < leftPaddingGoal ?
120303
120356
  " ".repeat(leftPaddingGoal - errorCountDigitsLength)
120304
120357
  : "";
120305
- var relativePath = ts.getRelativePathFromDirectory(host.getCurrentDirectory(), file.fileName, /* ignoreCase */ false);
120306
- tabularData += "" + leftPadding + errorCount + " " + relativePath + ":" + file.line + "\n";
120358
+ var fileRef = prettyPathForFileError(file, host.getCurrentDirectory());
120359
+ tabularData += "" + leftPadding + errorCount + " " + fileRef + "\n";
120307
120360
  });
120308
120361
  return tabularData;
120309
120362
  }
@@ -120804,6 +120857,7 @@ var ts;
120804
120857
  var sharedExtendedConfigFileWatchers; // Map of file watchers for extended files, shared between different referenced projects
120805
120858
  var extendedConfigCache = host.extendedConfigCache; // Cache for extended config evaluation
120806
120859
  var changesAffectResolution = false; // Flag for indicating non-config changes affect module resolution
120860
+ var reportFileChangeDetectedOnCreateProgram = false; // True if synchronizeProgram should report "File change detected..." when a new program is created
120807
120861
  var sourceFilesCache = new ts.Map(); // Cache that stores the source file and version info
120808
120862
  var missingFilePathsRequestedForRelease; // These paths are held temporarily so that we can remove the entry from source file cache if the file is not tracked by missing files
120809
120863
  var hasChangedCompilerOptions = false; // True if the compiler options have changed between compilations
@@ -120966,14 +121020,21 @@ var ts;
120966
121020
  var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution || changesAffectResolution);
120967
121021
  if (ts.isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
120968
121022
  if (hasChangedConfigFileParsingErrors) {
121023
+ if (reportFileChangeDetectedOnCreateProgram) {
121024
+ reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
121025
+ }
120969
121026
  builderProgram = createProgram(/*rootNames*/ undefined, /*options*/ undefined, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
120970
121027
  hasChangedConfigFileParsingErrors = false;
120971
121028
  }
120972
121029
  }
120973
121030
  else {
121031
+ if (reportFileChangeDetectedOnCreateProgram) {
121032
+ reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
121033
+ }
120974
121034
  createNewProgram(hasInvalidatedResolution);
120975
121035
  }
120976
121036
  changesAffectResolution = false; // reset for next sync
121037
+ reportFileChangeDetectedOnCreateProgram = false;
120977
121038
  if (host.afterProgramCreate && program !== builderProgram) {
120978
121039
  host.afterProgramCreate(builderProgram);
120979
121040
  }
@@ -121175,7 +121236,7 @@ var ts;
121175
121236
  }
121176
121237
  function updateProgramWithWatchStatus() {
121177
121238
  timerToUpdateProgram = undefined;
121178
- reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
121239
+ reportFileChangeDetectedOnCreateProgram = true;
121179
121240
  updateProgram();
121180
121241
  }
121181
121242
  function updateProgram() {
@@ -123282,6 +123343,7 @@ var ts;
123282
123343
  ScriptElementKind["externalModuleName"] = "external module name";
123283
123344
  /**
123284
123345
  * <JsxTagName attribute1 attribute2={0} />
123346
+ * @deprecated
123285
123347
  */
123286
123348
  ScriptElementKind["jsxAttribute"] = "JSX attribute";
123287
123349
  /** String literal */
@@ -124607,7 +124669,7 @@ var ts;
124607
124669
  isWhiteSpaceOnlyJsxText(child);
124608
124670
  if (lookInPreviousChild) {
124609
124671
  // actual start of the node is past the position - previous token should be at the end of previous child
124610
- var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
124672
+ var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile, n.kind);
124611
124673
  return candidate_1 && findRightmostToken(candidate_1, sourceFile);
124612
124674
  }
124613
124675
  else {
@@ -124621,7 +124683,7 @@ var ts;
124621
124683
  // the only known case is when position is at the end of the file.
124622
124684
  // Try to find the rightmost token in the file without filtering.
124623
124685
  // Namely we are skipping the check: 'position < node.end'
124624
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
124686
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
124625
124687
  return candidate && findRightmostToken(candidate, sourceFile);
124626
124688
  }
124627
124689
  }
@@ -124637,17 +124699,19 @@ var ts;
124637
124699
  if (children.length === 0) {
124638
124700
  return n;
124639
124701
  }
124640
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
124702
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
124641
124703
  return candidate && findRightmostToken(candidate, sourceFile);
124642
124704
  }
124643
124705
  /**
124644
124706
  * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
124645
124707
  */
124646
- function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile) {
124708
+ function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile, parentKind) {
124647
124709
  for (var i = exclusiveStartPosition - 1; i >= 0; i--) {
124648
124710
  var child = children[i];
124649
124711
  if (isWhiteSpaceOnlyJsxText(child)) {
124650
- ts.Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
124712
+ if (i === 0 && (parentKind === 11 /* JsxText */ || parentKind === 278 /* JsxSelfClosingElement */)) {
124713
+ ts.Debug.fail("`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
124714
+ }
124651
124715
  }
124652
124716
  else if (nodeHasTokens(children[i], sourceFile)) {
124653
124717
  return children[i];
@@ -125173,6 +125237,7 @@ var ts;
125173
125237
  useCaseSensitiveFileNames: ts.maybeBind(host, host.useCaseSensitiveFileNames),
125174
125238
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache) || program.getSymlinkCache,
125175
125239
  getModuleSpecifierCache: ts.maybeBind(host, host.getModuleSpecifierCache),
125240
+ getPackageJsonInfoCache: function () { var _a; return (_a = program.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache(); },
125176
125241
  getGlobalTypingsCacheLocation: ts.maybeBind(host, host.getGlobalTypingsCacheLocation),
125177
125242
  redirectTargetsMap: program.redirectTargetsMap,
125178
125243
  getProjectReferenceRedirect: function (fileName) { return program.getProjectReferenceRedirect(fileName); },
@@ -128917,6 +128982,7 @@ var ts;
128917
128982
  function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, preferences, isForImportStatementCompletion, cb) {
128918
128983
  var _a, _b, _c;
128919
128984
  var start = ts.timestamp();
128985
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
128920
128986
  var resolutionLimitExceeded = false;
128921
128987
  var ambientCount = 0;
128922
128988
  var resolvedCount = 0;
@@ -128939,7 +129005,7 @@ var ts;
128939
129005
  var shouldResolveModuleSpecifier = isForImportStatementCompletion || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
128940
129006
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
128941
129007
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
128942
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, shouldGetModuleSpecifierFromCache)
129008
+ ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
128943
129009
  : undefined;
128944
129010
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
128945
129011
  resolutionLimitExceeded = true;
@@ -130337,9 +130403,7 @@ var ts;
130337
130403
  // GH#39946. Pulling on the type of a node inside of a function with a contextual `this` parameter can result in a circularity
130338
130404
  // if the `node` is part of the exprssion of a `yield` or `return`. This circularity doesn't exist at compile time because
130339
130405
  // we will check (and cache) the type of `this` *before* checking the type of the node.
130340
- var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false);
130341
- if (!ts.isSourceFile(container) && container.parent)
130342
- typeChecker.getTypeAtLocation(container);
130406
+ typeChecker.tryGetThisTypeAt(node, /*includeGlobalThis*/ false);
130343
130407
  var type = typeChecker.getTypeAtLocation(node).getNonOptionalType();
130344
130408
  var insertQuestionDot = false;
130345
130409
  if (type.isNullableType()) {
@@ -133194,7 +133258,7 @@ var ts;
133194
133258
  ts.Debug.assert(parent.name === node);
133195
133259
  return true;
133196
133260
  case 202 /* BindingElement */:
133197
- return ts.isInJSFile(node) && ts.isRequireVariableDeclaration(parent);
133261
+ return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent);
133198
133262
  default:
133199
133263
  return false;
133200
133264
  }
@@ -134594,7 +134658,7 @@ var ts;
134594
134658
  // Use the parent symbol if the location is commonjs require syntax on javascript files only.
134595
134659
  if (ts.isInJSFile(referenceLocation)
134596
134660
  && referenceLocation.parent.kind === 202 /* BindingElement */
134597
- && ts.isRequireVariableDeclaration(referenceLocation.parent)) {
134661
+ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) {
134598
134662
  referenceSymbol = referenceLocation.parent.symbol;
134599
134663
  // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In
134600
134664
  // this case, just skip it, since the bound identifiers are not an alias of the import.
@@ -136305,7 +136369,7 @@ var ts;
136305
136369
  return declaration.parent.kind === 268 /* NamedImports */;
136306
136370
  case 202 /* BindingElement */:
136307
136371
  case 253 /* VariableDeclaration */:
136308
- return ts.isInJSFile(declaration) && ts.isRequireVariableDeclaration(declaration);
136372
+ return ts.isInJSFile(declaration) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(declaration);
136309
136373
  default:
136310
136374
  return false;
136311
136375
  }
@@ -141209,18 +141273,7 @@ var ts;
141209
141273
  }
141210
141274
  return unionPropertyKind;
141211
141275
  }
141212
- // If we requested completions after `x.` at the top-level, we may be at a source file location.
141213
- switch (location.parent && location.parent.kind) {
141214
- // If we've typed a character of the attribute name, will be 'JsxAttribute', else will be 'JsxOpeningElement'.
141215
- case 279 /* JsxOpeningElement */:
141216
- case 277 /* JsxElement */:
141217
- case 278 /* JsxSelfClosingElement */:
141218
- return location.kind === 79 /* Identifier */ ? "property" /* memberVariableElement */ : "JSX attribute" /* jsxAttribute */;
141219
- case 284 /* JsxAttribute */:
141220
- return "JSX attribute" /* jsxAttribute */;
141221
- default:
141222
- return "property" /* memberVariableElement */;
141223
- }
141276
+ return "property" /* memberVariableElement */;
141224
141277
  }
141225
141278
  return "" /* unknown */;
141226
141279
  }
@@ -145238,7 +145291,11 @@ var ts;
145238
145291
  oldTags[i] = merged;
145239
145292
  return !!merged;
145240
145293
  }); });
145241
- var tag = ts.factory.createJSDocComment(ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n"))), ts.factory.createNodeArray(__spreadArray(__spreadArray([], oldTags, true), unmergedNewTags, true)));
145294
+ var tags = __spreadArray(__spreadArray([], oldTags, true), unmergedNewTags, true);
145295
+ var jsDoc = ts.singleOrUndefined(parent.jsDoc);
145296
+ var comment = jsDoc && ts.positionsAreOnSameLine(jsDoc.pos, jsDoc.end, sourceFile) && !ts.length(comments) ? undefined :
145297
+ ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n")));
145298
+ var tag = ts.factory.createJSDocComment(comment, ts.factory.createNodeArray(tags));
145242
145299
  var host = updateJSDocHost(parent);
145243
145300
  this.insertJsdocCommentBefore(sourceFile, host, tag);
145244
145301
  };
@@ -145668,6 +145725,8 @@ var ts;
145668
145725
  }
145669
145726
  case 339 /* JSDocReturnTag */:
145670
145727
  return ts.factory.createJSDocReturnTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
145728
+ case 341 /* JSDocTypeTag */:
145729
+ return ts.factory.createJSDocTypeTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
145671
145730
  }
145672
145731
  }
145673
145732
  // find first non-whitespace position in the leading trivia of the node
@@ -149206,7 +149265,8 @@ var ts;
149206
149265
  codefix.getImportCompletionAction = getImportCompletionAction;
149207
149266
  function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
149208
149267
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
149209
- return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
149268
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
149269
+ return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, packageJsonImportFilter);
149210
149270
  }
149211
149271
  function codeFixActionToCodeAction(_a) {
149212
149272
  var description = _a.description, changes = _a.changes, commands = _a.commands;
@@ -149261,12 +149321,12 @@ var ts;
149261
149321
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
149262
149322
  }
149263
149323
  }
149264
- function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
149324
+ function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
149265
149325
  var _a = getNewImportFixes(program, importingFile,
149266
149326
  /*position*/ undefined,
149267
149327
  /*isValidTypeOnlyUseSite*/ false,
149268
149328
  /*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
149269
- var result = getBestFix(fixes, importingFile, program, host, preferences);
149329
+ var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host));
149270
149330
  return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
149271
149331
  }
149272
149332
  codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
@@ -149400,7 +149460,7 @@ var ts;
149400
149460
  var importKind = getImportKind(importingFile, exportKind, compilerOptions);
149401
149461
  return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
149402
149462
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
149403
- if (ts.isRequireVariableDeclaration(i.parent)) {
149463
+ if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
149404
149464
  return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
149405
149465
  }
149406
149466
  if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
@@ -149486,23 +149546,22 @@ var ts;
149486
149546
  var info = errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code
149487
149547
  ? getFixesInfoForUMDImport(context, symbolToken)
149488
149548
  : ts.isIdentifier(symbolToken) ? getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider) : undefined;
149489
- return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, context.host, context.preferences) });
149549
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
149550
+ return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, packageJsonImportFilter) });
149490
149551
  }
149491
- function sortFixes(fixes, sourceFile, program, host, preferences) {
149492
- var allowsImportingSpecifier = ts.createPackageJsonImportFilter(sourceFile, preferences, host).allowsImportingSpecifier;
149493
- return ts.sort(fixes, function (a, b) { return ts.compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, allowsImportingSpecifier); });
149552
+ function sortFixes(fixes, sourceFile, program, packageJsonImportFilter) {
149553
+ return ts.sort(fixes, function (a, b) { return ts.compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier); });
149494
149554
  }
149495
- function getBestFix(fixes, sourceFile, program, host, preferences) {
149555
+ function getBestFix(fixes, sourceFile, program, packageJsonImportFilter) {
149496
149556
  if (!ts.some(fixes))
149497
149557
  return;
149498
149558
  // These will always be placed first if available, and are better than other kinds
149499
149559
  if (fixes[0].kind === 0 /* UseNamespace */ || fixes[0].kind === 2 /* AddToExisting */) {
149500
149560
  return fixes[0];
149501
149561
  }
149502
- var allowsImportingSpecifier = ts.createPackageJsonImportFilter(sourceFile, preferences, host).allowsImportingSpecifier;
149503
149562
  return fixes.reduce(function (best, fix) {
149504
149563
  // Takes true branch of conditional if `fix` is better than `best`
149505
- return compareModuleSpecifiers(fix, best, sourceFile, program, allowsImportingSpecifier) === -1 /* LessThan */ ? fix : best;
149564
+ return compareModuleSpecifiers(fix, best, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier) === -1 /* LessThan */ ? fix : best;
149506
149565
  });
149507
149566
  }
149508
149567
  /** @returns `Comparison.LessThan` if `a` is better than `b`. */
@@ -152354,7 +152413,7 @@ var ts;
152354
152413
  });
152355
152414
  var name = declaration && ts.getNameOfDeclaration(declaration);
152356
152415
  return !name || changes.length === 0 ? undefined
152357
- : [codefix.createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, ts.Diagnostics.Infer_all_types_from_usage)];
152416
+ : [codefix.createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), ts.getTextOfNode(name)], fixId, ts.Diagnostics.Infer_all_types_from_usage)];
152358
152417
  },
152359
152418
  fixIds: [fixId],
152360
152419
  getAllCodeActions: function (context) {
@@ -152432,7 +152491,7 @@ var ts;
152432
152491
  case ts.Diagnostics.Variable_0_implicitly_has_an_1_type.code: {
152433
152492
  var symbol = program.getTypeChecker().getSymbolAtLocation(token);
152434
152493
  if (symbol && symbol.valueDeclaration && ts.isVariableDeclaration(symbol.valueDeclaration) && markSeen(symbol.valueDeclaration)) {
152435
- annotateVariableDeclaration(changes, importAdder, sourceFile, symbol.valueDeclaration, program, host, cancellationToken);
152494
+ annotateVariableDeclaration(changes, importAdder, ts.getSourceFileOfNode(symbol.valueDeclaration), symbol.valueDeclaration, program, host, cancellationToken);
152436
152495
  importAdder.writeFixes(changes);
152437
152496
  return symbol.valueDeclaration;
152438
152497
  }
@@ -154131,35 +154190,34 @@ var ts;
154131
154190
  codefix.registerCodeFix({
154132
154191
  errorCodes: errorCodes,
154133
154192
  getCodeActions: function getCodeActionsForStrictClassInitializationErrors(context) {
154134
- var propertyDeclaration = getPropertyDeclaration(context.sourceFile, context.span.start);
154135
- if (!propertyDeclaration)
154193
+ var info = getInfo(context.sourceFile, context.span.start);
154194
+ if (!info)
154136
154195
  return;
154137
- var result = [
154138
- getActionForAddMissingUndefinedType(context, propertyDeclaration),
154139
- getActionForAddMissingDefiniteAssignmentAssertion(context, propertyDeclaration)
154140
- ];
154141
- ts.append(result, getActionForAddMissingInitializer(context, propertyDeclaration));
154196
+ var result = [];
154197
+ ts.append(result, getActionForAddMissingUndefinedType(context, info));
154198
+ ts.append(result, getActionForAddMissingDefiniteAssignmentAssertion(context, info));
154199
+ ts.append(result, getActionForAddMissingInitializer(context, info));
154142
154200
  return result;
154143
154201
  },
154144
154202
  fixIds: [fixIdAddDefiniteAssignmentAssertions, fixIdAddUndefinedType, fixIdAddInitializer],
154145
154203
  getAllCodeActions: function (context) {
154146
154204
  return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
154147
- var propertyDeclaration = getPropertyDeclaration(diag.file, diag.start);
154148
- if (!propertyDeclaration)
154205
+ var info = getInfo(diag.file, diag.start);
154206
+ if (!info)
154149
154207
  return;
154150
154208
  switch (context.fixId) {
154151
154209
  case fixIdAddDefiniteAssignmentAssertions:
154152
- addDefiniteAssignmentAssertion(changes, diag.file, propertyDeclaration);
154210
+ addDefiniteAssignmentAssertion(changes, diag.file, info.prop);
154153
154211
  break;
154154
154212
  case fixIdAddUndefinedType:
154155
- addUndefinedType(changes, diag.file, propertyDeclaration);
154213
+ addUndefinedType(changes, diag.file, info);
154156
154214
  break;
154157
154215
  case fixIdAddInitializer:
154158
154216
  var checker = context.program.getTypeChecker();
154159
- var initializer = getInitializer(checker, propertyDeclaration);
154217
+ var initializer = getInitializer(checker, info.prop);
154160
154218
  if (!initializer)
154161
154219
  return;
154162
- addInitializer(changes, diag.file, propertyDeclaration, initializer);
154220
+ addInitializer(changes, diag.file, info.prop, initializer);
154163
154221
  break;
154164
154222
  default:
154165
154223
  ts.Debug.fail(JSON.stringify(context.fixId));
@@ -154167,35 +154225,50 @@ var ts;
154167
154225
  });
154168
154226
  },
154169
154227
  });
154170
- function getPropertyDeclaration(sourceFile, pos) {
154228
+ function getInfo(sourceFile, pos) {
154171
154229
  var token = ts.getTokenAtPosition(sourceFile, pos);
154172
- return ts.isIdentifier(token) ? ts.cast(token.parent, ts.isPropertyDeclaration) : undefined;
154230
+ if (ts.isIdentifier(token) && ts.isPropertyDeclaration(token.parent)) {
154231
+ var type = ts.getEffectiveTypeAnnotationNode(token.parent);
154232
+ if (type) {
154233
+ return { type: type, prop: token.parent, isJs: ts.isInJSFile(token.parent) };
154234
+ }
154235
+ }
154236
+ return undefined;
154173
154237
  }
154174
- function getActionForAddMissingDefiniteAssignmentAssertion(context, propertyDeclaration) {
154175
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addDefiniteAssignmentAssertion(t, context.sourceFile, propertyDeclaration); });
154176
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_definite_assignment_assertion_to_property_0, propertyDeclaration.getText()], fixIdAddDefiniteAssignmentAssertions, ts.Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
154238
+ function getActionForAddMissingDefiniteAssignmentAssertion(context, info) {
154239
+ if (info.isJs)
154240
+ return undefined;
154241
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addDefiniteAssignmentAssertion(t, context.sourceFile, info.prop); });
154242
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_definite_assignment_assertion_to_property_0, info.prop.getText()], fixIdAddDefiniteAssignmentAssertions, ts.Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
154177
154243
  }
154178
154244
  function addDefiniteAssignmentAssertion(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
154179
154245
  var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, ts.factory.createToken(53 /* ExclamationToken */), propertyDeclaration.type, propertyDeclaration.initializer);
154180
154246
  changeTracker.replaceNode(propertyDeclarationSourceFile, propertyDeclaration, property);
154181
154247
  }
154182
- function getActionForAddMissingUndefinedType(context, propertyDeclaration) {
154183
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile, propertyDeclaration); });
154184
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0, propertyDeclaration.name.getText()], fixIdAddUndefinedType, ts.Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
154248
+ function getActionForAddMissingUndefinedType(context, info) {
154249
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile, info); });
154250
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0, info.prop.name.getText()], fixIdAddUndefinedType, ts.Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
154185
154251
  }
154186
- function addUndefinedType(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
154252
+ function addUndefinedType(changeTracker, sourceFile, info) {
154187
154253
  var undefinedTypeNode = ts.factory.createKeywordTypeNode(152 /* UndefinedKeyword */);
154188
- var type = propertyDeclaration.type; // TODO: GH#18217
154189
- var types = ts.isUnionTypeNode(type) ? type.types.concat(undefinedTypeNode) : [type, undefinedTypeNode];
154190
- changeTracker.replaceNode(propertyDeclarationSourceFile, type, ts.factory.createUnionTypeNode(types));
154254
+ var types = ts.isUnionTypeNode(info.type) ? info.type.types.concat(undefinedTypeNode) : [info.type, undefinedTypeNode];
154255
+ var unionTypeNode = ts.factory.createUnionTypeNode(types);
154256
+ if (info.isJs) {
154257
+ changeTracker.addJSDocTags(sourceFile, info.prop, [ts.factory.createJSDocTypeTag(/*tagName*/ undefined, ts.factory.createJSDocTypeExpression(unionTypeNode))]);
154258
+ }
154259
+ else {
154260
+ changeTracker.replaceNode(sourceFile, info.type, unionTypeNode);
154261
+ }
154191
154262
  }
154192
- function getActionForAddMissingInitializer(context, propertyDeclaration) {
154263
+ function getActionForAddMissingInitializer(context, info) {
154264
+ if (info.isJs)
154265
+ return undefined;
154193
154266
  var checker = context.program.getTypeChecker();
154194
- var initializer = getInitializer(checker, propertyDeclaration);
154267
+ var initializer = getInitializer(checker, info.prop);
154195
154268
  if (!initializer)
154196
154269
  return undefined;
154197
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile, propertyDeclaration, initializer); });
154198
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0, propertyDeclaration.name.getText()], fixIdAddInitializer, ts.Diagnostics.Add_initializers_to_all_uninitialized_properties);
154270
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile, info.prop, initializer); });
154271
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0, info.prop.name.getText()], fixIdAddInitializer, ts.Diagnostics.Add_initializers_to_all_uninitialized_properties);
154199
154272
  }
154200
154273
  function addInitializer(changeTracker, propertyDeclarationSourceFile, propertyDeclaration, initializer) {
154201
154274
  var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, propertyDeclaration.questionToken, propertyDeclaration.type, initializer);
@@ -160572,6 +160645,7 @@ var ts;
160572
160645
  ], false);
160573
160646
  function createLanguageService(host, documentRegistry, syntaxOnlyOrLanguageServiceMode) {
160574
160647
  var _a;
160648
+ var _b;
160575
160649
  if (documentRegistry === void 0) { documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); }
160576
160650
  var languageServiceMode;
160577
160651
  if (syntaxOnlyOrLanguageServiceMode === undefined) {
@@ -160592,10 +160666,8 @@ var ts;
160592
160666
  ? new CancellationTokenObject(host.getCancellationToken())
160593
160667
  : NoopCancellationToken;
160594
160668
  var currentDirectory = host.getCurrentDirectory();
160595
- // Check if the localized messages json is set, otherwise query the host for it
160596
- if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) {
160597
- ts.setLocalizedDiagnosticMessages(host.getLocalizedDiagnosticMessages());
160598
- }
160669
+ // Checks if the localized messages json is set, and if not, query the host for it
160670
+ ts.maybeSetLocalizedDiagnosticMessages((_b = host.getLocalizedDiagnosticMessages) === null || _b === void 0 ? void 0 : _b.bind(host));
160599
160671
  function log(message) {
160600
160672
  if (host.log) {
160601
160673
  host.log(message);
@@ -160697,6 +160769,7 @@ var ts;
160697
160769
  hasChangedAutomaticTypeDirectiveNames: hasChangedAutomaticTypeDirectiveNames,
160698
160770
  trace: parseConfigHost.trace,
160699
160771
  resolveModuleNames: ts.maybeBind(host, host.resolveModuleNames),
160772
+ getModuleResolutionCache: ts.maybeBind(host, host.getModuleResolutionCache),
160700
160773
  resolveTypeReferenceDirectives: ts.maybeBind(host, host.resolveTypeReferenceDirectives),
160701
160774
  useSourceOfProjectReferenceRedirect: ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect),
160702
160775
  getParsedCommandLine: getParsedCommandLine,
@@ -165327,6 +165400,9 @@ var ts;
165327
165400
  Project.prototype.resolveModuleNames = function (moduleNames, containingFile, reusedNames, redirectedReference, _options, containingSourceFile) {
165328
165401
  return this.resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile);
165329
165402
  };
165403
+ Project.prototype.getModuleResolutionCache = function () {
165404
+ return this.resolutionCache.getModuleResolutionCache();
165405
+ };
165330
165406
  Project.prototype.getResolvedModuleWithFailedLookupLocationsFromCache = function (moduleName, containingFile, resolutionMode) {
165331
165407
  return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode);
165332
165408
  };
@@ -166589,6 +166665,7 @@ var ts;
166589
166665
  if (!program) {
166590
166666
  return ts.emptyArray;
166591
166667
  }
166668
+ var start = ts.timestamp();
166592
166669
  var dependencyNames;
166593
166670
  var rootNames;
166594
166671
  var rootFileName = ts.combinePaths(hostProject.currentDirectory, ts.inferredTypesContainingFile);
@@ -166598,14 +166675,14 @@ var ts;
166598
166675
  (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a.forEach(function (_, dependenyName) { return addDependency(dependenyName); });
166599
166676
  (_b = packageJson.peerDependencies) === null || _b === void 0 ? void 0 : _b.forEach(function (_, dependencyName) { return addDependency(dependencyName); });
166600
166677
  }
166678
+ var dependenciesAdded = 0;
166601
166679
  if (dependencyNames) {
166602
- var dependenciesAdded = 0;
166603
166680
  var symlinkCache = hostProject.getSymlinkCache();
166604
166681
  for (var _c = 0, _d = ts.arrayFrom(dependencyNames.keys()); _c < _d.length; _c++) {
166605
166682
  var name = _d[_c];
166606
166683
  // Avoid creating a large project that would significantly slow down time to editor interactivity
166607
166684
  if (dependencySelection === 2 /* Auto */ && dependenciesAdded > this.maxDependencies) {
166608
- hostProject.log("Auto-import provider attempted to add more than " + this.maxDependencies + " dependencies.");
166685
+ hostProject.log("AutoImportProviderProject: attempted to add more than " + this.maxDependencies + " dependencies. Aborting.");
166609
166686
  return ts.emptyArray;
166610
166687
  }
166611
166688
  // 1. Try to load from the implementation package. For many dependencies, the
@@ -166639,6 +166716,9 @@ var ts;
166639
166716
  }
166640
166717
  }
166641
166718
  }
166719
+ if (rootNames === null || rootNames === void 0 ? void 0 : rootNames.length) {
166720
+ hostProject.log("AutoImportProviderProject: found " + rootNames.length + " root files in " + dependenciesAdded + " dependencies in " + (ts.timestamp() - start) + " ms");
166721
+ }
166642
166722
  return rootNames || ts.emptyArray;
166643
166723
  function addDependency(dependency) {
166644
166724
  if (!ts.startsWith(dependency, "@types/")) {
@@ -166739,6 +166819,11 @@ var ts;
166739
166819
  return this.hostProject.getSymlinkCache();
166740
166820
  };
166741
166821
  /*@internal*/
166822
+ AutoImportProviderProject.prototype.getModuleResolutionCache = function () {
166823
+ var _a;
166824
+ return (_a = this.hostProject.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getModuleResolutionCache();
166825
+ };
166826
+ /*@internal*/
166742
166827
  AutoImportProviderProject.maxDependencies = 10;
166743
166828
  /*@internal*/
166744
166829
  AutoImportProviderProject.compilerOptionsOverrides = {