There are three cases of module imports,
- all the that were exported
- some of the names that were exported
- just the default export
just because the language differentiates them doesn't mean that they need to be treated differently, for example something like the following would likely be much more cohesive.
syntax ala let {foo, bar} = import 'library'
:
- if
import 'library'
isn't at the top level through a syntax error* - if library has a default export then treat
import 'library'
like a function that returns the default export - if library doesn't have a default export
- if the left hand side has destructuring then do static analysis on the names and import them
- if it does't then treat
import 'library'
like a function that returns a module object
*or not, the pitfalls of conditional loading seemed to be a sticking point for some people but from my experience with browserify being able to use an if statement for statically analyzed imports makes cross module system support via UMD doable
I'm sympathetic to the argument that this should be:
instead of a standard
let
statement, to reflect the fact that these are actually magical mutable bindings in some cases. Both other than that syntactic tweak, I agree with your behavior suggestions 1-3.