Code coverage report for sc/lang/compiler/codegen/call-expr.js

Statements: 100% (31 / 31)      Branches: 100% (14 / 14)      Functions: 100% (9 / 9)      Lines: 100% (31 / 31)      Ignored: none     

All files » sc/lang/compiler/codegen/ » call-expr.js
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 821     1   1   1 41 6     41 2     39     1 39   39 2 2               37 24 24   50       24         13         1 2 2                       1 26   26 3 2   3   6         26      
(function(sc) {
  "use strict";
 
  require("./codegen");
 
  var CodeGen = sc.lang.compiler.CodeGen;
 
  CodeGen.addGenerateMethod("CallExpression", function(node) {
    if (node.segmented) {
      this.state.calledSegmentedMethod = true;
    }
 
    if (node.args.expand) {
      return generateExpandCall(this, node);
    }
 
    return generateSimpleCall(this, node);
  });
 
  function generateSimpleCall(that, node) {
    var list = node.args.list;
 
    if (node.stamp === "=") {
      return that.useTemporaryVariable(function(tempVar) {
        return [
          "(" + tempVar + "=", that.generate(list[0]), ",",
          that.generate(node.callee), ".$('" + node.method.name + "',[" + tempVar + "]), ",
          tempVar + ")"
        ];
      });
    }
 
    if (list.length || node.args.keywords) {
      var hasActualArgument = !!list.length;
      var args = [
        that.stitchWith(list, ",", function(item) {
          return that.generate(item);
        }),
        insertKeyValueElement(that, node.args.keywords, hasActualArgument)
      ];
      return [
        that.generate(node.callee), ".$('" + node.method.name + "',[", args, "])"
      ];
    }
 
    return [
      that.generate(node.callee), ".$('" + node.method.name + "')"
    ];
  }
 
  function generateExpandCall(that, node) {
    return that.useTemporaryVariable(function(tempVar) {
      return [
        "(" + tempVar + "=",
        that.generate(node.callee),
        "," + tempVar + ".$('" + node.method.name + "',",
        that.insertArrayElement(node.args.list), ".concat(",
        that.generate(node.args.expand), ".$('asArray')._",
        insertKeyValueElement(that, node.args.keywords, true),
        ")))"
      ];
    });
  }
 
  function insertKeyValueElement(that, keyValues, withComma) {
    var result = [];
 
    if (keyValues) {
      if (withComma) {
        result.push(",");
      }
      result.push(
        "{", that.stitchWith(Object.keys(keyValues), ",", function(key) {
          return [ key, ":", that.generate(keyValues[key]) ];
        }), "}"
      );
    }
 
    return result;
  }
})(sc);