Barrel import with module namespace:
Problem: loses granular intent as well as potential tree-shaking benefits.
import * as util from './util'Granular import without module namespace:
Problem: loses scope, conflicts with other local or imported module functions.
import { concurrent, stream, regex } from './util'Often, these conflicts force verbose remappings, such as:
import { concurrent as concurrentUtils, stream as streamUtils, regex as regexUtils } from './util'
Proposed syntax: keeps the scope and organization of a module namespace while preserving granular imports.
import { concurrent, stream, regex } as util from './util';
// ^^^^^^^Called as:
util.concurrent.someFunc(...)No good alternative exists, even using dynamic imports:
let util = await import('./util')
util = { concurrent: util.concurrent, stream: util.stream, regex: util.regex }