Skip to content

No empty export dump #6744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 22 additions & 18 deletions jscomp/core/js_dump_import_export.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like to add a new line when there is no other output here, but that's the best way I could come up with to keep the /* Not a pure module */ comment display in a good way.

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
Expand All @@ -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) =
Expand Down
3 changes: 0 additions & 3 deletions jscomp/test/es6_import.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ import * as Es6_export from "./es6_export.mjs";

console.log(Es6_export.default);

export {

}
/* Not a pure module */
3 changes: 0 additions & 3 deletions jscomp/test/gpr_4931_allow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ if(import.meta.hot) {
}
;

export {

}
/* Not a pure module */