mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(syntax): add loaded_modules to ModuleRecord
This commit is contained in:
parent
9ee75931ed
commit
75d928a20d
5 changed files with 47 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1816,6 +1816,8 @@ name = "oxc_syntax"
|
|||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"bitflags 2.4.0",
|
||||
"dashmap",
|
||||
"indexmap 2.0.0",
|
||||
"oxc_index",
|
||||
"oxc_span",
|
||||
"rustc-hash",
|
||||
|
|
|
|||
|
|
@ -139,6 +139,10 @@ impl Runtime {
|
|||
fn process_path(&self, path: &Path, tx_error: &DiagnosticSender) {
|
||||
let Ok(source_type) = SourceType::from_path(path) else { return };
|
||||
|
||||
if self.module_map.contains_key(path) {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.init_cache_state(path) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -205,17 +209,19 @@ impl Runtime {
|
|||
|
||||
// Retrieve all dependency modules from this module.
|
||||
module_record
|
||||
.module_requests
|
||||
.requested_modules
|
||||
.keys()
|
||||
.cloned()
|
||||
.par_bridge()
|
||||
.map_with(&self.resolver, |resolver, specifier| {
|
||||
resolver.resolve(dir, &specifier).ok()
|
||||
resolver.resolve(dir, &specifier).ok().map(|r| (specifier, r))
|
||||
})
|
||||
.flatten()
|
||||
.filter(|r| !self.module_map.contains_key(r.path()))
|
||||
.for_each_with(tx_error, |tx_error, resolution| {
|
||||
self.process_path(resolution.path(), tx_error);
|
||||
.for_each_with(tx_error, |tx_error, (specifier, resolution)| {
|
||||
let path = resolution.path();
|
||||
self.process_path(path, tx_error);
|
||||
let target_module_record = Arc::clone(&self.module_map.get(path).unwrap());
|
||||
module_record.loaded_modules.insert(specifier, target_module_record);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ impl ModuleRecordBuilder {
|
|||
|
||||
fn add_module_request(&mut self, name_span: &NameSpan) {
|
||||
self.module_record
|
||||
.module_requests
|
||||
.requested_modules
|
||||
.entry(name_span.name().clone())
|
||||
.or_default()
|
||||
.push(name_span.span());
|
||||
|
|
|
|||
|
|
@ -24,3 +24,5 @@ unicode-id-start = { workspace = true }
|
|||
serde = { workspace = true, features = ["derive"], optional = true }
|
||||
bitflags = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
indexmap = { workspace = true }
|
||||
dashmap = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -1,31 +1,56 @@
|
|||
//! [ECMAScript Module Record](https://tc39.es/ecma262/#sec-abstract-module-records)
|
||||
|
||||
use oxc_span::{Atom, Span};
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::{hash::BuildHasherDefault, sync::Arc};
|
||||
|
||||
/// [Source Text Module Record](https://tc39.es/ecma262/#table-additional-fields-of-source-text-module-records)
|
||||
use dashmap::DashMap;
|
||||
use indexmap::IndexMap;
|
||||
use oxc_span::{Atom, Span};
|
||||
use rustc_hash::{FxHashMap, FxHasher};
|
||||
|
||||
/// Module Record
|
||||
///
|
||||
/// See
|
||||
/// * <https://tc39.es/ecma262/#table-additional-fields-of-source-text-module-records>
|
||||
/// * <https://tc39.es/ecma262/#cyclic-module-record>
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ModuleRecord {
|
||||
/// <https://tc39.es/ecma262/#sec-static-semantics-modulerequests>
|
||||
/// `[[RequestedModules]]`
|
||||
///
|
||||
/// A List of all the ModuleSpecifier strings used by the module represented by this record to request the importation of a module. The List is in source text occurrence order.
|
||||
///
|
||||
/// Module requests from:
|
||||
/// import ImportClause FromClause
|
||||
/// import ModuleSpecifier
|
||||
/// export ExportFromClause FromClause
|
||||
/// Keyed by FromClause, valued by all node occurrences
|
||||
pub module_requests: FxHashMap<Atom, Vec<Span>>,
|
||||
/// Keyed by ModuleSpecifier, valued by all node occurrences
|
||||
pub requested_modules: IndexMap<Atom, Vec<Span>, BuildHasherDefault<FxHasher>>,
|
||||
|
||||
/// `[[LoadedModules]]`
|
||||
///
|
||||
/// A map from the specifier strings used by the module represented by this record to request the importation of a module to the resolved Module Record.
|
||||
/// The list does not contain two different Records with the same `[[Specifier]]`.
|
||||
pub loaded_modules: DashMap<Atom, Arc<ModuleRecord>, BuildHasherDefault<FxHasher>>,
|
||||
|
||||
/// `[[ImportEntries]]`
|
||||
///
|
||||
/// A List of ImportEntry records derived from the code of this module
|
||||
pub import_entries: Vec<ImportEntry>,
|
||||
|
||||
/// `[[LocalExportEntries]]`
|
||||
///
|
||||
/// A List of ExportEntry records derived from the code of this module
|
||||
/// that correspond to declarations that occur within the module
|
||||
pub local_export_entries: Vec<ExportEntry>,
|
||||
|
||||
/// `[[IndirectExportEntries]]`
|
||||
///
|
||||
/// A List of ExportEntry records derived from the code of this module
|
||||
/// that correspond to reexported imports that occur within the module
|
||||
/// or exports from export * as namespace declarations.
|
||||
pub indirect_export_entries: Vec<ExportEntry>,
|
||||
|
||||
/// `[[StarExportEntries]]`
|
||||
///
|
||||
/// A List of ExportEntry records derived from the code of this module
|
||||
/// that correspond to export * declarations that occur within the module,
|
||||
/// not including export * as namespace declarations.
|
||||
|
|
|
|||
Loading…
Reference in a new issue