Skip to content

Commit 04e9fb3

Browse files
committed
allow await as identifier in param lists of methods in async contexts
1 parent 6776a56 commit 04e9fb3

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

src/parser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,11 +2339,11 @@ export class GenericParser extends Tokenizer {
23392339
let previousAwaitLocation = this.firstAwaitLocation;
23402340
this.allowYieldExpression = false;
23412341
this.allowAwaitExpression = false;
2342-
this.previousAwaitLocation = null;
2342+
this.firstAwaitLocation = null;
23432343
let body = this.parseFunctionBody();
23442344
this.allowYieldExpression = previousYield;
23452345
this.allowAwaitExpression = previousAwait;
2346-
this.previousAwaitLocation = previousAwaitLocation;
2346+
this.firstAwaitLocation = previousAwaitLocation;
23472347
return {
23482348
methodOrKey: this.finishNode(new AST.Getter({ name, body }), startState),
23492349
kind: 'method',
@@ -2356,13 +2356,13 @@ export class GenericParser extends Tokenizer {
23562356
let previousAwaitLocation = this.firstAwaitLocation;
23572357
this.allowYieldExpression = false;
23582358
this.allowAwaitExpression = false;
2359-
this.previousAwaitLocation = null;
2359+
this.firstAwaitLocation = null;
23602360
let param = this.parseBindingElement();
23612361
this.expect(TokenType.RPAREN);
23622362
let body = this.parseFunctionBody();
23632363
this.allowYieldExpression = previousYield;
23642364
this.allowAwaitExpression = previousAwait;
2365-
this.previousAwaitLocation = previousAwaitLocation;
2365+
this.firstAwaitLocation = previousAwaitLocation;
23662366
return {
23672367
methodOrKey: this.finishNode(new AST.Setter({ name, param, body }), startState),
23682368
kind: 'method',
@@ -2398,7 +2398,7 @@ export class GenericParser extends Tokenizer {
23982398
let body = this.parseFunctionBody();
23992399
this.allowYieldExpression = previousYield;
24002400
this.allowAwaitExpression = previousAwait;
2401-
this.previousAwaitLocation = previousAwaitLocation;
2401+
this.firstAwaitLocation = previousAwaitLocation;
24022402

24032403
return {
24042404
methodOrKey: this.finishNode(new AST.Method({ isAsync, isGenerator, name, params, body }), startState),

test/miscellaneous/async-await.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,53 @@ suite('async', () => {
200200
}
201201
);
202202

203+
testParse('async (a = { b(await){} }) => {}', expr,
204+
{
205+
type: 'ArrowExpression',
206+
isAsync: true,
207+
params: {
208+
type: 'FormalParameters',
209+
items: [
210+
{
211+
type: 'BindingWithDefault',
212+
binding: { type: 'BindingIdentifier', name: 'a' },
213+
init: {
214+
type: 'ObjectExpression',
215+
properties: [
216+
{
217+
type: 'Method',
218+
isAsync: false,
219+
isGenerator: false,
220+
name: {
221+
type: 'StaticPropertyName',
222+
value: 'b',
223+
},
224+
params: {
225+
type: 'FormalParameters',
226+
items: [
227+
{
228+
type: 'BindingIdentifier',
229+
name: 'await',
230+
},
231+
],
232+
rest: null,
233+
},
234+
body: {
235+
type: 'FunctionBody',
236+
directives: [],
237+
statements: [],
238+
},
239+
},
240+
],
241+
},
242+
},
243+
],
244+
rest: null,
245+
},
246+
body: { type: 'FunctionBody', directives: [], statements: [] },
247+
}
248+
);
249+
203250
testParseFailure('let b = async () => []; for (a in await b());', 'Unexpected identifier');
204251
testParse('async () => { let b = async () => []; for (a in await b()); }', expr,
205252
{

0 commit comments

Comments
 (0)