ConvertNode.js 504 B

123456789101112131415161718192021222324252627282930313233
  1. import Node from '../core/Node.js';
  2. class ConvertNode extends Node {
  3. constructor( node, convertTo ) {
  4. super();
  5. this.node = node;
  6. this.convertTo = convertTo;
  7. }
  8. getNodeType( /*builder*/ ) {
  9. return this.convertTo;
  10. }
  11. generate( builder ) {
  12. const convertTo = this.convertTo;
  13. const convertToSnippet = builder.getType( convertTo );
  14. const nodeSnippet = this.node.build( builder, convertTo );
  15. return `${ convertToSnippet }( ${ nodeSnippet } )`;
  16. }
  17. }
  18. export default ConvertNode;