Skip to content

Commit

Permalink
fix(parser): permanently fixed yield edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jun 2, 2019
1 parent 9498c55 commit 6166b2b
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 206 deletions.
381 changes: 191 additions & 190 deletions src/parser.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/parser/declarations/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('Declarations - Function', () => {
['function foo() { 00004; }', Context.Strict],
['function 00004() { "use strict"; 00004; }', Context.None],
['function foo(001, 003) { "use strict"; }', Context.None],

['function f([x=x()=x]){}', Context.None],
['function foo(001, 003) { "use strict"; }', Context.None],
['function foo(001, 003) { "use strict"; }', Context.None],
['function foo(001, 003) { "use strict"; }', Context.None],
Expand Down
132 changes: 131 additions & 1 deletion test/parser/expressions/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,139 @@ describe('Expressions - Async', () => {
['async (a, ...true=b) => a;', Context.None],
['async (a, ...b=fail) => a;', Context.None],
['async (a, ...true) => a;', Context.None],
['async (a, ...true=fail) => a;', Context.None]
['await/x', Context.Module],
['await \n / x', Context.Module]
]);
pass('Expressions - Async (pass)', [
[
'async/x',
Context.OptionsRanges,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'async',
start: 0,
end: 5
},
right: {
type: 'Identifier',
name: 'x',
start: 6,
end: 7
},
operator: '/',
start: 0,
end: 7
},
start: 0,
end: 7
}
],
start: 0,
end: 7
}
],
[
'x / async',
Context.OptionsRanges,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'x',
start: 0,
end: 1
},
right: {
type: 'Identifier',
name: 'async',
start: 4,
end: 9
},
operator: '/',
start: 0,
end: 9
},
start: 0,
end: 9
}
],
start: 0,
end: 9
}
],
[
'async \n / x / g',
Context.None,
{
body: [
{
expression: {
left: {
left: {
name: 'async',
type: 'Identifier'
},
operator: '/',
right: {
name: 'x',
type: 'Identifier'
},
type: 'BinaryExpression'
},
operator: '/',
right: {
name: 'g',
type: 'Identifier'
},
type: 'BinaryExpression'
},
type: 'ExpressionStatement'
}
],
sourceType: 'script',
type: 'Program'
}
],
[
'async \n / x',
Context.None,
{
body: [
{
expression: {
left: {
name: 'async',
type: 'Identifier'
},
operator: '/',
right: {
name: 'x',
type: 'Identifier'
},
type: 'BinaryExpression'
},
type: 'ExpressionStatement'
}
],
sourceType: 'script',
type: 'Program'
}
],

