Import Shorthand Strawman

# Paul Tyng (9 years ago)

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

# Jordan Harband (9 years ago)

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.

# Jordan Harband (9 years ago)

also, would identifier would import '3d-is-cool'; create?

# Paul Tyng (9 years ago)

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.

# Paul Tyng (9 years ago)

Similar to object property literal shorthand which is also identifier only.

# Isiah Meadows (9 years ago)

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

# Paul Tyng (9 years ago)

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.

# Caridy Patiño (9 years ago)
import fs;
import "fs";

too confusing :/

# Isiah Meadows (9 years ago)

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.