Import Shorthand Strawman
That is currently valid syntax for a module that has no exports - ie, a
module for which you're relying solely on side effects. One popular usage
is import 'es6-shim';
for example.
That is currently valid syntax for a module that has no exports - ie, a module for which you're relying solely on side effects. One popular usage is `import 'es6-shim';` for example. On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net> wrote: > I went through the archives and existing proposals, I didn't see one > similar to this. I apologize if its been covered before. I thought that > redundant import statements could be simplified with a shorthand that works > similar to object literal notation. > > import fs; > > vs > > import fs from 'fs'; > > https://github.com/paultyng/proposal-shorthand-import > > I would welcome any feedback. > > Thanks, > Paul Tyng > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160126/f8fa5599/attachment.html>
also, would identifier would import '3d-is-cool';
create?
also, would identifier would `import '3d-is-cool';` create? On Tue, Jan 26, 2016 at 12:43 PM, Jordan Harband <ljharb at gmail.com> wrote: > That is currently valid syntax for a module that has no exports - ie, a > module for which you're relying solely on side effects. One popular usage > is `import 'es6-shim';` for example. > > On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net> wrote: > >> I went through the archives and existing proposals, I didn't see one >> similar to this. I apologize if its been covered before. I thought that >> redundant import statements could be simplified with a shorthand that works >> similar to object literal notation. >> >> import fs; >> >> vs >> >> import fs from 'fs'; >> >> https://github.com/paultyng/proposal-shorthand-import >> >> I would welcome any feedback. >> >> Thanks, >> Paul Tyng >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160126/fce369a5/attachment.html>
No it does not compete with the string literal version (see my proposal, no quotes), its an identifier only. 3d-is-cool is not a valid identifier so couldn't work, neither would es6-shim.
No it does not compete with the string literal version (see my proposal, no quotes), its an identifier only. 3d-is-cool is not a valid identifier so couldn't work, neither would es6-shim. On Tue, Jan 26, 2016 at 3:44 PM Jordan Harband <ljharb at gmail.com> wrote: > also, would identifier would `import '3d-is-cool';` create? > > On Tue, Jan 26, 2016 at 12:43 PM, Jordan Harband <ljharb at gmail.com> wrote: > >> That is currently valid syntax for a module that has no exports - ie, a >> module for which you're relying solely on side effects. One popular usage >> is `import 'es6-shim';` for example. >> >> On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net> wrote: >> >>> I went through the archives and existing proposals, I didn't see one >>> similar to this. I apologize if its been covered before. I thought that >>> redundant import statements could be simplified with a shorthand that works >>> similar to object literal notation. >>> >>> import fs; >>> >>> vs >>> >>> import fs from 'fs'; >>> >>> https://github.com/paultyng/proposal-shorthand-import >>> >>> I would welcome any feedback. >>> >>> Thanks, >>> Paul Tyng >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160126/3f9958da/attachment.html>
Similar to object property literal shorthand which is also identifier only.
Similar to object property literal shorthand which is also identifier only. On Tue, Jan 26, 2016 at 3:45 PM Paul Tyng <paul at paultyng.net> wrote: > No it does not compete with the string literal version (see my proposal, > no quotes), its an identifier only. 3d-is-cool is not a valid identifier > so couldn't work, neither would es6-shim. > > On Tue, Jan 26, 2016 at 3:44 PM Jordan Harband <ljharb at gmail.com> wrote: > >> also, would identifier would `import '3d-is-cool';` create? >> >> On Tue, Jan 26, 2016 at 12:43 PM, Jordan Harband <ljharb at gmail.com> >> wrote: >> >>> That is currently valid syntax for a module that has no exports - ie, a >>> module for which you're relying solely on side effects. One popular usage >>> is `import 'es6-shim';` for example. >>> >>> On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net> wrote: >>> >>>> I went through the archives and existing proposals, I didn't see one >>>> similar to this. I apologize if its been covered before. I thought that >>>> redundant import statements could be simplified with a shorthand that works >>>> similar to object literal notation. >>>> >>>> import fs; >>>> >>>> vs >>>> >>>> import fs from 'fs'; >>>> >>>> https://github.com/paultyng/proposal-shorthand-import >>>> >>>> I would welcome any feedback. >>>> >>>> Thanks, >>>> Paul Tyng >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160126/8f900307/attachment-0001.html>
I know of exactly one language that has this: LiveScript. And although it's convenient, I hardly need it in other languages, because I wrote a series of snippets for JS, and my editor came with one for CoffeeScript. Also, in LiveScript, it infers the identifier name from the module name, but to be honest, I don't really miss it in other languages. LiveScript is also so full of sugar and various shorthands that there's talk of maybe removing some of it. Snippets and macros make the shorthand kinda irrelevant. And if you're using an IDE, you probably have a similar set of snippets that already exists, if it supports ES6 modules.
I honestly don't see the large gain to be had from this.
# LiveScript shorthand
require! {
fs
'3d-is-cool'
}
# Equivalent using `require`
fs = require 'fs'
3dIsCool = require '3d-is-cool'
// Equivalent in JS
import * as fs from 'fs'
import * as 3dIsCool from '3d-is-cool'
Isiah Meadows me at isiahmeadows.com
I know of exactly one language that has this: LiveScript. And although it's convenient, I hardly need it in other languages, because I wrote a series of snippets for JS, and my editor came with one for CoffeeScript. Also, in LiveScript, it infers the identifier name from the module name, but to be honest, I don't really miss it in other languages. LiveScript is also so full of sugar and various shorthands that there's talk of maybe removing some of it. Snippets and macros make the shorthand kinda irrelevant. And if you're using an IDE, you probably have a similar set of snippets that already exists, if it supports ES6 modules. I honestly don't see the large gain to be had from this. ```ls # LiveScript shorthand require! { fs '3d-is-cool' } # Equivalent using `require` fs = require 'fs' 3dIsCool = require '3d-is-cool' ``` ```js // Equivalent in JS import * as fs from 'fs' import * as 3dIsCool from '3d-is-cool' ``` Isiah Meadows me at isiahmeadows.com On Tue, Jan 26, 2016 at 3:45 PM, Paul Tyng <paul at paultyng.net> wrote: > No it does not compete with the string literal version (see my proposal, no > quotes), its an identifier only. 3d-is-cool is not a valid identifier so > couldn't work, neither would es6-shim. > > On Tue, Jan 26, 2016 at 3:44 PM Jordan Harband <ljharb at gmail.com> wrote: >> >> also, would identifier would `import '3d-is-cool';` create? >> >> On Tue, Jan 26, 2016 at 12:43 PM, Jordan Harband <ljharb at gmail.com> wrote: >>> >>> That is currently valid syntax for a module that has no exports - ie, a >>> module for which you're relying solely on side effects. One popular usage is >>> `import 'es6-shim';` for example. >>> >>> On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net> wrote: >>>> >>>> I went through the archives and existing proposals, I didn't see one >>>> similar to this. I apologize if its been covered before. I thought that >>>> redundant import statements could be simplified with a shorthand that works >>>> similar to object literal notation. >>>> >>>> import fs; >>>> >>>> vs >>>> >>>> import fs from 'fs'; >>>> >>>> https://github.com/paultyng/proposal-shorthand-import >>>> >>>> I would welcome any feedback. >>>> >>>> Thanks, >>>> Paul Tyng >>>> >>>> _______________________________________________ >>>> 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 >
Yeah, its definitely limited in its scope as to which modules it applies to, but thats not necessarily a bad thing, i guess a side effect could be that it pushes more people towards underscore vs dash in module naming.
We don't need a shorthand on object literals either, but we do. Having the redundant text does increase the likelihood of a typo, but not by much.
This doesn't (in theory at least) impact any existing code, and I imagine would be fairly simplistic in implementation. Famous last words I guess.
Yeah, its definitely limited in its scope as to which modules it applies to, but thats not necessarily a bad thing, i guess a side effect could be that it pushes more people towards underscore vs dash in module naming. We don't need a shorthand on object literals either, but we do. Having the redundant text does increase the likelihood of a typo, but not by much. This doesn't (in theory at least) impact any existing code, and I imagine would be fairly simplistic in implementation. Famous last words I guess. On Tue, Jan 26, 2016 at 3:52 PM /#!/JoePea <trusktr at gmail.com> wrote: > So this is only valid with modules that have a valid JavaScript identifier > as their name. I think it could be nice in the cases where the identifier > matches a module name. I don't have an argument against it, and would use > it if it existed, though I can live without it. > > /#!/JoePea > On Jan 26, 2016 12:45 PM, "Paul Tyng" <paul at paultyng.net> wrote: > >> No it does not compete with the string literal version (see my proposal, >> no quotes), its an identifier only. 3d-is-cool is not a valid identifier >> so couldn't work, neither would es6-shim. >> >> On Tue, Jan 26, 2016 at 3:44 PM Jordan Harband <ljharb at gmail.com> wrote: >> >>> also, would identifier would `import '3d-is-cool';` create? >>> >>> On Tue, Jan 26, 2016 at 12:43 PM, Jordan Harband <ljharb at gmail.com> >>> wrote: >>> >>>> That is currently valid syntax for a module that has no exports - ie, a >>>> module for which you're relying solely on side effects. One popular usage >>>> is `import 'es6-shim';` for example. >>>> >>>> On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net> wrote: >>>> >>>>> I went through the archives and existing proposals, I didn't see one >>>>> similar to this. I apologize if its been covered before. I thought that >>>>> redundant import statements could be simplified with a shorthand that works >>>>> similar to object literal notation. >>>>> >>>>> import fs; >>>>> >>>>> vs >>>>> >>>>> import fs from 'fs'; >>>>> >>>>> https://github.com/paultyng/proposal-shorthand-import >>>>> >>>>> I would welcome any feedback. >>>>> >>>>> Thanks, >>>>> Paul Tyng >>>>> >>>>> _______________________________________________ >>>>> 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 >> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160126/95677a14/attachment.html>
import fs;
import "fs";
too confusing :/
``` import fs; import "fs"; ``` too confusing :/ > On Jan 26, 2016, at 12:59 PM, Paul Tyng <paul at paultyng.net> wrote: > > Yeah, its definitely limited in its scope as to which modules it applies to, but thats not necessarily a bad thing, i guess a side effect could be that it pushes more people towards underscore vs dash in module naming. > > We don't need a shorthand on object literals either, but we do. Having the redundant text does increase the likelihood of a typo, but not by much. > > This doesn't (in theory at least) impact any existing code, and I imagine would be fairly simplistic in implementation. Famous last words I guess. > > On Tue, Jan 26, 2016 at 3:52 PM /#!/JoePea <trusktr at gmail.com <mailto:trusktr at gmail.com>> wrote: > So this is only valid with modules that have a valid JavaScript identifier as their name. I think it could be nice in the cases where the identifier matches a module name. I don't have an argument against it, and would use it if it existed, though I can live without it. > > /#!/JoePea > > On Jan 26, 2016 12:45 PM, "Paul Tyng" <paul at paultyng.net <mailto:paul at paultyng.net>> wrote: > No it does not compete with the string literal version (see my proposal, no quotes), its an identifier only. 3d-is-cool is not a valid identifier so couldn't work, neither would es6-shim. > > On Tue, Jan 26, 2016 at 3:44 PM Jordan Harband <ljharb at gmail.com <mailto:ljharb at gmail.com>> wrote: > also, would identifier would `import '3d-is-cool';` create? > > On Tue, Jan 26, 2016 at 12:43 PM, Jordan Harband <ljharb at gmail.com <mailto:ljharb at gmail.com>> wrote: > That is currently valid syntax for a module that has no exports - ie, a module for which you're relying solely on side effects. One popular usage is `import 'es6-shim';` for example. > > On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net <mailto:paul at paultyng.net>> wrote: > I went through the archives and existing proposals, I didn't see one similar to this. I apologize if its been covered before. I thought that redundant import statements could be simplified with a shorthand that works similar to object literal notation. > > import fs; > > vs > > import fs from 'fs'; > > https://github.com/paultyng/proposal-shorthand-import <https://github.com/paultyng/proposal-shorthand-import> > > I would welcome any feedback. > > Thanks, > Paul Tyng > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160126/c3d2c998/attachment-0001.html>
Isiah Meadows me at isiahmeadows.com
On Tue, Jan 26, 2016 at 4:58 PM, Caridy Patiño <caridy at gmail.com> wrote:
import fs; import "fs";
too confusing :/
I would have to agree. In LiveScript, you have to do a standard
require
call if all you're doing is calling it for side effects, and
the shorthand always assigns a variable, so the confusion doesn't
exist. This proposal doesn't have that benefit.
Isiah Meadows me at isiahmeadows.com On Tue, Jan 26, 2016 at 4:58 PM, Caridy Patiño <caridy at gmail.com> wrote: > ``` > import fs; > import "fs"; > ``` > > too confusing :/ I would have to agree. In LiveScript, you have to do a standard `require` call if all you're doing is calling it for side effects, and the shorthand *always* assigns a variable, so the confusion doesn't exist. This proposal doesn't have that benefit. > > On Jan 26, 2016, at 12:59 PM, Paul Tyng <paul at paultyng.net> wrote: > > Yeah, its definitely limited in its scope as to which modules it applies to, > but thats not necessarily a bad thing, i guess a side effect could be that > it pushes more people towards underscore vs dash in module naming. > > We don't need a shorthand on object literals either, but we do. Having the > redundant text does increase the likelihood of a typo, but not by much. > > This doesn't (in theory at least) impact any existing code, and I imagine > would be fairly simplistic in implementation. Famous last words I guess. > > On Tue, Jan 26, 2016 at 3:52 PM /#!/JoePea <trusktr at gmail.com> wrote: >> >> So this is only valid with modules that have a valid JavaScript identifier >> as their name. I think it could be nice in the cases where the identifier >> matches a module name. I don't have an argument against it, and would use it >> if it existed, though I can live without it. >> >> /#!/JoePea >> >> On Jan 26, 2016 12:45 PM, "Paul Tyng" <paul at paultyng.net> wrote: >>> >>> No it does not compete with the string literal version (see my proposal, >>> no quotes), its an identifier only. 3d-is-cool is not a valid identifier so >>> couldn't work, neither would es6-shim. >>> >>> On Tue, Jan 26, 2016 at 3:44 PM Jordan Harband <ljharb at gmail.com> wrote: >>>> >>>> also, would identifier would `import '3d-is-cool';` create? >>>> >>>> On Tue, Jan 26, 2016 at 12:43 PM, Jordan Harband <ljharb at gmail.com> >>>> wrote: >>>>> >>>>> That is currently valid syntax for a module that has no exports - ie, a >>>>> module for which you're relying solely on side effects. One popular usage is >>>>> `import 'es6-shim';` for example. >>>>> >>>>> On Tue, Jan 26, 2016 at 12:31 PM, Paul Tyng <paul at paultyng.net> wrote: >>>>>> >>>>>> I went through the archives and existing proposals, I didn't see one >>>>>> similar to this. I apologize if its been covered before. I thought that >>>>>> redundant import statements could be simplified with a shorthand that works >>>>>> similar to object literal notation. >>>>>> >>>>>> import fs; >>>>>> >>>>>> vs >>>>>> >>>>>> import fs from 'fs'; >>>>>> >>>>>> https://github.com/paultyng/proposal-shorthand-import >>>>>> >>>>>> I would welcome any feedback. >>>>>> >>>>>> Thanks, >>>>>> Paul Tyng >>>>>> >>>>>> _______________________________________________ >>>>>> 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 >>> > _______________________________________________ > 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 >
I went through the archives and existing proposals, I didn't see one similar to this. I apologize if its been covered before. I thought that redundant import statements could be simplified with a shorthand that works similar to object literal notation.
import fs;
vs
import fs from 'fs';
paultyng/proposal-shorthand-import
I would welcome any feedback.
Thanks, Paul Tyng