typescript 4.7.3 → 4.7.4

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/tsc.js CHANGED
@@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  var ts;
70
70
  (function (ts) {
71
71
  ts.versionMajorMinor = "4.7";
72
- ts.version = "4.7.3";
72
+ ts.version = "4.7.4";
73
73
  var NativeCollections;
74
74
  (function (NativeCollections) {
75
75
  var globals = typeof globalThis !== "undefined" ? globalThis :
@@ -28447,9 +28447,10 @@ var ts;
28447
28447
  }
28448
28448
  nextToken();
28449
28449
  var typeArguments = parseDelimitedList(20, parseType);
28450
- if (!parseExpected(31)) {
28450
+ if (reScanGreaterToken() !== 31) {
28451
28451
  return undefined;
28452
28452
  }
28453
+ nextToken();
28453
28454
  return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments : undefined;
28454
28455
  }
28455
28456
  function canFollowTypeArgumentsInExpression() {
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 = "4.7.3";
103
+ ts.version = "4.7.4";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -35424,10 +35424,11 @@ var ts;
35424
35424
  }
35425
35425
  nextToken();
35426
35426
  var typeArguments = parseDelimitedList(20 /* ParsingContext.TypeArguments */, parseType);
35427
- if (!parseExpected(31 /* SyntaxKind.GreaterThanToken */)) {
35427
+ if (reScanGreaterToken() !== 31 /* SyntaxKind.GreaterThanToken */) {
35428
35428
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35429
35429
  return undefined;
35430
35430
  }
35431
+ nextToken();
35431
35432
  // We successfully parsed a type argument list. The next token determines whether we want to
35432
35433
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35433
35434
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -131465,10 +131466,9 @@ var ts;
131465
131466
  GlobalsSearch[GlobalsSearch["Success"] = 1] = "Success";
131466
131467
  GlobalsSearch[GlobalsSearch["Fail"] = 2] = "Fail";
131467
131468
  })(GlobalsSearch || (GlobalsSearch = {}));
131468
- function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
131469
+ function resolvingModuleSpecifiers(logPrefix, host, resolver, program, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
131469
131470
  var _a, _b, _c;
131470
131471
  var start = ts.timestamp();
131471
- var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
131472
131472
  // Under `--moduleResolution nodenext`, we have to resolve module specifiers up front, because
131473
131473
  // package.json exports can mean we *can't* resolve a module specifier (that doesn't include a
131474
131474
  // relative path into node_modules), and we want to filter those completions out entirely.
@@ -131493,7 +131493,7 @@ var ts;
131493
131493
  return result;
131494
131494
  function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
131495
131495
  if (isFromAmbientModule) {
131496
- var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences);
131496
+ var result_1 = resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite);
131497
131497
  if (result_1) {
131498
131498
  ambientCount++;
131499
131499
  }
@@ -131502,7 +131502,7 @@ var ts;
131502
131502
  var shouldResolveModuleSpecifier = needsFullResolution || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
131503
131503
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
131504
131504
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
131505
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131505
+ ? resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, shouldGetModuleSpecifierFromCache)
131506
131506
  : undefined;
131507
131507
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
131508
131508
  skippedAny = true;
@@ -131607,7 +131607,7 @@ var ts;
131607
131607
  return undefined;
131608
131608
  var lowerCaseTokenText = location.text.toLowerCase();
131609
131609
  var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
131610
- var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
131610
+ var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
131611
131611
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
131612
131612
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
131613
131613
  var _a;
@@ -132938,6 +132938,7 @@ var ts;
132938
132938
  var hasUnresolvedAutoImports = false;
132939
132939
  // This also gets mutated in nested-functions after the return
132940
132940
  var symbols = [];
132941
+ var importSpecifierResolver;
132941
132942
  var symbolToOriginInfoMap = [];
132942
132943
  var symbolToSortTextMap = [];
132943
132944
  var seenPropertySymbols = new ts.Map();
@@ -133159,14 +133160,14 @@ var ts;
133159
133160
  }
