Add multiMapAdd
helper
This commit is contained in:
parent
d2d5d42359
commit
949c517fdd
6 changed files with 21 additions and 10 deletions
|
@ -566,6 +566,21 @@ namespace ts {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the value to an array of values associated with the key, and returns the array.
|
||||
* Creates the array if it does not already exist.
|
||||
*/
|
||||
export function multiMapAdd<V>(map: Map<V[]>, key: string, value: V): V[] {
|
||||
const values = map[key];
|
||||
if (values) {
|
||||
values.push(value);
|
||||
return values;
|
||||
}
|
||||
else {
|
||||
return map[key] = [value];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether a value is an array.
|
||||
*/
|
||||
|
|
|
@ -6847,7 +6847,7 @@ const _super = (function (geti, seti) {
|
|||
// export { x, y }
|
||||
for (const specifier of (<ExportDeclaration>node).exportClause.elements) {
|
||||
const name = (specifier.propertyName || specifier.name).text;
|
||||
(exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier);
|
||||
multiMapAdd(exportSpecifiers, name, specifier);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -267,7 +267,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function addFileWatcherCallback(filePath: string, callback: FileWatcherCallback): void {
|
||||
(fileWatcherCallbacks[filePath] || (fileWatcherCallbacks[filePath] = [])).push(callback);
|
||||
multiMapAdd(fileWatcherCallbacks, filePath, callback);
|
||||
}
|
||||
|
||||
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
|
||||
|
|
|
@ -1635,8 +1635,7 @@ namespace FourSlash {
|
|||
const result = ts.createMap<Range[]>();
|
||||
for (const range of this.getRanges()) {
|
||||
const text = this.rangeText(range);
|
||||
const ranges = result[text] || (result[text] = []);
|
||||
ranges.push(range);
|
||||
ts.multiMapAdd(result, text, range);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -198,8 +198,7 @@ namespace ts {
|
|||
|
||||
watchDirectory(directoryName: string, callback: DirectoryWatcherCallback, recursive: boolean): DirectoryWatcher {
|
||||
const path = this.toPath(directoryName);
|
||||
const callbacks = this.watchedDirectories[path] || (this.watchedDirectories[path] = []);
|
||||
callbacks.push({ cb: callback, recursive });
|
||||
const callbacks = multiMapAdd(this.watchedDirectories, path, { cb: callback, recursive });
|
||||
return {
|
||||
referenceCount: 0,
|
||||
directoryName,
|
||||
|
@ -239,8 +238,7 @@ namespace ts {
|
|||
|
||||
watchFile(fileName: string, callback: FileWatcherCallback) {
|
||||
const path = this.toPath(fileName);
|
||||
const callbacks = this.watchedFiles[path] || (this.watchedFiles[path] = []);
|
||||
callbacks.push(callback);
|
||||
const callbacks = multiMapAdd(this.watchedFiles, path, callback);
|
||||
return {
|
||||
close: () => {
|
||||
const i = callbacks.indexOf(callback);
|
||||
|
|
|
@ -984,8 +984,7 @@ namespace ts {
|
|||
function addDeclaration(declaration: Declaration) {
|
||||
const name = getDeclarationName(declaration);
|
||||
if (name) {
|
||||
const declarations = getDeclarations(name);
|
||||
declarations.push(declaration);
|
||||
multiMapAdd(result, name, declaration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue