ConvertNode.js 722 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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, output ) {
  12. const convertTo = this.convertTo;
  13. const node = this.node;
  14. const type = this.getNodeType( builder );
  15. let snippet = null;
  16. if ( builder.isReference( convertTo ) === false ) {
  17. const nodeSnippet = node.build( builder, convertTo );
  18. snippet = builder.format( nodeSnippet, type, convertTo );
  19. } else {
  20. snippet = node.build( builder, convertTo );
  21. }
  22. return builder.format( snippet, type, output );
  23. }
  24. }
  25. export default ConvertNode;