typescript 4.6.0-dev.20220117 → 4.6.0-dev.20220121

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.
@@ -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.20220117";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220121";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -7004,11 +7004,15 @@ var ts;
7004
7004
  ts.getFileWatcherEventKind = getFileWatcherEventKind;
7005
7005
  /*@internal*/
7006
7006
  ts.ignoredPaths = ["/node_modules/.", "/.git", "/.#"];
7007
+ var curSysLog = ts.noop; // eslint-disable-line prefer-const
7007
7008
  /*@internal*/
7008
- ts.sysLog = ts.noop; // eslint-disable-line prefer-const
7009
+ function sysLog(s) {
7010
+ return curSysLog(s);
7011
+ }
7012
+ ts.sysLog = sysLog;
7009
7013
  /*@internal*/
7010
7014
  function setSysLog(logger) {
7011
- ts.sysLog = logger;
7015
+ curSysLog = logger;
7012
7016
  }
7013
7017
  ts.setSysLog = setSysLog;
7014
7018
  /**
@@ -7143,7 +7147,7 @@ var ts;
7143
7147
  }
7144
7148
  function onTimerToUpdateChildWatches() {
7145
7149
  timerToUpdateChildWatches = undefined;
7146
- ts.sysLog("sysLog:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size);
7150
+ sysLog("sysLog:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size);
7147
7151
  var start = ts.timestamp();
7148
7152
  var invokeMap = new ts.Map();
7149
7153
  while (!timerToUpdateChildWatches && cacheToUpdateChildWatches.size) {
@@ -7156,7 +7160,7 @@ var ts;
7156
7160
  var hasChanges = updateChildWatches(dirName, dirPath, options);
7157
7161
  invokeCallbacks(dirPath, invokeMap, hasChanges ? undefined : fileNames);
7158
7162
  }
7159
- ts.sysLog("sysLog:: invokingWatchers:: Elapsed:: " + (ts.timestamp() - start) + "ms:: " + cacheToUpdateChildWatches.size);
7163
+ sysLog("sysLog:: invokingWatchers:: Elapsed:: " + (ts.timestamp() - start) + "ms:: " + cacheToUpdateChildWatches.size);
7160
7164
  callbackCache.forEach(function (callbacks, rootDirName) {
7161
7165
  var existing = invokeMap.get(rootDirName);
7162
7166
  if (existing) {
@@ -7172,7 +7176,7 @@ var ts;
7172
7176
  }
7173
7177
  });
7174
7178
  var elapsed = ts.timestamp() - start;
7175
- ts.sysLog("sysLog:: Elapsed:: " + elapsed + "ms:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size + " " + timerToUpdateChildWatches);
7179
+ sysLog("sysLog:: Elapsed:: " + elapsed + "ms:: onTimerToUpdateChildWatches:: " + cacheToUpdateChildWatches.size + " " + timerToUpdateChildWatches);
7176
7180
  }
7177
7181
  function removeChildWatches(parentWatcher) {
7178
7182
  if (!parentWatcher)
@@ -7759,7 +7763,7 @@ var ts;
7759
7763
  * @param createWatcher
7760
7764
  */
7761
7765
  function invokeCallbackAndUpdateWatcher(createWatcher) {
7762
- ts.sysLog("sysLog:: " + fileOrDirectory + ":: Changing watcher to " + (createWatcher === watchPresentFileSystemEntry ? "Present" : "Missing") + "FileSystemEntryWatcher");
7766
+ sysLog("sysLog:: " + fileOrDirectory + ":: Changing watcher to " + (createWatcher === watchPresentFileSystemEntry ? "Present" : "Missing") + "FileSystemEntryWatcher");
7763
7767
  // Call the callback for current directory
7764
7768
  callback("rename", "");
7765
7769
  // If watcher is not closed, update it
@@ -7784,7 +7788,7 @@ var ts;
7784
7788
  }
7785
7789
  }
7786
7790
  if (hitSystemWatcherLimit) {
7787
- ts.sysLog("sysLog:: " + fileOrDirectory + ":: Defaulting to fsWatchFile");
7791
+ sysLog("sysLog:: " + fileOrDirectory + ":: Defaulting to fsWatchFile");
7788
7792
  return watchPresentFileSystemEntryWithFsWatchFile();
7789
7793
  }
7790
7794
  try {
@@ -7800,7 +7804,7 @@ var ts;
7800
7804
  // 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
7801
7805
  // so instead of throwing error, use fs.watchFile
7802
7806
  hitSystemWatcherLimit || (hitSystemWatcherLimit = e.code === "ENOSPC");
7803
- ts.sysLog("sysLog:: " + fileOrDirectory + ":: Changing to fsWatchFile");
7807
+ sysLog("sysLog:: " + fileOrDirectory + ":: Changing to fsWatchFile");
7804
7808
  return watchPresentFileSystemEntryWithFsWatchFile();
7805
7809
  }
7806
7810
  }
@@ -8399,6 +8403,7 @@ var ts;
8399
8403
  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"),
8400
8404
  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."),
8401
8405
  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."),
8406
+ catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8402
8407
  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."),
8403
8408
  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."),
8404
8409
  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),
@@ -8886,6 +8891,7 @@ var ts;
8886
8891
  Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_node12_or_nodenext_Consider_adding_an_extension_to_the_import_path: diag(2834, ts.DiagnosticCategory.Error, "Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_n_2834", "Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Consider adding an extension to the import path."),
8887
8892
  Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_node12_or_nodenext_Did_you_mean_0: diag(2835, ts.DiagnosticCategory.Error, "Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_n_2835", "Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean '{0}'?"),
8888
8893
  Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."),
8894
+ Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."),
8889
8895
  Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
8890
8896
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
8891
8897
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -9279,7 +9285,7 @@ var ts;
9279
9285
  Completeness: diag(6257, ts.DiagnosticCategory.Message, "Completeness_6257", "Completeness"),
9280
9286
  _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"),
9281
9287
  Found_1_error_in_1: diag(6259, ts.DiagnosticCategory.Message, "Found_1_error_in_1_6259", "Found 1 error in {1}"),
9282
- Found_0_errors_in_1_file: diag(6260, ts.DiagnosticCategory.Message, "Found_0_errors_in_1_file_6260", "Found {0} errors in 1 file."),
9288
+ 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}"),
9283
9289
  Found_0_errors_in_1_files: diag(6261, ts.DiagnosticCategory.Message, "Found_0_errors_in_1_files_6261", "Found {0} errors in {1} files."),
