Implement optional chaining (#5164)

The work is based on PR #4843, only fixed some conflicts and cppcheck errors.

Co-authored-by: Robert Fancsik robert.fancsik@h-lab.eu
JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi gergocs@inf.u-szeged.hu
This commit is contained in:
Gergo Csizi
2024-11-20 11:57:58 +01:00
committed by GitHub
parent e9f08a7879
commit f54f2d3a7b
14 changed files with 1012 additions and 412 deletions
+30
View File
@@ -381,6 +381,29 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */
}
} /* lexer_skip_spaces */
/**
* Checks the next token start character.
*
* @return LIT_INVALID_CP - if there is no more characters to read
* next byte - otherwise
*/
lit_code_point_t
lexer_peek_next_character (parser_context_t *context_p) /**< context */
{
if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES))
{
lexer_skip_spaces (context_p);
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
}
if (context_p->source_p < context_p->source_end_p)
{
return context_p->source_p[0];
}
return LIT_INVALID_CP;
} /* lexer_check_next_character */
/**
* Skip all the continuous empty statements.
*/
@@ -1738,6 +1761,13 @@ lexer_next_token (parser_context_t *context_p) /**< context */
length = 2;
break;
}
if (context_p->source_p[1] == (uint8_t) LIT_CHAR_DOT
&& (length < 3 || !lit_char_is_decimal_digit (context_p->source_p[2])))
{
context_p->token.type = LEXER_QUESTION_MARK_DOT;
length = 2;
break;
}
}
context_p->token.type = LEXER_QUESTION_MARK;