Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 681755x 681755x 1x 1x 1x 1x 1x 1x 57559x 35475x 35475x 57559x 57559x 1x 1x 629930x 629930x 629930x 1x 1x 2186703x 2186703x 1x 1x 4162x 4162x 1x 1x 53536x 53536x 1x 1x | import {INode} from "./_inode";
import {AbstractToken} from "../1_lexer/tokens/abstract_token";
// shared constant, so nodes without children don't waste memory on empty arrays
const EMPTY: readonly INode[] = Object.freeze([]);
export abstract class AbstractNode<T extends INode> implements INode {
protected children: T[];
public constructor() {
this.children = EMPTY as T[];
}
public abstract get(): any;
public abstract getFirstToken(): AbstractToken;
public abstract getLastToken(): AbstractToken;
public addChild(n: T) {
if (this.children === EMPTY) {
this.children = [];
}
this.children.push(n);
}
public setChildren(children: T[]) {
// copy, input arrays are built via push() and carry over-allocated backing stores
this.children = children.slice();
}
public getChildren(): readonly T[] {
return this.children;
}
public getFirstChild(): T | undefined {
return this.children[0];
}
public getLastChild(): T | undefined {
return this.children[this.children.length - 1];
}
} |