9284
9290
  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."),
9285
9291
  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}'."),
@@ -16052,7 +16058,7 @@ var ts;
16052
16058
  }
16053
16059
  ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
16054
16060
  function getExternalModuleRequireArgument(node) {
16055
- return isRequireVariableDeclaration(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
16061
+ return isVariableDeclarationInitializedToBareOrAccessedRequire(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
16056
16062
  }
16057
16063
  ts.getExternalModuleRequireArgument = getExternalModuleRequireArgument;
16058
16064
  function isInternalModuleImportEqualsDeclaration(node) {
@@ -16110,17 +16116,29 @@ var ts;
16110
16116
  * Returns true if the node is a VariableDeclaration initialized to a require call (see `isRequireCall`).
16111
16117
  * This function does not test if the node is in a JavaScript file or not.
16112
16118
  */
16113
- function isRequireVariableDeclaration(node) {
16119
+ function isVariableDeclarationInitializedToRequire(node) {
16120
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ false);
16121
+ }
16122
+ ts.isVariableDeclarationInitializedToRequire = isVariableDeclarationInitializedToRequire;
16123
+ /**
16124
+ * Like {@link isVariableDeclarationInitializedToRequire} but allows things like `require("...").foo.bar` or `require("...")["baz"]`.
16125
+ */
16126
+ function isVariableDeclarationInitializedToBareOrAccessedRequire(node) {
16127
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ true);
16128
+ }
16129
+ ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire;
16130
+ function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
16114
16131
  if (node.kind === 202 /* BindingElement */) {
16115
16132
  node = node.parent.parent;
16116
16133
  }
16117
- return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostAccessExpression(node.initializer), /*requireStringLiteralLikeArgument*/ true);
16134
+ return ts.isVariableDeclaration(node) &&
16135
+ !!node.initializer &&
16136
+ isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true);
16118
16137
  }
16119
- ts.isRequireVariableDeclaration = isRequireVariableDeclaration;
16120
16138
  function isRequireVariableStatement(node) {
16121
16139
  return ts.isVariableStatement(node)
16122
16140
  && node.declarationList.declarations.length > 0
16123
- && ts.every(node.declarationList.declarations, function (decl) { return isRequireVariableDeclaration(decl); });
16141
+ && ts.every(node.declarationList.declarations, function (decl) { return isVariableDeclarationInitializedToRequire(decl); });
16124
16142
  }
16125
16143
  ts.isRequireVariableStatement = isRequireVariableStatement;
16126
16144
  function isSingleOrDoubleQuote(charCode) {
@@ -19607,7 +19625,7 @@ var ts;
19607
19625
  getSourceMapSourceConstructor: function () { return SourceMapSource; },
19608
19626
  };
19609
19627
  function setObjectAllocator(alloc) {
19610
- ts.objectAllocator = alloc;
19628
+ Object.assign(ts.objectAllocator, alloc);
19611
19629
  }
19612
19630
  ts.setObjectAllocator = setObjectAllocator;
19613
19631
  function formatStringFromArgs(text, args, baseIndex) {
@@ -19615,13 +19633,22 @@ var ts;
19615
19633
  return text.replace(/{(\d+)}/g, function (_match, index) { return "" + ts.Debug.checkDefined(args[+index + baseIndex]); });
19616
19634
  }
19617
19635
  ts.formatStringFromArgs = formatStringFromArgs;
19636
+ var localizedDiagnosticMessages;
19618
19637
  /* @internal */
19619
19638
  function setLocalizedDiagnosticMessages(messages) {
19620
- ts.localizedDiagnosticMessages = messages;
19639
+ localizedDiagnosticMessages = messages;
19621
19640
  }
19622
19641
  ts.setLocalizedDiagnosticMessages = setLocalizedDiagnosticMessages;
19642
+ /* @internal */
19643
+ // If the localized messages json is unset, and if given function use it to set the json
19644
+ function maybeSetLocalizedDiagnosticMessages(getMessages) {
19645
+ if (!localizedDiagnosticMessages && getMessages) {
19646
+ localizedDiagnosticMessages = getMessages();
19647
+ }
19648
+ }
19649
+ ts.maybeSetLocalizedDiagnosticMessages = maybeSetLocalizedDiagnosticMessages;
19623
19650
  function getLocaleSpecificMessage(message) {
19624
- return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message.key] || message.message;
19651
+ return localizedDiagnosticMessages && localizedDiagnosticMessages[message.key] || message.message;
19625
19652
  }
19626
19653
  ts.getLocaleSpecificMessage = getLocaleSpecificMessage;
19627
19654
  function createDetachedDiagnostic(fileName, start, length, message) {
@@ -35230,7 +35257,7 @@ var ts;
35230
35257
  // one out no matter what.
35231
35258
  var finallyBlock;
35232
35259
  if (!catchClause || token() === 96 /* FinallyKeyword */) {
35233
- parseExpected(96 /* FinallyKeyword */);
35260
+ parseExpected(96 /* FinallyKeyword */, ts.Diagnostics.catch_or_finally_expected);
35234
35261
  finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
35235
35262
  }
35236
35263
  return withJSDoc(finishNode(factory.createTryStatement(tryBlock, catchClause, finallyBlock), pos), hasJSDoc);
@@ -36274,7 +36301,7 @@ var ts;
36274
36301
  var pos = getNodePos();
36275
36302
  var name = ts.tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(10 /* StringLiteral */);
36276
36303
  parseExpected(58 /* ColonToken */);
36277
- var value = parseLiteralLikeNode(10 /* StringLiteral */);
36304
+ var value = parseAssignmentExpressionOrHigher();
36278
36305
  return finishNode(factory.createAssertEntry(name, value), pos);
36279
36306
  }
36280
36307
  function parseAssertClause() {
@@ -44691,7 +44718,7 @@ var ts;
44691
44718
  maybeBindExpressionFlowIfCall(node.expression);
44692
44719
  }
44693
44720
  function maybeBindExpressionFlowIfCall(node) {
44694
- // A top level or LHS of comma expression call expression with a dotted function name and at least one argument
44721
+ // A top level or comma expression call expression with a dotted function name and at least one argument
44695
44722
  // is potentially an assertion and is therefore included in the control flow.
44696
44723
  if (node.kind === 207 /* CallExpression */) {
44697
44724
  var call = node;
@@ -44859,22 +44886,27 @@ var ts;
44859
44886
  }
44860
44887
  return state;
44861
44888
  }
