Skip to content

Commit 8a6a10c

Browse files
committed
deprecated es6 and es6-global in favor of esmodule
1 parent 1ec144b commit 8a6a10c

17 files changed

+74
-37
lines changed

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 -> esm 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

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")

jscomp/core/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
77
(flags
88
(:standard -w +a-4-9-27-30-40-41-42-48-70))
9-
(libraries depends frontend gentype js_parser))
9+
(libraries depends ext frontend gentype js_parser))

jscomp/core/js_dump_program.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ let node_program ~output_dir f (x : J.deps_program) =
7979
| true -> None
8080
| false ->
8181
Some ( x.id,
82-
Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS,
82+
Js_name_of_module_id.string_of_module_id x ~output_dir Commonjs,
8383
is_default x.kind )))
8484
in
8585
program f cxt x.program
@@ -129,8 +129,8 @@ let pp_deps_program ~(output_prefix : string)
129129
let output_dir = Filename.dirname output_prefix in
130130
ignore
131131
(match kind with
132-
| Es6 | Es6_global -> es6_program ~output_dir kind f program
133-
| NodeJS -> node_program ~output_dir f program);
132+
| Esmodule | Es6_global -> es6_program ~output_dir kind f program
133+
| Commonjs -> node_program ~output_dir f program);
134134
P.newline f;
135135
P.string f
136136
(match program.side_effect with

jscomp/core/js_name_of_module_id.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ let get_runtime_module_path
7777
*)
7878
else
7979
match module_system with
80-
| NodeJS | Es6 ->
80+
| Commonjs | Esmodule ->
8181
Js_packages_info.runtime_package_path module_system js_file
8282
(* Note we did a post-processing when working on Windows *)
8383
| Es6_global
@@ -164,7 +164,7 @@ let string_of_module_id
164164
get_runtime_module_path dep_module_id current_package_info module_system
165165
else
166166
begin match module_system with
167-
| NodeJS | Es6 ->
167+
| Commonjs | Esmodule ->
168168
dep_pkg.pkg_rel_path // js_file
169169
(* Note we did a post-processing when working on Windows *)
170170
| Es6_global
@@ -200,4 +200,4 @@ let string_of_module_id
200200
| None ->
201201
Bs_exception.error (Js_not_found js_file))
202202

203-
#endif
203+
#endif

jscomp/core/js_packages_info.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
[@@@warning "+9"]
2626

27-
type module_system = NodeJS | Es6 | Es6_global
27+
type module_system = Ext_module_system.t
2828
(* ignore node_modules, just calcluating relative path *)
2929

3030
(* ocamlopt could not optimize such simple case..*)
3131
let compatible (dep : module_system) (query : module_system) =
3232
match query with
33-
| NodeJS -> dep = NodeJS
34-
| Es6 -> dep = Es6
35-
| Es6_global -> dep = Es6_global || dep = Es6
33+
| Commonjs -> dep = Commonjs
34+
| Esmodule -> dep = Esmodule
35+
| Es6_global -> dep = Es6_global || dep = Esmodule
3636
(* As a dependency Leaf Node, it is the same either [global] or [not] *)
3737

