Use ImmutableString for import alias.
This commit is contained in:
parent
038b058e63
commit
08ca90a136
@ -36,7 +36,6 @@ use crate::utils::ImmutableString;
|
||||
use crate::any::DynamicWriteLock;
|
||||
|
||||
use crate::stdlib::{
|
||||
borrow::Cow,
|
||||
boxed::Box,
|
||||
collections::{HashMap, HashSet},
|
||||
fmt, format,
|
||||
@ -70,7 +69,11 @@ pub type Map = HashMap<ImmutableString, Dynamic>;
|
||||
/// ## WARNING
|
||||
///
|
||||
/// This type is volatile and may change.
|
||||
pub type Imports<'a> = Vec<(Cow<'a, str>, Module)>;
|
||||
//
|
||||
// Note - We cannot use &str or Cow<str> here because `eval` may load a module
|
||||
// and the module name will live beyond the AST of the eval script text.
|
||||
// The best we can do is a shared reference.
|
||||
pub type Imports = Vec<(ImmutableString, Module)>;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
#[cfg(debug_assertions)]
|
||||
@ -1826,7 +1829,7 @@ impl Engine {
|
||||
|
||||
if let Some((name, _)) = alias {
|
||||
module.index_all_sub_modules();
|
||||
mods.push((name.clone().into(), module));
|
||||
mods.push((name.clone(), module));
|
||||
}
|
||||
|
||||
state.modules += 1;
|
||||
|
@ -592,7 +592,7 @@ pub enum Stmt {
|
||||
ReturnWithVal(Box<((ReturnType, Position), Option<Expr>, Position)>),
|
||||
/// import expr as module
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Import(Box<(Expr, Option<(String, Position)>, Position)>),
|
||||
Import(Box<(Expr, Option<(ImmutableString, Position)>, Position)>),
|
||||
/// expr id as name, ...
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Export(
|
||||
@ -2753,7 +2753,7 @@ fn parse_import(
|
||||
|
||||
Ok(Stmt::Import(Box::new((
|
||||
expr,
|
||||
Some((name, settings.pos)),
|
||||
Some((name.into(), settings.pos)),
|
||||
token_pos,
|
||||
))))
|
||||
}
|
||||
|
@ -74,8 +74,8 @@ impl fmt::Debug for CustomSyntax {
|
||||
|
||||
/// Context of a script evaluation process.
|
||||
#[derive(Debug)]
|
||||
pub struct EvalContext<'a, 'b: 'a, 's, 'm, 't, 'd: 't> {
|
||||
pub(crate) mods: &'a mut Imports<'b>,
|
||||
pub struct EvalContext<'a, 's, 'm, 't, 'd: 't> {
|
||||
pub(crate) mods: &'a mut Imports,
|
||||
pub(crate) state: &'s mut State,
|
||||
pub(crate) lib: &'m Module,
|
||||
pub(crate) this_ptr: &'t mut Option<&'d mut Dynamic>,
|
||||
|
Loading…
Reference in New Issue
Block a user