Fix bug in chain parsing.

This commit is contained in:
Stephen Chung 2023-01-25 07:37:44 +08:00
parent ea3efe654c
commit 733bb07d2d
3 changed files with 19 additions and 2 deletions

View File

@ -7,6 +7,7 @@ Version 1.13.0
Bug fixes
---------
* Complex indexing/dotting chains now parse correctly, for example: `a[b][c[d]].e`
* `map` and `filter` for arrays are marked `pure`. Warnings are added to the documentation of pure array methods that take `this` closures.

View File

@ -2102,8 +2102,10 @@ impl Engine {
op_pos: Position,
) -> ParseResult<Expr> {
match (lhs, rhs) {
// lhs[idx_expr].rhs
(Expr::Index(mut x, options, pos), rhs) => {
// lhs[...][...].rhs
(Expr::Index(mut x, options, pos), rhs)
if !parent_options.contains(ASTFlags::BREAK) =>
{
let options = options | parent_options;
x.rhs = Self::make_dot_expr(state, x.rhs, rhs, options, op_flags, op_pos)?;
Ok(Expr::Index(x, ASTFlags::NONE, pos))

View File

@ -133,6 +133,20 @@ fn test_arrays() -> Result<(), Box<EvalAltResult>> {
);
}
#[cfg(not(feature = "no_object"))]
assert_eq!(
engine.eval::<INT>(
"
let x = #{ foo: 42 };
let n = 0;
let a = [[x]];
let i = [n];
a[n][i[n]].foo
"
)?,
42
);
assert_eq!(
engine
.eval::<Dynamic>(