44862
- function onLeft(left, state, _node) {
44889
+ function onLeft(left, state, node) {
44863
44890
  if (!state.skip) {
44864
- return maybeBind(left);
44891
+ var maybeBound = maybeBind(left);
44892
+ if (node.operatorToken.kind === 27 /* CommaToken */) {
44893
+ maybeBindExpressionFlowIfCall(left);
44894
+ }
44895
+ return maybeBound;
44865
44896
  }
44866
44897
  }
44867
- function onOperator(operatorToken, state, node) {
44898
+ function onOperator(operatorToken, state, _node) {
44868
44899
  if (!state.skip) {
44869
- if (operatorToken.kind === 27 /* CommaToken */) {
44870
- maybeBindExpressionFlowIfCall(node.left);
44871
- }
44872
44900
  bind(operatorToken);
44873
44901
  }
44874
44902
  }
44875
- function onRight(right, state, _node) {
44903
+ function onRight(right, state, node) {
44876
44904
  if (!state.skip) {
44877
- return maybeBind(right);
44905
+ var maybeBound = maybeBind(right);
44906
+ if (node.operatorToken.kind === 27 /* CommaToken */) {
44907
+ maybeBindExpressionFlowIfCall(right);
44908
+ }
44909
+ return maybeBound;
44878
44910
  }
44879
44911
  }
44880
44912
  function onExit(node, state) {
@@ -45617,6 +45649,8 @@ var ts;
45617
45649
  return;
45618
45650
  }
45619
45651
  ts.setParent(node, parent);
45652
+ if (ts.tracing)
45653
+ node.tracingPath = file.path;
45620
45654
  var saveInStrictMode = inStrictMode;
45621
45655
  // Even though in the AST the jsdoc @typedef node belongs to the current node,
45622
45656
  // its symbol might be in the same scope with the current node's symbol. Consider:
@@ -46437,7 +46471,7 @@ var ts;
46437
46471
  checkStrictModeEvalOrArguments(node, node.name);
46438
46472
  }
46439
46473
  if (!ts.isBindingPattern(node.name)) {
46440
- if (ts.isInJSFile(node) && ts.isRequireVariableDeclaration(node) && !ts.getJSDocTypeTag(node)) {
46474
+ if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node)) {
46441
46475
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
46442
46476
  }
46443
46477
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -49220,7 +49254,7 @@ var ts;
49220
49254
  && isAliasableOrJsExpression(node.parent.right)
49221
49255
  || node.kind === 295 /* ShorthandPropertyAssignment */
49222
49256
  || node.kind === 294 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
49223
- || ts.isRequireVariableDeclaration(node);
49257
+ || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
49224
49258
  }
49225
49259
  function isAliasableOrJsExpression(e) {
49226
49260
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50008,8 +50042,14 @@ var ts;
50008
50042
  var mode = contextSpecifier && ts.isStringLiteralLike(contextSpecifier) ? ts.getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
50009
50043
  var resolvedModule = ts.getResolvedModule(currentSourceFile, moduleReference, mode);
50010
50044
  var resolutionDiagnostic = resolvedModule && ts.getResolutionDiagnostic(compilerOptions, resolvedModule);
50011
- var sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
50045
+ var sourceFile = resolvedModule
50046
+ && (!resolutionDiagnostic || resolutionDiagnostic === ts.Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set)
50047
+ && host.getSourceFile(resolvedModule.resolvedFileName);
50012
50048
  if (sourceFile) {
50049
+ // If there's a resolutionDiagnostic we need to report it even if a sourceFile is found.
50050
+ if (resolutionDiagnostic) {
50051
+ error(errorNode, resolutionDiagnostic, moduleReference, resolvedModule.resolvedFileName);
50052
+ }
50013
50053
  if (sourceFile.symbol) {
50014
50054
  if (resolvedModule.isExternalLibraryImport && !ts.resolutionExtensionIsTSOrJson(resolvedModule.extension)) {
50015
50055
  errorOnImplicitAnyModule(/*isError*/ false, errorNode, resolvedModule, moduleReference);
@@ -51151,6 +51191,7 @@ var ts;
51151
51191
  getCommonSourceDirectory: !!host.getCommonSourceDirectory ? function () { return host.getCommonSourceDirectory(); } : function () { return ""; },
51152
51192
  getCurrentDirectory: function () { return host.getCurrentDirectory(); },
51153
51193
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache),
51194
+ getPackageJsonInfoCache: function () { var _a; return (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host); },
51154
51195
  useCaseSensitiveFileNames: ts.maybeBind(host, host.useCaseSensitiveFileNames),
51155
51196
  redirectTargetsMap: host.redirectTargetsMap,
51156
51197
  getProjectReferenceRedirect: function (fileName) { return host.getProjectReferenceRedirect(fileName); },
@@ -78097,7 +78138,7 @@ var ts;
78097
78138
  }
78098
78139
  }
78099
78140
  function checkExpression(node, checkMode, forceTuple) {
78100
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("check" /* Check */, "checkExpression", { kind: node.kind, pos: node.pos, end: node.end });
78141
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("check" /* Check */, "checkExpression", { kind: node.kind, pos: node.pos, end: node.end, path: node.tracingPath });
78101
78142
  var saveCurrentNode = currentNode;
78102
78143
  currentNode = node;
78103
78144
  instantiationCount = 0;
@@ -80778,7 +80819,7 @@ var ts;
80778
80819
  }
80779
80820
  // For a commonjs `const x = require`, validate the alias and exit
80780
80821
  var symbol = getSymbolOfNode(node);
80781
- if (symbol.flags & 2097152 /* Alias */ && ts.isRequireVariableDeclaration(node)) {
80822
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
80782
80823
  checkAliasSymbol(node);
80783
80824
  return;
80784
80825
  }
@@ -80856,7 +80897,7 @@ var ts;
80856
80897
  return ts.getSelectedEffectiveModifierFlags(left, interestingFlags) === ts.getSelectedEffectiveModifierFlags(right, interestingFlags);
80857
80898
  }
80858
80899
  function checkVariableDeclaration(node) {
80859
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("check" /* Check */, "checkVariableDeclaration", { kind: node.kind, pos: node.pos, end: node.end });
80900
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("check" /* Check */, "checkVariableDeclaration", { kind: node.kind, pos: node.pos, end: node.end, path: node.tracingPath });
80860
80901
  checkGrammarVariableDeclaration(node);
80861
80902
  checkVariableLikeDeclaration(node);
80862
80903
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
@@ -83246,6 +83287,17 @@ var ts;
83246
83287
  return false;
83247
83288
  }
83248
83289
  }
