fix(linter): handle named export default in import-plugin/named (#3158)

This commit is contained in:
Boshen 2024-05-04 17:40:56 +08:00 committed by GitHub
parent b1bddacd09
commit fde7d65992
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1 @@
export default () => {}

View file

@ -88,11 +88,16 @@ impl Rule for Named {
};
let remote_module_record = remote_module_record_ref.value();
// Check remote bindings
if remote_module_record.exported_bindings.contains_key(import_name.name()) {
let name = import_name.name();
// `export { default as foo } from './source'` <> `export default xxx`
if *name == "default" && remote_module_record.export_default.is_some() {
continue;
}
if remote_module_record.exported_bindings.contains_key(name) {
continue;
}
ctx.diagnostic(NamedDiagnostic(
import_name.name().to_string(),
name.to_string(),
specifier.to_string(),
import_name.span(),
));
@ -175,6 +180,7 @@ fn test() {
"import { foo } from './export-all'",
// TypeScript export assignment
"import x from './typescript-export-assign-object'",
"export { default as foo } from './typescript-export-default'",
];
let fail = vec![