ArrayElementNode.js 478 B

12345678910111213141516171819202122232425262728293031
  1. import Node from '../core/Node.js';
  2. class ArrayElementNode extends Node {
  3. constructor( node, indexNode ) {
  4. super();
  5. this.node = node;
  6. this.indexNode = indexNode;
  7. }
  8. getNodeType( builder ) {
  9. return this.node.getNodeType( builder );
  10. }
  11. generate( builder ) {
  12. const nodeSnippet = this.node.build( builder );
  13. const indexSnippet = this.indexNode.build( builder, 'int' );
  14. return `${nodeSnippet}[ ${indexSnippet} ]`;
  15. }
  16. }
  17. export default ArrayElementNode;