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.
55 lines
856 B
55 lines
856 B
import Node from '../core/Node.js';
|
|
|
|
class SplitNode extends Node {
|
|
|
|
constructor( node, components = 'x' ) {
|
|
|
|
super();
|
|
|
|
this.node = node;
|
|
this.components = components;
|
|
|
|
}
|
|
|
|
getNodeType( builder ) {
|
|
|
|
return builder.getTypeFromLength( this.components.length );
|
|
|
|
}
|
|
|
|
generate( builder ) {
|
|
|
|
const node = this.node;
|
|
const nodeTypeLength = builder.getTypeLength( node.getNodeType( builder ) );
|
|
|
|
if ( nodeTypeLength > 1 ) {
|
|
|
|
const components = this.components;
|
|
|
|
let type = null;
|
|
|
|
if ( components.length >= nodeTypeLength ) {
|
|
|
|
// need expand the input node
|
|
|
|
type = this.getNodeType( builder );
|
|
|
|
}
|
|
|
|
const nodeSnippet = node.build( builder, type );
|
|
|
|
return `${nodeSnippet}.${this.components}`;
|
|
|
|
} else {
|
|
|
|
// ignore components if node is a float
|
|
|
|
return node.build( builder );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default SplitNode;
|
|
|