mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Don't treat '?.' followed by decimal digit as QuestionMarkPeriod
From the spec: https://tc39.es/ecma262/#sec-punctuators OptionalChainingPunctuator :: ?. [lookahead ∉ DecimalDigit] We were missing the lookahead and therefore incorrectly treating any '?.' as TokenType::QuestionMarkPeriod. Fixes #4409.
This commit is contained in:
parent
6e7edd6e77
commit
0974991d05
Notes:
sideshowbarker
2024-07-19 00:52:17 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/0974991d051 Pull-request: https://github.com/SerenityOS/serenity/pull/4410 Issue: https://github.com/SerenityOS/serenity/issues/4409
2 changed files with 11 additions and 4 deletions
|
@ -598,10 +598,13 @@ Token Lexer::next()
|
|||
auto two_chars_view = m_source.substring_view(m_position - 1, 2);
|
||||
auto it = s_two_char_tokens.find(two_chars_view.hash(), [&](auto& entry) { return entry.key == two_chars_view; });
|
||||
if (it != s_two_char_tokens.end()) {
|
||||
found_two_char_token = true;
|
||||
consume();
|
||||
consume();
|
||||
token_type = it->value;
|
||||
// OptionalChainingPunctuator :: ?. [lookahead ∉ DecimalDigit]
|
||||
if (!(it->value == TokenType::QuestionMarkPeriod && m_position + 1 < m_source.length() && isdigit(m_source[m_position + 1]))) {
|
||||
found_two_char_token = true;
|
||||
consume();
|
||||
consume();
|
||||
token_type = it->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,3 +14,7 @@ test("object values", () => {
|
|||
expect(o.f ? true : false).toBeTrue();
|
||||
expect(1 ? o.f : null).toBeTrue();
|
||||
});
|
||||
|
||||
test("issue #4409, '?.' followed by decimal digit", () => {
|
||||
expect("return false?.1:.2").toEvalTo(0.2);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue