mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(linter): read exported_bindings_from_star_export lazily (#8062)
This commit is contained in:
parent
547c102b6b
commit
774babb7f2
4 changed files with 37 additions and 39 deletions
|
|
@ -3,7 +3,7 @@
|
|||
use std::{
|
||||
fmt,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, RwLock},
|
||||
sync::{Arc, OnceLock, RwLock},
|
||||
};
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
|
|
@ -78,7 +78,7 @@ pub struct ModuleRecord {
|
|||
|
||||
/// Reexported bindings from `export * from 'specifier'`
|
||||
/// Keyed by resolved path
|
||||
pub exported_bindings_from_star_export: RwLock<FxHashMap<PathBuf, Vec<CompactStr>>>,
|
||||
exported_bindings_from_star_export: OnceLock<FxHashMap<PathBuf, Vec<CompactStr>>>,
|
||||
|
||||
/// `export default name`
|
||||
/// ^^^^^^^ span
|
||||
|
|
@ -491,4 +491,37 @@ impl ModuleRecord {
|
|||
..ModuleRecord::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn exported_bindings_from_star_export(
|
||||
&self,
|
||||
) -> &FxHashMap<PathBuf, Vec<CompactStr>> {
|
||||
self.exported_bindings_from_star_export.get_or_init(|| {
|
||||
let mut exported_bindings_from_star_export: FxHashMap<PathBuf, Vec<CompactStr>> =
|
||||
FxHashMap::default();
|
||||
let loaded_modules = self.loaded_modules.read().unwrap();
|
||||
for export_entry in &self.star_export_entries {
|
||||
let Some(module_request) = &export_entry.module_request else {
|
||||
continue;
|
||||
};
|
||||
let Some(remote_module_record) = loaded_modules.get(module_request.name()) else {
|
||||
continue;
|
||||
};
|
||||
// Append both remote `bindings` and `exported_bindings_from_star_export`
|
||||
let remote_exported_bindings_from_star_export = remote_module_record
|
||||
.exported_bindings_from_star_export()
|
||||
.iter()
|
||||
.flat_map(|(_, value)| value.clone());
|
||||
let remote_bindings = remote_module_record
|
||||
.exported_bindings
|
||||
.keys()
|
||||
.cloned()
|
||||
.chain(remote_exported_bindings_from_star_export);
|
||||
exported_bindings_from_star_export
|
||||
.entry(remote_module_record.resolved_absolute_path.clone())
|
||||
.or_default()
|
||||
.extend(remote_bindings);
|
||||
}
|
||||
exported_bindings_from_star_export
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,9 +117,7 @@ impl Rule for Named {
|
|||
}
|
||||
// check re-export
|
||||
if remote_module_record
|
||||
.exported_bindings_from_star_export
|
||||
.read()
|
||||
.unwrap()
|
||||
.exported_bindings_from_star_export()
|
||||
.iter()
|
||||
.any(|(_, value)| value.contains(&import_name.name))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -356,9 +356,7 @@ fn check_binding_exported(
|
|||
if module.exported_bindings.contains_key(name)
|
||||
|| (name == "default" && module.export_default.is_some())
|
||||
|| module
|
||||
.exported_bindings_from_star_export
|
||||
.read()
|
||||
.unwrap()
|
||||
.exported_bindings_from_star_export()
|
||||
.iter()
|
||||
.any(|(_, value)| value.iter().any(|s| s.as_str() == name))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -264,37 +264,6 @@ impl Runtime {
|
|||
|
||||
// The thread is blocked here until all dependent modules are resolved.
|
||||
|
||||
// Resolve and append `star_export_bindings`
|
||||
for export_entry in &module_record.star_export_entries {
|
||||
let Some(module_request) = &export_entry.module_request else {
|
||||
continue;
|
||||
};
|
||||
let loaded_modules = module_record.loaded_modules.read().unwrap();
|
||||
let Some(remote_module_record) = loaded_modules.get(module_request.name()) else {
|
||||
continue;
|
||||
};
|
||||
// Append both remote `bindings` and `exported_bindings_from_star_export`
|
||||
let remote_exported_bindings_from_star_export =
|
||||
remote_module_record.exported_bindings_from_star_export.read().unwrap();
|
||||
let remote_exported_bindings_from_star_export =
|
||||
remote_exported_bindings_from_star_export
|
||||
.iter()
|
||||
.flat_map(|(_, value)| value.clone());
|
||||
let remote_bindings = remote_module_record
|
||||
.exported_bindings
|
||||
.keys()
|
||||
.cloned()
|
||||
.chain(remote_exported_bindings_from_star_export)
|
||||
.collect::<Vec<_>>();
|
||||
module_record
|
||||
.exported_bindings_from_star_export
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(remote_module_record.resolved_absolute_path.clone())
|
||||
.or_default()
|
||||
.extend(remote_bindings);
|
||||
}
|
||||
|
||||
// Stop if the current module is not marked for lint.
|
||||
if !self.paths.contains(path) {
|
||||
return vec![];
|
||||
|
|
|
|||
Loading…
Reference in a new issue