Skip to content

Commit

Permalink
No empty export dump (#6744)
Browse files Browse the repository at this point in the history
* Don't dump empty export

* Update test compiled files

* Update changelog
  • Loading branch information
DZakh committed Apr 28, 2024
1 parent fde6708 commit 17804a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -28,6 +28,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 empty return in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6745
- 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
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;
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
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
Expand Up @@ -8,7 +8,4 @@ if(import.meta.hot) {
}
;

export {

}
/* Not a pure module */

0 comments on commit 17804a4

Please sign in to comment.