133160
133161
  else {
133161
133162
  var fileName = ts.isExternalModuleNameRelative(ts.stripQuotes(moduleSymbol.name)) ? (_a = ts.getSourceFileOfModule(moduleSymbol)) === null || _a === void 0 ? void 0 : _a.fileName : undefined;
133162
- var moduleSpecifier = (ts.codefix.getModuleSpecifierForBestExportInfo([{
133163
+ var moduleSpecifier = ((importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences))).getModuleSpecifierForBestExportInfo([{
133163
133164
  exportKind: 0 /* ExportKind.Named */,
133164
133165
  moduleFileName: fileName,
133165
133166
  isFromPackageJson: false,
133166
133167
  moduleSymbol: moduleSymbol,
133167
133168
  symbol: firstAccessibleSymbol,
133168
133169
  targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
133169
- }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location), sourceFile, program, host, preferences) || {}).moduleSpecifier;
133170
+ }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location)) || {}).moduleSpecifier;
133170
133171
  if (moduleSpecifier) {
133171
133172
  var origin = {
133172
133173
  kind: getNullableSymbolOriginInfoKind(6 /* SymbolOriginInfoKind.SymbolMemberExport */),
@@ -133422,7 +133423,7 @@ var ts;
133422
133423
  var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
133423
133424
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
133424
133425
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
133425
- resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
133426
+ resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
133426
133427
  exportInfo.search(sourceFile.path,
133427
133428
  /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
133428
133429
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
@@ -152453,6 +152454,18 @@ var ts;
152453
152454
  return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
152454
152455
  }
152455
152456
  }
152457
+ function createImportSpecifierResolver(importingFile, program, host, preferences) {
152458
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(importingFile, preferences, host);
152459
+ var importMap = createExistingImportMap(program.getTypeChecker(), importingFile, program.getCompilerOptions());
152460
+ return { getModuleSpecifierForBestExportInfo: getModuleSpecifierForBestExportInfo };
152461
+ function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, fromCacheOnly) {
152462
+ var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
152463
+ /*useRequire*/ false, program, importingFile, host, preferences, importMap, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152464
+ var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter, host);
152465
+ return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
152466
+ }
152467
+ }
152468
+ codefix.createImportSpecifierResolver = createImportSpecifierResolver;
152456
152469
  // Sorted with the preferred fix coming first.
152457
152470
  var ImportFixKind;
152458
152471
  (function (ImportFixKind) {
@@ -152553,18 +152566,12 @@ var ts;
152553
152566
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
152554
152567
  }
152555
152568
  }
152556
- function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
152557
- var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
152558
- /*useRequire*/ false, program, importingFile, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152559
- var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host), host);
152560
- return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
152561
- }
152562
- codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
152563
152569
  function getImportFixes(exportInfos, useNamespaceInfo,
152564
152570
  /** undefined only for missing JSX namespace */
152565
- isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, fromCacheOnly) {
152571
+ isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap, fromCacheOnly) {
152572
+ if (importMap === void 0) { importMap = createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()); }
152566
152573
  var checker = program.getTypeChecker();
152567
- var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
152574
+ var existingImports = ts.flatMap(exportInfos, importMap.getImportsForExportInfo);
152568
152575
  var useNamespace = useNamespaceInfo && tryUseExistingNamespaceImport(existingImports, useNamespaceInfo.symbolName, useNamespaceInfo.position, checker);
152569
152576
  var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
152570
152577
  if (addToExisting) {
@@ -152692,21 +152699,37 @@ var ts;
152692
152699
  };
152693
152700
  });
152694
152701
  }
152695
- function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
152696
- var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
152697
- // Can't use an es6 import for a type in JS.
152698
- if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
152699
- return ts.emptyArray;
152700
- var importKind = getImportKind(importingFile, exportKind, compilerOptions);
152701
- return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
152702
+ function createExistingImportMap(checker, importingFile, compilerOptions) {
152703
+ var importMap;
152704
+ for (var _i = 0, _a = importingFile.imports; _i < _a.length; _i++) {
152705
+ var moduleSpecifier = _a[_i];
152702
152706
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
152703
152707
  if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
152704
- return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
152708
+ var moduleSymbol = checker.resolveExternalModuleName(moduleSpecifier);
152709
+ if (moduleSymbol) {
152710
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i.parent);
152711
+ }
152705
152712
  }
152706
- if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
152707
- return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
152713
+ else if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
152714
+ var moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
152715
+ if (moduleSymbol) {
152716
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i);
152717
+ }
152708
152718
  }
152709
- });
152719
+ }
152720
+ return {
152721
+ getImportsForExportInfo: function (_a) {
152722
+ var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
152723
+ // Can't use an es6 import for a type in JS.
152724
+ if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
152725
+ return ts.emptyArray;
152726
+ var matchingDeclarations = importMap === null || importMap === void 0 ? void 0 : importMap.get(ts.getSymbolId(moduleSymbol));
152727
+ if (!matchingDeclarations)
152728
+ return ts.emptyArray;
152729
+ var importKind = getImportKind(importingFile, exportKind, compilerOptions);
152730
+ return matchingDeclarations.map(function (declaration) { return ({ declaration: declaration, importKind: importKind, symbol: symbol, targetFlags: targetFlags }); });
152731
+ }
152732
+ };
152710
152733
  }