83290
+ if (!ts.isImportEqualsDeclaration(node) && node.assertClause) {
83291
+ var hasError = false;
83292
+ for (var _i = 0, _a = node.assertClause.elements; _i < _a.length; _i++) {
83293
+ var clause = _a[_i];
83294
+ if (!ts.isStringLiteral(clause.value)) {
83295
+ hasError = true;
83296
+ error(clause.value, ts.Diagnostics.Import_assertion_values_must_be_string_literal_expressions);
83297
+ }
83298
+ }
83299
+ return !hasError;
83300
+ }
83249
83301
  return true;
83250
83302
  }
83251
83303
  function checkAliasSymbol(node) {
@@ -83939,7 +83991,7 @@ var ts;
83939
83991
  }
83940
83992
  }
83941
83993
  function checkDeferredNode(node) {
83942
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("check" /* Check */, "checkDeferredNode", { kind: node.kind, pos: node.pos, end: node.end });
83994
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("check" /* Check */, "checkDeferredNode", { kind: node.kind, pos: node.pos, end: node.end, path: node.tracingPath });
83943
83995
  var saveCurrentNode = currentNode;
83944
83996
  currentNode = node;
83945
83997
  instantiationCount = 0;
@@ -87873,7 +87925,7 @@ var ts;
87873
87925
  return factory.updateAssertClause(node, nodesVisitor(node.elements, visitor, ts.isAssertEntry), node.multiLine);
87874
87926
  case 293 /* AssertEntry */:
87875
87927
  ts.Debug.type(node);
87876
- return factory.updateAssertEntry(node, nodeVisitor(node.name, visitor, ts.isAssertionKey), nodeVisitor(node.value, visitor, ts.isStringLiteral));
87928
+ return factory.updateAssertEntry(node, nodeVisitor(node.name, visitor, ts.isAssertionKey), nodeVisitor(node.value, visitor, ts.isExpressionNode));
87877
87929
  case 266 /* ImportClause */:
87878
87930
  ts.Debug.type(node);
87879
87931
  return factory.updateImportClause(node, node.isTypeOnly, nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.namedBindings, visitor, ts.isNamedImportBindings));
@@ -95723,10 +95775,19 @@ var ts;
95723
95775
  var _a;
95724
95776
  var nonWhitespaceChildren = ts.getSemanticJsxChildren(children);
95725
95777
  var isStaticChildren = ts.length(nonWhitespaceChildren) > 1 || !!((_a = nonWhitespaceChildren[0]) === null || _a === void 0 ? void 0 : _a.dotDotDotToken);
95726
- var args = [tagName, objectProperties, !keyAttr ? factory.createVoidZero() : transformJsxAttributeInitializer(keyAttr.initializer)];
95778
+ var args = [tagName, objectProperties];
95779
+ // function jsx(type, config, maybeKey) {}
95780
+ // "maybeKey" is optional. It is acceptable to use "_jsx" without a third argument
95781
+ if (keyAttr) {
95782
+ args.push(transformJsxAttributeInitializer(keyAttr.initializer));
95783
+ }
95727
95784
  if (compilerOptions.jsx === 5 /* ReactJSXDev */) {
95728
95785
  var originalFile = ts.getOriginalNode(currentSourceFile);
95729
95786
  if (originalFile && ts.isSourceFile(originalFile)) {
95787
+ // "maybeKey" has to be replaced with "void 0" to not break the jsxDEV signature
95788
+ if (keyAttr === undefined) {
95789
+ args.push(factory.createVoidZero());
95790
+ }
95730
95791
  // isStaticChildren development flag
95731
95792
  args.push(isStaticChildren ? factory.createTrue() : factory.createFalse());
95732
95793
  // __source development flag
@@ -119591,11 +119652,12 @@ var ts;
119591
119652
  };
119592
119653
  }
119593
119654
  function isFormatRequiringExtensions(compilerOptions, importingSourceFileName, host) {
119655
+ var _a;
119594
119656
  if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node12
119595
119657
  && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) {
119596
119658
  return false;
119597
119659
  }
119598
- return ts.getImpliedNodeFormatForFile(importingSourceFileName, /*packageJsonInfoCache*/ undefined, getModuleResolutionHost(host), compilerOptions) !== ts.ModuleKind.CommonJS;
119660
+ return ts.getImpliedNodeFormatForFile(importingSourceFileName, (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host), getModuleResolutionHost(host), compilerOptions) !== ts.ModuleKind.CommonJS;
119599
119661
  }
