diff --git a/CHANGELOG.md b/CHANGELOG.md index a445046183..81b82dc033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Make the `--help` arg be prioritized in the CLI, so correctly prints help message and skip other commands. https://github.com/rescript-lang/rescript-compiler/pull/6667 - Remove redundant space for export in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6560 +- Remove empty export blocks in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6744 # 11.1.0 diff --git a/jscomp/core/js_dump_import_export.ml b/jscomp/core/js_dump_import_export.ml index 1b45555d05..b70048e6fe 100644 --- a/jscomp/core/js_dump_import_export.ml +++ b/jscomp/core/js_dump_import_export.ml @@ -70,7 +70,11 @@ let exports cxt f (idents : Ident.t list) = (** Print module in ES6 format, it is ES6, trailing comma is valid ES6 code *) let es6_export cxt f (idents : Ident.t list) = - let outer_cxt, reversed_list = + P.at_least_two_lines f; + match idents with + | [] -> cxt + | _ -> + let outer_cxt, reversed_list = Ext_list.fold_left idents (cxt, []) (fun (cxt, acc) id -> let id_name = id.name in let s = Ext_ident.convert id_name in @@ -79,23 +83,23 @@ let es6_export cxt f (idents : Ident.t list) = if id_name = default_export then (default_export, str) :: acc else (s, str) :: acc )) - in - P.at_least_two_lines f; - P.string f L.export; - P.space f; - P.brace_vgroup f 1 (fun _ -> - rev_iter_inter reversed_list - (fun (s, export) -> - P.group f 0 (fun _ -> - P.string f export; - if not @@ Ext_string.equal export s then ( - P.space f; - P.string f L.as_; - P.space f; - P.string f s); - P.string f L.comma)) - (fun _ -> P.newline f)); - outer_cxt + in + P.string f L.export; + P.space f; + P.brace_vgroup f 1 (fun _ -> + rev_iter_inter reversed_list + (fun (s, export) -> + P.group f 0 (fun _ -> + P.string f export; + if not @@ Ext_string.equal export s then ( + P.space f; + P.string f L.as_; + P.space f; + P.string f s); + P.string f L.comma)) + (fun _ -> P.newline f)); + outer_cxt + (** Node or Google module style imports *) let requires require_lit cxt f (modules : (Ident.t * string * bool) list) = diff --git a/jscomp/test/es6_import.mjs b/jscomp/test/es6_import.mjs index e6f57256d3..4af69f9aa5 100644 --- a/jscomp/test/es6_import.mjs +++ b/jscomp/test/es6_import.mjs @@ -4,7 +4,4 @@ import * as Es6_export from "./es6_export.mjs"; console.log(Es6_export.default); -export { - -} /* Not a pure module */ diff --git a/jscomp/test/gpr_4931_allow.mjs b/jscomp/test/gpr_4931_allow.mjs index 52d3994474..0996420696 100644 --- a/jscomp/test/gpr_4931_allow.mjs +++ b/jscomp/test/gpr_4931_allow.mjs @@ -8,7 +8,4 @@ if(import.meta.hot) { } ; -export { - -} /* Not a pure module */