Skip to content

Commit 9302343

Browse files
committed
more fix for async
1 parent 4b17dfb commit 9302343

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

compiler/lib/js_parser.mly

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ decl:
260260
{ let i,f = $1 in Function_declaration (i,f), p $symbolstartpos }
261261
| generator_decl
262262
{ let i,f = $1 in Function_declaration (i,f), p $symbolstartpos }
263+
| async_generator_decl
264+
{ let i,f = $1 in Function_declaration (i,f), p $symbolstartpos }
263265
| async_decl
264266
{ let i,f = $1 in Function_declaration (i,f), p $symbolstartpos }
265267
| lexical_decl { $1, p $symbolstartpos }
@@ -432,6 +434,18 @@ async_function_expr:
432434
| T_ASYNC T_FUNCTION name=ident? args=call_signature "{" b=function_body "}"
433435
{ EFun (name, ({async = true; generator = false}, args, b, p $symbolstartpos)) }
434436

437+
(*************************************************************************)
438+
(* async generators *)
439+
(*************************************************************************)
440+
441+
async_generator_decl:
442+
| T_ASYNC T_FUNCTION "*" name=ident args=call_signature "{" b=function_body "}"
443+
{ (name, ({async = true; generator = true}, args, b, p $symbolstartpos)) }
444+
445+
async_generator_expr:
446+
| T_ASYNC T_FUNCTION "*" name=ident? args=call_signature "{" b=function_body "}"
447+
{ EFun (name, ({async = true; generator = true}, args, b, p $symbolstartpos)) }
448+
435449
(*************************************************************************)
436450
(* Class declaration *)
437451
(*************************************************************************)
@@ -766,6 +780,7 @@ primary_with_stmt:
766780
| generator_expr { $1 }
767781
(* es7: *)
768782
| async_function_expr { $1 }
783+
| async_generator_expr{ $1 }
769784

770785

771786
primary_expr_no_braces:
@@ -988,6 +1003,7 @@ primary_for_consise_body:
9881003
| generator_expr { $1 }
9891004
(* es7: *)
9901005
| async_function_expr { $1 }
1006+
| async_generator_expr{ $1 }
9911007

9921008
assignment_expr_for_consise_body:
9931009
| conditional_expr(primary_for_consise_body) { $1 }

compiler/lib/parse_js.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,12 @@ let rec offer_one t (lexbuf : Lexer.t) =
353353
* one LineTerminator, then a semicolon is automatically inserted before the
354354
* restricted token. *)
355355
match State.Cursor.last_token h, tok with
356-
| ( Some (((T_RETURN | T_CONTINUE | T_BREAK | T_THROW | T_YIELD), _, _), _)
356+
| ( Some
357+
(((T_RETURN | T_CONTINUE | T_BREAK | T_THROW | T_YIELD | T_ASYNC), _, _), _)
357358
, (((T_SEMICOLON | T_VIRTUAL_SEMICOLON), _, _) as tok) ) -> tok
358-
| Some (((T_RETURN | T_CONTINUE | T_BREAK | T_THROW | T_YIELD), _, _), _), _
359+
| ( Some
360+
(((T_RETURN | T_CONTINUE | T_BREAK | T_THROW | T_YIELD | T_ASYNC), _, _), _)
361+
, _ )
359362
when nl_separated h tok && acceptable t T_VIRTUAL_SEMICOLON ->
360363
(* restricted token can also appear as regular identifier such
361364
as in [x.return]. In such case, feeding a virtual semicolon

compiler/tests-compiler/js_parser_printer.ml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ let%expect_test "async/await" =
341341
const glslang = await glslangModule.default();
342342
return glslang.compileGLSL(src, "compute");
343343
}
344+
345+
346+
async
347+
function test() { }
348+
349+
async function test() { }
350+
351+
async
352+
function* test() { }
353+
354+
async function * test() { }
355+
356+
1 + async function * test() { }
357+
344358
|};
345359

346360
[%expect
@@ -355,7 +369,14 @@ let%expect_test "async/await" =
355369
glslang = await /*<<fake:7:33>>*/ glslangModule.default();
356370
/*<<fake:8:11>>*/ return /*<<fake:8:18>>*/ glslang.compileGLSL
357371
(src, "compute");
358-
/*<<fake:2:9>>*/ } |}]
372+
/*<<fake:2:9>>*/ }
373+
/*<<fake:12:4>>*/ async;
374+
/*<<fake:13:4>>*/ function test(){ /*<<fake:13:22>>*/ }
375+
/*<<fake:15:4>>*/ async function test(){ /*<<fake:15:4>>*/ }
376+
/*<<fake:17:4>>*/ async;
377+
/*<<fake:18:4>>*/ function* test(){ /*<<fake:18:4>>*/ }
378+
/*<<fake:20:4>>*/ async function* test(){ /*<<fake:20:4>>*/ }
379+
/*<<fake:22:4>>*/ 1 + async function* test(){ /*<<fake:22:8>>*/ }; |}]
359380

360381
let%expect_test "get/set property" =
361382
(* GH#1017 *)
@@ -948,6 +969,18 @@ a:while(true){
948969
do { x } while (true) y
949970
do ; while (true) y
950971

972+
async
973+
function test() { }
974+
975+
async function test() { }
976+
977+
async
978+
function* test() { }
979+
980+
async function * test() { }
981+
982+
1 + async function * test() { }
983+
951984
|};
952985
[%expect
953986
{|
@@ -974,7 +1007,14 @@ a:while(true){
9741007
26: 4:a (identifier), 6:=, 8:b (identifier), 10:+, 12:c (identifier),
9751008
27: 4:(, 5:d (identifier), 7:+, 9:e (identifier), 10:), 11:., 12:print (identifier), 17:(, 18:), 0:; (virtual),
9761009
29: 4:do, 7:{, 9:x (identifier), 0:; (virtual), 11:}, 13:while, 19:(, 20:true, 24:), 0:; (virtual), 26:y (identifier), 0:; (virtual),
977-
30: 4:do, 7:;, 9:while, 15:(, 16:true, 20:), 0:; (virtual), 22:y (identifier), 0:; (virtual), |}]
1010+
30: 4:do, 7:;, 9:while, 15:(, 16:true, 20:), 0:; (virtual), 22:y (identifier), 0:; (virtual),
1011+
32: 4:async, 0:; (virtual),
1012+
33: 4:function, 13:test (identifier), 17:(, 18:), 20:{, 22:},
1013+
35: 4:async, 10:function, 19:test (identifier), 23:(, 24:), 26:{, 28:},
1014+
37: 4:async, 0:; (virtual),
1015+
38: 4:function, 12:*, 14:test (identifier), 18:(, 19:), 21:{, 23:},
1016+
40: 4:async, 10:function, 19:*, 21:test (identifier), 25:(, 26:), 28:{, 30:},
1017+
42: 4:1, 6:+, 8:async, 14:function, 23:*, 25:test (identifier), 29:(, 30:), 32:{, 34:}, 0:; (virtual), |}]
9781018

9791019
let%expect_test _ =
9801020
parse_print_token

0 commit comments

Comments
 (0)