From aef01cc7a796e7d0ee5ff1f56076b9594922304c Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 5 Jun 2023 16:36:11 +0200 Subject: [PATCH 01/12] Compiler: ignore virtual semicolon token when reporting parsing error --- compiler/lib/parse_js.ml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/lib/parse_js.ml b/compiler/lib/parse_js.ml index 3e34a084e5..e404e6a1c0 100644 --- a/compiler/lib/parse_js.ml +++ b/compiler/lib/parse_js.ml @@ -496,10 +496,15 @@ let parse_aux the_parser (lexbuf : Lexer.t) = let checkpoint = State.create init in match loop checkpoint checkpoint with | `Ok x -> x - | `Error t -> ( - match State.Cursor.last_token (State.cursor t) with - | None -> assert false - | Some ((_, p, _), _) -> raise (Parsing_error (Parse_info.t_of_pos p))) + | `Error t -> + let rec last cursor = + match State.Cursor.last_token cursor with + | None -> assert false + | Some ((T_VIRTUAL_SEMICOLON, _, _), cursor) -> last cursor + | Some ((_, p, _), _) -> p + in + let p = last (State.cursor t) in + raise (Parsing_error (Parse_info.t_of_pos p)) let fail_early = object From d496198082aeea56aea55d1d8a3a868f8ce21a22 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 5 Jun 2023 16:38:00 +0200 Subject: [PATCH 02/12] Compiler: add block method for Js_traverse.iter --- compiler/lib/js_traverse.ml | 14 +++++++++----- compiler/lib/js_traverse.mli | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/lib/js_traverse.ml b/compiler/lib/js_traverse.ml index 0b422d7df4..2179d56ad1 100644 --- a/compiler/lib/js_traverse.ml +++ b/compiler/lib/js_traverse.ml @@ -315,6 +315,8 @@ class type iterator = method switch_case : Javascript.expression -> unit + method block : Javascript.statement_list -> unit + method initialiser : Javascript.expression * Javascript.location -> unit method initialiser_o : (Javascript.expression * Javascript.location) option -> unit @@ -345,6 +347,8 @@ class iter : iterator = method early_error _ = () + method block l = m#statements l + method statements l = List.iter l ~f:(fun (s, _) -> m#statement s) method variable_declaration _ x = @@ -383,7 +387,7 @@ class iter : iterator = | CEField (_static, n, i) -> m#class_element_name n; m#initialiser_o i - | CEStaticBLock b -> m#statements b + | CEStaticBLock b -> m#block b method private class_element_name x = match x with @@ -392,7 +396,7 @@ class iter : iterator = method statement s = match s with - | Block b -> m#statements b + | Block b -> m#block b | Variable_statement (k, l) -> List.iter l ~f:(m#variable_declaration k) | Function_declaration (id, fun_decl) -> m#ident id; @@ -451,15 +455,15 @@ class iter : iterator = m#switch_case e; m#statements s) | Try_statement (b, catch, final) -> ( - m#statements b; + m#block b; (match catch with | None -> () | Some (id, b) -> Option.iter ~f:m#param id; - m#statements b); + m#block b); match final with | None -> () - | Some s -> m#statements s) + | Some s -> m#block s) method statement_o x = match x with diff --git a/compiler/lib/js_traverse.mli b/compiler/lib/js_traverse.mli index c97cf18de1..855449b7e7 100644 --- a/compiler/lib/js_traverse.mli +++ b/compiler/lib/js_traverse.mli @@ -78,6 +78,8 @@ class type iterator = method switch_case : Javascript.expression -> unit + method block : Javascript.statement_list -> unit + method initialiser : Javascript.expression * Javascript.location -> unit method initialiser_o : (Javascript.expression * Javascript.location) option -> unit From 28687268ecf7e593ff39be819d81073772b157cd Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 5 Jun 2023 17:23:48 +0200 Subject: [PATCH 03/12] Compiler: add failing tests --- compiler/tests-compiler/minify.ml | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/compiler/tests-compiler/minify.ml b/compiler/tests-compiler/minify.ml index 647ca06dfb..a66a6fb4a3 100644 --- a/compiler/tests-compiler/minify.ml +++ b/compiler/tests-compiler/minify.ml @@ -258,3 +258,87 @@ let%expect_test _ = 6: a=1;let 7: b=2;const 8: c=3} |}]) + +let%expect_test _ = + with_temp_dir ~f:(fun () -> + let js_prog = + {| + function f() { + const v = 2; + if(true) { + var x = v; + { const v = x + 1 } + } + } + |} + in + let js_file = + js_prog |> Filetype.js_text_of_string |> Filetype.write_js ~name:"test.js" + in + let js_min_file = + js_file |> jsoo_minify ~flags:[ "--enable"; "shortvar" ] ~pretty:false + in + print_file (Filetype.path_of_js_file js_file); + print_file (Filetype.path_of_js_file js_min_file); + [%expect.unreachable]) +[@@expect.uncaught_exn {| + (* CR expect_test_collector: This test expectation appears to contain a backtrace. + This is strongly discouraged as backtraces are fragile. + Please change this test to not include a backtrace. *) + + (Failure "non-zero exit code") + Raised at Stdlib__Buffer.add_channel in file "buffer.ml", line 211, characters 18-35 + Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string.loop in file "compiler/tests-compiler/util/util.ml", line 169, characters 4-52 + Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string in file "compiler/tests-compiler/util/util.ml", line 172, characters 7-14 + + Trailing output + --------------- + Some variables escaped (#1). Use [--debug js_assign] for more info. + /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe: You found a bug. Please report it at https://github.com/ocsigen/js_of_ocaml/issues : + Error: File "compiler/lib/js_assign.ml", line 386, characters 5-11: Assertion failed + + process exited with error code 1 + /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe --enable shortvar test.js -o test.min.js |}] + +let%expect_test _ = + with_temp_dir ~f:(fun () -> + let js_prog = + {| +(function () { + class f { + f() { + const y = 2; + return v + } + }; + const w = y +})() + |} + in + let js_file = + js_prog |> Filetype.js_text_of_string |> Filetype.write_js ~name:"test.js" + in + let js_min_file = + js_file |> jsoo_minify ~flags:[ "--enable"; "shortvar" ] ~pretty:false + in + print_file (Filetype.path_of_js_file js_file); + print_file (Filetype.path_of_js_file js_min_file); + [%expect.unreachable]) +[@@expect.uncaught_exn {| + (* CR expect_test_collector: This test expectation appears to contain a backtrace. + This is strongly discouraged as backtraces are fragile. + Please change this test to not include a backtrace. *) + + (Failure "non-zero exit code") + Raised at Stdlib__Buffer.add_channel in file "buffer.ml", line 211, characters 18-35 + Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string.loop in file "compiler/tests-compiler/util/util.ml", line 169, characters 4-52 + Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string in file "compiler/tests-compiler/util/util.ml", line 172, characters 7-14 + + Trailing output + --------------- + Some variables escaped (#1). Use [--debug js_assign] for more info. + /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe: You found a bug. Please report it at https://github.com/ocsigen/js_of_ocaml/issues : + Error: File "compiler/lib/js_assign.ml", line 386, characters 5-11: Assertion failed + + process exited with error code 1 + /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe --enable shortvar test.js -o test.min.js |}] From b1f3389d1b67b51314d9f9cfbfc550772c4cffdc Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 5 Jun 2023 17:09:43 +0200 Subject: [PATCH 04/12] Compiler: fix variable renaming in presence of let and const Also add a fix in presence of class and method --- compiler/lib/js_traverse.ml | 68 +++++++++++++++++----------- compiler/tests-compiler/minify.ml | 73 +++++++++++++++---------------- 2 files changed, 77 insertions(+), 64 deletions(-) diff --git a/compiler/lib/js_traverse.ml b/compiler/lib/js_traverse.ml index 2179d56ad1..ab2f61c76b 100644 --- a/compiler/lib/js_traverse.ml +++ b/compiler/lib/js_traverse.ml @@ -909,42 +909,58 @@ class free = super#for_binding k x end +type scope = + | Lexical_block + | Fun_block of ident option + class rename_variable = - let declared local_only ident params body = + let declared scope params body = let declared_names = ref StringSet.empty in let decl_var x = match x with | S { name = Utf8 name; _ } -> declared_names := StringSet.add name !declared_names | _ -> () in - Option.iter ~f:decl_var ident; + (match scope with + | Lexical_block -> () + | Fun_block None -> () + | Fun_block (Some x) -> decl_var x); List.iter params ~f:(fun x -> decl_var x); - (object + (object (self) + val depth = 0 + inherit iter as super method expression _ = () + method fun_decl _ = () + method statement x = - match x with - | Function_declaration (id, _) -> if not local_only then decl_var id - | _ -> super#statement x + match scope, x with + | Fun_block _, Function_declaration (id, fd) -> + decl_var id; + self#fun_decl fd + | Lexical_block, Function_declaration (_, fd) -> self#fun_decl fd + | (Fun_block _ | Lexical_block), _ -> super#statement x method variable_declaration k l = - if (not local_only) - || - match k with - | Let | Const -> true - | Var -> false + if match scope, k with + | (Lexical_block | Fun_block _), (Let | Const) -> depth = 0 + | Lexical_block, Var -> false + | Fun_block _, Var -> true then let ids = bound_idents_of_variable_declaration l in List.iter ids ~f:decl_var + method block l = + let m = {} in + m#statements l + method for_binding k p = - if (not local_only) - || - match k with - | Let | Const -> true - | Var -> false + if match scope, k with + | (Lexical_block | Fun_block _), (Let | Const) -> depth = 0 + | Lexical_block, Var -> false + | Fun_block _, Var -> true then match p with | BindingIdent i -> decl_var i @@ -963,8 +979,8 @@ class rename_variable = val decl = StringSet.empty - method private update_state local_only ident params iter_body = - let declared_names = declared local_only ident params iter_body in + method private update_state scope params iter_body = + let declared_names = declared scope params iter_body in { StringMap.add name (Code.Var.fresh_n name) subst) declared_names @@ -979,18 +995,18 @@ class rename_variable = method fun_decl (k, params, body, nid) = let ids = bound_idents_of_params params in - let m' = m#update_state false None ids body in + let m' = m#update_state (Fun_block None) ids body in k, m'#formal_parameter_list params, m'#function_body body, m#loc nid method program p = - let m' = m#update_state true None [] p in + let m' = m#update_state Lexical_block [] p in m'#statements p method expression e = match e with | EFun (ident, (k, params, body, nid)) -> let ids = bound_idents_of_params params in - let m' = m#update_state false ident ids body in + let m' = m#update_state (Fun_block ident) ids body in EFun ( Option.map ident ~f:m'#ident , (k, m'#formal_parameter_list params, m'#function_body body, m#loc nid) ) @@ -1000,23 +1016,23 @@ class rename_variable = match s with | Function_declaration (id, (k, params, body, nid)) -> let ids = bound_idents_of_params params in - let m' = m#update_state false None ids body in + let m' = m#update_state (Fun_block None) ids body in Function_declaration ( m#ident id , (k, m'#formal_parameter_list params, m'#function_body body, m#loc nid) ) | Block l -> - let m' = m#update_state true None [] l in + let m' = m#update_state Lexical_block [] l in Block (m'#statements l) | Try_statement (block, catch, final) -> let block = - let m' = m#update_state true None [] block in + let m' = m#update_state Lexical_block [] block in m'#statements block in let final = match final with | None -> None | Some final -> - let m' = m#update_state true None [] final in + let m' = m#update_state Lexical_block [] final in Some (m'#statements final) in let catch = @@ -1035,7 +1051,7 @@ class rename_variable = in Some p, l in - let m' = m#update_state true None l catch in + let m' = m#update_state Lexical_block l catch in let i = match i with | None -> None diff --git a/compiler/tests-compiler/minify.ml b/compiler/tests-compiler/minify.ml index a66a6fb4a3..93915f56b2 100644 --- a/compiler/tests-compiler/minify.ml +++ b/compiler/tests-compiler/minify.ml @@ -280,25 +280,23 @@ let%expect_test _ = in print_file (Filetype.path_of_js_file js_file); print_file (Filetype.path_of_js_file js_min_file); - [%expect.unreachable]) -[@@expect.uncaught_exn {| - (* CR expect_test_collector: This test expectation appears to contain a backtrace. - This is strongly discouraged as backtraces are fragile. - Please change this test to not include a backtrace. *) - - (Failure "non-zero exit code") - Raised at Stdlib__Buffer.add_channel in file "buffer.ml", line 211, characters 18-35 - Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string.loop in file "compiler/tests-compiler/util/util.ml", line 169, characters 4-52 - Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string in file "compiler/tests-compiler/util/util.ml", line 172, characters 7-14 - - Trailing output - --------------- - Some variables escaped (#1). Use [--debug js_assign] for more info. - /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe: You found a bug. Please report it at https://github.com/ocsigen/js_of_ocaml/issues : - Error: File "compiler/lib/js_assign.ml", line 386, characters 5-11: Assertion failed - - process exited with error code 1 - /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe --enable shortvar test.js -o test.min.js |}] + [%expect{| + $ cat "test.js" + 1: + 2: function f() { + 3: const v = 2; + 4: if(true) { + 5: var x = v; + 6: { const v = x + 1 } + 7: } + 8: } + 9: + $ cat "test.min.js" + 1: function + 2: f(){const + 3: a=2;if(true){var + 4: b=a;const + 5: c=b+1}} |}]) let%expect_test _ = with_temp_dir ~f:(fun () -> @@ -323,22 +321,21 @@ let%expect_test _ = in print_file (Filetype.path_of_js_file js_file); print_file (Filetype.path_of_js_file js_min_file); - [%expect.unreachable]) -[@@expect.uncaught_exn {| - (* CR expect_test_collector: This test expectation appears to contain a backtrace. - This is strongly discouraged as backtraces are fragile. - Please change this test to not include a backtrace. *) - - (Failure "non-zero exit code") - Raised at Stdlib__Buffer.add_channel in file "buffer.ml", line 211, characters 18-35 - Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string.loop in file "compiler/tests-compiler/util/util.ml", line 169, characters 4-52 - Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string in file "compiler/tests-compiler/util/util.ml", line 172, characters 7-14 - - Trailing output - --------------- - Some variables escaped (#1). Use [--debug js_assign] for more info. - /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe: You found a bug. Please report it at https://github.com/ocsigen/js_of_ocaml/issues : - Error: File "compiler/lib/js_assign.ml", line 386, characters 5-11: Assertion failed - - process exited with error code 1 - /home/hugo/js_of_ocaml/_build/default/compiler/bin-jsoo_minify/jsoo_minify.exe --enable shortvar test.js -o test.min.js |}] + [%expect{| + $ cat "test.js" + 1: + 2: (function () { + 3: class f { + 4: f() { + 5: const y = 2; + 6: return v + 7: } + 8: }; + 9: const w = y + 10: })() + 11: + $ cat "test.min.js" + 1: (function(){class + 2: f{f(){const + 3: a=2;return v}}const + 4: a=y}()); |}]) From 1586206ec170e4b339e87f2a1c9a385853a91592 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 5 Jun 2023 17:38:57 +0200 Subject: [PATCH 05/12] Compiler: Fix restricted token used in identifier position --- compiler/lib/parse_js.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/lib/parse_js.ml b/compiler/lib/parse_js.ml index e404e6a1c0..3a9edff265 100644 --- a/compiler/lib/parse_js.ml +++ b/compiler/lib/parse_js.ml @@ -356,7 +356,11 @@ let rec offer_one t (lexbuf : Lexer.t) = | ( Some (((T_RETURN | T_CONTINUE | T_BREAK | T_THROW | T_YIELD), _, _), _) , (((T_SEMICOLON | T_VIRTUAL_SEMICOLON), _, _) as tok) ) -> tok | Some (((T_RETURN | T_CONTINUE | T_BREAK | T_THROW | T_YIELD), _, _), _), _ - when nl_separated h tok -> + when nl_separated h tok && acceptable t T_VIRTUAL_SEMICOLON -> + (* restricted token can also appear as regular identifier such + as in [x.return]. In such case, feeding a virtual semicolon + could trigger a parser error. Here, we first checkpoint + that a virtual semicolon is acceptable. *) Lexer.rollback lexbuf; semicolon (* The practical effect of these restricted productions is as follows: From 4cdb32a26ec58e88b77fd295b6ca02d3576ec969 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 5 Jun 2023 18:11:24 +0200 Subject: [PATCH 06/12] Misc: fmt --- compiler/tests-compiler/minify.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/tests-compiler/minify.ml b/compiler/tests-compiler/minify.ml index 93915f56b2..a942792789 100644 --- a/compiler/tests-compiler/minify.ml +++ b/compiler/tests-compiler/minify.ml @@ -280,7 +280,8 @@ let%expect_test _ = in print_file (Filetype.path_of_js_file js_file); print_file (Filetype.path_of_js_file js_min_file); - [%expect{| + [%expect + {| $ cat "test.js" 1: 2: function f() { @@ -321,7 +322,8 @@ let%expect_test _ = in print_file (Filetype.path_of_js_file js_file); print_file (Filetype.path_of_js_file js_min_file); - [%expect{| + [%expect + {| $ cat "test.js" 1: 2: (function () { From 038e802ee6620df2143d48b45e507b78474b1dd1 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 5 Jun 2023 18:15:56 +0200 Subject: [PATCH 07/12] Changes --- CHANGES.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 75ead1eec7..350b7c9573 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,13 @@ +# Dev (2023-??-??) - ?? +## Features/Changes +* Misc: Bump magic number for ocaml 5.1 +* Misc: changes to stay compatible with the next version of ppx_expect + +## Bug fixes +* Compiler: fix location for parsing errors when last token is a virtual semicolon +* Compiler: fix variable renaming with nested const/let decl with identical names +* Compiler: fix variable renaming inside js method + # 5.2.0 (2023-04-28) - Lille ## Features/Changes * Compiler: jsoo link archive with -a (#1428) From caa3febd2cc0e2c06d12a150119c205c54de55ed Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 6 Jun 2023 08:07:55 +0200 Subject: [PATCH 08/12] Compiler: add failing test parsing iife inside arrow --- compiler/tests-compiler/js_parser_printer.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/tests-compiler/js_parser_printer.ml b/compiler/tests-compiler/js_parser_printer.ml index 70ace1cf9f..fab1c45f8c 100644 --- a/compiler/tests-compiler/js_parser_printer.ml +++ b/compiler/tests-compiler/js_parser_printer.ml @@ -609,6 +609,20 @@ if(a) { this(is, not, small) + this(is, bigger); } |}] +let%expect_test "" = + print + ~debuginfo:false + ~compact:false + ~report:true + {| +var e = function () { } () + +var e = f(x => function () { } ()) +|}; + [%expect + {| + cannot parse js (from l:4, c:31)@. |}] + let%expect_test "error reporting" = (try print ~invalid:true ~compact:false {| From 74da1e80e491fd4174204a0538e75c4c8931021e Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 6 Jun 2023 11:12:15 +0200 Subject: [PATCH 09/12] Compiler: preserve new construct without arguments --- compiler/lib/js_output.ml | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/lib/js_output.ml b/compiler/lib/js_output.ml index c115f819ca..f724f093ec 100644 --- a/compiler/lib/js_output.ml +++ b/compiler/lib/js_output.ml @@ -732,8 +732,6 @@ struct PP.string f "new"; PP.space f; expression NewExpression f e; - PP.break f; - PP.string f "()"; PP.end_group f; if Prec.(l > NewExpression) then ( From ee7de7e63865b4e4a370b29852cce625fa49b082 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 6 Jun 2023 11:12:52 +0200 Subject: [PATCH 10/12] Compiler: fix consise body for fat arrow --- compiler/lib/js_parser.mly | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/compiler/lib/js_parser.mly b/compiler/lib/js_parser.mly index 57191c31dd..8d7d6150a0 100644 --- a/compiler/lib/js_parser.mly +++ b/compiler/lib/js_parser.mly @@ -911,9 +911,7 @@ async_arrow_function: (* was called consise body in spec *) arrow_body: | "{" b=function_body "}" { b } - | e=assignment_expr_no_stmt { [(Return_statement (Some e), p $symbolstartpos)] } - (* ugly *) - | e=function_expr { [(Expression_statement e, p $symbolstartpos)] } + | e=assignment_expr_for_consise_body { [(Return_statement (Some e), p $symbolstartpos)] } (*----------------------------*) (* no in *) @@ -982,6 +980,31 @@ assignment_expr_no_stmt: | T_YIELD e=assignment_expr { EYield (Some e) } | T_YIELD "*" e=assignment_expr { EYield (Some e) } + +primary_for_consise_body: + | function_expr { $1 } + | class_expr { $1 } + (* es6: *) + | generator_expr { $1 } + (* es7: *) + | async_function_expr { $1 } + +assignment_expr_for_consise_body: + | conditional_expr(primary_for_consise_body) { $1 } + | e1=left_hand_side_expr_(primary_for_consise_body) op=assignment_operator e2=assignment_expr + { + match assignment_pattern_of_expr (Some op) e1 with + | None -> EBin (op, e1, e2) + | Some pat -> EBin (op, EAssignTarget pat, e2) + } + (* es6: *) + | arrow_function { $1 } + | async_arrow_function { $1 } + (* es6: *) + | T_YIELD { EYield None } + | T_YIELD e=assignment_expr { EYield (Some e) } + | T_YIELD "*" e=assignment_expr { EYield (Some e) } + (* no object_literal here *) primary_no_stmt: T_ERROR TComment { assert false } From ea6eb3c492bbfe1b9f16384c22f027bc98ce2817 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 6 Jun 2023 11:13:38 +0200 Subject: [PATCH 11/12] Tests: accept test diff --- CHANGES.md | 2 ++ compiler/tests-compiler/js_parser_printer.ml | 23 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 350b7c9573..1fc6c3dc86 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ * Compiler: fix location for parsing errors when last token is a virtual semicolon * Compiler: fix variable renaming with nested const/let decl with identical names * Compiler: fix variable renaming inside js method +* Compiler: consise body should allow any expression but object literals +* Compiler: preverve [new] without arguments [new C] (vs [new C()] # 5.2.0 (2023-04-28) - Lille ## Features/Changes diff --git a/compiler/tests-compiler/js_parser_printer.ml b/compiler/tests-compiler/js_parser_printer.ml index fab1c45f8c..53014de09a 100644 --- a/compiler/tests-compiler/js_parser_printer.ml +++ b/compiler/tests-compiler/js_parser_printer.ml @@ -609,7 +609,7 @@ if(a) { this(is, not, small) + this(is, bigger); } |}] -let%expect_test "" = +let%expect_test "consise body can be anything that doesn't start with curly brackets" = print ~debuginfo:false ~compact:false @@ -618,10 +618,29 @@ let%expect_test "" = var e = function () { } () var e = f(x => function () { } ()) + +var e = f(x => new class f {}) +|}; + [%expect + {| + var e = function(){}(); + var e = f(x=>function(){}()); + var e = f(x=>new class f{}); |}] + +let%expect_test "new kw with no arguments should be preserve" = + print + ~debuginfo:false + ~compact:false + ~report:true + {| +var e = new f +var e = new f() +var e = new class f {} +var e = new (class f {}) |}; [%expect {| - cannot parse js (from l:4, c:31)@. |}] + var e = new f; var e = new f(); var e = new class f{}; var e = new class f{}; |}] let%expect_test "error reporting" = (try From cabea2a29c1676c2d4a02b13f31596fb32da59ec Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 6 Jun 2023 11:56:20 +0200 Subject: [PATCH 12/12] Misc: Temporary fix issue with base.v0.16 on windows --- dune-project | 1 + js_of_ocaml-compiler.opam | 1 + 2 files changed, 2 insertions(+) diff --git a/dune-project b/dune-project index a3e9e081da..0344c66c20 100644 --- a/dune-project +++ b/dune-project @@ -34,6 +34,7 @@ (conflicts (ocamlfind (< 1.5.1)) (js_of_ocaml (< 3.0)) + (base (= v0.16.0)) )) (package diff --git a/js_of_ocaml-compiler.opam b/js_of_ocaml-compiler.opam index 0630d7b7c1..880dbbc485 100644 --- a/js_of_ocaml-compiler.opam +++ b/js_of_ocaml-compiler.opam @@ -30,6 +30,7 @@ depopts: ["ocamlfind"] conflicts: [ "ocamlfind" {< "1.5.1"} "js_of_ocaml" {< "3.0"} + "base" {= "v0.16.0"} ] dev-repo: "git+https://github.com/ocsigen/js_of_ocaml.git" build: [