Merge pull request #52 from ryangjchandler/fix/nullsafe-property-fetch

This commit is contained in:
Ryan Chandler 2022-09-13 00:27:14 +01:00 committed by GitHub
commit b070f7b07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -237,7 +237,7 @@ impl Lexer {
TokenKind::QuestionColon
} else if self.try_read("->") {
self.col += 1;
self.skip(3);
self.skip(2);
TokenKind::NullsafeArrow
} else {
TokenKind::Question

View File

@ -3177,6 +3177,17 @@ mod tests {
);
}
#[test]
fn nullsafe_operator() {
assert_ast(
"<?php $a?->b;",
&[expr!(Expression::NullsafePropertyFetch {
target: Box::new(Expression::Variable { name: "a".into() }),
property: Box::new(Expression::Identifier { name: "b".into() })
})],
);
}
fn assert_ast(source: &str, expected: &[Statement]) {
let mut lexer = Lexer::new(None);
let tokens = lexer.tokenize(source).unwrap();