Skip to content

Commit f3553e2

Browse files
committed
Incorrect object shorthand error in lambda
The object definition at lambda param should be treated as object pattern. However we had deduced that we are on right side of an expression. Which is clearly not the case. Fixed that, by let the statement boundary determines that there is any shorthand error deferred and then throw error.
1 parent ba2e065 commit f3553e2

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

lib/Parser/Parse.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8423,7 +8423,6 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
84238423

84248424
this->GetScanner()->Capture(&termStart);
84258425

8426-
bool deferredErrorFoundOnLeftSide = false;
84278426
bool savedDeferredInitError = m_hasDeferredShorthandInitError;
84288427
m_hasDeferredShorthandInitError = false;
84298428

@@ -8607,7 +8606,9 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
86078606
*pfLikelyPattern = !!fLikelyPattern;
86088607
}
86098608

8610-
if (m_token.tk == tkDArrow)
8609+
if (m_token.tk == tkDArrow
8610+
// If we have introduced shorthand error above in the ParseExpr, we need to reset if next token is the assignment.
8611+
|| (m_token.tk == tkAsg && oplMin <= koplAsg))
86118612
{
86128613
m_hasDeferredShorthandInitError = false;
86138614
}
@@ -8703,8 +8704,6 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
87038704
}
87048705
}
87058706

8706-
deferredErrorFoundOnLeftSide = m_hasDeferredShorthandInitError;
8707-
87088707
// Process a sequence of operators and operands.
87098708
for (;;)
87108709
{
@@ -8929,13 +8928,6 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
89298928
}
89308929
}
89318930

8932-
if (m_hasDeferredShorthandInitError && !deferredErrorFoundOnLeftSide)
8933-
{
8934-
// Raise error only if it is found not on the right side of the expression.
8935-
// such as <expr> = {x = 1}
8936-
Error(ERRnoColon);
8937-
}
8938-
89398931
m_hasDeferredShorthandInitError = m_hasDeferredShorthandInitError || savedDeferredInitError;
89408932

89418933
if (NULL != pfCanAssign)

test/es6/destructuring_bugs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ var tests = [
3030
assert.doesNotThrow(function () { eval("for([] = ((...a) => {}) in '' ) { }"); }, "Having a lambda function with rest parameter as initializer should not assert and is a valid syntax");
3131
assert.doesNotThrow(function () { eval("[[[] = [function () { }] ] = []]"); }, "Nested array has array pattern which has function expression is a valid syntax");
3232
assert.doesNotThrow(function () { eval("var a = ({x = 1}) => x;"); }, "Lambda has Object destructuring as parameter which has initializer on shorthand is a valid syntax");
33+
assert.doesNotThrow(function () { eval("var a = (b, {x = 1}) => x;"); }, "Lambda has Object destructuring as a second parameter which has initializer on shorthand is a valid syntax");
34+
assert.doesNotThrow(function () { eval("var a = ({x = 1}, b) => x;"); }, "Lambda has Object destructuring as first parameter which has initializer on shorthand is a valid syntax");
35+
assert.throws(function () { eval("let a = ({name = 'foo'}, 1) = {}"); }, ReferenceError, "Object shorthand will behave as pattern when on left-hand side and should not throw syntax error");
3336
}
3437
},
3538
{

0 commit comments

Comments
 (0)