Skip to content

Webpack2 doesn't use local variable from destructuring and taking imported variable from module instead #3273

@asvetliakov

Description

@asvetliakov

Webpack version:
webpack 2.1.0-beta.25

Please tell us about your environment:
Windows 10

a.js

"use strict";

export const test = {
   a: "b"
};

test.js

"use strict";
import { test } from "./a";
class Test {
    constructor() {
        this.internalProp = {
            test: {
                d: "e"
            }
        };
    }
    test() {
        const { test } = this.internalProp;
        console.log(test);
    }
}
new Test().test();

webpack.config.js

"use strict";

module.exports = {
    entry: "./test.js",
    output: { filename: "main.js" }
};

Part of transpiled output:

/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__a__ = __webpack_require__(0);
"use strict";

class Test {
    constructor() {
        this.internalProp = {
            test: {
                d: "e"
            }
        };
    }
    test() {
        const { test } = this.internalProp;
        console.log(__WEBPACK_IMPORTED_MODULE_0__a__["a" /* test */]);
    }
}
new Test().test();


/***/ }

Notice it uses imported test rather then local const varaible.

I think this is very serious bug and it should be fixed asap.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions