parser: support static variable variable property fetches

This commit is contained in:
Ryan Chandler 2022-09-16 10:43:18 +01:00
parent c91d7a495f
commit 15e84edab6
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -2099,7 +2099,7 @@ impl Parser {
}
}
TokenKind::DoubleColon => match self.current.kind.clone() {
TokenKind::Variable(_) => {
TokenKind::Dollar | TokenKind::Variable(_) => {
let var = self.expression(Precedence::Lowest)?;
Expression::StaticPropertyFetch {
@ -4268,6 +4268,20 @@ mod tests {
);
}
#[test]
fn variable_variable_static_property_fetch() {
assert_ast("<?php Foo::$$a;", &[
expr!(Expression::StaticPropertyFetch {
target: Box::new(Expression::Identifier { name: "Foo".into() }),
property: Box::new(Expression::DynamicVariable {
name: Box::new(Expression::Variable {
name: "a".into()
})
})
})
]);
}
fn assert_ast(source: &str, expected: &[Statement]) {
let mut lexer = Lexer::new(None);
let tokens = lexer.tokenize(source).unwrap();