JoinNode.js 867 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import TempNode from '../core/Node.js';
  2. class JoinNode extends TempNode {
  3. constructor( nodes = [], nodeType = null ) {
  4. super( nodeType );
  5. this.nodes = nodes;
  6. }
  7. getNodeType( builder ) {
  8. if ( this.nodeType !== null ) {
  9. return builder.getVectorType( this.nodeType );
  10. }
  11. return builder.getTypeFromLength( this.nodes.reduce( ( count, cur ) => count + builder.getTypeLength( cur.getNodeType( builder ) ), 0 ) );
  12. }
  13. generate( builder, output ) {
  14. const type = this.getNodeType( builder );
  15. const nodes = this.nodes;
  16. const snippetValues = [];
  17. for ( const input of nodes ) {
  18. const inputSnippet = input.build( builder );
  19. snippetValues.push( inputSnippet );
  20. }
  21. const snippet = `${ builder.getType( type ) }( ${ snippetValues.join( ', ' ) } )`;
  22. return builder.format( snippet, type, output );
  23. }
  24. }
  25. export default JoinNode;