diff options
Diffstat (limited to 'node_modules/istanbul-lib-instrument/dist/visitor.js')
-rw-r--r-- | node_modules/istanbul-lib-instrument/dist/visitor.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/node_modules/istanbul-lib-instrument/dist/visitor.js b/node_modules/istanbul-lib-instrument/dist/visitor.js index edceff7ff..79744abf2 100644 --- a/node_modules/istanbul-lib-instrument/dist/visitor.js +++ b/node_modules/istanbul-lib-instrument/dist/visitor.js @@ -22,6 +22,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons // istanbul ignore comment pattern var COMMENT_RE = /^\s*istanbul\s+ignore\s+(if|else|next)(?=\W|$)/; +// istanbul ignore file pattern +var COMMENT_FILE_RE = /^\s*istanbul\s+ignore\s+(file)(?=\W|$)/; // source map URL pattern var SOURCE_MAP_RE = /[#@]\s*sourceMappingURL=(.*)\s*$/m; @@ -376,6 +378,19 @@ function blockProp(prop) { }; } +function makeParenthesizedExpression(path) { + var T = this.types; + if (path.node) { + path.replaceWith(T.parenthesizedExpression(path.node)); + } +} + +function parenthesizedExpressionProp(prop) { + return function (path) { + makeParenthesizedExpression.call(this, path.get(prop)); + }; +} + function convertArrowExpression(path) { var n = path.node; var T = this.types; @@ -467,6 +482,7 @@ var codeVisitor = { AssignmentPattern: entries(coverAssignmentPattern), BlockStatement: entries(), // ignore processing only ClassMethod: entries(coverFunction), + ClassDeclaration: entries(parenthesizedExpressionProp('superClass')), ExpressionStatement: entries(coverStatement), BreakStatement: entries(coverStatement), ContinueStatement: entries(coverStatement), @@ -501,6 +517,11 @@ var coverageTemplate = (0, _babelTemplate2.default)('\n var COVERAGE_VAR = (f function alreadyInstrumented(path, visitState) { return path.scope.hasBinding(visitState.varName); } +function shouldIgnoreFile(programNode) { + return programNode.parent && programNode.parent.comments.some(function (c) { + return COMMENT_FILE_RE.test(c.value); + }); +} /** * programVisitor is a `babel` adaptor for instrumentation. * It returns an object with two methods `enter` and `exit`. @@ -529,6 +550,11 @@ function programVisitor(types) { var visitState = new VisitState(types, sourceFilePath, opts.inputSourceMap); return { enter: function enter(path) { + if (shouldIgnoreFile(path.find(function (p) { + return p.isProgram(); + }))) { + return; + } if (alreadyInstrumented(path, visitState)) { return; } @@ -540,6 +566,11 @@ function programVisitor(types) { } visitState.cov.freeze(); var coverageData = visitState.cov.toJSON(); + if (shouldIgnoreFile(path.find(function (p) { + return p.isProgram(); + }))) { + return { fileCoverage: coverageData, sourceMappingURL: visitState.sourceMappingURL }; + } coverageData[_constants.MAGIC_KEY] = _constants.MAGIC_VALUE; var hash = (0, _crypto.createHash)(_constants.SHA).update(JSON.stringify(coverageData)).digest('hex'); var coverageNode = T.valueToNode(coverageData); |