Repository navigation
Use amd for transpiling modules with babel@5. - #6827
Conversation
In order to allow gradual migration from babel@5 to babel@6 we
must be able update addons on a case by case basis to
ember-cli-babel@6. This means that at any given time we will
have both babel@5 and babel@6 transpiled modules present in the
system. Unfortunately, our prior default module transpilation
target (`amdStrict`) is not compatible with babel@6 transpiled
modules. The issue is best illustrated with an example.
Given the following input content:
```js
import defaultThingy from './a';
import { namedThingy } from './b';
export default function() {
defaultThingy();
}
export function namedExport() {
namedThingy();
}
```
Babel 5 with `amdStrict` will emit:
```js
define('some/file/name', ['exports', './a', './b'], function (exports, _a, _b) {
'use strict';
exports.namedExport = namedExport;
exports['default'] = function () {
(0, _a['default'])();
};
function namedExport() {
(0, _b.namedThingy)();
}
});
```
And Babel 6 with `transform-es2015-modules-amd` will emit:
```js
define('some/file/here', ['exports', './a', './b'], function (exports, _a, _b) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function () {
(0, _a2.default)();
};
exports.namedExport = namedExport;
var _a2 = _interopRequireDefault(_a);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function namedExport() {
(0, _b.namedThingy)();
}
});
```
The issue is not immediately obvious, but the babel@5 module
does not define `__esModule` on the `exports` object which means
that when the babel@6 module attempts to import the default
export from the babel@5 module it will result in getting the raw
`exports` object (not `exports.default`).
Switching our default transpilation while still using babel@5 from
`amdStrict` to `amd` will emit interoperable modules:
```js
define('some/file/name', ['exports', './a', './b'], function (exports, _a, _b) {
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.namedExport = namedExport;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _defaultThingy = _interopRequireDefault(_a);
exports['default'] = function () {
(0, _defaultThingy['default'])();
};
function namedExport() {
(0, _b.namedThingy)();
}
});
```
|
Note: this targets |
stefanpenner
left a comment
There was a problem hiding this comment.
This seems good.
Originally amdStrict was added for compat with browsers without support for ES5's Object.defineProperty, I do not believe we support those any-longer anyways?
I suppose amdStrict also shipped less bytes, but I suspect that is ok as there are other important benefits to babel 6 that trump this. Even just in the module system.
--
I am also fine with this riding the beta train, as long as we get some users testing this before it hits stable we should be good.
|
I'm a little worried about putting this on the beta branch given that we planned to release it on Monday. If we do it we should at least add another week to the beta cycle. Is there no way to configure the Babel 6 plugin to skip the interop part? /cc @hzoo |
I'm happy to push a week (I think ember will need to delay a week anyways). I'm also fine if we decide to only land on master (for 2.13) so this gets a full beta cycle. |
|
FWIW, the tests are failing due to the bug fixed in ember-cli/loader.js#113. |
Addresses issue with babel@6 and babel@5 interop.
|
📌 Commit 0429795 has been approved by |
Use `amd` for transpiling modules with babel@5.
In order to allow gradual migration from babel@5 to babel@6 we must be able update addons on a case by case basis to ember-cli-babel@6. This means that at any given time we will have both babel@5 and babel@6 transpiled modules present in the system. Unfortunately, our prior default module transpilation target (`amdStrict`) is not compatible with babel@6 transpiled modules. The issue is best illustrated with an example.
Given the following input content:
```js
import defaultThingy from './a';
import { namedThingy } from './b';
export default function() {
defaultThingy();
}
export function namedExport() {
namedThingy();
}
```
Babel 5 with `amdStrict` will emit:
```js
define('some/file/name', ['exports', './a', './b'], function (exports, _a, _b) {
'use strict';
exports.namedExport = namedExport;
exports['default'] = function () {
(0, _a['default'])();
};
function namedExport() {
(0, _b.namedThingy)();
}
});
```
And Babel 6 with `transform-es2015-modules-amd` will emit:
```js
define('some/file/here', ['exports', './a', './b'], function (exports, _a, _b) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function () {
(0, _a2.default)();
};
exports.namedExport = namedExport;
var _a2 = _interopRequireDefault(_a);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function namedExport() {
(0, _b.namedThingy)();
}
});
```
The issue is not immediately obvious, but the babel@5 module does not define `__esModule` on the `exports` object which means that when the babel@6 module attempts to import the default export from the babel@5 module it will result in getting the raw `exports` object (not `exports.default`).
Switching our default transpilation while still using babel@5 from `amdStrict` to `amd` will emit interoperable modules:
```js
define('some/file/name', ['exports', './a', './b'], function (exports, _a, _b) {
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.namedExport = namedExport;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _defaultThingy = _interopRequireDefault(_a);
exports['default'] = function () {
(0, _defaultThingy['default'])();
};
function namedExport() {
(0, _b.namedThingy)();
}
});
```
|
⚡ Test exempted - status |
In order to allow gradual migration from babel@5 to babel@6 we must be able update addons on a case by case basis to ember-cli-babel@6. This means that at any given time we will have both babel@5 and babel@6 transpiled modules present in the system. Unfortunately, our prior default module transpilation target (
amdStrict) is not compatible with babel@6 transpiled modules. The issue is best illustrated with an example.Given the following input content:
Babel 5 with
amdStrictwill emit:And Babel 6 with
transform-es2015-modules-amdwill emit:The issue is not immediately obvious, but the babel@5 module does not define
__esModuleon theexportsobject which means that when the babel@6 module attempts to import the default export from the babel@5 module it will result in getting the rawexportsobject (notexports.default).Switching our default transpilation while still using babel@5 from
amdStricttoamdwill emit interoperable modules: