Skip to content

Commit 49eadfc

Browse files
vouillonhhugo
authored andcommitted
JavaScript parser: fix parsing of labels
Identifiers such as 'of' and 'async' are valid labels. Fixes #1440.
1 parent c47b871 commit 49eadfc

File tree

3 files changed

+4
-21
lines changed

3 files changed

+4
-21
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Compiler: jsoo link archive with -a (#1428)
44

55
## Bug fixes
6+
* Compiler (js parser): fix parsing of js labels (fix #1440)
67

78
# 5.1.1 (2023-03-15) - Lille
89
## Bug fixes

compiler/lib/js_parser.mly

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,7 @@ stmt1:
509509
| debugger_stmt { $1 }
510510

511511
label:
512-
| T_IDENTIFIER {
513-
let name, _raw = $1 in
514-
Label.of_string name }
512+
| id { Label.of_string $1 }
515513

516514
(* Library definitions *)
517515

compiler/tests-compiler/js_parser_printer.ml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,21 +1042,5 @@ let%expect_test "label parsing" =
10421042
{|
10431043
get:{of:{from:{async:{break async}break from}break of}break get}
10441044
|};
1045-
[%expect.unreachable]
1046-
[@@expect.uncaught_exn {|
1047-
(* CR expect_test_collector: This test expectation appears to contain a backtrace.
1048-
This is strongly discouraged as backtraces are fragile.
1049-
Please change this test to not include a backtrace. *)
1050-
1051-
("Js_of_ocaml_compiler.Parse_js.Parsing_error(_)")
1052-
Raised at Js_of_ocaml_compiler__Parse_js.parse_aux in file "compiler/lib/parse_js.ml", line 425, characters 6-37
1053-
Called from Js_of_ocaml_compiler__Parse_js.parse' in file "compiler/lib/parse_js.ml", line 440, characters 16-59
1054-
Called from Js_parser_printer_15__Js_parser_printer.parse_print_token in file "compiler/tests-compiler/js_parser_printer.ml", line 700, characters 8-27
1055-
Re-raised at Js_parser_printer_15__Js_parser_printer.parse_print_token in file "compiler/tests-compiler/js_parser_printer.ml", line 703, characters 6-13
1056-
Called from Js_parser_printer_15__Js_parser_printer.(fun) in file "compiler/tests-compiler/js_parser_printer.ml", line 1040, characters 2-110
1057-
Called from Expect_test_collector.Make.Instance_io.exec in file "collector/expect_test_collector.ml", line 262, characters 12-19
1058-
1059-
Trailing output
1060-
---------------
1061-
1062-
cannot parse l:2:3@. |}]
1045+
[%expect
1046+
{| 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:}, |}]

0 commit comments

Comments
 (0)