frameStack.js (1288B)
1 export const topFrameName = "<top>"; 2 export class Frame { 3 isFrame() { 4 return 1; 5 } 6 constructor(name, location) { 7 this.name = name; 8 this.location = location; 9 } 10 toString() { 11 return (this.name + 12 (this.location 13 ? ` at line ${this.location.start.line}, column ${this.location.start.column}, file ${this.location.source}` 14 : "")); 15 } 16 } 17 export class FrameStack { 18 constructor(frame, parent) { 19 this.frame = frame; 20 this.parent = parent; 21 } 22 static make() { 23 return new FrameStack(new Frame("<root>")); 24 } 25 extend(name, location) { 26 return new FrameStack(new Frame(name, location), this); 27 } 28 toString() { 29 return this.toFrameArray() 30 .map((f) => " " + f.toString()) 31 .join("\n"); 32 } 33 toFrameArray() { 34 const result = []; 35 let t = this; 36 while (t && t.frame) { 37 if (!t.parent) 38 break; 39 result.push(t.frame); 40 t = t.parent; 41 } 42 return result; 43 } 44 getTopFrame() { 45 return this.parent ? this.frame : undefined; 46 } 47 isEmpty() { 48 return this.parent === undefined; 49 } 50 } 51 //# sourceMappingURL=frameStack.js.map