OperatorNode.js 570 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import Node from '../core/Node.js';
  2. class OperatorNode extends Node {
  3. constructor( op, a, b ) {
  4. super();
  5. this.op = op;
  6. this.a = a;
  7. this.b = b;
  8. }
  9. getType( builder ) {
  10. // ignore auto length for now
  11. return this.a.getType( builder );
  12. }
  13. generate( builder, output ) {
  14. const nodeType = this.getType( builder );
  15. const a = this.a.build( builder, nodeType );
  16. const b = this.b.build( builder, nodeType );
  17. return builder.format( '( ' + a + ' ' + this.op + ' ' + b + ' )', nodeType, output );
  18. }
  19. }
  20. export default OperatorNode;