152711
152734
  function shouldUseRequire(sourceFile, program) {
152712
152735
  // 1. TypeScript files don't use require variable declarations
@@ -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 = "4.7.3";
297
+ ts.version = "4.7.4";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -35618,10 +35618,11 @@ var ts;
35618
35618
  }
35619
35619
  nextToken();
35620
35620
  var typeArguments = parseDelimitedList(20 /* ParsingContext.TypeArguments */, parseType);
35621
- if (!parseExpected(31 /* SyntaxKind.GreaterThanToken */)) {
35621
+ if (reScanGreaterToken() !== 31 /* SyntaxKind.GreaterThanToken */) {
35622
35622
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35623
35623
  return undefined;
35624
35624
  }
35625
+ nextToken();
35625
35626
  // We successfully parsed a type argument list. The next token determines whether we want to
35626
35627
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35627
35628
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -132076,10 +132077,9 @@ var ts;
132076
132077
  GlobalsSearch[GlobalsSearch["Success"] = 1] = "Success";
132077
132078
  GlobalsSearch[GlobalsSearch["Fail"] = 2] = "Fail";
132078
132079
  })(GlobalsSearch || (GlobalsSearch = {}));
132079
- function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
132080
+ function resolvingModuleSpecifiers(logPrefix, host, resolver, program, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
132080
132081
  var _a, _b, _c;
132081
132082
  var start = ts.timestamp();
132082
- var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
132083
132083
  // Under `--moduleResolution nodenext`, we have to resolve module specifiers up front, because
132084
132084
  // package.json exports can mean we *can't* resolve a module specifier (that doesn't include a
132085
132085
  // relative path into node_modules), and we want to filter those completions out entirely.
@@ -132104,7 +132104,7 @@ var ts;
132104
132104
  return result;
132105
132105
  function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
132106
132106
  if (isFromAmbientModule) {
132107
- var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences);
132107
+ var result_1 = resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite);
132108
132108
  if (result_1) {
132109
132109
  ambientCount++;
132110
132110
  }
@@ -132113,7 +132113,7 @@ var ts;
132113
132113
  var shouldResolveModuleSpecifier = needsFullResolution || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
132114
132114
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
132115
132115
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
132116
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
132116
+ ? resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, shouldGetModuleSpecifierFromCache)
132117
132117
  : undefined;
132118
132118
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
132119
132119
  skippedAny = true;
@@ -132218,7 +132218,7 @@ var ts;
132218
132218
  return undefined;
132219
132219
  var lowerCaseTokenText = location.text.toLowerCase();
132220
132220
  var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
132221
- var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
132221
+ var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
132222
132222
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
132223
132223
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
132224
132224
  var _a;
@@ -133549,6 +133549,7 @@ var ts;
133549
133549
  var hasUnresolvedAutoImports = false;
133550
133550
  // This also gets mutated in nested-functions after the return
133551
133551
  var symbols = [];
133552
+ var importSpecifierResolver;
133552
133553
  var symbolToOriginInfoMap = [];
133553
133554
  var symbolToSortTextMap = [];
133554
133555
  var seenPropertySymbols = new ts.Map();
@@ -133770,14 +133771,14 @@ var ts;
133770
133771
  }
