diff --git a/lib/instrumenter.js b/lib/instrumenter.js index 42a547c7..6273a5eb 100644 --- a/lib/instrumenter.js +++ b/lib/instrumenter.js @@ -815,7 +815,7 @@ // We let `coverExport` handle ExportNamedDeclarations. parent = walker.parent(); if (parent && parent.node.type === SYNTAX.ExportNamedDeclaration.name) { - return; + return; } sName = this.statementName(node.loc); diff --git a/test/es6.js b/test/es6.js index b4e96cc3..e47c7fec 100644 --- a/test/es6.js +++ b/test/es6.js @@ -1,15 +1,12 @@ var esprima = require('esprima'); function tryThis(str, feature) { - // We can test instrumentation of exports even if the environment doesn't support them. - if (feature !== 'export') { - try { - /*jshint evil: true */ - eval(str); - } catch (ex) { - console.error('ES6 feature [' + feature + '] is not available in this environment'); - return false; - } + try { + /*jshint evil: true */ + eval(str); + } catch (ex) { + console.error('ES6 feature [' + feature + '] is not available in this environment'); + return false; } // esprima parses sources with sourceType 'script' per default. @@ -51,6 +48,7 @@ module.exports = { }, isExportAvailable: function () { - return tryThis('export default function foo() {}', 'export'); + // We can test instrumentation of exports even if the environment doesn't support them. + return true; } }; diff --git a/test/helper.js b/test/helper.js index 3f3d8420..59678417 100644 --- a/test/helper.js +++ b/test/helper.js @@ -107,7 +107,9 @@ function setup(file, codeArray, opts) { // `export`/`import` cannot be wrapped inside a function. // For our purposes, simply remove the `export` from export declarations. - generated = generated.replace(/export (var|function|let|const)/g, '$1'); + if ( opts.esModules ) { + generated = generated.replace(/export (var|function|let|const)/g, '$1'); + } var wrappedCode = '(function (args) { var output;\n' + generated + '\nreturn output;\n})', fn; diff --git a/test/instrumentation/test-es6-export.js b/test/instrumentation/test-es6-export.js index e1578647..0efebbec 100644 --- a/test/instrumentation/test-es6-export.js +++ b/test/instrumentation/test-es6-export.js @@ -24,21 +24,21 @@ if (require('../es6').isExportAvailable()) { }, 'should cover export declarations': function (test) { - code = [ - 'export var a = 2, b = 3;', - 'output = a + b' - ]; - verifier = helper.verifier(__filename, code, { - esModules: true, - noAutoWrap: true - }); - verifier.verify(test, [], 5, { - lines: {'1':1, '2': 1}, - branches: {}, - functions: {}, - statements: {'1': 1, '2': 1} - }); - test.done(); + code = [ + 'export var a = 2, b = 3;', + 'output = a + b' + ]; + verifier = helper.verifier(__filename, code, { + esModules: true, + noAutoWrap: true + }); + verifier.verify(test, [], 5, { + lines: {'1':1, '2': 1}, + branches: {}, + functions: {}, + statements: {'1': 1, '2': 1} + }); + test.done(); } }; }