Skip to content

Commit

Permalink
fix(parser): fixed edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 30, 2019
1 parent e443537 commit 6397c0f
Show file tree
Hide file tree
Showing 12 changed files with 5,056 additions and 2,054 deletions.
8 changes: 4 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2899,9 +2899,9 @@ export function parsePrimaryExpressionExtended(

if ((token & Token.IsUpdateOp) === Token.IsUpdateOp) {
if (inNewExpression) report(parser, Errors.InvalidIncDecNew);
const { token, index } = parser;
const { token } = parser;
nextToken(parser, context | Context.AllowRegExp);
const arg = parseLeftHandSideExpression(parser, context, /* assignable */ 0, index);
const arg = parseLeftHandSideExpression(parser, context, /* assignable */ 0, parser.startIndex);
if (parser.assignable & AssignmentKind.CannotAssign) {
report(
parser,
Expand Down Expand Up @@ -4948,8 +4948,6 @@ export function parseParenthesizedExpression(
}
}

consume(parser, context, Token.RightParen);

if (toplevelComma) {
parser.assignable = AssignmentKind.CannotAssign;

Expand All @@ -4959,6 +4957,8 @@ export function parseParenthesizedExpression(
});
}

consume(parser, context, Token.RightParen);

if (destructible & DestructuringKind.CannotDestruct && destructible & DestructuringKind.MustDestruct)
report(parser, Errors.InvalidLHSValidRHS);

Expand Down
84 changes: 84 additions & 0 deletions test/parser/expressions/arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4267,6 +4267,90 @@ describe('Expressions - Arrow', () => {
sourceType: 'script'
}
],
[
'(a, b => {}, a => a + 1)',
Context.OptionsRanges,
{
type: 'Program',
start: 0,
end: 24,
body: [
{
type: 'ExpressionStatement',
start: 0,
end: 24,
expression: {
type: 'SequenceExpression',
start: 1,
end: 23,
expressions: [
{
type: 'Identifier',
start: 1,
end: 2,
name: 'a'
},
{
type: 'ArrowFunctionExpression',
start: 4,
end: 11,
expression: false,
async: false,
params: [
{
type: 'Identifier',
start: 4,
end: 5,
name: 'b'
}
],
body: {
type: 'BlockStatement',
start: 9,
end: 11,
body: []
}
},
{
type: 'ArrowFunctionExpression',
start: 13,
end: 23,
expression: true,
async: false,
params: [
{
type: 'Identifier',
start: 13,
end: 14,
name: 'a'
}
],
body: {
type: 'BinaryExpression',
start: 18,
end: 23,
left: {
type: 'Identifier',
start: 18,
end: 19,
name: 'a'
},
operator: '+',
right: {
type: 'Literal',
start: 22,
end: 23,
value: 1
}
}
}
]
}
}
],
sourceType: 'script'
}
],
[
'() => a + b - yield / 1',
Context.OptionsRanges,
Expand Down
Loading

0 comments on commit 6397c0f

Please sign in to comment.