133771
133772
  else {
133772
133773
  var fileName = ts.isExternalModuleNameRelative(ts.stripQuotes(moduleSymbol.name)) ? (_a = ts.getSourceFileOfModule(moduleSymbol)) === null || _a === void 0 ? void 0 : _a.fileName : undefined;
133773
- var moduleSpecifier = (ts.codefix.getModuleSpecifierForBestExportInfo([{
133774
+ var moduleSpecifier = ((importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences))).getModuleSpecifierForBestExportInfo([{
133774
133775
  exportKind: 0 /* ExportKind.Named */,
133775
133776
  moduleFileName: fileName,
133776
133777
  isFromPackageJson: false,
133777
133778
  moduleSymbol: moduleSymbol,
133778
133779
  symbol: firstAccessibleSymbol,
133779
133780
  targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
133780
- }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location), sourceFile, program, host, preferences) || {}).moduleSpecifier;
133781
+ }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location)) || {}).moduleSpecifier;
133781
133782
  if (moduleSpecifier) {
133782
133783
  var origin = {
133783
133784
  kind: getNullableSymbolOriginInfoKind(6 /* SymbolOriginInfoKind.SymbolMemberExport */),
@@ -134033,7 +134034,7 @@ var ts;
134033
134034
  var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
134034
134035
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
134035
134036
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
134036
- resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
134037
+ resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
134037
134038
  exportInfo.search(sourceFile.path,
134038
134039
  /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
134039
134040
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
@@ -153064,6 +153065,18 @@ var ts;
153064
153065
  return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
153065
153066
  }
153066
153067
  }
153068
+ function createImportSpecifierResolver(importingFile, program, host, preferences) {
153069
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(importingFile, preferences, host);
153070
+ var importMap = createExistingImportMap(program.getTypeChecker(), importingFile, program.getCompilerOptions());
153071
+ return { getModuleSpecifierForBestExportInfo: getModuleSpecifierForBestExportInfo };
153072
+ function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, fromCacheOnly) {
153073
+ var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
153074
+ /*useRequire*/ false, program, importingFile, host, preferences, importMap, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
153075
+ var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter, host);
153076
+ return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
153077
+ }
153078
+ }
153079
+ codefix.createImportSpecifierResolver = createImportSpecifierResolver;
153067
153080
  // Sorted with the preferred fix coming first.
153068
153081
  var ImportFixKind;
153069
153082
  (function (ImportFixKind) {
@@ -153164,18 +153177,12 @@ var ts;
153164
153177
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
153165
153178
  }
153166
153179
  }
153167
- function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
153168
- var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
153169
- /*useRequire*/ false, program, importingFile, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
153170
- var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host), host);
153171
- return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
153172
- }
153173
- codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
153174
153180
  function getImportFixes(exportInfos, useNamespaceInfo,
153175
153181
  /** undefined only for missing JSX namespace */
153176
- isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, fromCacheOnly) {
153182
+ isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap, fromCacheOnly) {
153183
+ if (importMap === void 0) { importMap = createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()); }
153177
153184
  var checker = program.getTypeChecker();
153178
- var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
153185
+ var existingImports = ts.flatMap(exportInfos, importMap.getImportsForExportInfo);
153179
153186
  var useNamespace = useNamespaceInfo && tryUseExistingNamespaceImport(existingImports, useNamespaceInfo.symbolName, useNamespaceInfo.position, checker);
153180
153187
  var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
153181
153188
  if (addToExisting) {
@@ -153303,21 +153310,37 @@ var ts;
153303
153310
  };
153304
153311
  });
153305
153312
  }
153306
- function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
153307
- var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
153308
- // Can't use an es6 import for a type in JS.
153309
- if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
153310
- return ts.emptyArray;
153311
- var importKind = getImportKind(importingFile, exportKind, compilerOptions);
153312
- return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
153313
+ function createExistingImportMap(checker, importingFile, compilerOptions) {
153314
+ var importMap;
153315
+ for (var _i = 0, _a = importingFile.imports; _i < _a.length; _i++) {
153316
+ var moduleSpecifier = _a[_i];
153313
153317
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
153314
153318
  if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
153315
- return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
153319
+ var moduleSymbol = checker.resolveExternalModuleName(moduleSpecifier);
153320
+ if (moduleSymbol) {
153321
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i.parent);
153322
+ }
153316
153323
  }
153317
- if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
153318
- return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
153324
+ else if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
153325
+ var moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
153326
+ if (moduleSymbol) {
153327
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i);
153328
+ }
153319
153329
  }
153320
- });
153330
+ }
153331
+ return {
153332
+ getImportsForExportInfo: function (_a) {
153333
+ var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
153334
+ // Can't use an es6 import for a type in JS.
153335
+ if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
153336
+ return ts.emptyArray;
153337
+ var matchingDeclarations = importMap === null || importMap === void 0 ? void 0 : importMap.get(ts.getSymbolId(moduleSymbol));
153338
+ if (!matchingDeclarations)
153339
+ return ts.emptyArray;
153340
+ var importKind = getImportKind(importingFile, exportKind, compilerOptions);
153341
+ return matchingDeclarations.map(function (declaration) { return ({ declaration: declaration, importKind: importKind, symbol: symbol, targetFlags: targetFlags }); });
153342
+ }
153343
+ };
153321
153344
  }
