Skip to content

Commit

Permalink
Add inline coverignore
Browse files Browse the repository at this point in the history
  • Loading branch information
floriancargoet committed Dec 4, 2012
1 parent 2e05342 commit 3f3e9d8
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions instrument.js
Expand Up @@ -117,11 +117,21 @@ Instrumentor.prototype.instrument = function(code) {
var wrappedCode = header + code + footer;

// Parse the wrapped code
var tree = esprima.parse(wrappedCode, {range: true, loc: true});

var tree = esprima.parse(wrappedCode, {range: true, loc: true, comment: true});

var ignoredLines = {};
var ignoreRe = /^\s*cover\s*:\s*false\s*$/
tree.comments.
filter(function(commentNode) {
return ignoreRe.test(commentNode.value);
}).
forEach(function(commentNode) {
ignoredLines[commentNode.loc.start.line] = true;
});

// We only "instrument" the original part, which is in this sub-statement
this.wrap(tree.body[0].expression.callee.body.body);
this.wrap(tree.body[0].expression.callee.body.body, ignoredLines);

// We need to adjust the nodes for everything on the first line,
// such that their location statements will start at 1 and not at header.length
for(var nodeKey in this.nodes) {
Expand Down Expand Up @@ -227,13 +237,16 @@ Instrumentor.prototype.traverseAndWrap = function(object, visitor, master) {
return object.noCover ? undefined : returned;
};

Instrumentor.prototype.wrap = function(tree) {
Instrumentor.prototype.wrap = function(tree, ignoredLines) {
var that = this;
this.traverseAndWrap(tree, function(node, path) {
this.traverseAndWrap(tree, function(node, path) {
if (node.noCover) {
return;
}

if (node.loc && node.loc.start.line in ignoredLines) {
return false;
}

parent = path[0];
switch(node.type) {
case esprima.Syntax.ExpressionStatement:
Expand Down

0 comments on commit 3f3e9d8

Please sign in to comment.