Preparing for release with more logging and more safety checks

This commit is contained in:
Noah Santschi-Cooney 2018-08-04 21:18:03 +01:00
parent 9660263dad
commit 41cce2121c
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
8 changed files with 50 additions and 37 deletions

View file

@ -1,3 +1,9 @@
// can you imagine that some people out there would import a whole library just for this?
export type Pair<T, S> = {
first: T,
second: S
}
type Node = {
parents: Map<string, Pair<number, Node>>
children: Map<string, Node>
@ -10,6 +16,11 @@ export class Graph {
return this.nodes.has(uri) ? this.nodes.get(uri).parents.size > 0 : false
}
public get(uri: string): Node {
if (!this.nodes.has(uri)) this.nodes.set(uri, {parents: new Map(), children: new Map()})
return this.nodes.get(uri)
}
public setParent(uri: string, parent: string, lineNum: number) {
const par: Node = this.nodes.has(parent) ? this.nodes.get(parent) : {parents: new Map(), children: new Map()}
if (this.nodes.has(uri)) {
@ -17,21 +28,14 @@ export class Graph {
node.parents.set(parent, {first: lineNum, second: par})
par.children.set(uri, node)
} else {
const node: Node = {parents: new Map([par].map(p => [parent, {first: lineNum, second: p}]) as [string, Pair<number, Node>][]), children: new Map()}
const node: Node = {
parents: new Map([par].map(p => [parent, {first: lineNum, second: p}]) as [string, Pair<number, Node>][]),
children: new Map()
}
par.children.set(uri, node)
this.nodes.set(uri, node)
}
this.nodes.set(parent, par)
}
public get(uri: string): Node {
if (!this.nodes.has(uri)) this.nodes.set(uri, {parents: new Map(), children: new Map()})
return this.nodes.get(uri)
}
}
// can you imagine that some people out there would import a whole library just for this?
export type Pair<T, S> = {
first: T,
second: S
}