-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Refactor: convert to ESM module (.js files) #19719
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
Comments
Of the last two, perhaps the first should be module.exports = require('mod');
// =>
export * from 'mod';
export {default} from 'mod'; since the And perhaps the second should be module.exports = {foo: function () { } ... };
// =>
export default {foo: function () {}}; as, if the module is consumed natively as an ESM by a NodeJS ESM, the named export |
@aluanhaddad I think |
I don't believe that's always the case. It doesn't appear to be true for Babel's |
Just tested with |
@aluanhaddad Can you clarify what you mean by the second comment? If I write |
Yes, I did not mean to imply otherwise. All exports (except the Here is the specification text that describes the https://tc39.github.io/ecma262/#sec-getexportednames See section 7.c.i |
By second I meant the one starting with |
@aluanhaddad is correct, |
Ah, sorry, my brain kind of went to sleep for a second 😪. I meant that since Node.js is not yet supporting named exports, unless something has changed, and since this concerns a refactoring transformation that might be output using module.exports = {foo: function () { } ... };
// =>
export default {foo: function () {}}; |
var mod = require('mod');
=>mod
is callable thenimport mod from 'mod'
mod
is not callable theimport { a, b } from "mod"
and replacemod.a
andmod.b
var mod= require('mod').a;
=>import { a } from "mod"
;const { a } = require('mod');
=>import { a } from "mod"
;if (__DEV__) { var warning = require('warning'); }
function f() { var warning = require('warning'); }
=>async function f() { var warning = await import('warning'); }
module.exports = EventPlugin;
=>export default EventPlugin;
require("mod")
torequire("mod").default
?module.exports.blah = 0
=>export const blah = 0
module.exports = require('mod');
=>export * from 'mod';
module.exports = {foo: function () { } ... }
=>export function foo() {}
?The text was updated successfully, but these errors were encountered: