export var uses getter via Object.defineProperty that breaks <=IE8

I’m submitting a bug report

Webpack version:
2.1.0-beta.15

Please tell us about your environment:
Windows 10

Current behavior:
Original Code:

let dateNow = Date.now;
if (typeof dateNow !== 'function') {
  dateNow = function() {
    return (new Date()).getTime();
  };
}
export { dateNow };

After webpack:

/* harmony export */ __webpack_require__.d(exports, "f", function() { return dateNow; });
...
var dateNow = Date.now;
if (typeof dateNow !== 'function') {
  dateNow = function () {
    return new Date().getTime();
  };
}

Expected/desired behavior:

var dateNow = Date.now;
if (typeof dateNow !== 'function') {
  dateNow = function () {
    return new Date().getTime();
  };
}
exports["f"] = dateNow;

What is the expected behavior?
I expect that instead of hoisting the exports to the top, they could instead be placed where the export occurred and then the code could be. This would eliminate the necessity of using a getter for the case above.

What is the motivation / use case for changing the behavior?
Currently there’s no way to polyfill Object.defineProperty with a getter, see es5-shim’s shams. I can’t find a way to export a variable without it using Object.defineProperty. When using commonjs, there were ways to export without requiring the use of Object.defineProperty.

Browser:
IE 6-8

Language:
ES6/7 (with Babel)

Author: Fantashit

2 thoughts on “export var uses getter via Object.defineProperty that breaks <=IE8

  1. After some discussion we decided for the following statement regarding IE8:

    We don’t support IE8 in webpack 2. IE8 is not supported by Microsoft and doesn’t get security fixes. We think it’s no responsible to allow web developers to build webapps which support IE8. They must break!

Comments are closed.