Skip to content

Commit

Permalink
Update according to @guybedford's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Oskar Segersvärd committed Mar 24, 2016
1 parent 8c4343f commit d828255
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions test/es6.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}
};
4 changes: 3 additions & 1 deletion test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 15 additions & 15 deletions test/instrumentation/test-es6-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
}

0 comments on commit d828255

Please sign in to comment.