# All files / src/generator binary-expression.js

100% Statements 7/7
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    22x
    22x
    22x

    22x

    294x

    294x

    294x

     // @flow
    import mapSyntax from './map-syntax';
    import mergeBlock from './merge-block';
    import { opcodeFromOperator } from '../emitter/opcode';
    import type { GeneratorType } from './flow/types';

    /**
     * Transform a binary expression node into a list of opcodes
     */
    const generateBinaryExpression: GeneratorType = (node, parent) => {
      // Map operands first
      const block = node.params.map(mapSyntax(parent)).reduce(mergeBlock, []);

      // Map the operator last
      block.push({
        kind: opcodeFromOperator({
          ...node,
          type: node.type,
        }),
        params: [],
      });

      return block;
    };

    export default generateBinaryExpression;