Skip to content

Commit 17804a4

Browse files
authored
No empty export dump (#6744)
* Don't dump empty export * Update test compiled files * Update changelog
1 parent fde6708 commit 17804a4

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- 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
2929
- Remove redundant space for empty return in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6745
3030
- Remove redundant space for export in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6560
31+
- Remove empty export blocks in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6744
3132

3233
# 11.1.0
3334

jscomp/core/js_dump_import_export.ml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ let exports cxt f (idents : Ident.t list) =
7070

7171
(** Print module in ES6 format, it is ES6, trailing comma is valid ES6 code *)
7272
let es6_export cxt f (idents : Ident.t list) =
73-
let outer_cxt, reversed_list =
73+
P.at_least_two_lines f;
74+
match idents with
75+
| [] -> cxt
76+
| _ ->
77+
let outer_cxt, reversed_list =
7478
Ext_list.fold_left idents (cxt, []) (fun (cxt, acc) id ->
7579
let id_name = id.name in
7680
let s = Ext_ident.convert id_name in
@@ -79,23 +83,23 @@ let es6_export cxt f (idents : Ident.t list) =
7983
if id_name = default_export then
8084
(default_export, str) :: acc
8185
else (s, str) :: acc ))
82-
in
83-
P.at_least_two_lines f;
84-
P.string f L.export;
85-
P.space f;
86-
P.brace_vgroup f 1 (fun _ ->
87-
rev_iter_inter reversed_list
88-
(fun (s, export) ->
89-
P.group f 0 (fun _ ->
90-
P.string f export;
91-
if not @@ Ext_string.equal export s then (
92-
P.space f;
93-
P.string f L.as_;
94-
P.space f;
95-
P.string f s);
96-
P.string f L.comma))
97-
(fun _ -> P.newline f));
98-
outer_cxt
86+
in
87+
P.string f L.export;
88+
P.space f;
89+
P.brace_vgroup f 1 (fun _ ->
90+
rev_iter_inter reversed_list
91+
(fun (s, export) ->
92+
P.group f 0 (fun _ ->
93+
P.string f export;
94+
if not @@ Ext_string.equal export s then (
95+
P.space f;
96+
P.string f L.as_;
97+
P.space f;
98+
P.string f s);
99+
P.string f L.comma))
100+
(fun _ -> P.newline f));
101+
outer_cxt
102+
99103

100104
(** Node or Google module style imports *)
101105
let requires require_lit cxt f (modules : (Ident.t * string * bool) list) =

jscomp/test/es6_import.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@ import * as Es6_export from "./es6_export.mjs";
44

55
console.log(Es6_export.default);
66

7-
export {
8-
9-
}
107
/* Not a pure module */

jscomp/test/gpr_4931_allow.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ if(import.meta.hot) {
88
}
99
;
1010

11-
export {
12-
13-
}
1411
/* Not a pure module */

0 commit comments

Comments
 (0)