Add object maps.

This commit is contained in:
Stephen Chung
2020-03-29 23:53:35 +08:00
parent ef6c6ea6d2
commit 45ee51874f
9 changed files with 632 additions and 202 deletions

View File

@@ -371,19 +371,23 @@ fn optimize_expr<'a>(expr: Expr, state: &mut State<'a>) -> Expr {
// [ items .. ]
#[cfg(not(feature = "no_index"))]
Expr::Array(items, pos) => {
let orig_len = items.len();
let items: Vec<_> = items
.into_iter()
.map(|expr| optimize_expr(expr, state))
.collect();
if orig_len != items.len() {
state.set_dirty();
}
Expr::Array(items, pos)
}
// [ items .. ]
#[cfg(not(feature = "no_object"))]
Expr::Map(items, pos) => {
let items: Vec<_> = items
.into_iter()
.map(|(key, expr, pos)| (key, optimize_expr(expr, state), pos))
.collect();
Expr::Map(items, pos)
}
// lhs && rhs
Expr::And(lhs, rhs) => match (*lhs, *rhs) {
// true && rhs -> rhs