import { TextRange } from "../model/TextRange"; import { NodeKind } from "./NodeKind"; import Graph from "graphology"; import { ScopeToScope } from "../edge/EdgeKind"; export class LocalScope extends NodeKind { range: TextRange; constructor(range: TextRange) { super(range); this.range = range; } } export class ScopeStack implements Iterable { private scopeGraph: Graph; private start: string | undefined; constructor(scopeGraph: Graph, start: string | undefined = undefined) { this.scopeGraph = scopeGraph; this.start = start; } [Symbol.iterator](): Iterator { let current = this.start; return { next: () => { if (current) { const parentId = this.scopeGraph.outEdges(current) .filter(edge => this.scopeGraph.getEdgeAttributes(edge) instanceof ScopeToScope) .map(edge => this.scopeGraph.target(edge))[0]; const original = current; current = parentId; return { value: original, done: false }; } else { return { value: undefined, done: true }; } } }; } }