aboutsummaryrefslogtreecommitdiff
path: root/node_modules/istanbul-lib-instrument/dist/visitor.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/istanbul-lib-instrument/dist/visitor.js')
-rw-r--r--node_modules/istanbul-lib-instrument/dist/visitor.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/node_modules/istanbul-lib-instrument/dist/visitor.js b/node_modules/istanbul-lib-instrument/dist/visitor.js
index beae5d91b..3462f9314 100644
--- a/node_modules/istanbul-lib-instrument/dist/visitor.js
+++ b/node_modules/istanbul-lib-instrument/dist/visitor.js
@@ -101,6 +101,15 @@ var VisitState = function () {
extractURL(node.trailingComments);
}
+ // for these expressions the statement counter needs to be hoisted, so
+ // function name inference can be preserved
+
+ }, {
+ key: 'counterNeedsHoisting',
+ value: function counterNeedsHoisting(path) {
+ return path.isFunctionExpression() || path.isArrowFunctionExpression() || path.isClassExpression();
+ }
+
// all the generic stuff that needs to be done on enter for every node
}, {
@@ -174,7 +183,7 @@ var VisitState = function () {
} : function (x) {
return x;
};
- return T.unaryExpression('++', wrap(T.memberExpression(T.memberExpression(T.identifier(this.varName), T.identifier(type)), T.numericLiteral(id), true)));
+ return T.updateExpression('++', wrap(T.memberExpression(T.memberExpression(T.identifier(this.varName), T.identifier(type)), T.numericLiteral(id), true)));
}
}, {
key: 'insertCounter',
@@ -184,7 +193,7 @@ var VisitState = function () {
path.node.body.unshift(T.expressionStatement(increment));
} else if (path.isStatement()) {
path.insertBefore(T.expressionStatement(increment));
- } else if ((path.isFunctionExpression() || path.isArrowFunctionExpression()) && T.isVariableDeclarator(path.parentPath)) {
+ } else if (this.counterNeedsHoisting(path) && T.isVariableDeclarator(path.parentPath)) {
// make an attempt to hoist the statement counter, so that
// function names are maintained.
var parent = path.parentPath.parentPath;