@@ -438,9 +438,8 @@ namespace FourSlash {
438
438
private getAllDiagnostics ( ) : ts . Diagnostic [ ] {
439
439
const diagnostics : ts . Diagnostic [ ] = [ ] ;
440
440
441
- const fileNames = this . languageServiceAdapterHost . getFilenames ( ) ;
442
- for ( let i = 0 , n = fileNames . length ; i < n ; i ++ ) {
443
- diagnostics . push . apply ( this . getDiagnostics ( fileNames [ i ] ) ) ;
441
+ for ( const fileName of this . languageServiceAdapterHost . getFilenames ( ) ) {
442
+ diagnostics . push . apply ( this . getDiagnostics ( fileName ) ) ;
444
443
}
445
444
446
445
return diagnostics ;
@@ -580,12 +579,12 @@ namespace FourSlash {
580
579
this . raiseError ( `goToDefinitions failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
581
580
}
582
581
583
- for ( let i = 0 ; i < endMarkers . length ; i ++ ) {
584
- const marker = this . getMarkerByName ( endMarkers [ i ] ) , definition = definitions [ i ] ;
582
+ ts . zipWith ( endMarkers , definitions , ( endMarker , definition , i ) => {
583
+ const marker = this . getMarkerByName ( endMarker ) ;
585
584
if ( marker . fileName !== definition . fileName || marker . position !== definition . textSpan . start ) {
586
585
this . raiseError ( `goToDefinition failed for definition ${ i } : expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } ` ) ;
587
586
}
588
- }
587
+ } ) ;
589
588
}
590
589
591
590
public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
@@ -602,10 +601,10 @@ namespace FourSlash {
602
601
public verifyGetEmitOutputContentsForCurrentFile ( expected : ts . OutputFile [ ] ) : void {
603
602
const emit = this . languageService . getEmitOutput ( this . activeFile . fileName ) ;
604
603
assert . equal ( emit . outputFiles . length , expected . length , "Number of emit output files" ) ;
605
- for ( let i = 0 ; i < emit . outputFiles . length ; i ++ ) {
606
- assert . equal ( emit . outputFiles [ i ] . name , expected [ i ] . name , "FileName" ) ;
607
- assert . equal ( emit . outputFiles [ i ] . text , expected [ i ] . text , "Content" ) ;
608
- }
604
+ ts . zipWith ( emit . outputFiles , expected , ( outputFile , expected ) => {
605
+ assert . equal ( outputFile . name , expected . name , "FileName" ) ;
606
+ assert . equal ( outputFile . text , expected . text , "Content" ) ;
607
+ } ) ;
609
608
}
610
609
611
610
public verifyMemberListContains ( symbol : string , text ?: string , documentation ?: string , kind ?: string ) {
@@ -668,9 +667,9 @@ namespace FourSlash {
668
667
669
668
const entries = this . getCompletionListAtCaret ( ) . entries ;
670
669
assert . isTrue ( items . length <= entries . length , `Amount of expected items in completion list [ ${ items . length } ] is greater than actual number of items in list [ ${ entries . length } ]` ) ;
671
- for ( let i = 0 ; i < items . length ; i ++ ) {
672
- assert . equal ( entries [ i ] . name , items [ i ] , `Unexpected item in completion list` ) ;
673
- }
670
+ ts . zipWith ( entries , items , ( entry , item ) => {
671
+ assert . equal ( entry . name , item , `Unexpected item in completion list` ) ;
672
+ } ) ;
674
673
}
675
674
676
675
public noItemsWithSameNameButDifferentKind ( ) : void {
@@ -692,15 +691,7 @@ namespace FourSlash {
692
691
this . raiseError ( "Member list is empty at Caret" ) ;
693
692
}
694
693
else if ( ( members && members . entries . length !== 0 ) && ! negative ) {
695
-
696
- let errorMsg = "\n" + "Member List contains: [" + members . entries [ 0 ] . name ;
697
- for ( let i = 1 ; i < members . entries . length ; i ++ ) {
698
- errorMsg += ", " + members . entries [ i ] . name ;
699
- }
700
- errorMsg += "]\n" ;
701
-
702
- this . raiseError ( "Member list is not empty at Caret: " + errorMsg ) ;
703
-
694
+ this . raiseError ( `Member list is not empty at Caret:\nMember List contains: ${ stringify ( members . entries . map ( e => e . name ) ) } ` ) ;
704
695
}
705
696
}
706
697
@@ -710,13 +701,8 @@ namespace FourSlash {
710
701
this . raiseError ( "Completion list is empty at caret at position " + this . activeFile . fileName + " " + this . currentCaretPosition ) ;
711
702
}
712
703
else if ( completions && completions . entries . length !== 0 && ! negative ) {
713
- let errorMsg = "\n" + "Completion List contains: [" + completions . entries [ 0 ] . name ;
714
- for ( let i = 1 ; i < completions . entries . length ; i ++ ) {
715
- errorMsg += ", " + completions . entries [ i ] . name ;
716
- }
717
- errorMsg += "]\n" ;
718
-
719
- this . raiseError ( "Completion list is not empty at caret at position " + this . activeFile . fileName + " " + this . currentCaretPosition + errorMsg ) ;
704
+ this . raiseError ( `Completion list is not empty at caret at position ${ this . activeFile . fileName } ${ this . currentCaretPosition } \n` +
705
+ `Completion List contains: ${ stringify ( completions . entries . map ( e => e . name ) ) } ` ) ;
720
706
}
721
707
}
722
708
@@ -890,8 +876,7 @@ namespace FourSlash {
890
876
}
891
877
892
878
private verifyReferencesWorker ( references : ts . ReferenceEntry [ ] , fileName : string , start : number , end : number , isWriteAccess ?: boolean , isDefinition ?: boolean ) {
893
- for ( let i = 0 ; i < references . length ; i ++ ) {
894
- const reference = references [ i ] ;
879
+ for ( const reference of references ) {
895
880
if ( reference && reference . fileName === fileName && reference . textSpan . start === start && ts . textSpanEnd ( reference . textSpan ) === end ) {
896
881
if ( typeof isWriteAccess !== "undefined" && reference . isWriteAccess !== isWriteAccess ) {
897
882
this . raiseError ( `verifyReferencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ${ reference . isWriteAccess } , expected: ${ isWriteAccess } .` ) ;
@@ -1008,16 +993,11 @@ namespace FourSlash {
1008
993
ranges = ranges . sort ( ( r1 , r2 ) => r1 . start - r2 . start ) ;
1009
994
references = references . sort ( ( r1 , r2 ) => r1 . textSpan . start - r2 . textSpan . start ) ;
1010
995
1011
- for ( let i = 0 , n = ranges . length ; i < n ; i ++ ) {
1012
- const reference = references [ i ] ;
1013
- const range = ranges [ i ] ;
1014
-
1015
- if ( reference . textSpan . start !== range . start ||
1016
- ts . textSpanEnd ( reference . textSpan ) !== range . end ) {
1017
-
996
+ ts . zipWith ( references , ranges , ( reference , range ) => {
997
+ if ( reference . textSpan . start !== range . start || ts . textSpanEnd ( reference . textSpan ) !== range . end ) {
1018
998
this . raiseError ( "Rename location results do not match.\n\nExpected: " + stringify ( ranges ) + "\n\nActual:" + JSON . stringify ( references ) ) ;
1019
999
}
1020
- }
1000
+ } ) ;
1021
1001
}
1022
1002
else {
1023
1003
this . raiseError ( "Expected rename to succeed, but it actually failed." ) ;
@@ -1247,8 +1227,7 @@ namespace FourSlash {
1247
1227
const emitFiles : FourSlashFile [ ] = [ ] ; // List of FourSlashFile that has emitThisFile flag on
1248
1228
1249
1229
const allFourSlashFiles = this . testData . files ;
1250
- for ( let idx = 0 ; idx < allFourSlashFiles . length ; idx ++ ) {
1251
- const file = allFourSlashFiles [ idx ] ;
1230
+ for ( const file of allFourSlashFiles ) {
1252
1231
if ( file . fileOptions [ metadataOptionNames . emitThisFile ] === "true" ) {
1253
1232
// Find a file with the flag emitThisFile turned on
1254
1233
emitFiles . push ( file ) ;
@@ -1273,8 +1252,8 @@ namespace FourSlash {
1273
1252
if ( emitOutput . emitSkipped ) {
1274
1253
resultString += "Diagnostics:" + Harness . IO . newLine ( ) ;
1275
1254
const diagnostics = ts . getPreEmitDiagnostics ( this . languageService . getProgram ( ) ) ;
1276
- for ( let i = 0 , n = diagnostics . length ; i < n ; i ++ ) {
1277
- resultString += " " + diagnostics [ 0 ] . messageText + Harness . IO . newLine ( ) ;
1255
+ for ( const diagnostic of diagnostics ) {
1256
+ resultString += " " + diagnostic . messageText + Harness . IO . newLine ( ) ;
1278
1257
}
1279
1258
}
1280
1259
@@ -1340,8 +1319,7 @@ namespace FourSlash {
1340
1319
}
1341
1320
1342
1321
public printCurrentFileState ( makeWhitespaceVisible = false , makeCaretVisible = true ) {
1343
- for ( let i = 0 ; i < this . testData . files . length ; i ++ ) {
1344
- const file = this . testData . files [ i ] ;
1322
+ for ( const file of this . testData . files ) {
1345
1323
const active = ( this . activeFile === file ) ;
1346
1324
Harness . IO . log ( `=== Script (${ file . fileName } ) ${ ( active ? "(active, cursor at |)" : "" ) } ===` ) ;
1347
1325
let content = this . getFileContent ( file . fileName ) ;
@@ -1576,10 +1554,10 @@ namespace FourSlash {
1576
1554
edits = edits . sort ( ( a , b ) => a . span . start - b . span . start ) ;
1577
1555
// Get a snapshot of the content of the file so we can make sure any formatting edits didn't destroy non-whitespace characters
1578
1556
const oldContent = this . getFileContent ( this . activeFile . fileName ) ;
1579
- for ( let j = 0 ; j < edits . length ; j ++ ) {
1580
- this . languageServiceAdapterHost . editScript ( fileName , edits [ j ] . span . start + runningOffset , ts . textSpanEnd ( edits [ j ] . span ) + runningOffset , edits [ j ] . newText ) ;
1581
- this . updateMarkersForEdit ( fileName , edits [ j ] . span . start + runningOffset , ts . textSpanEnd ( edits [ j ] . span ) + runningOffset , edits [ j ] . newText ) ;
1582
- const change = ( edits [ j ] . span . start - ts . textSpanEnd ( edits [ j ] . span ) ) + edits [ j ] . newText . length ;
1557
+ for ( const edit of edits ) {
1558
+ this . languageServiceAdapterHost . editScript ( fileName , edit . span . start + runningOffset , ts . textSpanEnd ( edit . span ) + runningOffset , edit . newText ) ;
1559
+ this . updateMarkersForEdit ( fileName , edit . span . start + runningOffset , ts . textSpanEnd ( edit . span ) + runningOffset , edit . newText ) ;
1560
+ const change = ( edit . span . start - ts . textSpanEnd ( edit . span ) ) + edit . newText . length ;
1583
1561
runningOffset += change ;
1584
1562
// TODO: Consider doing this at least some of the time for higher fidelity. Currently causes a failure (bug 707150)
1585
1563
// this.languageService.getScriptLexicalStructure(fileName);
@@ -1913,10 +1891,7 @@ namespace FourSlash {
1913
1891
jsonMismatchString ( ) ) ;
1914
1892
}
1915
1893
1916
- for ( let i = 0 ; i < expected . length ; i ++ ) {
1917
- const expectedClassification = expected [ i ] ;
1918
- const actualClassification = actual [ i ] ;
1919
-
1894
+ ts . zipWith ( expected , actual , ( expectedClassification , actualClassification ) => {
1920
1895
const expectedType : string = ( < any > ts . ClassificationTypeNames ) [ expectedClassification . classificationType ] ;
1921
1896
if ( expectedType !== actualClassification . classificationType ) {
1922
1897
this . raiseError ( "verifyClassifications failed - expected classifications type to be " +
@@ -1946,7 +1921,7 @@ namespace FourSlash {
1946
1921
actualText +
1947
1922
jsonMismatchString ( ) ) ;
1948
1923
}
1949
- }
1924
+ } ) ;
1950
1925
1951
1926
function jsonMismatchString ( ) {
1952
1927
return Harness . IO . newLine ( ) +
@@ -1991,13 +1966,11 @@ namespace FourSlash {
1991
1966
this . raiseError ( `verifyOutliningSpans failed - expected total spans to be ${ spans . length } , but was ${ actual . length } ` ) ;
1992
1967
}
1993
1968
1994
- for ( let i = 0 ; i < spans . length ; i ++ ) {
1995
- const expectedSpan = spans [ i ] ;
1996
- const actualSpan = actual [ i ] ;
1969
+ ts . zipWith ( spans , actual , ( expectedSpan , actualSpan , i ) => {
1997
1970
if ( expectedSpan . start !== actualSpan . textSpan . start || expectedSpan . end !== ts . textSpanEnd ( actualSpan . textSpan ) ) {
1998
1971
this . raiseError ( `verifyOutliningSpans failed - span ${ ( i + 1 ) } expected: (${ expectedSpan . start } ,${ expectedSpan . end } ), actual: (${ actualSpan . textSpan . start } ,${ ts . textSpanEnd ( actualSpan . textSpan ) } )` ) ;
1999
1972
}
2000
- }
1973
+ } ) ;
2001
1974
}
2002
1975
2003
1976
public verifyTodoComments ( descriptors : string [ ] , spans : TextSpan [ ] ) {
@@ -2008,15 +1981,13 @@ namespace FourSlash {
2008
1981
this . raiseError ( `verifyTodoComments failed - expected total spans to be ${ spans . length } , but was ${ actual . length } ` ) ;
2009
1982
}
2010
1983
2011
- for ( let i = 0 ; i < spans . length ; i ++ ) {
2012
- const expectedSpan = spans [ i ] ;
2013
- const actualComment = actual [ i ] ;
1984
+ ts . zipWith ( spans , actual , ( expectedSpan , actualComment , i ) => {
2014
1985
const actualCommentSpan = ts . createTextSpan ( actualComment . position , actualComment . message . length ) ;
2015
1986
2016
1987
if ( expectedSpan . start !== actualCommentSpan . start || expectedSpan . end !== ts . textSpanEnd ( actualCommentSpan ) ) {
2017
1988
this . raiseError ( `verifyOutliningSpans failed - span ${ ( i + 1 ) } expected: (${ expectedSpan . start } ,${ expectedSpan . end } ), actual: (${ actualCommentSpan . start } ,${ ts . textSpanEnd ( actualCommentSpan ) } )` ) ;
2018
1989
}
2019
- }
1990
+ } ) ;
2020
1991
}
2021
1992
2022
1993
private getCodeFixes ( errorCode ?: number ) {
@@ -2163,11 +2134,9 @@ namespace FourSlash {
2163
2134
public verifyNavigationItemsCount ( expected : number , searchValue : string , matchKind ?: string , fileName ?: string ) {
2164
2135
const items = this . languageService . getNavigateToItems ( searchValue , /*maxResultCount*/ undefined , fileName ) ;
2165
2136
let actual = 0 ;
2166
- let item : ts . NavigateToItem ;
2167
2137
2168
2138
// Count only the match that match the same MatchKind
2169
- for ( let i = 0 ; i < items . length ; i ++ ) {
2170
- item = items [ i ] ;
2139
+ for ( const item of items ) {
2171
2140
if ( ! matchKind || item . matchKind === matchKind ) {
2172
2141
actual ++ ;
2173
2142
}
@@ -2195,8 +2164,7 @@ namespace FourSlash {
2195
2164
this . raiseError ( "verifyNavigationItemsListContains failed - found 0 navigation items, expected at least one." ) ;
2196
2165
}
2197
2166
2198
- for ( let i = 0 ; i < items . length ; i ++ ) {
2199
- const item = items [ i ] ;
2167
+ for ( const item of items ) {
2200
2168
if ( item && item . name === name && item . kind === kind &&
2201
2169
( matchKind === undefined || item . matchKind === matchKind ) &&
2202
2170
( fileName === undefined || item . fileName === fileName ) &&
@@ -2247,24 +2215,16 @@ namespace FourSlash {
2247
2215
2248
2216
public printNavigationItems ( searchValue : string ) {
2249
2217
const items = this . languageService . getNavigateToItems ( searchValue ) ;
2250
- const length = items && items . length ;
2251
-
2252
- Harness . IO . log ( `NavigationItems list (${ length } items)` ) ;
2253
-
2254
- for ( let i = 0 ; i < length ; i ++ ) {
2255
- const item = items [ i ] ;
2218
+ Harness . IO . log ( `NavigationItems list (${ items . length } items)` ) ;
2219
+ for ( const item of items ) {
2256
2220
Harness . IO . log ( `name: ${ item . name } , kind: ${ item . kind } , parentName: ${ item . containerName } , fileName: ${ item . fileName } ` ) ;
2257
2221
}
2258
2222
}
2259
2223
2260
2224
public printNavigationBar ( ) {
2261
2225
const items = this . languageService . getNavigationBarItems ( this . activeFile . fileName ) ;
2262
- const length = items && items . length ;
2263
-
2264
- Harness . IO . log ( `Navigation bar (${ length } items)` ) ;
2265
-
2266
- for ( let i = 0 ; i < length ; i ++ ) {
2267
- const item = items [ i ] ;
2226
+ Harness . IO . log ( `Navigation bar (${ items . length } items)` ) ;
2227
+ for ( const item of items ) {
2268
2228
Harness . IO . log ( `${ repeatString ( item . indent , " " ) } name: ${ item . text } , kind: ${ item . kind } , childItems: ${ item . childItems . map ( child => child . text ) } ` ) ;
2269
2229
}
2270
2230
}
@@ -2385,8 +2345,7 @@ namespace FourSlash {
2385
2345
}
2386
2346
2387
2347
private assertItemInCompletionList ( items : ts . CompletionEntry [ ] , name : string , text ?: string , documentation ?: string , kind ?: string , spanIndex ?: number ) {
2388
- for ( let i = 0 ; i < items . length ; i ++ ) {
2389
- const item = items [ i ] ;
2348
+ for ( const item of items ) {
2390
2349
if ( item . name === name ) {
2391
2350
if ( documentation != undefined || text !== undefined ) {
2392
2351
const details = this . getCompletionEntryDetails ( item . name ) ;
@@ -2435,20 +2394,17 @@ namespace FourSlash {
2435
2394
name = name . indexOf ( "/" ) === - 1 ? ( this . basePath + "/" + name ) : name ;
2436
2395
2437
2396
const availableNames : string [ ] = [ ] ;
2438
- let foundIt = false ;
2439
- for ( let i = 0 ; i < this . testData . files . length ; i ++ ) {
2440
- const fn = this . testData . files [ i ] . fileName ;
2397
+ result = ts . forEach ( this . testData . files , file => {
2398
+ const fn = file . fileName ;
2441
2399
if ( fn ) {
2442
2400
if ( fn === name ) {
2443
- result = this . testData . files [ i ] ;
2444
- foundIt = true ;
2445
- break ;
2401
+ return file ;
2446
2402
}
2447
2403
availableNames . push ( fn ) ;
2448
2404
}
2449
- }
2405
+ } ) ;
2450
2406
2451
- if ( ! foundIt ) {
2407
+ if ( ! result ) {
2452
2408
throw new Error ( `No test file named "${ name } " exists. Available file names are: ${ availableNames . join ( ", " ) } ` ) ;
2453
2409
}
2454
2410
}
@@ -2549,8 +2505,8 @@ ${code}
2549
2505
2550
2506
function chompLeadingSpace ( content : string ) {
2551
2507
const lines = content . split ( "\n" ) ;
2552
- for ( let i = 0 ; i < lines . length ; i ++ ) {
2553
- if ( ( lines [ i ] . length !== 0 ) && ( lines [ i ] . charAt ( 0 ) !== " " ) ) {
2508
+ for ( const line of lines ) {
2509
+ if ( ( line . length !== 0 ) && ( line . charAt ( 0 ) !== " " ) ) {
2554
2510
return content ;
2555
2511
}
2556
2512
}
@@ -2588,8 +2544,7 @@ ${code}
2588
2544
currentFileName = fileName ;
2589
2545
}
2590
2546
2591
- for ( let i = 0 ; i < lines . length ; i ++ ) {
2592
- let line = lines [ i ] ;
2547
+ for ( let line of lines ) {
2593
2548
const lineLength = line . length ;
2594
2549
2595
2550
if ( lineLength > 0 && line . charAt ( lineLength - 1 ) === "\r" ) {
0 commit comments