diff --git a/src/parser.rs b/src/parser.rs index 9c3721f5..c7ecb6ea 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1135,6 +1135,12 @@ fn parse_primary( // Method access #[cfg(not(feature = "no_object"))] (expr, Token::Period) => { + // prevents capturing of the object properties as vars: xxx. + #[cfg(not(feature = "no_closure"))] + if let (Token::Identifier(_), _) = input.peek().unwrap() { + state.allow_capture = false; + } + let rhs = parse_unary(input, state, lib, settings.level_up())?; make_dot_expr(state, expr, rhs, token_pos)? } @@ -1694,16 +1700,6 @@ fn parse_binary_op( let (op_token, pos) = input.next().unwrap(); - if cfg!(not(feature = "no_object")) && op_token == Token::Period { - if let (Token::Identifier(_), _) = input.peek().unwrap() { - // prevents capturing of the object properties as vars: xxx. - #[cfg(not(feature = "no_closure"))] - { - state.allow_capture = false; - } - } - } - let rhs = parse_unary(input, state, lib, settings)?; let (next_op, next_pos) = input.peek().unwrap(); diff --git a/tests/closures.rs b/tests/closures.rs index 792f1ca7..4a0cd74b 100644 --- a/tests/closures.rs +++ b/tests/closures.rs @@ -54,6 +54,17 @@ fn test_closures() -> Result<(), Box> { ParseErrorType::BadInput(_) )); + assert_eq!( + engine.eval::( + r" + let foo = #{ x: 42 }; + let f = || { this.x }; + foo.call(f) + ", + )?, + 42 + ); + assert_eq!( engine.eval::( r#"