JoinNode.js 749 B

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