153322
153345
  function shouldUseRequire(sourceFile, program) {
153323
153346
  // 1. TypeScript files don't use require variable declarations
package/lib/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = "4.7.3";
297
+ ts.version = "4.7.4";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -35618,10 +35618,11 @@ var ts;
35618
35618
  }
35619
35619
  nextToken();
35620
35620
  var typeArguments = parseDelimitedList(20 /* ParsingContext.TypeArguments */, parseType);
35621
- if (!parseExpected(31 /* SyntaxKind.GreaterThanToken */)) {
35621
+ if (reScanGreaterToken() !== 31 /* SyntaxKind.GreaterThanToken */) {
35622
35622
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35623
35623
  return undefined;
35624
35624
  }
35625
+ nextToken();
35625
35626
  // We successfully parsed a type argument list. The next token determines whether we want to
35626
35627
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35627
35628
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -132076,10 +132077,9 @@ var ts;
132076
132077
  GlobalsSearch[GlobalsSearch["Success"] = 1] = "Success";
132077
132078
  GlobalsSearch[GlobalsSearch["Fail"] = 2] = "Fail";
132078
132079
  })(GlobalsSearch || (GlobalsSearch = {}));
132079
- function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
132080
+ function resolvingModuleSpecifiers(logPrefix, host, resolver, program, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
132080
132081
  var _a, _b, _c;
132081
132082
  var start = ts.timestamp();
132082
- var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
132083
132083
  // Under `--moduleResolution nodenext`, we have to resolve module specifiers up front, because
132084
132084
  // package.json exports can mean we *can't* resolve a module specifier (that doesn't include a
132085
132085
  // relative path into node_modules), and we want to filter those completions out entirely.
@@ -132104,7 +132104,7 @@ var ts;
132104
132104
  return result;
132105
132105
  function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
132106
132106
  if (isFromAmbientModule) {
132107
- var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences);
132107
+ var result_1 = resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite);
132108
132108
  if (result_1) {
132109
132109
  ambientCount++;
132110
132110
  }
@@ -132113,7 +132113,7 @@ var ts;
132113
132113
  var shouldResolveModuleSpecifier = needsFullResolution || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
132114
132114
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
132115
132115
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
132116
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
132116
+ ? resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, shouldGetModuleSpecifierFromCache)
132117
132117
  : undefined;
132118
132118
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
132119
132119
  skippedAny = true;
@@ -132218,7 +132218,7 @@ var ts;
132218
132218
  return undefined;
132219
132219
  var lowerCaseTokenText = location.text.toLowerCase();
132220
132220
  var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
132221
- var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
132221
+ var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
132222
132222
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
132223
132223
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
132224
132224
  var _a;
@@ -133549,6 +133549,7 @@ var ts;
133549
133549
  var hasUnresolvedAutoImports = false;
133550
133550
  // This also gets mutated in nested-functions after the return
133551
133551
  var symbols = [];
133552
+ var importSpecifierResolver;
133552
133553
  var symbolToOriginInfoMap = [];
133553
133554
  var symbolToSortTextMap = [];
133554
133555
  var seenPropertySymbols = new ts.Map();
@@ -133770,14 +133771,14 @@ var ts;
133770
133771
  }
133771
133772
  else {
133772
133773
  var fileName = ts.isExternalModuleNameRelative(ts.stripQuotes(moduleSymbol.name)) ? (_a = ts.getSourceFileOfModule(moduleSymbol)) === null || _a === void 0 ? void 0 : _a.fileName : undefined;
133773
- var moduleSpecifier = (ts.codefix.getModuleSpecifierForBestExportInfo([{
133774
+ var moduleSpecifier = ((importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences))).getModuleSpecifierForBestExportInfo([{
133774
133775
  exportKind: 0 /* ExportKind.Named */,
133775
133776
  moduleFileName: fileName,
133776
133777
  isFromPackageJson: false,
133777
133778
  moduleSymbol: moduleSymbol,
133778
133779
  symbol: firstAccessibleSymbol,
133779
133780
  targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
133780
- }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location), sourceFile, program, host, preferences) || {}).moduleSpecifier;
133781
+ }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location)) || {}).moduleSpecifier;
133781
133782
  if (moduleSpecifier) {
133782
133783
  var origin = {
133783
133784
  kind: getNullableSymbolOriginInfoKind(6 /* SymbolOriginInfoKind.SymbolMemberExport */),
@@ -134033,7 +134034,7 @@ var ts;
134033
134034
  var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
134034
134035
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
134035
134036
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
134036
- resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
134037
+ resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
134037
134038
  exportInfo.search(sourceFile.path,
134038
134039
  /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
134039
134040
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
@@ -153064,6 +153065,18 @@ var ts;
153064
153065
  return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
153065
153066
  }
153066
153067
  }
153068
+ function createImportSpecifierResolver(importingFile, program, host, preferences) {
153069
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(importingFile, preferences, host);
153070
+ var importMap = createExistingImportMap(program.getTypeChecker(), importingFile, program.getCompilerOptions());
153071
+ return { getModuleSpecifierForBestExportInfo: getModuleSpecifierForBestExportInfo };
153072
+ function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, fromCacheOnly) {
153073
+ var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
153074
+ /*useRequire*/ false, program, importingFile, host, preferences, importMap, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
153075
+ var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter, host);
153076
+ return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
153077
+ }
153078
+ }
153079
+ codefix.createImportSpecifierResolver = createImportSpecifierResolver;
153067
153080
  // Sorted with the preferred fix coming first.
