@@ -1509,6 +1509,55 @@ lexer_parse_number (parser_context_t *context_p) /**< context */
1509
1509
break; \
1510
1510
}
1511
1511
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
+
1512
1561
/**
1513
1562
* Get next token.
1514
1563
*/
@@ -1759,18 +1808,22 @@ lexer_next_token (parser_context_t *context_p) /**< context */
1759
1808
LEXER_TYPE_B_TOKEN (LIT_CHAR_SLASH , LEXER_DIVIDE , LIT_CHAR_EQUALS , LEXER_ASSIGN_DIVIDE )
1760
1809
LEXER_TYPE_B_TOKEN (LIT_CHAR_PERCENT , LEXER_MODULO , LIT_CHAR_EQUALS , LEXER_ASSIGN_MODULO )
1761
1810
1762
- LEXER_TYPE_C_TOKEN (LIT_CHAR_AMPERSAND ,
1811
+ LEXER_TYPE_D_TOKEN (LIT_CHAR_AMPERSAND ,
1763
1812
LEXER_BIT_AND ,
1764
1813
LIT_CHAR_EQUALS ,
1765
1814
LEXER_ASSIGN_BIT_AND ,
1766
1815
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 ,
1769
1820
LEXER_BIT_OR ,
1770
1821
LIT_CHAR_EQUALS ,
1771
1822
LEXER_ASSIGN_BIT_OR ,
1772
1823
LIT_CHAR_VLINE ,
1773
- LEXER_LOGICAL_OR )
1824
+ LEXER_LOGICAL_OR ,
1825
+ LIT_CHAR_EQUALS ,
1826
+ LEXER_ASSIGN_LOGICAL_OR )
1774
1827
1775
1828
LEXER_TYPE_B_TOKEN (LIT_CHAR_CIRCUMFLEX , LEXER_BIT_XOR , LIT_CHAR_EQUALS , LEXER_ASSIGN_BIT_XOR )
1776
1829
@@ -1782,6 +1835,12 @@ lexer_next_token (parser_context_t *context_p) /**< context */
1782
1835
{
1783
1836
if (context_p -> source_p [1 ] == (uint8_t ) LIT_CHAR_QUESTION )
1784
1837
{
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
+ }
1785
1844
context_p -> token .type = LEXER_NULLISH_COALESCING ;
1786
1845
length = 2 ;
1787
1846
break ;
0 commit comments