Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Fixed
- [`no-duplicates`]: fix `prefer-inline` autofix producing invalid syntax when an identifier named `from` is imported ([#3236])
- [`no-duplicates`]: avoid false positives for TypeScript namespace and default type imports that cannot be merged ([#3195])
- ExportMap: resolve export * as ns re-exports under modern parsers ([#3250])

### Changed
- [Docs] `no-unused-modules`: Fix docs of `ignoreUnusedTypeExports` option ([#3233], thanks [@ej612])
Expand Down Expand Up @@ -1191,6 +1192,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#3250]: https://github.com/import-js/eslint-plugin-import/pull/3250
[#3237]: https://github.com/import-js/eslint-plugin-import/pull/3237
[#3236]: https://github.com/import-js/eslint-plugin-import/pull/3236
[#3233]: https://github.com/import-js/eslint-plugin-import/pull/3233
Expand Down
19 changes: 15 additions & 4 deletions src/exportMap/specifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@ export default function processSpecifier(specifier, astNode, exportMap, namespac
local = 'default';
break;
case 'ExportNamespaceSpecifier':
exportMap.namespace.set(specifier.exported.name, Object.defineProperty(exportMeta, 'namespace', {
Object.defineProperty(exportMeta, 'namespace', {
get() { return namespace.resolveImport(nsource); },
}));
});
exportMap.namespace.set(specifier.exported.name, exportMeta);
return;
case 'ExportAllDeclaration':
exportMap.namespace.set(specifier.exported.name || specifier.exported.value, namespace.add(exportMeta, specifier.source.value));
Object.defineProperty(exportMeta, 'namespace', {
get() { return namespace.resolveImport(specifier.source.value); },
});
exportMap.namespace.set(
specifier.exported.name || specifier.exported.value,
exportMeta,
);
return;
case 'ExportSpecifier':
if (!astNode.source) {
exportMap.namespace.set(specifier.exported.name || specifier.exported.value, namespace.add(exportMeta, specifier.local));
namespace.add(exportMeta, specifier.local);
exportMap.namespace.set(
specifier.exported.name || specifier.exported.value,
exportMeta,
);
return;
}
// else falls through
Expand Down
5 changes: 4 additions & 1 deletion src/exportMap/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ export default class ImportExportVisitorBuilder {
},
ExportAllDeclaration() {
const getter = captureDependency(astNode, astNode.exportKind === 'type', this.remotePathResolver, this.exportMap, this.context, this.thunkFor);
if (getter) { this.exportMap.dependencies.add(getter); }
if (astNode.exported) {
// `export * as ns from './mod'` — named namespace, not a star-export
processSpecifier(astNode, astNode.exported, this.exportMap, this.namespace);
} else if (getter) {
// `export * from './mod'` — star-export flattens into current module
this.exportMap.dependencies.add(getter);
}
},
/** capture namespaces in case of later export */
Expand Down
12 changes: 12 additions & 0 deletions tests/src/rules/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ const invalid = [].concat(
errors: ["'e' not found in deeply imported namespace 'b.c'."],
parserOptions: { ecmaVersion: 2022 },
})),

// #3250: `export * as` re-export resolves under espree
testVersion('>= 6', () => ({
code: `
import * as middle from './middle';

console.log(middle.myName.b);
`,
filename: testFilePath('export-star-2/downstream.js'),
parserOptions: { ecmaVersion: 2020 },
errors: ["'b' not found in deeply imported namespace 'middle.myName'."],
})),
);

///////////////////////
Expand Down
Loading