Permalink
Browse files

Merge pull request #34 from unindented/master

Fix for error on array with empty positions
  • Loading branch information...
2 parents edbf75b + 749b292 commit d966f753b0b08ca3e544262546c9ebbd4bdb6af6 @gotwarlost committed Mar 8, 2013
Showing with 21 additions and 4 deletions.
  1. +6 −4 lib/instrumenter.js
  2. +15 −0 test/instrumentation/test-expressions.js
View
@@ -178,10 +178,12 @@
for (j = 0; j < childNode.length; j += 1) {
childElement = childNode[j];
pathElement.index = j;
- assignNode = walker.walk(childElement, null, pathElement) || childElement;
- if (isArray(assignNode.prepend)) {
- pushAll(childArray, assignNode.prepend);
- delete assignNode.prepend;
+ if (childElement) {
+ assignNode = walker.walk(childElement, null, pathElement) || childElement;
+ if (isArray(assignNode.prepend)) {
+ pushAll(childArray, assignNode.prepend);
+ delete assignNode.prepend;
+ }
}
pushAll(childArray, assignNode);
}
@@ -50,6 +50,21 @@ module.exports = {
verifier.verify(test, [ 3 ], true, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 1, 0 ]}, functions: {}, statements: { '1': 1, '2': 1 } });
test.done();
}
+ },
+ "with an array expression with empty positions": {
+ setUp: function (cb) {
+ code = [
+ 'var x = [, , args[0], ];',
+ 'output = x.indexOf(args[0]) === x.length - 1;'
+ ];
+ verifier = helper.verifier(__filename, code);
+ cb();
+ },
+
+ "should not barf in any way": function (test) {
+ verifier.verify(test, [ 5 ], true, { lines: { 1: 1, 2: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1 } });
+ test.done();
+ }
}
};

0 comments on commit d966f75

Please sign in to comment.