119600
119662
  function getModuleResolutionHost(host) {
119601
119663
  var _a;
@@ -120155,11 +120217,13 @@ var ts;
120155
120217
  // For classic resolution, only allow importing from node_modules/@types, not other node_modules
120156
120218
  return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Classic && packageName === nodeModulesDirectoryName ? undefined : packageName;
120157
120219
  function tryDirectoryWithPackageJson(packageRootIndex) {
120220
+ var _a, _b;
120158
120221
  var packageRootPath = path.substring(0, packageRootIndex);
120159
120222
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
120160
120223
  var moduleFileToTry = path;
120161
- if (host.fileExists(packageJsonPath)) {
120162
- var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
120224
+ var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
120225
+ if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
120226
+ var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
120163
120227
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
120164
120228
  // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
120165
120229
  // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
@@ -120459,22 +120523,31 @@ var ts;
120459
120523
  ts.Diagnostics.Found_0_errors_Watching_for_file_changes;
120460
120524
  }
120461
120525
  ts.getWatchErrorSummaryDiagnosticMessage = getWatchErrorSummaryDiagnosticMessage;
120526
+ function prettyPathForFileError(error, cwd) {
120527
+ var line = ts.formatColorAndReset(":" + error.line, ts.ForegroundColorEscapeSequences.Grey);
120528
+ if (ts.pathIsAbsolute(error.fileName) && ts.pathIsAbsolute(cwd)) {
120529
+ return ts.getRelativePathFromDirectory(cwd, error.fileName, /* ignoreCase */ false) + line;
120530
+ }
120531
+ return error.fileName + line;
120532
+ }
120462
120533
  function getErrorSummaryText(errorCount, filesInError, newLine, host) {
120463
120534
  if (errorCount === 0)
120464
120535
  return "";
120465
120536
  var nonNilFiles = filesInError.filter(function (fileInError) { return fileInError !== undefined; });
120466
120537
  var distinctFileNamesWithLines = nonNilFiles.map(function (fileInError) { return fileInError.fileName + ":" + fileInError.line; })
120467
120538
  .filter(function (value, index, self) { return self.indexOf(value) === index; });
120539
+ var firstFileReference = nonNilFiles[0] && prettyPathForFileError(nonNilFiles[0], host.getCurrentDirectory());
120468
120540
  var d = errorCount === 1 ?
120469
120541
  ts.createCompilerDiagnostic(filesInError[0] !== undefined ?
120470
120542
  ts.Diagnostics.Found_1_error_in_1 :
120471
- ts.Diagnostics.Found_1_error, errorCount, distinctFileNamesWithLines[0]) :
120543
+ ts.Diagnostics.Found_1_error, errorCount, firstFileReference) :
120472
120544
  ts.createCompilerDiagnostic(distinctFileNamesWithLines.length === 0 ?
120473
120545
  ts.Diagnostics.Found_0_errors :
120474
120546
  distinctFileNamesWithLines.length === 1 ?
120475
- ts.Diagnostics.Found_0_errors_in_1_file :
120476
- ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length);
120477
- return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "");
120547
+ ts.Diagnostics.Found_0_errors_in_the_same_file_starting_at_Colon_1 :
120548
+ ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length === 1 ? firstFileReference : distinctFileNamesWithLines.length);
120549
+ var suffix = distinctFileNamesWithLines.length > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "";
120550
+ return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + suffix;
120478
120551
  }
120479
120552
  ts.getErrorSummaryText = getErrorSummaryText;
120480
120553
  function createTabularErrorsDisplay(filesInError, host) {
@@ -120496,8 +120569,8 @@ var ts;
120496
120569
  var leftPadding = errorCountDigitsLength < leftPaddingGoal ?
120497
120570
  " ".repeat(leftPaddingGoal - errorCountDigitsLength)
120498
120571
  : "";
120499
- var relativePath = ts.getRelativePathFromDirectory(host.getCurrentDirectory(), file.fileName, /* ignoreCase */ false);
120500
- tabularData += "" + leftPadding + errorCount + " " + relativePath + ":" + file.line + "\n";
120572
+ var fileRef = prettyPathForFileError(file, host.getCurrentDirectory());
120573
+ tabularData += "" + leftPadding + errorCount + " " + fileRef + "\n";
120501
120574
  });
120502
120575
  return tabularData;
120503
120576
  }
@@ -120998,6 +121071,7 @@ var ts;
120998
121071
  var sharedExtendedConfigFileWatchers; // Map of file watchers for extended files, shared between different referenced projects
120999
121072
  var extendedConfigCache = host.extendedConfigCache; // Cache for extended config evaluation
121000
121073
  var changesAffectResolution = false; // Flag for indicating non-config changes affect module resolution
121074
+ var reportFileChangeDetectedOnCreateProgram = false; // True if synchronizeProgram should report "File change detected..." when a new program is created
121001
121075
  var sourceFilesCache = new ts.Map(); // Cache that stores the source file and version info
121002
121076
  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
121003
121077
  var hasChangedCompilerOptions = false; // True if the compiler options have changed between compilations
@@ -121160,14 +121234,21 @@ var ts;
121160
121234
  var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution || changesAffectResolution);
121161
121235
  if (ts.isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
121162
121236
  if (hasChangedConfigFileParsingErrors) {
121237
+ if (reportFileChangeDetectedOnCreateProgram) {
121238
+ reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
121239
+ }
121163
121240
  builderProgram = createProgram(/*rootNames*/ undefined, /*options*/ undefined, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
121164
121241
  hasChangedConfigFileParsingErrors = false;
121165
121242
  }
121166
121243
  }
121167
121244
  else {
121245
+ if (reportFileChangeDetectedOnCreateProgram) {
121246
+ reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
121247
+ }
121168
121248
  createNewProgram(hasInvalidatedResolution);
121169
121249
  }
121170
121250
  changesAffectResolution = false; // reset for next sync
121251
+ reportFileChangeDetectedOnCreateProgram = false;
121171
121252
  if (host.afterProgramCreate && program !== builderProgram) {
121172
121253
  host.afterProgramCreate(builderProgram);
121173
121254
  }
@@ -121369,7 +121450,7 @@ var ts;
121369
121450
  }
121370
121451
  function updateProgramWithWatchStatus() {
121371
121452
  timerToUpdateProgram = undefined;
121372
- reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
121453
+ reportFileChangeDetectedOnCreateProgram = true;
121373
121454
  updateProgram();
121374
121455
  }
121375
121456
  function updateProgram() {
@@ -123893,6 +123974,7 @@ var ts;
123893
123974
  ScriptElementKind["externalModuleName"] = "external module name";
123894
123975
  /**
123895
123976
  * <JsxTagName attribute1 attribute2={0} />
123977
+ * @deprecated
123896
123978
  */
123897
123979
  ScriptElementKind["jsxAttribute"] = "JSX attribute";
123898
123980
  /** String literal */
@@ -125218,7 +125300,7 @@ var ts;
125218
125300
  isWhiteSpaceOnlyJsxText(child);
125219
125301
  if (lookInPreviousChild) {
125220
125302
  // actual start of the node is past the position - previous token should be at the end of previous child
125221
- var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
125303
+ var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile, n.kind);
125222
125304
  return candidate_1 && findRightmostToken(candidate_1, sourceFile);
125223
125305
  }
125224
125306
  else {
@@ -125232,7 +125314,7 @@ var ts;
125232
125314
  // the only known case is when position is at the end of the file.
125233
125315
  // Try to find the rightmost token in the file without filtering.
125234
125316
  // Namely we are skipping the check: 'position < node.end'
125235
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
125317
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
125236
125318
  return candidate && findRightmostToken(candidate, sourceFile);
125237
125319
  }
125238
125320
  }
@@ -125248,17 +125330,19 @@ var ts;
125248
125330
  if (children.length === 0) {
125249
125331
  return n;
125250
125332
  }
125251
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
125333
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
125252
125334
  return candidate && findRightmostToken(candidate, sourceFile);
