ContextNode.js 569 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Node from './Node.js';
  2. class ContextNode extends Node {
  3. constructor( node, context = {} ) {
  4. super();
  5. this.isContextNode = true;
  6. this.node = node;
  7. this.context = context;
  8. }
  9. getNodeType( builder ) {
  10. return this.node.getNodeType( builder );
  11. }
  12. generate( builder, output ) {
  13. const previousContext = builder.getContext();
  14. builder.setContext( { ...builder.context, ...this.context } );
  15. const snippet = this.node.build( builder, output );
  16. builder.setContext( previousContext );
  17. return snippet;
  18. }
  19. }
  20. export default ContextNode;
粤ICP备19079148号