File tree Expand file tree Collapse file tree 6 files changed +21
-10
lines changed Expand file tree Collapse file tree 6 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -566,6 +566,21 @@ namespace ts {
566
566
return result ;
567
567
}
568
568
569
+ /**
570
+ * Adds the value to an array of values associated with the key, and returns the array.
571
+ * Creates the array if it does not already exist.
572
+ */
573
+ export function multiMapAdd < V > ( map : Map < V [ ] > , key : string , value : V ) : V [ ] {
574
+ const values = map [ key ] ;
575
+ if ( values ) {
576
+ values . push ( value ) ;
577
+ return values ;
578
+ }
579
+ else {
580
+ return map [ key ] = [ value ] ;
581
+ }
582
+ }
583
+
569
584
/**
570
585
* Tests whether a value is an array.
571
586
*/
Original file line number Diff line number Diff line change @@ -6851,7 +6851,7 @@ const _super = (function (geti, seti) {
6851
6851
// export { x, y }
6852
6852
for ( const specifier of ( < ExportDeclaration > node ) . exportClause . elements ) {
6853
6853
const name = ( specifier . propertyName || specifier . name ) . text ;
6854
- ( exportSpecifiers [ name ] || ( exportSpecifiers [ name ] = [ ] ) ) . push ( specifier ) ;
6854
+ multiMapAdd ( exportSpecifiers , name , specifier ) ;
6855
6855
}
6856
6856
}
6857
6857
break ;
Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ namespace ts {
267
267
}
268
268
269
269
function addFileWatcherCallback ( filePath : string , callback : FileWatcherCallback ) : void {
270
- ( fileWatcherCallbacks [ filePath ] || ( fileWatcherCallbacks [ filePath ] = [ ] ) ) . push ( callback ) ;
270
+ multiMapAdd ( fileWatcherCallbacks , filePath , callback ) ;
271
271
}
272
272
273
273
function addFile ( fileName : string , callback : FileWatcherCallback ) : WatchedFile {
Original file line number Diff line number Diff line change @@ -1649,8 +1649,7 @@ namespace FourSlash {
1649
1649
const result = ts . createMap < Range [ ] > ( ) ;
1650
1650
for ( const range of this . getRanges ( ) ) {
1651
1651
const text = this . rangeText ( range ) ;
1652
- const ranges = result [ text ] || ( result [ text ] = [ ] ) ;
1653
- ranges . push ( range ) ;
1652
+ ts . multiMapAdd ( result , text , range ) ;
1654
1653
}
1655
1654
return result ;
1656
1655
}
Original file line number Diff line number Diff line change @@ -198,9 +198,8 @@ namespace ts {
198
198
199
199
watchDirectory ( directoryName : string , callback : DirectoryWatcherCallback , recursive : boolean ) : DirectoryWatcher {
200
200
const path = this . toPath ( directoryName ) ;
201
- const callbacks = this . watchedDirectories [ path ] || ( this . watchedDirectories [ path ] = [ ] ) ;
202
201
const cbWithRecursive = { cb : callback , recursive } ;
203
- callbacks . push ( cbWithRecursive ) ;
202
+ const callbacks = multiMapAdd ( this . watchedDirectories , path , cbWithRecursive ) ;
204
203
return {
205
204
referenceCount : 0 ,
206
205
directoryName,
@@ -235,8 +234,7 @@ namespace ts {
235
234
236
235
watchFile ( fileName : string , callback : FileWatcherCallback ) {
237
236
const path = this . toPath ( fileName ) ;
238
- const callbacks = this . watchedFiles [ path ] || ( this . watchedFiles [ path ] = [ ] ) ;
239
- callbacks . push ( callback ) ;
237
+ const callbacks = multiMapAdd ( this . watchedFiles , path , callback ) ;
240
238
return {
241
239
close : ( ) => {
242
240
unorderedRemoveItem ( callbacks , callback ) ;
Original file line number Diff line number Diff line change @@ -987,8 +987,7 @@ namespace ts {
987
987
function addDeclaration ( declaration : Declaration ) {
988
988
const name = getDeclarationName ( declaration ) ;
989
989
if ( name ) {
990
- const declarations = getDeclarations ( name ) ;
991
- declarations . push ( declaration ) ;
990
+ multiMapAdd ( result , name , declaration ) ;
992
991
}
993
992
}
994
993
You can’t perform that action at this time.
0 commit comments