125253
125335
  }
125254
125336
  /**
125255
125337
  * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
125256
125338
  */
125257
- function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile) {
125339
+ function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile, parentKind) {
125258
125340
  for (var i = exclusiveStartPosition - 1; i >= 0; i--) {
125259
125341
  var child = children[i];
125260
125342
  if (isWhiteSpaceOnlyJsxText(child)) {
125261
- ts.Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
125343
+ if (i === 0 && (parentKind === 11 /* JsxText */ || parentKind === 278 /* JsxSelfClosingElement */)) {
125344
+ ts.Debug.fail("`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
125345
+ }
125262
125346
  }
125263
125347
  else if (nodeHasTokens(children[i], sourceFile)) {
125264
125348
  return children[i];
@@ -125784,6 +125868,7 @@ var ts;
125784
125868
  useCaseSensitiveFileNames: ts.maybeBind(host, host.useCaseSensitiveFileNames),
125785
125869
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache) || program.getSymlinkCache,
125786
125870
  getModuleSpecifierCache: ts.maybeBind(host, host.getModuleSpecifierCache),
125871
+ getPackageJsonInfoCache: function () { var _a; return (_a = program.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache(); },
125787
125872
  getGlobalTypingsCacheLocation: ts.maybeBind(host, host.getGlobalTypingsCacheLocation),
125788
125873
  redirectTargetsMap: program.redirectTargetsMap,
125789
125874
  getProjectReferenceRedirect: function (fileName) { return program.getProjectReferenceRedirect(fileName); },
@@ -129528,6 +129613,7 @@ var ts;
129528
129613
  function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, preferences, isForImportStatementCompletion, cb) {
129529
129614
  var _a, _b, _c;
129530
129615
  var start = ts.timestamp();
129616
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
129531
129617
  var resolutionLimitExceeded = false;
129532
129618
  var ambientCount = 0;
129533
129619
  var resolvedCount = 0;
@@ -129550,7 +129636,7 @@ var ts;
129550
129636
  var shouldResolveModuleSpecifier = isForImportStatementCompletion || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
129551
129637
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
129552
129638
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
129553
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, shouldGetModuleSpecifierFromCache)
129639
+ ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
129554
129640
  : undefined;
129555
129641
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
129556
129642
  resolutionLimitExceeded = true;
@@ -130948,9 +131034,7 @@ var ts;
130948
131034
  // GH#39946. Pulling on the type of a node inside of a function with a contextual `this` parameter can result in a circularity
130949
131035
  // if the `node` is part of the exprssion of a `yield` or `return`. This circularity doesn't exist at compile time because
130950
131036
  // we will check (and cache) the type of `this` *before* checking the type of the node.
130951
- var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false);
130952
- if (!ts.isSourceFile(container) && container.parent)
130953
- typeChecker.getTypeAtLocation(container);
131037
+ typeChecker.tryGetThisTypeAt(node, /*includeGlobalThis*/ false);
130954
131038
  var type = typeChecker.getTypeAtLocation(node).getNonOptionalType();
130955
131039
  var insertQuestionDot = false;
130956
131040
  if (type.isNullableType()) {
@@ -133805,7 +133889,7 @@ var ts;
133805
133889
  ts.Debug.assert(parent.name === node);
133806
133890
  return true;
133807
133891
  case 202 /* BindingElement */:
133808
- return ts.isInJSFile(node) && ts.isRequireVariableDeclaration(parent);
133892
+ return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent);
133809
133893
  default:
133810
133894
  return false;
133811
133895
  }
@@ -134286,7 +134370,7 @@ var ts;
134286
134370
  function getTextSpan(node, sourceFile, endNode) {
134287
134371
  var start = node.getStart(sourceFile);
134288
134372
  var end = (endNode || node).getEnd();
134289
- if (ts.isStringLiteralLike(node)) {
134373
+ if (ts.isStringLiteralLike(node) && (end - start) > 2) {
134290
134374
  ts.Debug.assert(endNode === undefined);
134291
134375
  start += 1;
134292
134376
  end -= 1;
@@ -135205,7 +135289,7 @@ var ts;
135205
135289
  // Use the parent symbol if the location is commonjs require syntax on javascript files only.
135206
135290
  if (ts.isInJSFile(referenceLocation)
135207
135291
  && referenceLocation.parent.kind === 202 /* BindingElement */
135208
- && ts.isRequireVariableDeclaration(referenceLocation.parent)) {
135292
+ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) {
135209
135293
  referenceSymbol = referenceLocation.parent.symbol;
135210
135294
  // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In
135211
135295
  // this case, just skip it, since the bound identifiers are not an alias of the import.
@@ -136916,7 +137000,7 @@ var ts;
136916
137000
  return declaration.parent.kind === 268 /* NamedImports */;
136917
137001
  case 202 /* BindingElement */:
136918
137002
  case 253 /* VariableDeclaration */:
136919
- return ts.isInJSFile(declaration) && ts.isRequireVariableDeclaration(declaration);
137003
+ return ts.isInJSFile(declaration) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(declaration);
136920
137004
  default:
136921
137005
  return false;
136922
137006
  }
@@ -137606,7 +137690,7 @@ var ts;
137606
137690
  textSpan: ts.createTextSpanFromNode(declaration),
137607
137691
  // TODO(jfreeman): What should be the containerName when the container has a computed name?
137608
137692
  containerName: containerName ? containerName.text : "",
137609
- containerKind: containerName ? ts.getNodeKind(container) : "" /* unknown */, // TODO: GH#18217 Just use `container ? ...`
137693
+ containerKind: containerName ? ts.getNodeKind(container) : "" /* unknown */,
137610
137694
  };
137611
137695
  }
137612
137696
  })(NavigateTo = ts.NavigateTo || (ts.NavigateTo = {}));
@@ -141820,18 +141904,7 @@ var ts;
141820
141904
  }
141821
141905
  return unionPropertyKind;
141822
141906
  }
141823
- // If we requested completions after `x.` at the top-level, we may be at a source file location.
141824
- switch (location.parent && location.parent.kind) {
141825
- // If we've typed a character of the attribute name, will be 'JsxAttribute', else will be 'JsxOpeningElement'.
141826
- case 279 /* JsxOpeningElement */:
141827
- case 277 /* JsxElement */:
141828
- case 278 /* JsxSelfClosingElement */:
141829
- return location.kind === 79 /* Identifier */ ? "property" /* memberVariableElement */ : "JSX attribute" /* jsxAttribute */;
141830
- case 284 /* JsxAttribute */:
141831
- return "JSX attribute" /* jsxAttribute */;
141832
- default:
141833
- return "property" /* memberVariableElement */;
141834
- }
141907
+ return "property" /* memberVariableElement */;
141835
141908
  }