153068
153081
  var ImportFixKind;
153069
153082
  (function (ImportFixKind) {
@@ -153164,18 +153177,12 @@ var ts;
153164
153177
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
153165
153178
  }
153166
153179
  }
153167
- function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
153168
- var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
153169
- /*useRequire*/ false, program, importingFile, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
153170
- var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host), host);
153171
- return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
153172
- }
153173
- codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
153174
153180
  function getImportFixes(exportInfos, useNamespaceInfo,
153175
153181
  /** undefined only for missing JSX namespace */
153176
- isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, fromCacheOnly) {
153182
+ isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap, fromCacheOnly) {
153183
+ if (importMap === void 0) { importMap = createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()); }
153177
153184
  var checker = program.getTypeChecker();
153178
- var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
153185
+ var existingImports = ts.flatMap(exportInfos, importMap.getImportsForExportInfo);
153179
153186
  var useNamespace = useNamespaceInfo && tryUseExistingNamespaceImport(existingImports, useNamespaceInfo.symbolName, useNamespaceInfo.position, checker);
153180
153187
  var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
153181
153188
  if (addToExisting) {
@@ -153303,21 +153310,37 @@ var ts;
153303
153310
  };
153304
153311
  });
153305
153312
  }
153306
- function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
153307
- var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
153308
- // Can't use an es6 import for a type in JS.
153309
- if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
153310
- return ts.emptyArray;
153311
- var importKind = getImportKind(importingFile, exportKind, compilerOptions);
153312
- return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
153313
+ function createExistingImportMap(checker, importingFile, compilerOptions) {
153314
+ var importMap;
153315
+ for (var _i = 0, _a = importingFile.imports; _i < _a.length; _i++) {
153316
+ var moduleSpecifier = _a[_i];
153313
153317
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
153314
153318
  if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
153315
- return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
153319
+ var moduleSymbol = checker.resolveExternalModuleName(moduleSpecifier);
153320
+ if (moduleSymbol) {
153321
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i.parent);
153322
+ }
153316
153323
  }
153317
- if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
153318
- return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
153324
+ else if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
153325
+ var moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
153326
+ if (moduleSymbol) {
153327
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i);
153328
+ }
153319
153329
  }
153320
- });
153330
+ }
153331
+ return {
153332
+ getImportsForExportInfo: function (_a) {
153333
+ var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
153334
+ // Can't use an es6 import for a type in JS.
153335
+ if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
153336
+ return ts.emptyArray;
153337
+ var matchingDeclarations = importMap === null || importMap === void 0 ? void 0 : importMap.get(ts.getSymbolId(moduleSymbol));
153338
+ if (!matchingDeclarations)
153339
+ return ts.emptyArray;
153340
+ var importKind = getImportKind(importingFile, exportKind, compilerOptions);
153341
+ return matchingDeclarations.map(function (declaration) { return ({ declaration: declaration, importKind: importKind, symbol: symbol, targetFlags: targetFlags }); });
153342
+ }
153343
+ };
153321
153344
  }
153322
153345
  function shouldUseRequire(sourceFile, program) {
153323
153346
  // 1. TypeScript files don't use require variable declarations
@@ -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 = "4.7.3";
297
+ ts.version = "4.7.4";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -35618,10 +35618,11 @@ var ts;
35618
35618
  }
35619
35619
  nextToken();
35620
35620
  var typeArguments = parseDelimitedList(20 /* ParsingContext.TypeArguments */, parseType);
