import() should access default by default

Do you want to request a feature or report a bug?
Feature request

What is the current behavior?
When using import() the default property must be accessed before executing the module.

// a.js
export default function() {
    console.log("hello from a");
}

// index.js
// transpiles to: __webpack_require__.e/* import() */(0).then(__webpack_require__.bind(null, 0)).then(function (module) {
  return module();
});
// should be: __webpack_require__.e/* import() */(0).then(__webpack_require__.bind(null, 0)).then(module => Promise.resolve(module.default || module)).then(function (module) {
  return module();
});
import('./deps/a.js').then(module => module());  // Uncaught (in promise) TypeError: module is not a function

// this works now, but shouldn't be required
// import('./deps/a.js').then(module => {
//     module.default();
// });

If the current behavior is a bug, please provide the steps to reproduce.
Code in this branch:
https://github.com/jouni-kantola/webpack-output-by-build-type/tree/webpack2-import

What is the expected behavior?
Transpile to:

// should be: __webpack_require__.e/* import() */(0).then(__webpack_require__.bind(null, 0)).then(module => Promise.resolve(module.default || module)).then(function (module) {
  return module();
});

If this is a feature request, what is motivation or use case for changing the behavior?
The proposal for import() is listed here: https://github.com/tc39/proposal-dynamic-import
The examples doesn’t require access to default.

Please mention other relevant information such as the browser version, Node.js version, Operating System and programming language.
OS: MacOS 10.12.1
Node: v6.8.0
Deps:

"devDependencies": {
    "babel-core": "^6.21.0",
    "babel-loader": "^6.2.10",
    "babel-preset-env": "^1.1.4",
    "babel-plugin-dynamic-import-webpack": "^1.0.1",
    "html-webpack-plugin": "^2.24.1",
    "webpack": "^2.2.0-rc.3",
    "webpack-dev-server": "^2.2.0-rc.0"
  }

Author: Fantashit

1 thought on “import() should access default by default

  1. @chicoxyzzy: I interpreted the examples incorrect. Ofc, the examples explained something like:

    export const loadPageInto = () => {
      ...
    }
    

    I just felt it was a bit off to differ the interface between an async and sync import a from './deps/a.js. After reading the issue you linked, I understand that import() aligns with import * from './deps/a.js'.

Comments are closed.