You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
815 B
52 lines
815 B
import Node from './Node.js';
|
|
|
|
class ContextNode extends Node {
|
|
|
|
constructor( node, context = {} ) {
|
|
|
|
super();
|
|
|
|
this.isContextNode = true;
|
|
|
|
this.node = node;
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
getNodeType( builder ) {
|
|
|
|
return this.node.getNodeType( builder );
|
|
|
|
}
|
|
|
|
construct( builder ) {
|
|
|
|
const previousContext = builder.getContext();
|
|
|
|
builder.setContext( { ...builder.context, ...this.context } );
|
|
|
|
const node = this.node.build( builder );
|
|
|
|
builder.setContext( previousContext );
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
generate( builder, output ) {
|
|
|
|
const previousContext = builder.getContext();
|
|
|
|
builder.setContext( { ...builder.context, ...this.context } );
|
|
|
|
const snippet = this.node.build( builder, output );
|
|
|
|
builder.setContext( previousContext );
|
|
|
|
return snippet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default ContextNode;
|
|
|