35621
- if (!parseExpected(31 /* SyntaxKind.GreaterThanToken */)) {
35621
+ if (reScanGreaterToken() !== 31 /* SyntaxKind.GreaterThanToken */) {
35622
35622
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35623
35623
  return undefined;
35624
35624
  }
35625
+ nextToken();
35625
35626
  // We successfully parsed a type argument list. The next token determines whether we want to
35626
35627
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35627
35628
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -132076,10 +132077,9 @@ var ts;
132076
132077
  GlobalsSearch[GlobalsSearch["Success"] = 1] = "Success";
132077
132078
  GlobalsSearch[GlobalsSearch["Fail"] = 2] = "Fail";
132078
132079
  })(GlobalsSearch || (GlobalsSearch = {}));
132079
- function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
132080
+ function resolvingModuleSpecifiers(logPrefix, host, resolver, program, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
132080
132081
  var _a, _b, _c;
132081
132082
  var start = ts.timestamp();
132082
- var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
132083
132083
  // Under `--moduleResolution nodenext`, we have to resolve module specifiers up front, because
132084
132084
  // package.json exports can mean we *can't* resolve a module specifier (that doesn't include a
132085
132085
  // relative path into node_modules), and we want to filter those completions out entirely.
@@ -132104,7 +132104,7 @@ var ts;
132104
132104
  return result;
132105
132105
  function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
132106
132106
  if (isFromAmbientModule) {
132107
- var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences);
132107
+ var result_1 = resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite);
132108
132108
  if (result_1) {
132109
132109
  ambientCount++;
132110
132110
  }
@@ -132113,7 +132113,7 @@ var ts;
132113
132113
  var shouldResolveModuleSpecifier = needsFullResolution || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
132114
132114
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
132115
132115
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
132116
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
132116
+ ? resolver.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, shouldGetModuleSpecifierFromCache)
132117
132117
  : undefined;
132118
132118
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
132119
132119
  skippedAny = true;
@@ -132218,7 +132218,7 @@ var ts;
132218
132218
  return undefined;
132219
132219
  var lowerCaseTokenText = location.text.toLowerCase();
132220
132220
  var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
132221
- var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
132221
+ var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
132222
132222
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
132223
132223
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
132224
132224
  var _a;
@@ -133549,6 +133549,7 @@ var ts;
133549
133549
  var hasUnresolvedAutoImports = false;
133550
133550
  // This also gets mutated in nested-functions after the return
133551
133551
  var symbols = [];
133552
+ var importSpecifierResolver;
133552
133553
  var symbolToOriginInfoMap = [];
133553
133554
  var symbolToSortTextMap = [];
133554
133555
  var seenPropertySymbols = new ts.Map();
@@ -133770,14 +133771,14 @@ var ts;
133770
133771
  }
133771
133772
  else {
133772
133773
  var fileName = ts.isExternalModuleNameRelative(ts.stripQuotes(moduleSymbol.name)) ? (_a = ts.getSourceFileOfModule(moduleSymbol)) === null || _a === void 0 ? void 0 : _a.fileName : undefined;
133773
- var moduleSpecifier = (ts.codefix.getModuleSpecifierForBestExportInfo([{
133774
+ var moduleSpecifier = ((importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences))).getModuleSpecifierForBestExportInfo([{
133774
133775
  exportKind: 0 /* ExportKind.Named */,
133775
133776
  moduleFileName: fileName,
133776
133777
  isFromPackageJson: false,
133777
133778
  moduleSymbol: moduleSymbol,
133778
133779
  symbol: firstAccessibleSymbol,
133779
133780
  targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
133780
- }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location), sourceFile, program, host, preferences) || {}).moduleSpecifier;
133781
+ }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location)) || {}).moduleSpecifier;
133781
133782
  if (moduleSpecifier) {
133782
133783
  var origin = {
133783
133784
  kind: getNullableSymbolOriginInfoKind(6 /* SymbolOriginInfoKind.SymbolMemberExport */),
@@ -134033,7 +134034,7 @@ var ts;
134033
134034
  var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
134034
134035
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
134035
134036
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
134036
- resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
134037
+ resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
134037
134038
  exportInfo.search(sourceFile.path,
134038
134039
  /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
134039
134040
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
@@ -153064,6 +153065,18 @@ var ts;
153064
153065
  return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
153065
153066
  }
153066
153067
  }
153068
+ function createImportSpecifierResolver(importingFile, program, host, preferences) {
153069
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(importingFile, preferences, host);
153070
+ var importMap = createExistingImportMap(program.getTypeChecker(), importingFile, program.getCompilerOptions());
153071
+ return { getModuleSpecifierForBestExportInfo: getModuleSpecifierForBestExportInfo };
153072
+ function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, fromCacheOnly) {
153073
+ var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
153074
+ /*useRequire*/ false, program, importingFile, host, preferences, importMap, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
153075
+ var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter, host);
153076
+ return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
153077
+ }
153078
+ }
153079
+ codefix.createImportSpecifierResolver = createImportSpecifierResolver;
153067
153080
  // Sorted with the preferred fix coming first.
