Skip to content
Browse files

Merge pull request #32 from floriancargoet/cover-ignore-inline

Add support to ignore specific lines using comments.
  • Loading branch information...
2 parents a6f027c + 3f3e9d8 commit 66086cf821009ce34bc9cb6dec7d03c4593ede96 @itay committed
Showing with 1,555 additions and 1,440 deletions.
  1. +1,535 −1,433 contrib/esprima.js
  2. +20 −7 instrument.js
View
2,968 contrib/esprima.js
1,535 additions, 1,433 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
27 instrument.js
@@ -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) {
@@ -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:

0 comments on commit 66086cf

Please sign in to comment.
Something went wrong with that request. Please try again.