Skip to content

Commit

Permalink
Compiler: js-parser, allow optional semi at the end of export default…
Browse files Browse the repository at this point in the history
… decl
  • Loading branch information
hhugo committed Dec 15, 2023
1 parent 00711b7 commit d8071c5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/lib/js_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ T_BACKQUOTE

%token T_VIRTUAL_SEMICOLON
%token T_VIRTUAL_SEMICOLON_DO_WHILE
%token T_VIRTUAL_SEMICOLON_EXPORT_DEFAULT
%token T_LPAREN_ARROW
%token T_INCR_NB T_DECR_NB

Expand Down Expand Up @@ -399,7 +400,7 @@ export_decl:
let k = ExportDefaultExpression e in
let pos = $symbolstartpos in
Export (k,pi pos), p pos }
| T_EXPORT T_DEFAULT e=export_fun_class
| T_EXPORT T_DEFAULT e=export_fun_class endrule(sc | T_VIRTUAL_SEMICOLON_EXPORT_DEFAULT { () } )
{
let k = match e with
| EFun (id, decl) ->
Expand Down
3 changes: 3 additions & 0 deletions compiler/lib/js_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ type t =
| T_EOF
| T_VIRTUAL_SEMICOLON
| T_VIRTUAL_SEMICOLON_DO_WHILE
| T_VIRTUAL_SEMICOLON_EXPORT_DEFAULT
| T_DECR_NB
| T_INCR_NB
| T_LPAREN_ARROW
Expand Down Expand Up @@ -266,6 +267,7 @@ let to_string = function
| T_VOID -> "void"
| T_VIRTUAL_SEMICOLON -> ";"
| T_VIRTUAL_SEMICOLON_DO_WHILE -> ";"
| T_VIRTUAL_SEMICOLON_EXPORT_DEFAULT -> ";"
| T_ARROW -> "=>"
| T_AT -> "@"
| T_POUND -> "#"
Expand Down Expand Up @@ -319,6 +321,7 @@ let to_string_extra x =
| T_DECR -> " (DECR)"
| T_VIRTUAL_SEMICOLON -> " (virtual)"
| T_VIRTUAL_SEMICOLON_DO_WHILE -> " (virtual-do-while)"
| T_VIRTUAL_SEMICOLON_EXPORT_DEFAULT -> " (virtual-export-default)"
| TAnnot _ -> "(annot)"
| T_ERROR _ -> "(error)"
| T_LPAREN_ARROW -> "(arrow)"
Expand Down
1 change: 1 addition & 0 deletions compiler/lib/js_token.mli
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ type t =
| T_EOF
| T_VIRTUAL_SEMICOLON
| T_VIRTUAL_SEMICOLON_DO_WHILE
| T_VIRTUAL_SEMICOLON_EXPORT_DEFAULT
| T_DECR_NB
| T_INCR_NB
| T_LPAREN_ARROW
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/parse_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ let recover error_checkpoint previous_checkpoint =
State.Cursor.insert_token rest semicolon dummy_loc |> State.try_recover
| T_RPAREN
when acceptable previous_checkpoint Js_token.T_VIRTUAL_SEMICOLON_DO_WHILE
-> State.Cursor.insert_token rest semicolon dummy_loc |> State.try_recover | T_RCURLY
when acceptable previous_checkpoint Js_token.T_VIRTUAL_SEMICOLON_EXPORT_DEFAULT
-> State.Cursor.insert_token rest semicolon dummy_loc |> State.try_recover
| _ -> error_checkpoint)))

Expand Down

0 comments on commit d8071c5

Please sign in to comment.