1 thought on “[ES2015] Import module used before it’s declaration

  1. So it’s really hard to verify if there is an issue since TS is responsible for the transpilation. (Thus why I’m looking for an issue reproducible in JS first).

    So far I’ve tested the following.

    index.js (entry property)

    import {getStuff, number, fromExport} from './export';
    
    console.log(getStuff());

    export.js

    export * from "./vendor"; 
    
    const fromExport = "FROM EXPORT";
    export {fromExport}

    vendor.js

    const foo = "FROM VENDOR";
    const getStuff = () => {
        return {some: "FROM VENDOR"};
    }
    
    export const number = 43;
    export {getStuff, foo};

    My resulting bundle looks as the following:

    bundle.js (runtime omitted)

    /************************************************************************/
    /******/ ([
    /* 0 */
    /***/ (function(module, __webpack_exports__, __webpack_require__) {
    
    "use strict";
    /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__vendor__ = __webpack_require__(1);
    /* harmony namespace reexport (by used) */ __webpack_require__.d(__webpack_exports__, "a", function() { return __WEBPACK_IMPORTED_MODULE_0__vendor__["a"]; });
    /* unused harmony export fromExport */
     //EXPORT ALL EXPORTS FROM VENDOR
    
    const fromExport = "FROM EXPORT";
    
    
    /***/ }),
    /* 1 */
    /***/ (function(module, __webpack_exports__, __webpack_require__) {
    
    "use strict";
    /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getStuff; });
    /* unused harmony export foo */
    const foo = "FROM VENDOR";
    const getStuff = () => {
        return {some: "FROM VENDOR"};
    }
    
    const number = 43;
    /* unused harmony export number */
    
    
    
    /***/ }),
    /* 2 */
    /***/ (function(module, __webpack_exports__, __webpack_require__) {
    
    "use strict";
    Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
    /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__export__ = __webpack_require__(0);
    
    
    console.log(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__export__["a" /* getStuff */])());
    
    
    /***/ })
    /******/ ]);

    So far it appears in this case that the ordering is correct when just ES2015. (Thus my concern).

Comments are closed.