restrictions on module import export names

Erik Arvidsson erik.arvidsson at gmail.com
Wed Jan 29 14:00:51 PST 2014


`export default 1` works.

https://people.mozilla.org/~jorendorff/es6-draft.html#sec-exports

ExportDeclaration :
  ...
  export default AssignmentExpression ;


On Wed, Jan 29, 2014 at 11:03 AM, Calvin Metcalf
<calvin.metcalf at gmail.com>wrote:

> related, is it possible to export anonymous objects?
>
> from looking at the spec it would seem that
>
> ```js
> let foo = 1;
> export foo as default;
> ```
>
> would be allowed but
>
> ```js
> export 1 as default;
> ```
>
> would not
>
> so to export an object that doesn't already have a name you'd have to
> something like:
>
> ```js
> export let default = 1;
> ```
>
> less contrived examples of this in practice are exporting the results of a
> function (extremely common in node, for me at least) and exporting an array:
>
> ```js
> export let default = foo();
> export let default = [thing1, thing2];
> ```
>
> is there a reason
>
> ```js
> export expression;
> ```
>
> doesn't desuger to
>
> ```js
> export const default = expression;
> ```
>
> or am I missing something?
>
>
> On Wed, Jan 29, 2014 at 12:35 PM, Allen Wirfs-Brock <allen at wirfs-brock.com
> > wrote:
>
>> There are still unresolved issues in the Rev22 spec. with the newModule
>> (or possibly new Module) API. t probably needs to say that any property
>> names must conform to IdentifierName.
>>
>> The grammar requirement of IdentifierName is intentional and I don't
>> believe there is any intent to allow that restriction to be circumvented
>> via the Module API.
>>
>> Allen
>>
>> On Jan 29, 2014, at 8:54 AM, John Lenz wrote:
>>
>> I assume that I can access this like so:
>>
>> var mod = newModule({'a.b.c':1})
>> use(mod['a.b.c']);
>>
>> It isn't clear to me why imports and export names are restricted.
>>
>>
>>
>> On Wed, Jan 29, 2014 at 8:40 AM, Kevin Smith <zenparsing at gmail.com>wrote:
>>
>>> // a.js
>>>>
>>>> var foo = 1;
>>>> export foo as 'a.b.c';
>>>>
>>>> // b.js
>>>>
>>>> import 'a.b.c' as foo from "a.js"
>>>>
>>>>
>>> That is not valid.  Export binding names (where you have 'a.b.c') must
>>> be IdentifierName.
>>>
>>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
>
> --
> -Calvin W. Metcalf
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140129/3891c641/attachment.html>


More information about the es-discuss mailing list