@@ -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
0 commit comments