141836
141909
  return "" /* unknown */;
141837
141910
  }
@@ -149823,7 +149896,8 @@ var ts;
149823
149896
  codefix.getImportCompletionAction = getImportCompletionAction;
149824
149897
  function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
149825
149898
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
149826
- return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
149899
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
149900
+ return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, packageJsonImportFilter);
149827
149901
  }
149828
149902
  function codeFixActionToCodeAction(_a) {
149829
149903
  var description = _a.description, changes = _a.changes, commands = _a.commands;
@@ -149878,12 +149952,12 @@ var ts;
149878
149952
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
149879
149953
  }
149880
149954
  }
149881
- function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
149955
+ function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
149882
149956
  var _a = getNewImportFixes(program, importingFile,
149883
149957
  /*position*/ undefined,
149884
149958
  /*isValidTypeOnlyUseSite*/ false,
149885
149959
  /*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
149886
- var result = getBestFix(fixes, importingFile, program, host, preferences);
149960
+ var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host));
149887
149961
  return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
149888
149962
  }
149889
149963
  codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
@@ -150017,7 +150091,7 @@ var ts;
150017
150091
  var importKind = getImportKind(importingFile, exportKind, compilerOptions);
150018
150092
  return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
150019
150093
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
150020
- if (ts.isRequireVariableDeclaration(i.parent)) {
150094
+ if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
150021
150095
  return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
150022
150096
  }
150023
150097
  if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
@@ -150103,23 +150177,22 @@ var ts;
150103
150177
  var info = errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code
150104
150178
  ? getFixesInfoForUMDImport(context, symbolToken)
150105
150179
  : ts.isIdentifier(symbolToken) ? getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider) : undefined;
150106
- return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, context.host, context.preferences) });
150180
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
150181
+ return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, packageJsonImportFilter) });
150107
150182
  }
150108
- function sortFixes(fixes, sourceFile, program, host, preferences) {
150109
- var allowsImportingSpecifier = ts.createPackageJsonImportFilter(sourceFile, preferences, host).allowsImportingSpecifier;
150110
- return ts.sort(fixes, function (a, b) { return ts.compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, allowsImportingSpecifier); });
150183
+ function sortFixes(fixes, sourceFile, program, packageJsonImportFilter) {
150184
+ return ts.sort(fixes, function (a, b) { return ts.compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier); });
150111
150185
  }
150112
- function getBestFix(fixes, sourceFile, program, host, preferences) {
150186
+ function getBestFix(fixes, sourceFile, program, packageJsonImportFilter) {
150113
150187
  if (!ts.some(fixes))
150114
150188
  return;
150115
150189
  // These will always be placed first if available, and are better than other kinds
150116
150190
  if (fixes[0].kind === 0 /* UseNamespace */ || fixes[0].kind === 2 /* AddToExisting */) {
150117
150191
  return fixes[0];
150118
150192
  }
150119
- var allowsImportingSpecifier = ts.createPackageJsonImportFilter(sourceFile, preferences, host).allowsImportingSpecifier;
150120
150193
  return fixes.reduce(function (best, fix) {
150121
150194
  // Takes true branch of conditional if `fix` is better than `best`
150122
- return compareModuleSpecifiers(fix, best, sourceFile, program, allowsImportingSpecifier) === -1 /* LessThan */ ? fix : best;
150195
+ return compareModuleSpecifiers(fix, best, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier) === -1 /* LessThan */ ? fix : best;
150123
150196
  });
150124
150197
  }
150125
150198
  /** @returns `Comparison.LessThan` if `a` is better than `b`. */
@@ -150743,7 +150816,7 @@ var ts;
150743
150816
  var errorCodes = [ts.Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation.code];
150744
150817
  codefix.registerCodeFix({
150745
150818
  errorCodes: errorCodes,
150746
- getCodeActions: function (context) {
150819
+ getCodeActions: function getCodeActionsToFixImplicitThis(context) {
150747
150820
  var sourceFile = context.sourceFile, program = context.program, span = context.span;
150748
150821
  var diagnostic;
150749
150822
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) {
@@ -150758,7 +150831,8 @@ var ts;
150758
150831
  });
150759
150832
  function doChange(changes, sourceFile, pos, checker) {
150760
150833
  var token = ts.getTokenAtPosition(sourceFile, pos);
150761
- ts.Debug.assert(token.kind === 108 /* ThisKeyword */);
150834
+ if (!ts.isThis(token))
150835
+ return undefined;
150762
150836
  var fn = ts.getThisContainer(token, /*includeArrowFunctions*/ false);
150763
150837
  if (!ts.isFunctionDeclaration(fn) && !ts.isFunctionExpression(fn))
150764
150838
  return undefined;
@@ -152568,6 +152642,9 @@ var ts;
152568
152642
  codefix.registerCodeFix({
152569
152643
  errorCodes: errorCodes,
152570
152644
  getCodeActions: function (context) {
152645
+ var syntacticDiagnostics = context.program.getSyntacticDiagnostics(context.sourceFile, context.cancellationToken);
152646
+ if (syntacticDiagnostics.length)
152647
+ return;
152571
152648
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(t, context.sourceFile, context.span.start, context.span.length, context.errorCode); });
152572
152649
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Remove_unreachable_code, fixId, ts.Diagnostics.Remove_all_unreachable_code)];
152573
152650
  },
@@ -152971,7 +153048,7 @@ var ts;
152971
153048
  });
152972
153049
  var name = declaration && ts.getNameOfDeclaration(declaration);
152973
153050
  return !name || changes.length === 0 ? undefined
152974
- : [codefix.createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, ts.Diagnostics.Infer_all_types_from_usage)];
153051
+ : [codefix.createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), ts.getTextOfNode(name)], fixId, ts.Diagnostics.Infer_all_types_from_usage)];
152975
153052
  },
152976
153053
  fixIds: [fixId],
