Node.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { NodeFactory } from './NodeFactory.js';
  2. export declare type Property = string | number | boolean;
  3. export declare type PropertyList = {
  4. [key: string]: Property;
  5. };
  6. export interface Node {
  7. readonly kind: string;
  8. readonly factory: NodeFactory<Node, NodeClass>;
  9. parent: Node;
  10. childNodes: Node[];
  11. setProperty(name: string, value: Property): void;
  12. getProperty(name: string): Property;
  13. getPropertyNames(): string[];
  14. getAllProperties(): PropertyList;
  15. removeProperty(...names: string[]): void;
  16. isKind(kind: string): boolean;
  17. setChildren(children: Node[]): void;
  18. appendChild(child: Node): Node;
  19. replaceChild(newChild: Node, oldChild: Node): Node;
  20. removeChild(child: Node): Node;
  21. childIndex(child: Node): number;
  22. copy(): Node;
  23. findNodes(kind: string): Node[];
  24. walkTree(func: (node: Node, data?: any) => void, data?: any): void;
  25. }
  26. export interface NodeClass {
  27. new (factory: NodeFactory<Node, NodeClass>, properties?: PropertyList, children?: Node[]): Node;
  28. }
  29. export declare abstract class AbstractNode implements Node {
  30. readonly factory: NodeFactory<Node, NodeClass>;
  31. parent: Node;
  32. protected properties: PropertyList;
  33. childNodes: Node[];
  34. constructor(factory: NodeFactory<Node, NodeClass>, properties?: PropertyList, children?: Node[]);
  35. get kind(): string;
  36. setProperty(name: string, value: Property): void;
  37. getProperty(name: string): Property;
  38. getPropertyNames(): string[];
  39. getAllProperties(): PropertyList;
  40. removeProperty(...names: string[]): void;
  41. isKind(kind: string): boolean;
  42. setChildren(children: Node[]): void;
  43. appendChild(child: Node): Node;
  44. replaceChild(newChild: Node, oldChild: Node): Node;
  45. removeChild(child: Node): Node;
  46. childIndex(node: Node): number;
  47. copy(): AbstractNode;
  48. findNodes(kind: string): Node[];
  49. walkTree(func: (node: Node, data?: any) => void, data?: any): any;
  50. toString(): string;
  51. }
  52. export declare abstract class AbstractEmptyNode extends AbstractNode {
  53. setChildren(_children: Node[]): void;
  54. appendChild(child: Node): Node;
  55. replaceChild(_newChild: Node, oldChild: Node): Node;
  56. childIndex(_node: Node): number;
  57. walkTree(func: (node: Node, data?: any) => void, data?: any): any;
  58. toString(): string;
  59. }