Fix closure property access.
This commit is contained in:
parent
88f63fa24b
commit
48af8719e7
@ -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.<var>
|
||||
#[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.<var>
|
||||
#[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();
|
||||
|
@ -54,6 +54,17 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
|
||||
ParseErrorType::BadInput(_)
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r"
|
||||
let foo = #{ x: 42 };
|
||||
let f = || { this.x };
|
||||
foo.call(f)
|
||||
",
|
||||
)?,
|
||||
42
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r#"
|
||||
|
Loading…
Reference in New Issue
Block a user