summaryrefslogtreecommitdiff
path: root/js/src/frontend/TokenStream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/frontend/TokenStream.cpp')
-rw-r--r--js/src/frontend/TokenStream.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp
index 083bcd504..8f9e206d9 100644
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -1285,7 +1285,7 @@ static const uint8_t firstCharKinds[] = {
/* 30+ */ _______, _______, Space, _______, String, _______, Ident, _______, _______, String,
/* 40+ */ TOK_LP, TOK_RP, _______, _______, T_COMMA,_______, _______, _______,BasePrefix, Dec,
/* 50+ */ Dec, Dec, Dec, Dec, Dec, Dec, Dec, Dec, T_COLON,TOK_SEMI,
-/* 60+ */ _______, _______, _______,TOK_HOOK, _______, Ident, Ident, Ident, Ident, Ident,
+/* 60+ */ _______, _______, _______, _______, _______, Ident, Ident, Ident, Ident, Ident,
/* 70+ */ Ident, Ident, Ident, Ident, Ident, Ident, Ident, Ident, Ident, Ident,
/* 80+ */ Ident, Ident, Ident, Ident, Ident, Ident, Ident, Ident, Ident, Ident,
/* 90+ */ Ident, TOK_LB, _______, TOK_RB, _______, Ident, Templat, Ident, Ident, Ident,
@@ -1796,6 +1796,25 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
tp->type = matchChar('=') ? TOK_BITANDASSIGN : TOK_BITAND;
goto out;
+ case '?':
+ if (matchChar('.')) {
+ c = getCharIgnoreEOL();
+ if (JS7_ISDEC(c)) {
+ // if the code unit is followed by a number, for example it has
+ // the following form `<...> ?.5 <..> then it should be treated
+ // as a ternary rather than as an optional chain
+ tp->type = TOK_HOOK;
+ ungetCharIgnoreEOL(c);
+ ungetChar('.');
+ } else {
+ ungetCharIgnoreEOL(c);
+ tp->type = TOK_OPTCHAIN;
+ }
+ } else {
+ tp->type = TOK_HOOK;
+ }
+ goto out;
+
case '!':
if (matchChar('='))
tp->type = matchChar('=') ? TOK_STRICTNE : TOK_NE;