[
'function *f(){ async(x); }',
Context.None,
Expand Down
1 change: 1 addition & 0 deletions test/parser/expressions/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ describe('Expressions - Group', () => {
['(x--, y) => x;', Context.None],
['...x => x', Context.None],
['y, ...x => x', Context.None],
['({x:{1:y()=x},x:{7:3}})>x', Context.None],
[`({[foo]() {}} = y)`, Context.None],
['0, {a = 0}) => 0', Context.None],
['({a = 0}, {a = 0}, 0) => 0', Context.None],
Expand Down
31 changes: 18 additions & 13 deletions test/parser/expressions/yield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ import { parseSource } from '../../../src/parser';

describe('Expressions - Yield', () => {
for (const arg of [
'let g = function*() { try {yield 42} finally {yield 43; return 13} };',
'let g = function*() { try {yield 42} finally {yield 43; 13} };',
'let h = function*() { try {yield 42} finally {yield 43; return 13} };',
'let g = function*() { yield 1; yield yield* h(); };',
'let h = function*() { try {yield 42} finally {yield 43; 13} };',
'let foo = function*() { try {yield 42} finally {yield 43; return 13} };',
'let foo = function*() { try {yield 42} finally {yield 43; 13} };',
'let foo = function*() { try {yield 42} finally {yield 43; return 13} };',
'let foo = function*() { yield 1; yield yield* h(); };',
'let foo = function*() { try {yield 42} finally {yield 43; 13} };',
'{ function* inner() { yield 2; } function* g() { yield 1; return yield* inner(); } { let x = g(); } }',
'function* foo() { (yield* (c = d) => { }) }',
'function* foo() { class x extends (yield* (e = "x") => {}) {} }',
'function* foo() { return ( yield* ( ( j ) => {}) ) }',
`function* foo() { switch ( y (yield) - ((a) => {})) { } }`,
'function* foo() { a(yield* function t(k) {}, ...(c) => {}) }',
'function* foo() { yield 2; yield 3; yield 4 }',
'function* foo() { yield 2; if (true) { yield 3 }; yield 4 }',
'function* foo() { yield 2; if (true) { yield 3; yield 4 } }',
'function* foo() { yield 2; if (false) { yield 3 }; yield 4 }',
'countArgs(...(function*(){ yield 1; yield 2; yield 3; })())',
'function* g5(l) { "use strict"; yield 1; for (let x in l) { yield x; } }',
'function* g4() { var x = 10; yield 1; return x; }',
' function* g1(a, b, c) { yield 1; return [a, b, c]; }',
'function* f2() { return {["a"]: yield} }',
'function* foo(l) { "use strict"; yield 1; for (let x in l) { yield x; } }',
'function* foo() { var x = 10; yield 1; return x; }',
'function* foo(a, b, c) { yield 1; return [a, b, c]; }',
'function* foo() { return {["a"]: yield} }',
'bar(...(function*(){ yield 1; yield 2; yield 3; })());',
'(function*() { yield* {} })().next()',
'(function*() { yield* undefined })().next()',
'function* g() { yield; }',
'function* foo() { yield; }',
`{
let x = 42;
function* foo() {
Expand Down Expand Up @@ -615,14 +620,14 @@ yield d;
['function *g() { (x = yield) = {}; }', Context.None],
['function *g() { yield => {}; }', Context.None],
['function *g() { (x = yield) => {}; }', Context.None],
//['function *g() { (x = y = yield z) => {}; }', Context.None],
['function *g() { (x = y = yield z) => {}; }', Context.None],
['function *g() { (x = u + yield z) => {}; }', Context.None],
['function *g() { (x = x + yield); }', Context.None],
['function *g() { (x = x + yield y); }', Context.None],
['function *g() { (x = x + yield) => x; }', Context.None],
['function *g() { (x = x + yield y) => x; }', Context.None],
// ['function *g(){ (x = {[yield y]: 1}) => z }', Context.None],
// ['function *g(){ (x = {[yield]: 1}) => z }', Context.None],
['function *g(){ (x = {[yield y]: 1}) => z }', Context.None],
['function *g(){ (x = {[yield]: 1}) => z }', Context.None],
['(x = x) = x;', Context.None],
['{ (x = yield) = {}; }', Context.None],
['{ (x = y = yield z) => {}; }', Context.None],
Expand Down
2 changes: 1 addition & 1 deletion test/parser/miscellaneous/early-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Miscellaneous - Early errors', () => {
'class A extends B { constructor() { !function(a = super()){} } }',
'function f(a){ super() }',
'!function(a){ super() }',
// 'function* g(){ ({[yield]: a}) => 0; }',
'function* g(){ ({[yield]: a}) => 0; }',
'function* g(){ (a = x + f(yield)) => 0; }',
'function* g(){ (a = yield* b) => 0; }',
'function* g(){ (a = yield b) => 0; }',
Expand Down
1 change: 1 addition & 0 deletions test/parser/miscellaneous/failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('Miscellaneous - Failure', () => {
`({*[expr](){}} = x)`,
'({*[expr](){}}) = x',
'({a: {a=b}.x}) => x',
'class K extends {} {;async\\n async *1(){}}',
`for (a,b of c) d;`,
`for (a, b of c);`,
`for (a,b of c) d;`,
Expand Down

0 comments on commit 6166b2b

Please sign in to comment.