import Node, { addNodeClass } from './Node.js';
import { nodeProxy } from '../shadernode/ShaderNode.js';

class ExpressionNode extends Node {

	constructor( snippet = '', nodeType = 'void' ) {

		super( nodeType );

		this.snippet = snippet;

	}

	generate( builder, output ) {

		const type = this.getNodeType( builder );
		const snippet = this.snippet;

		if ( type === 'void' ) {

			builder.addFlowCode( snippet );

		} else {

			return builder.format( `( ${ snippet } )`, type, output );

		}

	}

}

export default ExpressionNode;

export const expression = nodeProxy( ExpressionNode );

addNodeClass( ExpressionNode );
