Skip to content

Commit

Permalink
better way to disambiguate optional chaining operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Fee0 authored and Fee314 committed Apr 9, 2024
1 parent 31faa06 commit 1f65b9b
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/tokenizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,23 +723,12 @@ impl<'a> Tokenizer<'a> {
self.gen_punct(Punct::DoubleQuestionMark)
} else if self.look_ahead_byte_matches('.') {
self.stream.skip_bytes(1);
if let Some(next) = self.stream.peek_char() {
if Self::is_id_start(next) {
// a?.b
self.gen_punct(Punct::QuestionMarkDot)
} else if self.look_ahead_byte_matches('(') {
// a?.()
self.gen_punct(Punct::QuestionMarkDot)
} else if self.look_ahead_byte_matches('[') {
// a?.['b']
self.gen_punct(Punct::QuestionMarkDot)
} else {
// ternary operator
self.stream.skip_back(1);
self.gen_punct(Punct::QuestionMark)
}
} else {
if self.stream.at_decimal() {
// floating point numbers can be defined with a leading period: ".123"
self.stream.skip_back(1);
self.gen_punct(Punct::QuestionMark)
} else {
self.gen_punct(Punct::QuestionMarkDot)
}
} else {
self.gen_punct(Punct::QuestionMark)
Expand Down

0 comments on commit 1f65b9b

Please sign in to comment.