@@ -1509,6 +1509,55 @@ lexer_parse_number (parser_context_t *context_p) /**< context */
15091509 break; \
15101510 }
15111511
1512+ /**
1513+ * Four tokens, where the first is the prefix of the other three
1514+ * and the second is prefix of the fourth (e.g. &, &&, &=, &&= ).
1515+ *
1516+ * @param char1 first character
1517+ * @param type1 type of the first character
1518+ * @param char2 second character
1519+ * @param type2 type of the second character
1520+ * @param char3 third character
1521+ * @param type3 type of the third character
1522+ * @param char4 fourth character
1523+ * @param type4 type of the fourth character
1524+ */
1525+ #if JERRY_ESNEXT
1526+ #define LEXER_TYPE_D_TOKEN (char1 , type1 , char2 , type2 , char3 , type3 , char4 , type4 ) \
1527+ case (uint8_t) (char1): \
1528+ { \
1529+ if (length >= 2) \
1530+ { \
1531+ if (context_p->source_p[1] == (uint8_t) (char2)) \
1532+ { \
1533+ context_p->token.type = (type2); \
1534+ length = 2; \
1535+ break; \
1536+ } \
1537+ \
1538+ if (context_p->source_p[1] == (uint8_t) (char3)) \
1539+ { \
1540+ if (length >= 3 && context_p->source_p[2] == (uint8_t) (char4)) \
1541+ { \
1542+ context_p->token.type = (type4); \
1543+ length = 3; \
1544+ break; \
1545+ } \
1546+ context_p->token.type = (type3); \
1547+ length = 2; \
1548+ break; \
1549+ } \
1550+ } \
1551+ \
1552+ context_p->token.type = (type1); \
1553+ length = 1; \
1554+ break; \
1555+ }
1556+ #else /* !JERRY_ESNEXT */
1557+ #define LEXER_TYPE_D_TOKEN (char1 , type1 , char2 , type2 , char3 , type3 , char4 , type4 ) \
1558+ LEXER_TYPE_C_TOKEN (char1, type1, char2, type2, char3, type3)
1559+ #endif /* JERRY_ESNEXT */
1560+
15121561/**
15131562 * Get next token.
15141563 */
@@ -1759,18 +1808,22 @@ lexer_next_token (parser_context_t *context_p) /**< context */
17591808 LEXER_TYPE_B_TOKEN (LIT_CHAR_SLASH , LEXER_DIVIDE , LIT_CHAR_EQUALS , LEXER_ASSIGN_DIVIDE )
17601809 LEXER_TYPE_B_TOKEN (LIT_CHAR_PERCENT , LEXER_MODULO , LIT_CHAR_EQUALS , LEXER_ASSIGN_MODULO )
17611810
1762- LEXER_TYPE_C_TOKEN (LIT_CHAR_AMPERSAND ,
1811+ LEXER_TYPE_D_TOKEN (LIT_CHAR_AMPERSAND ,
17631812 LEXER_BIT_AND ,
17641813 LIT_CHAR_EQUALS ,
17651814 LEXER_ASSIGN_BIT_AND ,
17661815 LIT_CHAR_AMPERSAND ,
1767- LEXER_LOGICAL_AND )
1768- LEXER_TYPE_C_TOKEN (LIT_CHAR_VLINE ,
1816+ LEXER_LOGICAL_AND ,
1817+ LIT_CHAR_EQUALS ,
1818+ LEXER_ASSIGN_LOGICAL_AND )
1819+ LEXER_TYPE_D_TOKEN (LIT_CHAR_VLINE ,
17691820 LEXER_BIT_OR ,
17701821 LIT_CHAR_EQUALS ,
17711822 LEXER_ASSIGN_BIT_OR ,
17721823 LIT_CHAR_VLINE ,
1773- LEXER_LOGICAL_OR )
1824+ LEXER_LOGICAL_OR ,
1825+ LIT_CHAR_EQUALS ,
1826+ LEXER_ASSIGN_LOGICAL_OR )
17741827
17751828 LEXER_TYPE_B_TOKEN (LIT_CHAR_CIRCUMFLEX , LEXER_BIT_XOR , LIT_CHAR_EQUALS , LEXER_ASSIGN_BIT_XOR )
17761829
@@ -1782,6 +1835,12 @@ lexer_next_token (parser_context_t *context_p) /**< context */
17821835 {
17831836 if (context_p -> source_p [1 ] == (uint8_t ) LIT_CHAR_QUESTION )
17841837 {
1838+ if (length >= 3 && context_p -> source_p [2 ] == (uint8_t ) LIT_CHAR_EQUALS )
1839+ {
1840+ context_p -> token .type = LEXER_ASSIGN_NULLISH_COALESCING ;
1841+ length = 3 ;
1842+ break ;
1843+ }
17851844 context_p -> token .type = LEXER_NULLISH_COALESCING ;
17861845 length = 2 ;
17871846 break ;
0 commit comments