Skip to content

Commit

Permalink
[1.6>1.7] [MERGE #3428 @curtisman] Fix Issue #3039: Arrow function sh…
Browse files Browse the repository at this point in the history
…ould terminate the expression unless followed by a comma

Merge pull request #3428 from curtisman:fix3039
  • Loading branch information
curtisman committed Jul 28, 2017
2 parents 786f348 + 59ea143 commit 391e601
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Parser/Parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8500,6 +8500,12 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
pnode->sxFnc.cbMin = iecpMin;
pnode->ichMin = ichMin;
}

// ArrowFunction/AsyncArrowFunction is part of AssignmentExpression, which should terminate the expression unless followed by a comma
if (m_token.tk != tkComma)
{
break;
}
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions test/es6/lambda-expr.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Expected ';'
2
3
Expected ';'
35 changes: 35 additions & 0 deletions test/es6/lambda-expr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

try
{
// Illegal case, arrow function terminates the expression
eval("x=>{}/print(1)/+print(2)")
}
catch (e)
{
print(e.message);
}

// Legal case, the line feed breaks the statement
x=>{}
/print(1)/+print(2)

// Legal case, comma separate ExpressionStatement
x=>{return 2;},y=>{return 3;}

// Legal case, comma separate Expression (with paren)
var a = (x=>{return 2;},y=>{return 3;})
print(a())


try
{
eval("var a = x=>{return 2;},y=>{return 3;}");
}
catch (e)
{
print(e.message);
}
6 changes: 6 additions & 0 deletions test/es6/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<compile-flags>-off:deferparse -args summary -endargs</compile-flags>
</default>
</test>
<test>
<default>
<files>lambda-expr.js</files>
<baseline>lambda-expr.baseline</baseline>
</default>
</test>
<test>
<default>
<files>lambda1.js</files>
Expand Down

0 comments on commit 391e601

Please sign in to comment.