153068
153081
  var ImportFixKind;
153069
153082
  (function (ImportFixKind) {
@@ -153164,18 +153177,12 @@ var ts;
153164
153177
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
153165
153178
  }
153166
153179
  }
153167
- function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
153168
- var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
153169
- /*useRequire*/ false, program, importingFile, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
153170
- var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host), host);
153171
- return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
153172
- }
153173
- codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
153174
153180
  function getImportFixes(exportInfos, useNamespaceInfo,
153175
153181
  /** undefined only for missing JSX namespace */
153176
- isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, fromCacheOnly) {
153182
+ isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap, fromCacheOnly) {
153183
+ if (importMap === void 0) { importMap = createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()); }
153177
153184
  var checker = program.getTypeChecker();
153178
- var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
153185
+ var existingImports = ts.flatMap(exportInfos, importMap.getImportsForExportInfo);
153179
153186
  var useNamespace = useNamespaceInfo && tryUseExistingNamespaceImport(existingImports, useNamespaceInfo.symbolName, useNamespaceInfo.position, checker);
153180
153187
  var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
153181
153188
  if (addToExisting) {
@@ -153303,21 +153310,37 @@ var ts;
153303
153310
  };
153304
153311
  });
153305
153312
  }
153306
- function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
153307
- var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
153308
- // Can't use an es6 import for a type in JS.
153309
- if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
153310
- return ts.emptyArray;
153311
- var importKind = getImportKind(importingFile, exportKind, compilerOptions);
153312
- return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
153313
+ function createExistingImportMap(checker, importingFile, compilerOptions) {
153314
+ var importMap;
153315
+ for (var _i = 0, _a = importingFile.imports; _i < _a.length; _i++) {
153316
+ var moduleSpecifier = _a[_i];
153313
153317
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
153314
153318
  if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
153315
- return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
153319
+ var moduleSymbol = checker.resolveExternalModuleName(moduleSpecifier);
153320
+ if (moduleSymbol) {
153321
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i.parent);
153322
+ }
153316
153323
  }
153317
- if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
153318
- return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
153324
+ else if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
153325
+ var moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
153326
+ if (moduleSymbol) {
153327
+ (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i);
153328
+ }
153319
153329
  }
153320
- });
153330
+ }
153331
+ return {
153332
+ getImportsForExportInfo: function (_a) {
153333
+ var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
153334
+ // Can't use an es6 import for a type in JS.
153335
+ if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
153336
+ return ts.emptyArray;
153337
+ var matchingDeclarations = importMap === null || importMap === void 0 ? void 0 : importMap.get(ts.getSymbolId(moduleSymbol));
153338
+ if (!matchingDeclarations)
153339
+ return ts.emptyArray;
153340
+ var importKind = getImportKind(importingFile, exportKind, compilerOptions);
153341
+ return matchingDeclarations.map(function (declaration) { return ({ declaration: declaration, importKind: importKind, symbol: symbol, targetFlags: targetFlags }); });
153342
+ }
153343
+ };
153321
153344
  }
153322
153345
  function shouldUseRequire(sourceFile, program) {
153323
153346
  // 1. TypeScript files don't use require variable declarations
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = "4.7.3";
92
+ ts.version = "4.7.4";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -35413,10 +35413,11 @@ var ts;
35413
35413
  }
35414
35414
  nextToken();
35415
35415
  var typeArguments = parseDelimitedList(20 /* ParsingContext.TypeArguments */, parseType);
35416
- if (!parseExpected(31 /* SyntaxKind.GreaterThanToken */)) {
35416
+ if (reScanGreaterToken() !== 31 /* SyntaxKind.GreaterThanToken */) {
35417
35417
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35418
35418
  return undefined;
35419
35419
  }
35420
+ nextToken();
35420
35421
  // We successfully parsed a type argument list. The next token determines whether we want to
35421
35422
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35422
35423
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "typescript",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "4.7.3",
5
+ "version": "4.7.4",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [