This repository was archived by the owner on Aug 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathparser.ts
More file actions
77 lines (64 loc) · 2.23 KB
/
Copy pathparser.ts
File metadata and controls
77 lines (64 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { YamlModel } from './interfaces/YamlModel';
import { Node } from './interfaces/TypeDocModel';
import { UidMapping } from './interfaces/UidMapping';
import * as _ from 'lodash';
import { Converter } from './converters/converter';
import { Context } from './converters/context';
export class Parser {
public traverse(node: Node, uidMapping: UidMapping, context: Context): YamlModel[] {
let collection = new Array<YamlModel>();
if (this.needIgnore(node)) {
return collection;
}
let models = new Converter().convert(node, context);
for (const model of models) {
uidMapping[node.id] = model.uid;
collection.push(model);
}
if (!node.children || node.children === []) {
return collection;
}
for (const child of node.children) {
const uid = models.length > 0 ? models[0].uid : context.PackageName;
const newContext = new Context(
context.Repo,
uid,
node.kindString,
context.PackageName,
context.References);
if (models.length > 0) {
models[0].children = [].concat(models[0].children, this.traverse(child, uidMapping, newContext));
} else {
collection = [].concat(collection, this.traverse(child, uidMapping, newContext));
}
}
return collection;
}
private needIgnore(node: Node): boolean {
if (node.name && node.name[0] === '_') {
return true;
}
if (node.flags.isPrivate || node.flags.isProtected) {
return true;
}
if (this.isInternal(node)) {
return true;
}
if (!node.flags.isExported
&& node.sources
&& !node.sources[0].fileName.toLowerCase().endsWith('.d.ts')) {
return true;
}
return false;
}
private isInternal(node: Node): boolean {
if (node && node.comment && node.comment.tags) {
node.comment.tags.forEach(tag => {
if (tag.tag === 'internal') {
return true;
}
});
}
return false;
}
}