Skip to content

Commit

Permalink
fix(parser): Fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 15, 2019
1 parent f48b486 commit 7805610
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,14 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
/** ArrowFunction[In, Yield, Await]:
* ArrowParameters[?Yield, ?Await][no LineTerminator here]=>ConciseBody[?In]
*/
expr =
parser.token === Token.LeftParen
? parseAsyncArrowOrCallExpression(parser, context & ~Context.DisallowInContext, expr, 1, asyncNewLine as 0 | 1)
: parser.token === Token.Arrow
? parseArrowFunctionExpression(parser, context, [expr], /* isAsync */ 0)
: expr;
if (parser.token === Token.LeftParen)
expr = parseAsyncArrowOrCallExpression(parser, context & ~Context.DisallowInContext, expr, 1, asyncNewLine as
| 0
| 1);
else if (parser.token === Token.Arrow) expr = parseArrowFunctionExpression(parser, context, [expr], /* isAsync */ 0);
else {
parser.assignable = AssignmentKind.Assignable;
}

/** MemberExpression :
* 1. PrimaryExpression
Expand Down Expand Up @@ -3158,8 +3160,8 @@ export function parseArrayExpressionOrPattern(
} else if (parser.token & Token.IsPatternStart) {
left =
parser.token === Token.LeftBrace
? parseObjectLiteralOrPattern(parser, context, skipInitializer, type)
: parseArrayExpressionOrPattern(parser, context, skipInitializer, type);
? parseObjectLiteralOrPattern(parser, context, /* skipInitializer*/ 0, type)
: parseArrayExpressionOrPattern(parser, context, /* skipInitializer*/ 0, type);

destructible |= parser.destructible;

Expand Down
65 changes: 65 additions & 0 deletions test/parser/declarations/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,71 @@ describe('Declarations - Function', () => {
sourceType: 'script'
}
],
[
'function* a( [ { x = y } = a ] ) { }',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'FunctionDeclaration',
params: [
{
type: 'ArrayPattern',
elements: [
{
type: 'AssignmentPattern',
left: {
type: 'ObjectPattern',
properties: [
{
type: 'Property',
kind: 'init',
key: {
type: 'Identifier',
name: 'x'
},
computed: false,
value: {
type: 'AssignmentPattern',
left: {
type: 'Identifier',
name: 'x'
},
right: {
type: 'Identifier',
name: 'y'
}
},
method: false,
shorthand: true
}
]
},
right: {
type: 'Identifier',
name: 'a'
}
}
]
}
],
body: {
type: 'BlockStatement',
body: []
},
async: false,
generator: true,
expression: false,
id: {
type: 'Identifier',
name: 'a'
}
}
]
}
],
[
'function a( a = b ) {} n => { "use strict"; }',
Context.None,
Expand Down
51 changes: 51 additions & 0 deletions test/parser/statements/if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,57 @@ describe('Statements - None', () => {
]);

pass('Statements - If (pass)', [
[
'if (async === void 0) { async = false; }',
Context.OptionsWebCompat,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'IfStatement',
test: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'async'
},
right: {
type: 'UnaryExpression',
operator: 'void',
argument: {
type: 'Literal',
value: 0
},
prefix: true
},
operator: '==='
},
consequent: {
type: 'BlockStatement',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'AssignmentExpression',
left: {
type: 'Identifier',
name: 'async'
},
operator: '=',
right: {
type: 'Literal',
value: false
}
}
}
]
},
alternate: null
}
]
}
],
[
'if (a) b()',
Context.OptionsWebCompat,
Expand Down

0 comments on commit 7805610

Please sign in to comment.