Skip to content

Commit 00ae476

Browse files
authored
Merge pull request #4228 from masatake/javascript--shift-op-and-jsx
JavaScript: (bugfix) consider << operator when detecting JSX area
2 parents fccad9b + 2cfc884 commit 00ae476

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a crash test.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--input-encoding=UTF-8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"\uFEFF"<<={
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"\uFEFF"<={
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"\uFEFF"<<{

parsers/jscript.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,29 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
12031203

12041204
case '<':
12051205
if (doesExpectBinaryOperator (LastTokenType))
1206+
{
12061207
token->type = TOKEN_BINARY_OPERATOR;
1208+
/*
1209+
* Skip '<<', '<<=', and '<='.
1210+
*
1211+
* '<<' must be handled here.
1212+
* If '<<' is read as two tokens, '<'
1213+
* and '<', the parser treats the second one
1214+
* as the start of JSX_TOKEN.
1215+
*
1216+
* Handling '<=' and '<<=' here is just for minor
1217+
* optimization.
1218+
*/
1219+
int d = getcFromInputFile ();
1220+
if (d == '<')
1221+
{
1222+
d = getcFromInputFile ();
1223+
if (d != '=')
1224+
ungetcToInputFile (d);
1225+
}
1226+
else if (d != '=')
1227+
ungetcToInputFile (d);
1228+
}
12071229
else
12081230
{
12091231
bool skip = !isXtagEnabled (XTAG_GUEST);
@@ -3789,8 +3811,16 @@ extern void javaScriptSkipObjectExpression (void)
37893811
deleteToken (token);
37903812

37913813
#ifdef HAVE_ICONV
3792-
if (JSUnicodeConverter != (iconv_t) -2 && /* not created */
3793-
JSUnicodeConverter != (iconv_t) -1 /* creation failed */)
3814+
if (
3815+
/* not created */
3816+
JSUnicodeConverter != (iconv_t) -2 &&
3817+
/* creation failed */
3818+
JSUnicodeConverter != (iconv_t) -1 &&
3819+
/* The convert was created before entering this function
3820+
* and no new converter is created in this function (and
3821+
* functions called from this functions). */
3822+
JSUnicodeConverter != originalJSUnicodeConverter
3823+
)
37943824
iconv_close (JSUnicodeConverter);
37953825

37963826
JSUnicodeConverter = originalJSUnicodeConverter;

0 commit comments

Comments
 (0)