Up-propogation of errors works. Now need to handle the case of changing includes

This commit is contained in:
Noah Santschi-Cooney 2018-08-03 15:46:17 +01:00
parent 24c5b5bf51
commit f5af65a701
4 changed files with 75 additions and 56 deletions

View file

@ -1,5 +1,5 @@
type Node = {
parents: Map<string, Node>
parents: Map<string, Pair<number, Node>>
children: Map<string, Node>
}
@ -10,14 +10,14 @@ export class Graph {
return this.nodes.has(uri) ? this.nodes.get(uri).parents.size > 0 : false
}
public setParent(uri: string, parent: string) {
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)) {
const node = this.nodes.get(uri)
node.parents.set(parent, par)
node.parents.set(parent, {first: lineNum, second: par})
par.children.set(uri, node)
} else {
const node: Node = {parents: new Map([par].map(p => [parent, p]) as [string, 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)
}
@ -28,4 +28,10 @@ export class Graph {
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
}