/rfc-js-import-infer-identifier

A proposal for JS `import as` shorthand that infers identifier.

MIT LicenseMIT

rfs-js-import-infer-token

More terse default imports using names of file imported as identifier. This probably wouldn't work when combined with named imports, pending a different syntax for that case.

import from './components/MyComponent'

or using ...:

import MyComponent from './components/...'

Equivalent to:

import MyComponent from './components/MyComponent'

Probably could not reasonable handle cases where file name isn't valid identifier.

Unless we automatically camel-case, which would also be useful for imports from npm, e.g.:

import from 'left-pad'

leftPad('foo', 5)

Equivalent to:

import leftPad from 'left-pad'

leftPad('foo', 5)

Additionally, an even more flexible syntax could allow for placeholders in the path based on the default identifier.

Either using regular string with ${id} placeholders that look like template literal expressions:

import MyComponent from './components/${id}'
import MyComponent from './components/${id}/main'
import myJSON from './data/${id}.json'

or a more terse placeholder, just $id:

import MyComponent from './components/$id'
import MyComponent from './components/$id/main'
import myJSON from './data/$id.json'

or actual template literal strings, where id is the default identifier used in the import:

import MyComponent from `./components/${id}`
import MyComponent from `./components/${id}/main`
import myJSON from `./data/${id}.json`

Equivalent to:

import MyComponent from './components/MyComponent'
import MyComponent from './components/MyComponent/main'
import myJSON from './data/myJSON.json'