diff --git a/CHANGES.md b/CHANGES.md index 48804b752d..c0802098b0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ ## Bug fixes * Compiler: put custom header at the top of the output file (fix #1441) +* Compiler (js parser): fix parsing of js labels (fix #1440) # 5.1.1 (2023-03-15) - Lille ## Bug fixes diff --git a/compiler/lib/js_parser.mly b/compiler/lib/js_parser.mly index 79d932d13d..a3f1040805 100644 --- a/compiler/lib/js_parser.mly +++ b/compiler/lib/js_parser.mly @@ -509,9 +509,7 @@ stmt1: | debugger_stmt { $1 } label: - | T_IDENTIFIER { - let name, _raw = $1 in - Label.of_string name } + | id { Label.of_string $1 } (* Library definitions *) diff --git a/compiler/tests-compiler/js_parser_printer.ml b/compiler/tests-compiler/js_parser_printer.ml index 51cf1afcd9..053d7c110f 100644 --- a/compiler/tests-compiler/js_parser_printer.ml +++ b/compiler/tests-compiler/js_parser_printer.ml @@ -1035,3 +1035,12 @@ var y = async => async 2: 0:var, 4:y (identifier), 6:=, 8:{, 10:async, 15::, 17:35, 19:}, 0:; (virtual), 4: 0:var, 4:y (identifier), 6:=, 8:async, 14:x (identifier), 16:=>, 19:x (identifier), 0:; (virtual), 5: 0:var, 4:y (identifier), 6:=, 8:async, 14:=>, 17:async, 0:; (virtual), |}] + +let%expect_test "label parsing" = + parse_print_token + ~extra:true + {| +get:{of:{from:{async:{break async}break from}break of}break get} +|}; + [%expect + {| 2: 0:get, 3::, 4:{, 5:of, 7::, 8:{, 9:from, 13::, 14:{, 15:async, 20::, 21:{, 22:break, 28:async, 0:; (virtual), 33:}, 34:break, 40:from, 0:; (virtual), 44:}, 45:break, 51:of, 0:; (virtual), 53:}, 54:break, 60:get, 0:; (virtual), 63:}, |}]