Fix Stmt size.
This commit is contained in:
parent
b11b8d6d39
commit
2ff2789326
16
src/ast.rs
16
src/ast.rs
@ -832,7 +832,7 @@ pub enum Stmt {
|
||||
/// `do` `{` stmt `}` `while`|`until` expr
|
||||
Do(Box<Stmt>, Expr, bool, Position),
|
||||
/// `for` id `in` expr `{` stmt `}`
|
||||
For(Expr, String, Box<Stmt>, Position),
|
||||
For(Expr, Box<(String, Stmt)>, Position),
|
||||
/// \[`export`\] `let` id `=` expr
|
||||
Let(Expr, Ident, Position),
|
||||
/// \[`export`\] `const` id `=` expr
|
||||
@ -853,7 +853,7 @@ pub enum Stmt {
|
||||
Return(ReturnType, Option<Expr>, Position),
|
||||
/// `import` expr `as` var
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Import(Expr, Option<Ident>, Position),
|
||||
Import(Expr, Ident, Position),
|
||||
/// `export` var `as` var `,` ...
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Export(Vec<(Ident, Option<Ident>)>, Position),
|
||||
@ -890,7 +890,7 @@ impl Stmt {
|
||||
| Self::Switch(_, _, pos)
|
||||
| Self::While(_, _, pos)
|
||||
| Self::Do(_, _, _, pos)
|
||||
| Self::For(_, _, _, pos)
|
||||
| Self::For(_, _, pos)
|
||||
| Self::Return(_, _, pos)
|
||||
| Self::Let(_, _, pos)
|
||||
| Self::Const(_, _, pos)
|
||||
@ -919,7 +919,7 @@ impl Stmt {
|
||||
| Self::Switch(_, _, pos)
|
||||
| Self::While(_, _, pos)
|
||||
| Self::Do(_, _, _, pos)
|
||||
| Self::For(_, _, _, pos)
|
||||
| Self::For(_, _, pos)
|
||||
| Self::Return(_, _, pos)
|
||||
| Self::Let(_, _, pos)
|
||||
| Self::Const(_, _, pos)
|
||||
@ -946,7 +946,7 @@ impl Stmt {
|
||||
Self::If(_, _, _)
|
||||
| Self::Switch(_, _, _)
|
||||
| Self::While(_, _, _)
|
||||
| Self::For(_, _, _, _)
|
||||
| Self::For(_, _, _)
|
||||
| Self::Block(_, _)
|
||||
| Self::TryCatch(_, _, _) => true,
|
||||
|
||||
@ -985,7 +985,7 @@ impl Stmt {
|
||||
Self::While(condition, block, _) | Self::Do(block, condition, _, _) => {
|
||||
condition.is_pure() && block.is_pure()
|
||||
}
|
||||
Self::For(iterable, _, block, _) => iterable.is_pure() && block.is_pure(),
|
||||
Self::For(iterable, x, _) => iterable.is_pure() && x.1.is_pure(),
|
||||
Self::Let(_, _, _) | Self::Const(_, _, _) | Self::Assignment(_, _) => false,
|
||||
Self::Block(block, _) => block.iter().all(|stmt| stmt.is_pure()),
|
||||
Self::Continue(_) | Self::Break(_) | Self::Return(_, _, _) => false,
|
||||
@ -1024,9 +1024,9 @@ impl Stmt {
|
||||
e.walk(path, on_node);
|
||||
s.walk(path, on_node);
|
||||
}
|
||||
Self::For(e, _, s, _) => {
|
||||
Self::For(e, x, _) => {
|
||||
e.walk(path, on_node);
|
||||
s.walk(path, on_node);
|
||||
x.1.walk(path, on_node);
|
||||
}
|
||||
Self::Assignment(x, _) => {
|
||||
x.0.walk(path, on_node);
|
||||
|
@ -2126,8 +2126,8 @@ impl Engine {
|
||||
},
|
||||
|
||||
// For loop
|
||||
Stmt::For(expr, name, x, _) => {
|
||||
let stmt = x.as_ref();
|
||||
Stmt::For(expr, x, _) => {
|
||||
let (name, stmt) = x.as_ref();
|
||||
let iter_obj = self
|
||||
.eval_expr(scope, mods, state, lib, this_ptr, expr, level)?
|
||||
.flatten();
|
||||
@ -2348,7 +2348,7 @@ impl Engine {
|
||||
|
||||
// Import statement
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Stmt::Import(expr, alias, _pos) => {
|
||||
Stmt::Import(expr, Ident { name, public, .. }, _pos) => {
|
||||
// Guard against too many modules
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if state.modules >= self.max_modules() {
|
||||
@ -2375,14 +2375,14 @@ impl Engine {
|
||||
})
|
||||
.unwrap_or_else(|| self.module_resolver.resolve(self, &path, expr_pos))?;
|
||||
|
||||
if let Some(name_def) = alias {
|
||||
if *public {
|
||||
if !module.is_indexed() {
|
||||
// Index the module (making a clone copy if necessary) if it is not indexed
|
||||
let mut module = crate::fn_native::shared_take_or_clone(module);
|
||||
module.build_index();
|
||||
mods.push(name_def.name.clone(), module);
|
||||
mods.push(name.clone(), module);
|
||||
} else {
|
||||
mods.push(name_def.name.clone(), module);
|
||||
mods.push(name.clone(), module);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -428,9 +428,9 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut State, preserve_result: bool) {
|
||||
optimize_expr(condition, state);
|
||||
}
|
||||
// for id in expr { block }
|
||||
Stmt::For(iterable, _, block, _) => {
|
||||
Stmt::For(iterable, x, _) => {
|
||||
optimize_expr(iterable, state);
|
||||
optimize_stmt(block, state, false);
|
||||
optimize_stmt(&mut x.1, state, false);
|
||||
}
|
||||
// let id = expr;
|
||||
Stmt::Let(expr, _, _) => optimize_expr(expr, state),
|
||||
|
@ -2138,7 +2138,7 @@ fn parse_for(
|
||||
|
||||
state.stack.truncate(prev_stack_len);
|
||||
|
||||
Ok(Stmt::For(expr, name, Box::new(body), settings.pos))
|
||||
Ok(Stmt::For(expr, Box::new((name, body)), settings.pos))
|
||||
}
|
||||
|
||||
/// Parse a variable definition statement.
|
||||
@ -2210,7 +2210,15 @@ fn parse_import(
|
||||
|
||||
// import expr as ...
|
||||
if !match_token(input, Token::As).0 {
|
||||
return Ok(Stmt::Import(expr, None, settings.pos));
|
||||
return Ok(Stmt::Import(
|
||||
expr,
|
||||
Ident {
|
||||
name: "".into(),
|
||||
pos: Position::NONE,
|
||||
public: false,
|
||||
},
|
||||
settings.pos,
|
||||
));
|
||||
}
|
||||
|
||||
// import expr as name ...
|
||||
@ -2228,11 +2236,11 @@ fn parse_import(
|
||||
|
||||
Ok(Stmt::Import(
|
||||
expr,
|
||||
Some(Ident {
|
||||
Ident {
|
||||
name,
|
||||
pos: name_pos,
|
||||
public: false,
|
||||
}),
|
||||
public: true,
|
||||
},
|
||||
settings.pos,
|
||||
))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user