Why two default export styles?

147 views
Skip to first unread message

Alice Bellard

unread,
May 9, 2016, 6:15:10 AM5/9/16
to Exploring ES6
In 16.3.2.2.1:

16.3.2.2.1 Why two default export styles?

The second default export style was introduced because variable declarations can’t be meaningfully turned into default exports if they declare multiple variables:

export default const foo = 1, bar = 2, baz = 3; // not legal JavaScript!

Which one of the three variables foo, bar and baz would be the default export?


So, you are saying the second export style was introduced so that we can do:

const foo = 1, bar = 2 , baz = 3;
export default foo;

Right? But I don't see how that can be an improvement over this one:

export default const foo = 1;
const bar = 2, baz = 3;

It's same two lines of code.

Raul-Sebastian Mihăilă

unread,
Jun 9, 2016, 1:32:30 AM6/9/16
to Exploring ES6
If you were to support 
export default const foo = 1;
you'd normally support
export default const foo = 1, bar = 2;
as well. Because it wouldn't make much sense to allow
const foo = 1, bar = 2;
but not
export default const foo = 1, bar = 2;

But you cannot allow
export default const foo = 1, bar = 2;
because only one thing can be exported as a default export.

Reply all
Reply to author
Forward
0 new messages