mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
refactor: let exportMapKey accepts bad symbol name (#54678)
This commit is contained in:
@@ -2427,7 +2427,7 @@ export class TestState {
|
||||
baselineFile,
|
||||
annotations + "\n\n" + stringify(result, (key, value) => {
|
||||
return key === "exportMapKey"
|
||||
? value.replace(/\|[0-9]+/g, "|*")
|
||||
? value.replace(/ \d+ /g, " * ")
|
||||
: value;
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
emptyArray,
|
||||
every,
|
||||
ExportKind,
|
||||
ExportMapInfoKey,
|
||||
factory,
|
||||
first,
|
||||
firstDefined,
|
||||
@@ -514,7 +515,7 @@ interface FixAddToExistingImportInfo {
|
||||
export function getImportCompletionAction(
|
||||
targetSymbol: Symbol,
|
||||
moduleSymbol: Symbol,
|
||||
exportMapKey: string | undefined,
|
||||
exportMapKey: ExportMapInfoKey | undefined,
|
||||
sourceFile: SourceFile,
|
||||
symbolName: string,
|
||||
isJsxTagName: boolean,
|
||||
|
||||
@@ -58,6 +58,7 @@ import {
|
||||
escapeSnippetText,
|
||||
every,
|
||||
ExportKind,
|
||||
ExportMapInfoKey,
|
||||
Expression,
|
||||
ExpressionWithTypeArguments,
|
||||
factory,
|
||||
@@ -485,14 +486,14 @@ interface SymbolOriginInfoExport extends SymbolOriginInfo {
|
||||
moduleSymbol: Symbol;
|
||||
isDefaultExport: boolean;
|
||||
exportName: string;
|
||||
exportMapKey: string;
|
||||
exportMapKey: ExportMapInfoKey;
|
||||
}
|
||||
|
||||
interface SymbolOriginInfoResolvedExport extends SymbolOriginInfo {
|
||||
symbolName: string;
|
||||
moduleSymbol: Symbol;
|
||||
exportName: string;
|
||||
exportMapKey?: string;
|
||||
exportMapKey?: ExportMapInfoKey;
|
||||
moduleSpecifier: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@ export interface ExportInfoMap {
|
||||
isUsableByFile(importingFile: Path): boolean;
|
||||
clear(): void;
|
||||
add(importingFile: Path, symbol: Symbol, key: __String, moduleSymbol: Symbol, moduleFile: SourceFile | undefined, exportKind: ExportKind, isFromPackageJson: boolean, checker: TypeChecker): void;
|
||||
get(importingFile: Path, key: string): readonly SymbolExportInfo[] | undefined;
|
||||
search<T>(importingFile: Path, preferCapitalized: boolean, matches: (name: string, targetFlags: SymbolFlags) => boolean, action: (info: readonly SymbolExportInfo[], symbolName: string, isFromAmbientModule: boolean, key: string) => T | undefined): T | undefined;
|
||||
get(importingFile: Path, key: ExportMapInfoKey): readonly SymbolExportInfo[] | undefined;
|
||||
search<T>(importingFile: Path, preferCapitalized: boolean, matches: (name: string, targetFlags: SymbolFlags) => boolean, action: (info: readonly SymbolExportInfo[], symbolName: string, isFromAmbientModule: boolean, key: ExportMapInfoKey) => T | undefined): T | undefined;
|
||||
releaseSymbols(): void;
|
||||
isEmpty(): boolean;
|
||||
/** @returns Whether the change resulted in the cache being cleared */
|
||||
@@ -127,10 +127,11 @@ export interface CacheableExportInfoMapHost {
|
||||
getGlobalTypingsCacheLocation(): string | undefined;
|
||||
}
|
||||
|
||||
export type ExportMapInfoKey = string & { __exportInfoKey: void; };
|
||||
/** @internal */
|
||||
export function createCacheableExportInfoMap(host: CacheableExportInfoMapHost): ExportInfoMap {
|
||||
let exportInfoId = 1;
|
||||
const exportInfo = createMultiMap<string, CachedSymbolExportInfo>();
|
||||
const exportInfo = createMultiMap<ExportMapInfoKey, CachedSymbolExportInfo>();
|
||||
const symbols = new Map<number, [symbol: Symbol, moduleSymbol: Symbol]>();
|
||||
/**
|
||||
* Key: node_modules package name (no @types).
|
||||
@@ -266,7 +267,7 @@ export function createCacheableExportInfoMap(host: CacheableExportInfoMapHost):
|
||||
},
|
||||
};
|
||||
if (Debug.isDebugging) {
|
||||
Object.defineProperty(cache, "__cache", { get: () => exportInfo });
|
||||
Object.defineProperty(cache, "__cache", { value: exportInfo });
|
||||
}
|
||||
return cache;
|
||||
|
||||
@@ -309,14 +310,19 @@ export function createCacheableExportInfoMap(host: CacheableExportInfoMapHost):
|
||||
};
|
||||
}
|
||||
|
||||
function key(importedName: string, symbol: Symbol, ambientModuleName: string | undefined, checker: TypeChecker): string {
|
||||
function key(importedName: string, symbol: Symbol, ambientModuleName: string | undefined, checker: TypeChecker) {
|
||||
const moduleKey = ambientModuleName || "";
|
||||
return `${importedName}|${getSymbolId(skipAlias(symbol, checker))}|${moduleKey}`;
|
||||
return `${importedName.length} ${getSymbolId(skipAlias(symbol, checker))} ${importedName} ${moduleKey}` as ExportMapInfoKey;
|
||||
}
|
||||
|
||||
function parseKey(key: string) {
|
||||
const symbolName = key.substring(0, key.indexOf("|"));
|
||||
const moduleKey = key.substring(key.lastIndexOf("|") + 1);
|
||||
function parseKey(key: ExportMapInfoKey) {
|
||||
const firstSpace = key.indexOf(" ");
|
||||
const secondSpace = key.indexOf(" ", firstSpace + 1);
|
||||
const symbolNameLength = parseInt(key.substring(0, firstSpace), 10);
|
||||
|
||||
const data = key.substring(secondSpace + 1);
|
||||
const symbolName = data.substring(0, symbolNameLength);
|
||||
const moduleKey = data.substring(symbolNameLength + 1);
|
||||
const ambientModuleName = moduleKey === "" ? undefined : moduleKey;
|
||||
return { symbolName, ambientModuleName };
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
DocumentPositionMapper,
|
||||
EmitOutput,
|
||||
ExportInfoMap,
|
||||
ExportMapInfoKey,
|
||||
FileReference,
|
||||
GetEffectiveTypeRootsHost,
|
||||
HasChangedAutomaticTypeDirectiveNames,
|
||||
@@ -1390,7 +1391,7 @@ export interface CompletionEntryDataAutoImport {
|
||||
* in the case of InternalSymbolName.ExportEquals and InternalSymbolName.Default.
|
||||
*/
|
||||
exportName: string;
|
||||
exportMapKey?: string;
|
||||
exportMapKey?: ExportMapInfoKey;
|
||||
moduleSpecifier?: string;
|
||||
/** The file name declaring the export's module symbol, if it was an external module */
|
||||
fileName?: string;
|
||||
@@ -1401,7 +1402,7 @@ export interface CompletionEntryDataAutoImport {
|
||||
}
|
||||
|
||||
export interface CompletionEntryDataUnresolved extends CompletionEntryDataAutoImport {
|
||||
exportMapKey: string;
|
||||
exportMapKey: ExportMapInfoKey;
|
||||
}
|
||||
|
||||
export interface CompletionEntryDataResolved extends CompletionEntryDataAutoImport {
|
||||
|
||||
@@ -160,7 +160,7 @@ function sanitizeLog(s: string): string {
|
||||
s = s.replace(/collectAutoImports: \d+(?:\.\d+)?/g, `collectAutoImports: *`);
|
||||
s = s.replace(/continuePreviousIncompleteResponse: \d+(?:\.\d+)?/g, `continuePreviousIncompleteResponse: *`);
|
||||
s = s.replace(/dependencies in \d+(?:\.\d+)?/g, `dependencies in *`);
|
||||
s = s.replace(/"exportMapKey":\s*"[_$a-zA-Z][_$_$a-zA-Z0-9]*\|\d+\|/g, match => match.replace(/\|\d+\|/, `|*|`));
|
||||
s = s.replace(/"exportMapKey":\s*"\d+ \d+ /g, match => match.replace(/ \d+ /, ` * `));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -11040,7 +11040,7 @@ declare namespace ts {
|
||||
* in the case of InternalSymbolName.ExportEquals and InternalSymbolName.Default.
|
||||
*/
|
||||
exportName: string;
|
||||
exportMapKey?: string;
|
||||
exportMapKey?: ExportMapInfoKey;
|
||||
moduleSpecifier?: string;
|
||||
/** The file name declaring the export's module symbol, if it was an external module */
|
||||
fileName?: string;
|
||||
@@ -11050,7 +11050,7 @@ declare namespace ts {
|
||||
isPackageJsonImport?: true;
|
||||
}
|
||||
interface CompletionEntryDataUnresolved extends CompletionEntryDataAutoImport {
|
||||
exportMapKey: string;
|
||||
exportMapKey: ExportMapInfoKey;
|
||||
}
|
||||
interface CompletionEntryDataResolved extends CompletionEntryDataAutoImport {
|
||||
moduleSpecifier: string;
|
||||
@@ -11365,6 +11365,9 @@ declare namespace ts {
|
||||
span: TextSpan;
|
||||
preferences: UserPreferences;
|
||||
}
|
||||
type ExportMapInfoKey = string & {
|
||||
__exportInfoKey: void;
|
||||
};
|
||||
/** The classifier is used for syntactic highlighting in editors via the TSServer */
|
||||
function createClassifier(): Classifier;
|
||||
interface DocumentHighlights {
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"isImportStatementCompletion": true,
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"moduleSpecifier": "./$foo",
|
||||
"fileName": "/tests/cases/fourslash/$foo.ts"
|
||||
},
|
||||
|
||||
+2
-2
@@ -558,7 +558,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/node_modules/@types/node/index",
|
||||
"data": {
|
||||
"exportName": "Stats",
|
||||
"exportMapKey": "Stats|*|",
|
||||
"exportMapKey": "5 * Stats ",
|
||||
"fileName": "/node_modules/@types/node/index.d.ts"
|
||||
}
|
||||
},
|
||||
@@ -572,7 +572,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"isPackageJsonImport": true,
|
||||
"data": {
|
||||
"exportName": "Volume",
|
||||
"exportMapKey": "Volume|*|",
|
||||
"exportMapKey": "6 * Volume ",
|
||||
"fileName": "/node_modules/memfs/lib/index.d.ts",
|
||||
"isPackageJsonImport": true
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/a.ts"
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ Info seq [hh:mm:ss:mss] request:
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"fileName": "/a.ts",
|
||||
"exportMapKey": "foo|*|"
|
||||
"exportMapKey": "3 * foo "
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -302,7 +302,7 @@ Info seq [hh:mm:ss:mss] request:
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"fileName": "/a.ts",
|
||||
"exportMapKey": "foo|*|"
|
||||
"exportMapKey": "3 * foo "
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
+600
-600
File diff suppressed because it is too large
Load Diff
+2500
-2500
File diff suppressed because it is too large
Load Diff
+300
-300
File diff suppressed because it is too large
Load Diff
+205
-205
File diff suppressed because it is too large
Load Diff
+302
-302
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -243,7 +243,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -243,7 +243,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -243,7 +243,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -243,7 +243,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -243,7 +243,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -243,7 +243,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
@@ -806,7 +806,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"isImportStatementCompletion": true,
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"moduleSpecifier": "./a",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
@@ -839,7 +839,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"isImportStatementCompletion": true,
|
||||
"data": {
|
||||
"exportName": "observable",
|
||||
"exportMapKey": "observable|*|",
|
||||
"exportMapKey": "10 * observable ",
|
||||
"moduleSpecifier": "mobx",
|
||||
"fileName": "/node_modules/mobx/index.d.ts",
|
||||
"isPackageJsonImport": true
|
||||
|
||||
+1
-1
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
@@ -806,7 +806,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"isImportStatementCompletion": true,
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"moduleSpecifier": "./a",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
@@ -839,7 +839,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"isImportStatementCompletion": true,
|
||||
"data": {
|
||||
"exportName": "observable",
|
||||
"exportMapKey": "observable|*|",
|
||||
"exportMapKey": "10 * observable ",
|
||||
"moduleSpecifier": "mobx",
|
||||
"fileName": "/node_modules/mobx/index.d.ts",
|
||||
"isPackageJsonImport": true
|
||||
|
||||
+1
-1
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -737,7 +737,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
@@ -1230,7 +1230,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
@@ -1720,7 +1720,7 @@ Info seq [hh:mm:ss:mss] response:
|
||||
"source": "/src/a",
|
||||
"data": {
|
||||
"exportName": "foo",
|
||||
"exportMapKey": "foo|*|",
|
||||
"exportMapKey": "3 * foo ",
|
||||
"fileName": "/src/a.ts"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user