152977
153054
  getAllCodeActions: function (context) {
@@ -153049,7 +153126,7 @@ var ts;
153049
153126
  case ts.Diagnostics.Variable_0_implicitly_has_an_1_type.code: {
153050
153127
  var symbol = program.getTypeChecker().getSymbolAtLocation(token);
153051
153128
  if (symbol && symbol.valueDeclaration && ts.isVariableDeclaration(symbol.valueDeclaration) && markSeen(symbol.valueDeclaration)) {
153052
- annotateVariableDeclaration(changes, importAdder, sourceFile, symbol.valueDeclaration, program, host, cancellationToken);
153129
+ annotateVariableDeclaration(changes, importAdder, ts.getSourceFileOfNode(symbol.valueDeclaration), symbol.valueDeclaration, program, host, cancellationToken);
153053
153130
  importAdder.writeFixes(changes);
153054
153131
  return symbol.valueDeclaration;
153055
153132
  }
@@ -161203,6 +161280,7 @@ var ts;
161203
161280
  ], false);
161204
161281
  function createLanguageService(host, documentRegistry, syntaxOnlyOrLanguageServiceMode) {
161205
161282
  var _a;
161283
+ var _b;
161206
161284
  if (documentRegistry === void 0) { documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); }
161207
161285
  var languageServiceMode;
161208
161286
  if (syntaxOnlyOrLanguageServiceMode === undefined) {
@@ -161223,10 +161301,8 @@ var ts;
161223
161301
  ? new CancellationTokenObject(host.getCancellationToken())
161224
161302
  : NoopCancellationToken;
161225
161303
  var currentDirectory = host.getCurrentDirectory();
161226
- // Check if the localized messages json is set, otherwise query the host for it
161227
- if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) {
161228
- ts.setLocalizedDiagnosticMessages(host.getLocalizedDiagnosticMessages());
161229
- }
161304
+ // Checks if the localized messages json is set, and if not, query the host for it
161305
+ ts.maybeSetLocalizedDiagnosticMessages((_b = host.getLocalizedDiagnosticMessages) === null || _b === void 0 ? void 0 : _b.bind(host));
161230
161306
  function log(message) {
161231
161307
  if (host.log) {
161232
161308
  host.log(message);
@@ -161328,6 +161404,7 @@ var ts;
161328
161404
  hasChangedAutomaticTypeDirectiveNames: hasChangedAutomaticTypeDirectiveNames,
161329
161405
  trace: parseConfigHost.trace,
161330
161406
  resolveModuleNames: ts.maybeBind(host, host.resolveModuleNames),
161407
+ getModuleResolutionCache: ts.maybeBind(host, host.getModuleResolutionCache),
161331
161408
  resolveTypeReferenceDirectives: ts.maybeBind(host, host.resolveTypeReferenceDirectives),
161332
161409
  useSourceOfProjectReferenceRedirect: ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect),
161333
161410
  getParsedCommandLine: getParsedCommandLine,
@@ -165541,6 +165618,9 @@ var ts;
165541
165618
  Project.prototype.resolveModuleNames = function (moduleNames, containingFile, reusedNames, redirectedReference, _options, containingSourceFile) {
165542
165619
  return this.resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile);
165543
165620
  };
165621
+ Project.prototype.getModuleResolutionCache = function () {
165622
+ return this.resolutionCache.getModuleResolutionCache();
165623
+ };
165544
165624
  Project.prototype.getResolvedModuleWithFailedLookupLocationsFromCache = function (moduleName, containingFile, resolutionMode) {
165545
165625
  return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode);
165546
165626
  };
@@ -166803,6 +166883,7 @@ var ts;
166803
166883
  if (!program) {
166804
166884
  return ts.emptyArray;
166805
166885
  }
166886
+ var start = ts.timestamp();
166806
166887
  var dependencyNames;
166807
166888
  var rootNames;
166808
166889
  var rootFileName = ts.combinePaths(hostProject.currentDirectory, ts.inferredTypesContainingFile);
@@ -166812,14 +166893,14 @@ var ts;
166812
166893
  (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a.forEach(function (_, dependenyName) { return addDependency(dependenyName); });
166813
166894
  (_b = packageJson.peerDependencies) === null || _b === void 0 ? void 0 : _b.forEach(function (_, dependencyName) { return addDependency(dependencyName); });
166814
166895
  }
166896
+ var dependenciesAdded = 0;
166815
166897
  if (dependencyNames) {
166816
- var dependenciesAdded = 0;
166817
166898
  var symlinkCache = hostProject.getSymlinkCache();
166818
166899
  for (var _c = 0, _d = ts.arrayFrom(dependencyNames.keys()); _c < _d.length; _c++) {
166819
166900
  var name = _d[_c];
166820
166901
  // Avoid creating a large project that would significantly slow down time to editor interactivity
166821
166902
  if (dependencySelection === 2 /* Auto */ && dependenciesAdded > this.maxDependencies) {
166822
- hostProject.log("Auto-import provider attempted to add more than " + this.maxDependencies + " dependencies.");
166903
+ hostProject.log("AutoImportProviderProject: attempted to add more than " + this.maxDependencies + " dependencies. Aborting.");
166823
166904
  return ts.emptyArray;
166824
166905
  }
166825
166906
  // 1. Try to load from the implementation package. For many dependencies, the
@@ -166853,6 +166934,9 @@ var ts;
166853
166934
  }
166854
166935
  }
166855
166936
  }
166937
+ if (rootNames === null || rootNames === void 0 ? void 0 : rootNames.length) {
166938
+ hostProject.log("AutoImportProviderProject: found " + rootNames.length + " root files in " + dependenciesAdded + " dependencies in " + (ts.timestamp() - start) + " ms");
166939
+ }
166856
166940
  return rootNames || ts.emptyArray;
166857
166941
  function addDependency(dependency) {
166858
166942
  if (!ts.startsWith(dependency, "@types/")) {
@@ -166953,6 +167037,11 @@ var ts;
166953
167037
  return this.hostProject.getSymlinkCache();
166954
167038
  };
166955
167039
  /*@internal*/
167040
+ AutoImportProviderProject.prototype.getModuleResolutionCache = function () {
167041
+ var _a;
167042
+ return (_a = this.hostProject.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getModuleResolutionCache();
167043
+ };
167044
+ /*@internal*/
166956
167045
  AutoImportProviderProject.maxDependencies = 10;
166957
167046
  /*@internal*/
166958
167047
  AutoImportProviderProject.compilerOptionsOverrides = {