2
votes

I just want to double check since I am trying to do this ES6 export default:

var Member = function(){}
export {
    Member as default
 };

JShint is error-ing out with this syntax (es6 enabled) but I thought it was valid. Is this really invalid or what is a valid way for writing a default export with the export syntax as

 export {
    Member 
 };

I was using this as reference: http://www.2ality.com/2014/09/es6-modules-final.html The example they gave was:

//------ module1.js ------
export default 123;
//------ module2.js ------
const D = 123;
export { D as default };

Why is this module2's 2nd line valid? (or is it?)

1
export default Member - elclanrs
How about if I were exporting multiple things with the export syntax last? - JerryFox
To post code, indent by 4 spaces (or use the {} button), don't use the ` character. Ah, Barmar has done it for you. - RobG
Does it work for your local transpiler/es6 environment while only jshint is bitching? - Bergi
What is the exact error message of jshint? - Bergi

1 Answers

3
votes

(As so often) this is is jshint's fault. The line is indeed valid, ES6 Export syntax does permit the use of any IdentifierName - which includes keywords such as default - for the exported name of an ExportClause.

I would however discourage from using it. Default exports are much easier to write and read in the export default notation, such as

var Member = function() {};
export default Member;
// or
export default function Member() {}

Admittedly export default Member; is not exactly equivalent to export { Member as default } but unless you are try to reassign it (you're not, right?) it doesn't make a difference.