2
0

FunctionCallNode.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import TempNode from './TempNode.js';
  2. class FunctionCallNode extends TempNode {
  3. constructor( functionNode = null, parameters = {} ) {
  4. super();
  5. this.functionNode = functionNode;
  6. this.parameters = parameters;
  7. }
  8. setParameters( parameters ) {
  9. this.parameters = parameters;
  10. return this;
  11. }
  12. getParameters() {
  13. return this.parameters;
  14. }
  15. getNodeType( builder ) {
  16. return this.functionNode.getNodeType( builder );
  17. }
  18. generate( builder ) {
  19. const params = [];
  20. const functionNode = this.functionNode;
  21. const inputs = functionNode.getInputs( builder );
  22. const parameters = this.parameters;
  23. for ( const inputNode of inputs ) {
  24. const node = parameters[ inputNode.name ];
  25. if ( node !== undefined ) {
  26. params.push( node.build( builder, inputNode.type ) );
  27. } else {
  28. throw new Error( `FunctionCallNode: Input '${inputNode.name}' not found in FunctionNode.` );
  29. }
  30. }
  31. const functionName = functionNode.build( builder, 'property' );
  32. return `${functionName}( ${params.join( ', ' )} )`;
  33. }
  34. }
  35. export default FunctionCallNode;