Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add proper handling for return statements and ternary expressions

  • Loading branch information...
commit 1cf6c224441c62e17c02ea88a503170f8a699519 1 parent aaa3467
@itay authored
Showing with 90 additions and 0 deletions.
  1. +82 −0 instrument.js
  2. +8 −0 test/src/coverage.js
View
82 instrument.js
@@ -233,6 +233,88 @@ Instrumentor.prototype.wrap = function(tree) {
return newNode;
}
+ case esprima.Syntax.ReturnStatement: {
+ var newNode = {
+ "type": "SequenceExpression",
+ "expressions": [
+ {
+ "type": "CallExpression",
+ "callee": {
+ "type": "Identifier",
+ "name": that.names.expression
+ },
+ "arguments": [
+ {
+ "type": "Identifier",
+ "name": that.nodeCounter++
+ }
+ ],
+ noCover: true
+ }
+ ],
+ }
+
+ if (node.argument) {
+ newNode.expressions.push(node.argument);
+ }
+
+ that.nodes[that.nodeCounter - 1] = node;
+ node.id = that.nodeCounter - 1;
+
+ node.argument = newNode
+ break;
+ }
+ case esprima.Syntax.ConditionalExpression: {
+ var newConsequentNode = {
+ "type": "SequenceExpression",
+ "expressions": [
+ {
+ "type": "CallExpression",
+ "callee": {
+ "type": "Identifier",
+ "name": that.names.expression
+ },
+ "arguments": [
+ {
+ "type": "Identifier",
+ "name": that.nodeCounter++
+ }
+ ],
+ noCover: true
+ },
+ node.consequent
+ ],
+ }
+ that.nodes[that.nodeCounter - 1] = node.consequent;
+ node.consequent.id = that.nodeCounter - 1
+
+ var newAlternateNode = {
+ "type": "SequenceExpression",
+ "expressions": [
+ {
+ "type": "CallExpression",
+ "callee": {
+ "type": "Identifier",
+ "name": that.names.expression
+ },
+ "arguments": [
+ {
+ "type": "Identifier",
+ "name": that.nodeCounter++
+ }
+ ],
+ noCover: true
+ },
+ node.alternate
+ ],
+ }
+ that.nodes[that.nodeCounter - 1] = node.alternate;
+ node.alternate.id = that.nodeCounter - 1
+
+ node.consequent = newConsequentNode;
+ node.alternate = newAlternateNode;
+ break;
+ }
case esprima.Syntax.BinaryExpression:
case esprima.Syntax.UpdateExpression:
case esprima.Syntax.LogicalExpression:
View
8 test/src/coverage.js
@@ -56,6 +56,14 @@ e = (function() { return 6; })()
f = d || (g = 3);
+var cond = function() {
+ return true ? a() : b();
+}
+
+cond();
+
+var g = 1;
+g++;
/*c = 1;
d = function() {
Please sign in to comment.
Something went wrong with that request. Please try again.