Import Expressions

Calvin Metcalf calvin.metcalf at gmail.com
Fri Jan 31 15:09:56 PST 2014


what I'm talking about would be sugar for something
functionally equivalent to:

```js
import 'bar' as ___temp1;
import 'baz' as ___temp2;
var foo = Math.random() > 0.5 ? ___temp1 :___temp2;
```

but if import statements that conditionally run is such an issue than make
it an error for them to be not in the top level scope or to be in ternary
expressions.

use cases would include:

 - importing functions that serve as methods

```js
obj.method = import 'something';
```
- or maybe you want to inherit from something in another module

```js
class foo extends import 'bar' {

}
```

- importing things into an array

```js
var thing = [import 'a', import 'b'];
```

- you want to import into a WeakMap

```js
wm.set(something, import 'somethingelse');
```

all of these can be rewritten in a more verbose manner to work with the
current syntax, but it's just awkwardly obtuse syntax.


On Fri, Jan 31, 2014 at 4:52 PM, Brendan Eich <brendan at mozilla.com> wrote:

> Calvin Metcalf wrote:
>
>>
>> Yes
>>
>>
> The smell of expressions which evaluate depending on control flow not
> matching both branches preloading is enough that TC39 defers this and
> sticks to the ES6 grammar as proposed. We need to see enough clear
> use-cases where it wins to have import expressions, *and* there's no
> blow-back from both loading.
>
> /be
>
>  On Jan 31, 2014 4:30 PM, "Domenic Denicola" <domenic at domenicdenicola.com<mailto:
>> domenic at domenicdenicola.com>> wrote:
>>
>>     Just to be clear: this is for an ask such that
>>
>>     ```js
>>     var foo = Math.random() > 0.5 ? import 'bar' : import 'baz';
>>     ```
>>
>>     loads both `'bar'` and a`'baz'` every time.
>>
>>


-- 
-Calvin W. Metcalf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140131/80765d93/attachment-0001.html>


More information about the es-discuss mailing list