mirror of
https://github.com/danog/parser.git
synced 2025-01-22 13:01:32 +01:00
parser: support arrow functions returning by ref
This commit is contained in:
parent
af11ff39c8
commit
4338b83254
@ -459,6 +459,7 @@ pub enum Expression {
|
||||
params: Vec<Param>,
|
||||
return_type: Option<Type>,
|
||||
expr: Box<Self>,
|
||||
by_ref: bool,
|
||||
},
|
||||
New {
|
||||
target: Box<Self>,
|
||||
|
@ -1730,6 +1730,13 @@ impl Parser {
|
||||
TokenKind::Fn => {
|
||||
self.next();
|
||||
|
||||
let by_ref = if self.current.kind == TokenKind::Ampersand {
|
||||
self.next();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
self.lparen()?;
|
||||
|
||||
let params = self.param_list()?;
|
||||
@ -1752,6 +1759,7 @@ impl Parser {
|
||||
params,
|
||||
return_type,
|
||||
expr: Box::new(value),
|
||||
by_ref,
|
||||
}
|
||||
}
|
||||
TokenKind::New => {
|
||||
@ -3781,7 +3789,8 @@ mod tests {
|
||||
&[expr!(Expression::ArrowFunction {
|
||||
params: vec![],
|
||||
return_type: None,
|
||||
expr: Box::new(Expression::Null)
|
||||
expr: Box::new(Expression::Null),
|
||||
by_ref: false,
|
||||
})],
|
||||
);
|
||||
}
|
||||
@ -3864,7 +3873,8 @@ mod tests {
|
||||
by_ref: true,
|
||||
}],
|
||||
return_type: None,
|
||||
expr: Box::new(Expression::Null)
|
||||
expr: Box::new(Expression::Null),
|
||||
by_ref: false,
|
||||
})],
|
||||
);
|
||||
}
|
||||
@ -3915,6 +3925,18 @@ mod tests {
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrow_functions_returning_by_ref() {
|
||||
assert_ast("<?php fn &() => null;", &[
|
||||
expr!(Expression::ArrowFunction {
|
||||
params: vec![],
|
||||
expr: Box::new(Expression::Null),
|
||||
return_type: None,
|
||||
by_ref: true,
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
fn assert_ast(source: &str, expected: &[Statement]) {
|
||||
let mut lexer = Lexer::new(None);
|
||||
let tokens = lexer.tokenize(source).unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user