Store path in module id.

This commit is contained in:
Stephen Chung 2022-08-25 22:17:01 +08:00
parent 1c335e24dc
commit 5c80157e7a
3 changed files with 9 additions and 2 deletions

View File

@ -26,6 +26,7 @@ Enhancements
------------
* `is_empty` method is added to arrays, BLOB's, object maps, strings and ranges.
* `StaticModuleResolver` now stores the path in the module's `id` field.
Version 1.9.0

View File

@ -113,7 +113,7 @@ impl Engine {
});
}
let mut ast = self.compile_scripts_with_scope(scope, &[script])?;
let mut ast = self.compile_with_scope(scope, script)?;
let mut resolver = StaticModuleResolver::new();
let mut imports = BTreeSet::new();

View File

@ -54,8 +54,14 @@ impl StaticModuleResolver {
/// Add a [module][Module] keyed by its path.
#[inline]
pub fn insert(&mut self, path: impl Into<Identifier>, mut module: Module) {
let path = path.into();
if module.id().is_none() {
module.set_id(path.clone());
}
module.build_index();
self.0.insert(path.into(), module.into());
self.0.insert(path, module.into());
}
/// Remove a [module][Module] given its path.
#[inline(always)]