@@ -4,12 +4,57 @@ namespace ts {
44 value : string ;
55 }
66
7- function countLines ( program : Program ) : number {
8- let count = 0 ;
7+ function countLines ( program : Program ) : Map < number > {
8+ const counts = getCountsMap ( ) ;
99 forEach ( program . getSourceFiles ( ) , file => {
10- count += getLineStarts ( file ) . length ;
10+ const key = getCountKey ( program , file ) ;
11+ const lineCount = getLineStarts ( file ) . length ;
12+ counts . set ( key , counts . get ( key ) ! + lineCount ) ;
1113 } ) ;
12- return count ;
14+ return counts ;
15+ }
16+
17+ function countNodes ( program : Program ) : Map < number > {
18+ const counts = getCountsMap ( ) ;
19+ forEach ( program . getSourceFiles ( ) , file => {
20+ const key = getCountKey ( program , file ) ;
21+ counts . set ( key , counts . get ( key ) ! + file . nodeCount ) ;
22+ } ) ;
23+ return counts ;
24+ }
25+
26+ function getCountsMap ( ) {
27+ const counts = createMap < number > ( ) ;
28+ counts . set ( "Library" , 0 ) ;
29+ counts . set ( "Definitions" , 0 ) ;
30+ counts . set ( "TypeScript" , 0 ) ;
31+ counts . set ( "JavaScript" , 0 ) ;
32+ counts . set ( "JSON" , 0 ) ;
33+ counts . set ( "Other" , 0 ) ;
34+ return counts ;
35+ }
36+
37+ function getCountKey ( program : Program , file : SourceFile ) {
38+ if ( program . isSourceFileDefaultLibrary ( file ) ) {
39+ return "Library" ;
40+ }
41+ else if ( file . isDeclarationFile ) {
42+ return "Definitions" ;
43+ }
44+
45+ const path = file . path ;
46+ if ( fileExtensionIsOneOf ( path , supportedTSExtensions ) ) {
47+ return "TypeScript" ;
48+ }
49+ else if ( fileExtensionIsOneOf ( path , supportedJSExtensions ) ) {
50+ return "JavaScript" ;
51+ }
52+ else if ( fileExtensionIs ( path , Extension . Json ) ) {
53+ return "JSON" ;
54+ }
55+ else {
56+ return "Other" ;
57+ }
1358 }
1459
1560 function updateReportDiagnostic (
@@ -637,8 +682,22 @@ namespace ts {
637682 statistics = [ ] ;
638683 const memoryUsed = sys . getMemoryUsage ? sys . getMemoryUsage ( ) : - 1 ;
639684 reportCountStatistic ( "Files" , program . getSourceFiles ( ) . length ) ;
640- reportCountStatistic ( "Lines" , countLines ( program ) ) ;
641- reportCountStatistic ( "Nodes" , program . getNodeCount ( ) ) ;
685+
686+ const lineCounts = countLines ( program ) ;
687+ const nodeCounts = countNodes ( program ) ;
688+ if ( compilerOptions . extendedDiagnostics ) {
689+ for ( const key of arrayFrom ( lineCounts . keys ( ) ) ) {
690+ reportCountStatistic ( "Lines of " + key , lineCounts . get ( key ) ! ) ;
691+ }
692+ for ( const key of arrayFrom ( nodeCounts . keys ( ) ) ) {
693+ reportCountStatistic ( "Nodes of " + key , nodeCounts . get ( key ) ! ) ;
694+ }
695+ }
696+ else {
697+ reportCountStatistic ( "Lines" , reduceLeftIterator ( lineCounts . values ( ) , ( sum , count ) => sum + count , 0 ) ) ;
698+ reportCountStatistic ( "Nodes" , reduceLeftIterator ( nodeCounts . values ( ) , ( sum , count ) => sum + count , 0 ) ) ;
699+ }
700+
642701 reportCountStatistic ( "Identifiers" , program . getIdentifierCount ( ) ) ;
643702 reportCountStatistic ( "Symbols" , program . getSymbolCount ( ) ) ;
644703 reportCountStatistic ( "Types" , program . getTypeCount ( ) ) ;
0 commit comments