Skip to content

Commit 9113ead

Browse files
committed
[New] no-named-as-default: ignore if imported obj is exported both as default and named
1 parent 777b97a commit 9113ead

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/rules/no-named-as-default.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ module.exports = {
1515

1616
create(context) {
1717
function checkDefault(nameKey, defaultSpecifier) {
18+
19+
/**
20+
* For ImportDefaultSpecifier we're interested in the "local" name (`foo` for `import {bar as foo} ...`)
21+
* For ExportDefaultSpecifier we're interested in the "exported" name (`foo` for `export {bar as foo} ...`)
22+
*/
23+
const analyzedName = defaultSpecifier[nameKey].name;
24+
1825
// #566: default is a valid specifier
19-
if (defaultSpecifier[nameKey].name === 'default') { return; }
26+
if (analyzedName === 'default') { return; }
2027

2128
const declaration = importDeclaration(context);
2229

@@ -28,7 +35,15 @@ module.exports = {
2835
return;
2936
}
3037

31-
if (imports.has('default') && imports.has(defaultSpecifier[nameKey].name)) {
38+
if (imports.has('default') && imports.has(analyzedName)) {
39+
40+
// #1594: the imported module exports the same thing via a default export and a named export
41+
const namedExportInImportedModule = imports.reexports.get(analyzedName);
42+
const defaultExportInImportedModule = imports.reexports.get('default');
43+
if (defaultExportInImportedModule.getImport().path === namedExportInImportedModule.getImport().path
44+
&& defaultExportInImportedModule.local === namedExportInImportedModule.local) {
45+
return;
46+
}
3247

3348
context.report(
3449
defaultSpecifier,

0 commit comments

Comments
 (0)