AbstractCustomNode.ts 1023 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import * as ESTree from 'estree';
  2. import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
  3. import { IOptions } from '../interfaces/IOptions';
  4. import { AppendState } from '../enums/AppendState';
  5. export abstract class AbstractCustomNode implements ICustomNode {
  6. /**
  7. * @type {AppendState}
  8. */
  9. protected abstract appendState: AppendState;
  10. /**
  11. * @type {IOptions}
  12. */
  13. protected options: IOptions;
  14. /**
  15. * @param options
  16. */
  17. constructor (options: IOptions) {
  18. this.options = options;
  19. }
  20. /**
  21. * @param astTree
  22. */
  23. public abstract appendNode (astTree: ESTree.Node): void;
  24. /**
  25. * @returns {AppendState}
  26. */
  27. public getAppendState (): AppendState {
  28. return this.appendState;
  29. }
  30. /**
  31. * @returns {ESTree.Node}
  32. */
  33. public getNode (): ESTree.Node {
  34. return this.getNodeStructure();
  35. }
  36. /**
  37. * @returns {ESTree.Node}
  38. */
  39. protected abstract getNodeStructure (): ESTree.Node;
  40. }