|
1 | 1 | import { SourceFile, TypeGuards, ClassDeclaration } from 'ts-simple-ast'; |
| 2 | +import { format } from '../helpers'; |
2 | 3 | export default function(sourceFiles: SourceFile[]) { |
3 | 4 | const classes = []; |
4 | 5 | const classesAnnotated = []; |
5 | 6 |
|
6 | | - |
7 | 7 | // see: https://github.com/compodoc/ts-stats/issues/12#issuecomment-380791091 |
8 | 8 | function visit(decorator: string, stats: string[]) { |
9 | 9 | stats.push(decorator); |
10 | 10 | } |
11 | | - |
| 11 | + |
12 | 12 | for (const sourceFile of sourceFiles) { |
13 | 13 | sourceFile.forEachDescendant(descendant => { |
14 | 14 | if (TypeGuards.isClassDeclaration(descendant)) { |
15 | | - const classeDeclaration = (descendant as ClassDeclaration); |
| 15 | + const classeDeclaration = descendant as ClassDeclaration; |
16 | 16 | if (classeDeclaration.getDecorators().length === 0) { |
17 | 17 | visit(classeDeclaration.getName(), classes); |
18 | | - } |
19 | | - else { |
| 18 | + } else { |
20 | 19 | visit(classeDeclaration.getName(), classesAnnotated); |
21 | 20 | } |
22 | 21 | } |
23 | 22 | }); |
24 | 23 | } |
25 | 24 |
|
26 | | - // sourceFiles.map(sourceFile => { |
27 | | - // sourceFile.getClasses().map(classe => { |
28 | | - // if (classe.getDecorators().length === 0) { |
29 | | - // // get classes without decorators |
30 | | - // classes.push(classe.getName()); |
31 | | - // } else { |
32 | | - // // get classes with decorators |
33 | | - // classesAnnotated.push(classe.getName()); |
34 | | - // } |
35 | | - // }); |
36 | | - // }); |
37 | | - |
38 | 25 | return { |
39 | 26 | keys: [['Classes', 'Classes (w/ annotation)', 'Classes (w/o annotation)'].join('\n')], |
40 | | - values: [[classesAnnotated.length + classes.length, classesAnnotated.length, classes.length].join('\n')] |
| 27 | + values: [[format(classesAnnotated.length + classes.length), format(classesAnnotated.length), format(classes.length)].join('\n')] |
41 | 28 | }; |
42 | 29 | } |
0 commit comments