Node.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { NodeUpdateType } from './constants.js';
  2. class Node {
  3. constructor( nodeType = null ) {
  4. this.nodeType = nodeType;
  5. this.updateType = NodeUpdateType.None;
  6. }
  7. get type() {
  8. return this.constructor.name;
  9. }
  10. getUpdateType( /*builder*/ ) {
  11. return this.updateType;
  12. }
  13. getNodeType( /*builder*/ ) {
  14. return this.nodeType;
  15. }
  16. getTypeLength( builder ) {
  17. return builder.getTypeLength( this.getNodeType( builder ) );
  18. }
  19. update( /*frame*/ ) {
  20. console.warn( 'Abstract function.' );
  21. }
  22. generate( /*builder, output*/ ) {
  23. console.warn( 'Abstract function.' );
  24. }
  25. build( builder, output = null ) {
  26. builder.addNode( this );
  27. const isGenerateOnce = this.generate.length === 1;
  28. if ( isGenerateOnce ) {
  29. const type = this.getNodeType( builder );
  30. const nodeData = builder.getDataFromNode( this );
  31. let snippet = nodeData.snippet;
  32. if ( snippet === undefined ) {
  33. snippet = this.generate( builder );
  34. nodeData.snippet = snippet;
  35. }
  36. return builder.format( snippet, type, output );
  37. }
  38. return this.generate( builder, output );
  39. }
  40. }
  41. Node.prototype.isNode = true;
  42. export default Node;