diff --git a/lib/instrumenter.js b/lib/instrumenter.js index d2995f85..dc04e3f0 100644 --- a/lib/instrumenter.js +++ b/lib/instrumenter.js @@ -109,6 +109,7 @@ Literal: [], LabeledStatement: ['label', 'body'], LogicalExpression: ['left', 'right'], + MetaProperty: ['meta', 'property'], MemberExpression: ['object', 'property'], MethodDefinition: ['key', 'value'], ModuleSpecifier: [], @@ -223,6 +224,10 @@ } } + if (node.skipSelf) { + return; + } + for (i = 0; i < children.length; i += 1) { childType = children[i]; childNode = node[childType]; @@ -418,7 +423,8 @@ LabeledStatement: this.coverStatement, ConditionalExpression: this.conditionalBranchInjector, LogicalExpression: this.logicalExpressionBranchInjector, - ObjectExpression: this.maybeAddType + ObjectExpression: this.maybeAddType, + MetaProperty: this.coverMetaProperty, }, this.extractCurrentHint, this, this.opts.walkDebug); //unit testing purposes only @@ -787,6 +793,10 @@ return false; }, + coverMetaProperty: function(node /* , walker */) { + node.skipSelf = true; + }, + coverStatement: function (node, walker) { var sName, incrStatementCount, @@ -1038,7 +1048,7 @@ child.type = SYNTAX.Property.name; } } - } + }, }; if (isNode) { diff --git a/test/instrumentation/test-statement.js b/test/instrumentation/test-statement.js index 0ad2e7c6..58fdd9de 100644 --- a/test/instrumentation/test-statement.js +++ b/test/instrumentation/test-statement.js @@ -24,6 +24,27 @@ module.exports = { test.done(); } }, + "with a metaproperty": { + setUp: function (cb) { + code = [ + 'class FooClass {', + ' constructor() {', + ' if (new.target === FooClass) {', + ' throw new Error(\'Cannot instanciate directly.\');', + ' }', + ' }', + '}' + ]; + verifier = helper.verifier(__filename, code); + cb(); + }, + "should be able to parse": function (test) { + // Do we need to test coverage here really? We're just checking + // that a new type of statement is parsable, the if-else logic + // is already covered in statement-if. + test.done(); + } + }, "with no filename": { setUp: function (cb) { code = [