Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 Module export default syntax

I'm using the es6-module-transpiler, esprima and JSHint with esnext: true options. JSHint complains when I put:

export default = { some: 'thing', other: 'thing' };

But esprima complains when I use

export default { some: 'thing', other: 'thing' };

The spec says

export default AssignmentExpression ;

Which makes me think that JSHint needs updating and esprima is properly bombing out because there isn't an assignment. Can someone be the deciderer for me here?

like image 583
Jacob Avatar asked Jan 25 '14 00:01

Jacob


People also ask

What is export default in es6?

Export Default is used to export only one value from a file which can be a class, function, or object. The default export can be imported with any name.

How do I make JavaScript default export?

return "This a default export." export { fun as default , x, y, square }; While importing this module. js we can use any name for fun because it is a default export and curly braces for other named exports.

What is export default in Vue?

This refers to the root Vue instance from which the rest of the application comes down. and it will work with the HTML document. See the example below: Using export default: Another way is declaring a component.


1 Answers

Actually an AssignmentExpression can be any expression, it's the expression at the top most level, the one that contains all other expressions (see the spec).

However,

export default = { some: 'thing', other: 'thing' };

really isn't an assignment expression it's a syntax error. If you use the assignment operator in an assignment expression, then you need a left hand side and a right hand side. So something like this would be valid:

export default foo = { some: 'thing', other: 'thing' };

Just using an object literal should be correct, because, as I said, an AssignmentExpression can be any expression.

So Esprima seems to be wrong.

like image 65
Felix Kling Avatar answered Oct 18 '22 15:10

Felix Kling