3838
type package_info = {
@@ -47,7 +47,7 @@ let ( // ) = Filename.concat
4747

4848
(* in runtime lib, [es6] and [es6] are treated the same wway *)
4949
let runtime_dir_of_module_system (ms : module_system) =
50-
match ms with NodeJS -> "js" | Es6 | Es6_global -> "es6"
50+
match ms with Commonjs -> "js" | Esmodule | Es6_global -> "es6"
5151

5252
let runtime_package_path (ms : module_system) js_file =
5353
!Bs_version.package_name // "lib"
@@ -61,8 +61,8 @@ let runtime_package_specs : t =
6161
name = Pkg_runtime;
6262
module_systems =
6363
[
64-
{ module_system = Es6; path = "lib/es6"; suffix = Literals.suffix_js };
65-
{ module_system = NodeJS; path = "lib/js"; suffix = Literals.suffix_js };
64+
{ module_system = Esmodule; path = "lib/es6"; suffix = Literals.suffix_js };
65+
{ module_system = Commonjs; path = "lib/js"; suffix = Literals.suffix_js };
6666
];
6767
}
6868

@@ -107,12 +107,12 @@ let from_name (name : string) : t =
107107
let is_empty (x : t) = x.name = Pkg_empty
108108

109109
let string_of_module_system (ms : module_system) =
110-
match ms with NodeJS -> "NodeJS" | Es6 -> "Es6" | Es6_global -> "Es6_global"
110+
match ms with Commonjs -> "CommonJS" | Esmodule -> "ESModule" | Es6_global -> "Es6_global"
111111

112112
let module_system_of_string package_name : module_system option =
113113
match package_name with
114-
| "commonjs" -> Some NodeJS
115-
| "es6" -> Some Es6
114+
| "commonjs" -> Some Commonjs
115+
| "esmodule" | "es6" -> Some Esmodule
116116
| "es6-global" -> Some Es6_global
117117
| _ -> None
118118

@@ -201,7 +201,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
201201
in
202202
let m =
203203
match Ext_string.split ~keep_empty:true s ':' with
204-
| [ path ] -> { module_system = NodeJS; path; suffix = Literals.suffix_js }
204+
| [ path ] -> { module_system = Esmodule; path; suffix = Literals.suffix_js }
205205
| [ module_system; path ] ->
206206
{
207207
module_system = handle_module_system module_system;

jscomp/core/js_packages_info.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
type module_system = NodeJS | Es6 | Es6_global
25+
type module_system = Ext_module_system.t
2626

2727
val runtime_dir_of_module_system : module_system -> string
2828

jscomp/core/lam_compile_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ let lambda_as_module
292292
: unit =
293293
let package_info = Js_packages_state.get_packages_info () in
294294
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
295-
Js_dump_program.dump_deps_program ~output_prefix NodeJS (lambda_output) stdout
295+
Js_dump_program.dump_deps_program ~output_prefix Commonjs (lambda_output) stdout
296296
end else
297297
Js_packages_info.iter package_info (fun {module_system; path; suffix} ->
298298
let output_chan chan =

jscomp/core/lam_compile_primitive.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ let get_module_system () =
4444
let package_info = Js_packages_state.get_packages_info () in
4545
let module_system =
4646
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then
47-
[Js_packages_info.NodeJS]
47+
[Ext_module_system.Commonjs]
4848
else Js_packages_info.map package_info (fun {module_system} -> module_system)
4949
in
5050
match module_system with
5151
| [module_system] -> module_system
52-
| _ -> NodeJS
52+
| _ -> Commonjs
5353

5454
let import_of_path path =
5555
E.call

jscomp/ext/ext_module_system.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type t = NodeJS | Es6 | Es6_global
1+
type t = Commonjs | Esmodule | Es6_global

jscomp/ext/literals.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ let suffix_gen_js = ".gen.js"
125125

126126
let suffix_gen_tsx = ".gen.tsx"
127127

128+
let esmodule = "esmodule"
129+
128130
let commonjs = "commonjs"
129131

130132
let es6 = "es6"
133+
[@@ocaml.deprecated "Will be removed in v12"]
131134

132135
let es6_global = "es6-global"
136+
[@@ocaml.deprecated "Will be removed in v12"]
133137

134138
let unused_attribute = "Unused attribute "
135139

jscomp/runtime/release.ninja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ o runtime/caml_exceptions.cmj : cc_cmi runtime/caml_exceptions.res | runtime/cam
2525
o runtime/caml_exceptions.cmi : cc runtime/caml_exceptions.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
2626
o runtime/caml_float.cmj : cc_cmi runtime/caml_float.res | runtime/caml_float.cmi runtime/caml_float_extern.cmj
2727
o runtime/caml_float.cmi : cc runtime/caml_float.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
28-
o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
28+
o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
2929
o runtime/caml_format.cmi : cc runtime/caml_format.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3030
o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj runtime/js.cmj
3131
o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
@@ -41,7 +41,7 @@ o runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.res | runtime/caml_array_extern
4141
o runtime/caml_md5.cmi : cc runtime/caml_md5.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4242
o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj
4343
o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
44-
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj
44+
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml.cmj runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj
4545
o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4646
o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj runtime/js.cmj
4747
o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
@@ -58,7 +58,7 @@ o runtime/caml_bigint_extern.cmi runtime/caml_bigint_extern.cmj : cc runtime/cam
5858
o runtime/caml_external_polyfill.cmi runtime/caml_external_polyfill.cmj : cc runtime/caml_external_polyfill.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
5959
o runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6060
o runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
61-
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/js.cmi runtime/js.cmj
61+
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj
6262
o runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6363
o runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6464
o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj

0 commit comments

Comments
 (0)