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.

48 lines
772 B

2 years ago
import Node from '../core/Node.js';
class ConvertNode extends Node {
constructor( node, convertTo ) {
super();
this.node = node;
this.convertTo = convertTo;
}
getNodeType( builder ) {
const requestType = this.node.getNodeType( builder );
let convertTo = null;
for ( const overloadingType of this.convertTo.split( '|' ) ) {
if ( convertTo === null || builder.getTypeLength( requestType ) === builder.getTypeLength( overloadingType ) ) {
convertTo = overloadingType;
}
}
return convertTo;
}
generate( builder, output ) {
const node = this.node;
const type = this.getNodeType( builder );
const snippet = node.build( builder, type );
return builder.format( snippet, type, output );
}
}
export default ConvertNode;