Skip to content

Commit 6fd1e73

Browse files
authored
Deprecated es6 and es6-global in favor of esmodule (#6709)
* deprecated es6 and es6-global in favor of esmodule * fix gentype * fix playground * migrate legecy options in tests * add changelog * maybe..?
1 parent 1df3b23 commit 6fd1e73

27 files changed

+100
-59
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
- Fix trailing undefined for optional parameters not omitted with `@send` and `@new`. https://github.com/rescript-lang/rescript-compiler/pull/6716
2424
- Fix JSX4 adding the incorrect type annotation for the prop `ref` in React.forwardRef component https://github.com/rescript-lang/rescript-compiler/pull/6718
2525

26+
#### :nail_care: Polish
27+
28+
- Module spec `es6` and `es6-global` is deprecated in favor of `esmodule`. https://github.com/rescript-lang/rescript-compiler/pull/6709
29+
2630
# 11.1.0-rc.7
2731

2832
#### :bug: Bug Fix

docs/docson/build-schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"$schema": "http://json-schema.org/draft-04/schema#",
33
"definitions": {
44
"module-format": {
5-
"enum": ["commonjs", "es6", "es6-global"],
6-
"description": "es6-global generate relative `require` paths instead of relying on NodeJS' module resolution. Default: commonjs."
5+
"enum": ["esmodule", "commonjs", "es6", "es6-global"],
6+
"description": "es6 and es6-global are deprecated. Default: commonjs."
77
},
88
"suffix-spec": {
99
"type": "string",

jscomp/bsb/bsb_config.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ let rev_lib_bs = ".." // ".."
4141

4242
(* access the js directory from "lib/bs",
4343
it would be '../js'
44+
45+
TODO: should be renamed, js -> cjs, es6 -> mjs in v12
4446
*)
4547
let lib_bs_prefix_of_format (x : Ext_module_system.t) =
4648
".."
47-
// match x with NodeJS -> "js" | Es6 -> "es6" | Es6_global -> "es6_global"
49+
// match x with Commonjs -> "js" | Esmodule -> "es6" | Es6_global -> "es6_global"
4850

4951
(* lib/js, lib/es6, lib/es6_global *)
5052
let top_prefix_of_format (x : Ext_module_system.t) =
5153
match x with
52-
| NodeJS -> lib_js
53-
| Es6 -> lib_es6
54+
| Commonjs -> lib_js
55+
| Esmodule -> lib_es6
5456
| Es6_global -> lib_es6_global
5557

5658
let rev_lib_bs_prefix p = rev_lib_bs // p

jscomp/bsb/bsb_config.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ val lib_js : string
3333
val lib_bs : string
3434

3535
val lib_es6 : string
36+
[@@ocaml.deprecated "will be removed in v12"]
3637

3738
val lib_es6_global : string
39+
[@@ocaml.deprecated "will be removed in v12"]
3840

3941
val lib_ocaml : string
4042

jscomp/bsb/bsb_package_specs.ml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,29 @@ let ( .?() ) = Map_string.find_opt
4040
let bad_module_format_message_exn ~loc format =
4141
Bsb_exception.errorf ~loc
4242
"package-specs: `%s` isn't a valid output module format. It has to be one \
43-
of: %s, %s or %s"
44-
format Literals.commonjs Literals.es6 Literals.es6_global
43+
of: %s or %s"
44+
format Literals.esmodule Literals.commonjs
4545

4646
let supported_format (x : string) loc : Ext_module_system.t =
47-
if x = Literals.commonjs then NodeJS
48-
else if x = Literals.es6 then Es6
47+
let _ =
48+
if x = Literals.es6 || x = Literals.es6_global then
49+
let loc_end =
50+
{loc with Lexing.pos_cnum = loc.Lexing.pos_cnum + String.length x}
51+
in
52+
let loc = {Warnings.loc_start = loc; loc_end; loc_ghost = false} in
53+
Location.deprecated loc
54+
(Printf.sprintf "Option \"%s\" is deprecated. Use \"%s\" instead." x
55+
Literals.esmodule)
56+
in
57+
if x = Literals.es6 || x = Literals.esmodule then Esmodule
58+
else if x = Literals.commonjs then Commonjs
4959
else if x = Literals.es6_global then Es6_global
5060
else bad_module_format_message_exn ~loc x
5161

5262
let string_of_format (x : Ext_module_system.t) =
5363
match x with
54-
| NodeJS -> Literals.commonjs
55-
| Es6 -> Literals.es6
64+
| Commonjs -> Literals.commonjs
65+
| Esmodule -> Literals.esmodule
5666
| Es6_global -> Literals.es6_global
5767

5868
let js_suffix_regexp = Str.regexp "[A-Za-z0-9-_.]*\\.[cm]?js"
@@ -158,7 +168,8 @@ let package_flag_of_package_specs (package_specs : t) ~(dirname : string) :
158168
| Some x -> Ext_string.inter3 res "-runtime" x
159169

160170
let default_package_specs suffix =
161-
Spec_set.singleton { format = NodeJS; in_source = false; suffix }
171+
(* TODO: swap default to Esmodule in v12 *)
172+
Spec_set.singleton { format = Commonjs; in_source = false; suffix }
162173

163174
(**
164175
[get_list_of_output_js specs "src/hi/hello"]

jscomp/bsb/bsb_spec_set.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
[@@@warning "+9"]
2626

2727
(* TODO: sync up with {!Js_packages_info.module_system} *)
28-
type format = Ext_module_system.t = NodeJS | Es6 | Es6_global
28+
type format = Ext_module_system.t
2929

3030
type spec = { format : format; in_source : bool; suffix : string }
3131

jscomp/build_tests/cycle1/rescript.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"subdirs": true
88
},
99
"package-specs": {
10-
"module": "es6",
10+
"module": "esmodule",
1111
"in-source": true
1212
},
1313
"suffix": ".bs.js"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const child_process = require("child_process");
2+
const assert = require("assert");
3+
const rescript_exe = require("../../../scripts/bin_path").rescript_exe;
4+
5+
const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" });
6+
assert.match(
7+
out.stderr,
8+
/deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./
9+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "deprecated-package-specs",
3+
"version": "0.1.0",
4+
"sources": "src",
5+
"package-specs": {
6+
"module": "es6-global"
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let () = Js.log("Hello, ReScript")

0 commit comments

Comments
 (0)