I get the error Multiple exports of name 'List' from both lines of components/pages/index.js in following example:
// components/pages/index.js
export * as Messages from "./messages";
export * as Users from "./users";
// components/pages/messages/index.js
export List from "./list";
export Show from "./show";
// components/pages/users/index.js
export Edit from "./edit";
export List from "./list";
// components/pages/messages/list.js => React Component
// components/pages/messages/show.js => React Component
// components/pages/users/edit.js => React Component
// components/pages/users/list.js => React Component
I understand that if I get it once, I'll get it twice, but I don't think it should be happening at all. The code itself works when I access my components (Pages.Users.List) leading me to believe this is a bug in the rule. I also made sure to update to the latest version (2.20.1) before submitting this
When you say "the code works", do you mean, in native browser or node ESM, or in babel/typescript?
In other words, I believe the spec requires this to be a syntax error, because you have two exports that conflict. Babel might paper over this by silently choosing the last one, but that doesn't mean it's valid.
Oh yeah, my bad. I'm using babel and I think the specific relevant plugin is plugin-proposal-export-namespace-from which looks like it's stage 4.
I think that might change the context of how it works, but do they conflict? With that plugin I can access both Pages.Messages.List and Pages.Users.List. I thought it was fine because it'd immediately assign the * export to the namespace (Messages or Users) so their contents wouldn't pollute anything
Also in case it's not clear, the commented out portions above are meant to denote individual files. They're not all in one file
When you say "the code works", do you mean, in native browser or node ESM, or in babel/typescript?
The example works without syntax error in node ESM. The index.js module has two exports, Messages and Users. But our plugin reports Multiple exports of name 'List'. Something is wrong here.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#export-star-as-namespace-syntax
The export * as was added in TypeScript v3.8
// ts
export * as Messages from "./messages";
export * as Users from "./users";
// js
exports.Messages = require("./messages");
exports.Users = require("./users");
Using export * as does not conflict even if the property names are the same.
No Multiple exports of name 'List' errors should occur.
Ah, very true - export * as X can't conflict with anything but another X.
This definitely seems like a bug.
@ljharb can you remove typescript label since Proposal: export ns from is part of standard js https://github.com/tc39/ecma262/pull/1174
Also ran into this issue with the following code:
export * as WorkerPhoneCreated from './phone/created';
export * as WorkerPhoneUpdated from './phone/updated';
Both the following imported files contain an EventType export, and should be referenced as WorkerPhoneCreated.EventType and WorkerPhoneUpdated.EventType respectively and so I think this "multiple exports" error is a false positive if I've understood correctly.
I agree; that should be addressed.
@ljharb any updates on this? I just ran into this recently.
@lifeiscontent no; nobody's sent a PR yet and I haven't had the time. One would be welcome :-)
I started to attempt a fix today and ran into an issue with the current ecmaVersion being too old for the syntax. But after I updated that, I found out the issue has already been fixed! Potentially here. Below is a test specifically for it that I can add, but I don't know if there are any further repercussions for updating the ecmaVersion
--- a/tests/src/rules/export.js
+++ b/tests/src/rules/export.js
@@ -35,6 +35,12 @@ ruleTester.run('export', rule, {
export { A, B };
`,
}),
+ test({
+ code: `
+ export * as A from './named-export-collision/a';
+ export * as B from './named-export-collision/b';
+ `,
+ }),
],
invalid: [
diff --git a/tests/src/utils.js b/tests/src/utils.js
index 0f45e7b..0892482 100644
--- a/tests/src/utils.js
+++ b/tests/src/utils.js
@@ -37,7 +37,7 @@ export function test(t) {
}, t, {
parserOptions: Object.assign({
sourceType: 'module',
- ecmaVersion: 9,
+ ecmaVersion: 11,
}, t.parserOptions),
})
}
Long story short, this is fixed on version 2.22.0. Thanks @ljharb!
No problem; the ecmaVersion can be changed on a per-test basis :-)
I've adapted your diff into a commit, thanks!
Most helpful comment
I started to attempt a fix today and ran into an issue with the current
ecmaVersionbeing too old for the syntax. But after I updated that, I found out the issue has already been fixed! Potentially here. Below is a test specifically for it that I can add, but I don't know if there are any further repercussions for updating theecmaVersionLong story short, this is fixed on version 2.22.0. Thanks @ljharb!