From 3b8a02cd9c51236f7fbd80fcca06b9413f8f974b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sun, 16 Jul 2023 11:59:51 +0200 Subject: [PATCH 1/3] don't export 2235default --- jscomp/core/js_dump_import_export.ml | 4 ++-- jscomp/test/default_export_test.js | 1 - jscomp/test/es6_export.js | 1 - jscomp/test/es6_export.mjs | 1 - jscomp/test/escape_esmodule.js | 1 - jscomp/test/key_word_property.js | 1 - lib/es6/js_option.js | 1 - lib/js/js_option.js | 1 - 8 files changed, 2 insertions(+), 9 deletions(-) diff --git a/jscomp/core/js_dump_import_export.ml b/jscomp/core/js_dump_import_export.ml index e867b789be..2832d59e8d 100644 --- a/jscomp/core/js_dump_import_export.ml +++ b/jscomp/core/js_dump_import_export.ml @@ -50,7 +50,7 @@ let exports cxt f (idents : Ident.t list) = ( cxt, if id_name = default_export then (* TODO check how it will affect AMDJS*) - esModule :: (default_export, str) :: (s, str) :: acc + esModule :: (default_export, str) :: acc else (s, str) :: acc )) in P.at_least_two_lines f; @@ -77,7 +77,7 @@ let es6_export cxt f (idents : Ident.t list) = let str, cxt = Ext_pp_scope.str_of_ident cxt id in ( cxt, if id_name = default_export then - (default_export, str) :: (s, str) :: acc + (default_export, str) :: acc else (s, str) :: acc )) in P.at_least_two_lines f; diff --git a/jscomp/test/default_export_test.js b/jscomp/test/default_export_test.js index 7937f7e30a..a2728d6e69 100644 --- a/jscomp/test/default_export_test.js +++ b/jscomp/test/default_export_test.js @@ -4,7 +4,6 @@ var $$default = "xx"; -exports.$$default = $$default; exports.default = $$default; exports.__esModule = true; /* No side effect */ diff --git a/jscomp/test/es6_export.js b/jscomp/test/es6_export.js index a7e1005573..6ea1b9683b 100644 --- a/jscomp/test/es6_export.js +++ b/jscomp/test/es6_export.js @@ -4,7 +4,6 @@ var $$default = 3; -exports.$$default = $$default; exports.default = $$default; exports.__esModule = true; /* No side effect */ diff --git a/jscomp/test/es6_export.mjs b/jscomp/test/es6_export.mjs index 6a4840eb3d..e20f50b87f 100644 --- a/jscomp/test/es6_export.mjs +++ b/jscomp/test/es6_export.mjs @@ -4,7 +4,6 @@ var $$default = 3; export { - $$default , $$default as default, } /* No side effect */ diff --git a/jscomp/test/escape_esmodule.js b/jscomp/test/escape_esmodule.js index f9f8cafcb3..40ca26b287 100644 --- a/jscomp/test/escape_esmodule.js +++ b/jscomp/test/escape_esmodule.js @@ -7,7 +7,6 @@ var $$__esModule = false; var $$default = 4; exports.$$__esModule = $$__esModule; -exports.$$default = $$default; exports.default = $$default; exports.__esModule = true; /* No side effect */ diff --git a/jscomp/test/key_word_property.js b/jscomp/test/key_word_property.js index 37ac9af4d9..be6b1e2451 100644 --- a/jscomp/test/key_word_property.js +++ b/jscomp/test/key_word_property.js @@ -52,7 +52,6 @@ function u(param) { var $$case = 3; -exports.$$default = $$default; exports.default = $$default; exports.__esModule = true; exports.default2 = default2; diff --git a/lib/es6/js_option.js b/lib/es6/js_option.js index 94caaa636f..b9e70f244a 100644 --- a/lib/es6/js_option.js +++ b/lib/es6/js_option.js @@ -96,7 +96,6 @@ export { andThen , map , getWithDefault , - $$default , $$default as default, filter , firstSome , diff --git a/lib/js/js_option.js b/lib/js/js_option.js index 692368fca5..1d61467206 100644 --- a/lib/js/js_option.js +++ b/lib/js/js_option.js @@ -95,7 +95,6 @@ exports.equal = equal; exports.andThen = andThen; exports.map = map; exports.getWithDefault = getWithDefault; -exports.$$default = $$default; exports.default = $$default; exports.__esModule = true; exports.filter = filter; From 7fad0d13ff64b023307cac25c9dc1ffd7c334fd9 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sun, 16 Jul 2023 12:25:47 +0200 Subject: [PATCH 2/3] handle that 2235default is now gone --- jscomp/core/js_dump.ml | 4 +++- jscomp/core/js_dump_import_export.mli | 2 ++ jscomp/test/es6_import.js | 2 +- jscomp/test/es6_import.mjs | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jscomp/core/js_dump.ml b/jscomp/core/js_dump.ml index 88082f8a31..48e7a6c4dd 100644 --- a/jscomp/core/js_dump.ml +++ b/jscomp/core/js_dump.ml @@ -500,7 +500,9 @@ and vident cxt f (v : J.vident) = | Qualified ({ id; kind = Ml | Runtime }, Some name) -> let cxt = Ext_pp_scope.ident cxt f id in P.string f L.dot; - P.string f (Ext_ident.convert name); + P.string f + (if name = Js_dump_import_export.default_export then name + else Ext_ident.convert name); cxt | Qualified ({ id; kind = External _ }, Some name) -> let cxt = Ext_pp_scope.ident cxt f id in diff --git a/jscomp/core/js_dump_import_export.mli b/jscomp/core/js_dump_import_export.mli index 2b9114ed8e..8fef82bd12 100644 --- a/jscomp/core/js_dump_import_export.mli +++ b/jscomp/core/js_dump_import_export.mli @@ -22,6 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +val default_export : string + val exports : Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t val es6_export : Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t diff --git a/jscomp/test/es6_import.js b/jscomp/test/es6_import.js index d0d1e8c55a..8af25c4b9f 100644 --- a/jscomp/test/es6_import.js +++ b/jscomp/test/es6_import.js @@ -3,6 +3,6 @@ var Es6_export = require("./es6_export.js"); -console.log(Es6_export.$$default); +console.log(Es6_export.default); /* Not a pure module */ diff --git a/jscomp/test/es6_import.mjs b/jscomp/test/es6_import.mjs index c66a104b2f..e6f57256d3 100644 --- a/jscomp/test/es6_import.mjs +++ b/jscomp/test/es6_import.mjs @@ -2,7 +2,7 @@ import * as Es6_export from "./es6_export.mjs"; -console.log(Es6_export.$$default); +console.log(Es6_export.default); export { From 099f058d841c10440326181a9afbd495db11cbd3 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Mon, 31 Jul 2023 11:50:19 +0200 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9db29e839..27de446739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ - GenType: Propagate comments from record fields to emitted TypeScript types. https://github.com/rescript-lang/rescript-compiler/pull/6333 +#### :boom: Breaking Change + +- `$$default` is no longer exported from the generated JavaScript when using default exports. https://github.com/rescript-lang/rescript-compiler/pull/6328 + # 11.0.0-beta.4 #### :rocket: New Feature