Skip to content

Commit

Permalink
Merge pull request #506 from steve-gray/master
Browse files Browse the repository at this point in the history
MetaProperty support
  • Loading branch information
gotwarlost committed Jan 24, 2016
2 parents d919f73 + 8b64df0 commit 048b4b3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
Literal: [],
LabeledStatement: ['label', 'body'],
LogicalExpression: ['left', 'right'],
MetaProperty: ['meta', 'property'],
MemberExpression: ['object', 'property'],
MethodDefinition: ['key', 'value'],
ModuleSpecifier: [],
Expand Down Expand Up @@ -223,6 +224,10 @@
}
}

if (node.skipSelf) {
return;
}

for (i = 0; i < children.length; i += 1) {
childType = children[i];
childNode = node[childType];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -787,6 +793,10 @@
return false;
},

coverMetaProperty: function(node /* , walker */) {
node.skipSelf = true;
},

coverStatement: function (node, walker) {
var sName,
incrStatementCount,
Expand Down Expand Up @@ -1038,7 +1048,7 @@
child.type = SYNTAX.Property.name;
}
}
}
},
};

if (isNode) {
Expand Down
21 changes: 21 additions & 0 deletions test/instrumentation/test-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 048b4b3

Please sign in to comment.