Node.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { ICustomNode } from '../interfaces/ICustomNode';
  2. import { INode } from '../interfaces/nodes/INode';
  3. import { IOptions } from "../interfaces/IOptions";
  4. import { AppendState } from '../enums/AppendState';
  5. import { NodeUtils } from "../NodeUtils";
  6. export abstract class Node implements ICustomNode {
  7. /**
  8. * @type {AppendState}
  9. */
  10. protected appendState: AppendState = AppendState.BeforeObfuscation;
  11. /**
  12. * @type {INode}
  13. */
  14. protected node: INode;
  15. /**
  16. * @type {IOptions}
  17. */
  18. protected options: IOptions;
  19. /**
  20. * @param options
  21. */
  22. constructor (options: IOptions = {}) {
  23. this.options = options;
  24. }
  25. public abstract appendNode (astTree: INode): void;
  26. /**
  27. * @returns {AppendState}
  28. */
  29. public getAppendState (): AppendState {
  30. return this.appendState;
  31. }
  32. /**
  33. * @returns any
  34. */
  35. public getNode (): INode {
  36. NodeUtils.parentize(this.node);
  37. return this.node;
  38. }
  39. /**
  40. * @param node
  41. */
  42. public setNode (node: INode): void {
  43. this.node = node;
  44. }
  45. public updateNode (): void {
  46. this.node = this.getNodeStructure();
  47. }
  48. /**
  49. * @returns any
  50. */
  51. protected abstract getNodeStructure (): any;
  52. }