Skip to content

Commit

Permalink
fix(parser): fixed a bunch of edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 16, 2019
1 parent d7e08fe commit fe941bc
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meriyah",
"version": "0.1.8",
"version": "0.1.9",
"description": "Fast and lightweight, standard-compliant javascript parser written in ECMAScript",
"main": "dist/meriyah.umd.js",
"module": "dist/meriyah.esm.js",
Expand Down
28 changes: 21 additions & 7 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2935,8 +2935,17 @@ export function parseFunctionDeclaration(
params: parseFormalParametersOrFormalList(parser, context | Context.InArgList, BindingType.ArgumentList),
body: parseFunctionBody(
parser,
(context | Context.TopLevel | Context.InGlobal | Context.InSwitchOrIteration | Context.InClass) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.InClass),
(context |
Context.TopLevel |
Context.InGlobal |
Context.InSwitchOrIteration |
Context.InClass |
Context.DisallowInContext) ^
(Context.InGlobal |
Context.TopLevel |
Context.InSwitchOrIteration |
Context.InClass |
Context.DisallowInContext),
BindingOrigin.Declaration,
firstRestricted
),
Expand Down Expand Up @@ -2987,8 +2996,13 @@ export function parseFunctionExpression(
const params = parseFormalParametersOrFormalList(parser, context | Context.InArgList, BindingType.ArgumentList);
const body = parseFunctionBody(
parser,
(context | Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.InClass) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.InClass),
(context |
Context.InGlobal |
Context.TopLevel |
Context.InSwitchOrIteration |
Context.InClass |
Context.DisallowInContext) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.InClass | Context.DisallowInContext),
0,
firstRestricted
);
Expand Down Expand Up @@ -3479,8 +3493,8 @@ export function parseMethodDefinition(
params: parseMethodFormals(parser, context | Context.InArgList, kind, BindingType.ArgumentList),
body: parseFunctionBody(
parser,
(context | Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration),
(context | Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.DisallowInContext) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.DisallowInContext),
BindingOrigin.None,
void 0
),
Expand Down Expand Up @@ -4906,7 +4920,7 @@ export function parseAsyncArrowOrCallExpression(
if (destructible & DestructuringKind.NotDestructible) report(parser, Errors.InvalidLHSInAsyncArrow);
if (destructible & DestructuringKind.Assignable) report(parser, Errors.InvalidArrowDestructLHS);
if (parser.flags & Flags.NewLine || asyncNewLine) report(parser, Errors.InvalidLineBreak);
if (parser.destructible & DestructuringKind.Await) report(parser, Errors.YieldInParameter);
if (parser.destructible & DestructuringKind.Await) report(parser, Errors.AwaitInParameter);
if (context & (Context.Strict | Context.InYieldContext) && parser.destructible & DestructuringKind.Yield)
report(parser, Errors.YieldInParameter);
return parseArrowFunctionExpression(parser, context, params as any, /* isAsync */ 1) as any;
Expand Down
7 changes: 6 additions & 1 deletion test/parser/declarations/async-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('Declarations - Async Function', () => {
'async function a() { function b() { return await; } }',
'async function a() { var k = { async: 4 } }',
'async function a() { await 4; }',

'async function a() { var t = !await 1 }',
'async function a() { var t = ~await 1; }',
'async function a() { var t = !(await 1); }',
Expand Down Expand Up @@ -335,17 +334,22 @@ describe('Declarations - Async Function', () => {
['async (b = {await}) => 1', Context.None],
['async (b = {a: await}) => 1', Context.None],
['async (b = [await]) => 1', Context.None],
['async function* f(a = await) {}', Context.None],
['async (b = [...await]) => 1', Context.None],
['async (b = class await {}) => 1', Context.Strict | Context.Module],
['async (b = (await) => {}) => 1', Context.None],
['async (await, b = async()) => 2', Context.None],
['async (await, b = async () => {}) => 1', Context.None],
['async function* a() { await; (r = a) => {} }', Context.None],
['async function* a() { (await) => {} }', Context.None],
['async function* f() { a = async function*(a = await) {}; }', Context.None],
['function f(a = async function(a = await) {}) {}', Context.None],
['({async\nfoo() { }})', Context.None],
['({async get foo() { }})', Context.None],
['({async set foo(value) { }})', Context.None],
['({async foo() { var await }})', Context.None],
['function f() { a = async function(a = await) {}; }', Context.None],
['async (a = await) => {}', Context.None],
['async function foo (foo) { super.prop };', Context.None],
['async function foo (foo) { super.prop };', Context.None],
['"use strict"; async function eval () { }', Context.None],
Expand All @@ -368,6 +372,7 @@ describe('Declarations - Async Function', () => {
['({async foo() { var await }})', Context.None],
['({async foo(await) { }})', Context.None],
['({async foo() { return {await} }})', Context.None],
['async function f(a = await) {}', Context.None],
['({async foo: 1})', Context.None],
['class A {async\nfoo() { }}', Context.None],
['class A {static async\nfoo() { }}', Context.None],
Expand Down
52 changes: 52 additions & 0 deletions test/parser/expressions/arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,58 @@ describe('Expressions - Arrow', () => {
]
}
],
[
'(a = await/r/g) => {}',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'ArrowFunctionExpression',
body: {
type: 'BlockStatement',
body: []
},
params: [
{
type: 'AssignmentPattern',
left: {
type: 'Identifier',
name: 'a'
},
right: {
type: 'BinaryExpression',
left: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'await'
},
right: {
type: 'Identifier',
name: 'r'
},
operator: '/'
},
right: {
type: 'Identifier',
name: 'g'
},
operator: '/'
}
}
],
id: null,
async: false,
expression: false
}
}
]
}
],
[
'a => a / x',
Context.None,
Expand Down
6 changes: 6 additions & 0 deletions test/parser/expressions/async-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ describe('Expressions - Async arrow', () => {
['async (var x) => {};', Context.None],
['async (x, y)[7] => {}', Context.None],
['a.x => {};', Context.None],
['async(a, ...await) => {}', Context.None],
['async(a = await/r/g) => {}', Context.None],
['async (x = (x) += await f) => {}', Context.None],
['var x = 1 y => y', Context.None],
['async(a, 1) => x', Context.None],
Expand Down Expand Up @@ -738,6 +740,10 @@ describe('Expressions - Async arrow', () => {
});
}
pass('Expressions - Async arrow', [
/* [
`async (a = async () => { await 1; }) => {}`,
Context.None,
{}], */
[
`async (() => 1)(), 1`,
Context.None,
Expand Down
65 changes: 64 additions & 1 deletion test/parser/statements/for-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,70 @@ describe('Statements - For in', () => {
sourceType: 'script'
}
],

[
'for (function* y() { new.target in /(?:()|[]|(?!))/iuy };; (null)) {}',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ForStatement',
body: {
type: 'BlockStatement',
body: []
},
init: {
type: 'FunctionExpression',
params: [],
body: {
type: 'BlockStatement',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
meta: {
type: 'Identifier',
name: 'new'
},
type: 'MetaProperty',
property: {
type: 'Identifier',
name: 'target'
}
},
right: {
type: 'Literal',
value: /(?:()|[]|(?!))/iuy,
regex: {
pattern: '(?:()|[]|(?!))',
flags: 'iuy'
}
},
operator: 'in'
}
}
]
},
async: false,
generator: true,
expression: false,
id: {
type: 'Identifier',
name: 'y'
}
},
test: null,
update: {
type: 'Literal',
value: null
}
}
]
}
],
[
'for (var {[x]: y} of obj);',
Context.None,
Expand Down

0 comments on commit fe941bc

Please sign in to comment.