-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make let default
work even better
#1987
Comments
this looks too much like an implementation detail. I wonder if there's an alternative |
Yes, https://babeljs.io/docs/plugins/transform-es2015-modules-commonjs/ describes the transform. microsoft/TypeScript#3586 is where typescript added support (although they've had some drama about it recently). |
@chenglou did you hit this case in practice |
Jason did (at Instagram). Their setup is rather idiomatic webpack/babel I think? |
So only when you use default export you need mark such property? Is this property a standard or just convention used by babel? |
It's something very specific to Babel as far as I know. |
I've hit it. Real-life example here: https://github.com/glennsl/reasonable-gatsby-starter/blob/master/src/layouts/layouts_index.re#L73. Gatsby uses Babel to transpile es6 to es5 before bundling with webpack. So while I could avoid this by using I've also seen several others needing to do this on Discord. |
so, if we detect |
I could be wrong, but I think that it is only exercised in the context of default imports. http://2ality.com/2015/12/babel-commonjs.html#default-imports is a code snippet that shows what gets generated when someone tries to do a default import with babel. So without knowing more, I think that it makes sense to only include the code when bsc would emit |
@JasonRose we can move forward with it, do you have a minimal way to confirm that intrument |
For people who are interested, here is my discovery, (apparently it is a babel-specific issue) import foo from "foo"
var u = foo var _foo = require("foo");
var _foo2 = _interopRequireDefault(_foo);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var u = _foo2.default; export default foo Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = foo; I think adding
should be good enough, let me know what you think? IIRC, |
Just as a data point: webpack does the same — https://github.com/webpack/webpack/blob/master/lib/dependencies/HarmonyCompatibilityDependency.js#L24 |
I believe that they use |
fixed in #2002 note that I did not use |
So apparently aside from
let default = ...
to export adefault
to be imported by babel/webpack through es6, we also needlet __esModule = {value: true}
also exported. I'm guessing this is how the es6 import of babel and such detect es6 modules?cc @JasonRose
The text was updated successfully, but these errors were encountered: