Skip to content

Commit e33c17f

Browse files
committed
Merge branch '11.0_release' into 11-to-master
# Conflicts: # CHANGELOG.md # jscomp/common/bs_version.ml # package-lock.json # package.json # packages/std/package.json
2 parents 2858ed7 + dc2518a commit e33c17f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+560
-107
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727

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

30+
# 11.1.0-rc.8
31+
32+
#### :rocket: New Feature
33+
34+
- Add `%todo` extension for leaving implementation for later. https://github.com/rescript-lang/rescript-compiler/pull/6713
35+
- Add `-warn-error` argument for generating errors in CI. Useful for `%todo` extension. https://github.com/rescript-lang/rescript-compiler/pull/6717
36+
37+
#### :bug: Bug Fix
38+
39+
- Improve error when using `@deriving(accessors)` on a variant with record arguments. https://github.com/rescript-lang/rescript-compiler/pull/6712
40+
- Stop escaping JSX prop names with hyphens. https://github.com/rescript-lang/rescript-compiler/pull/6705
41+
- Fix trailing undefined for optional parameters not omitted with `@send` and `@new`. https://github.com/rescript-lang/rescript-compiler/pull/6716
42+
- Fix JSX4 adding the incorrect type annotation for the prop `ref` in `React.forwardRef` component. https://github.com/rescript-lang/rescript-compiler/pull/6718
43+
- Fix description for warning number 110. https://github.com/rescript-lang/rescript-compiler/pull/6725
44+
45+
#### :nail_care: Polish
46+
47+
- Module spec `es6` and `es6-global` is deprecated in favor of `esmodule`. https://github.com/rescript-lang/rescript-compiler/pull/6709
48+
3049
# 11.1.0-rc.7
3150

3251
#### :bug: Bug Fix

docs/docson/build-schema.json

+2-2
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

+5-3
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

+2
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_ninja_regen.ml

+18-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let ( // ) = Ext_path.combine
3030
return None if we dont need regenerate
3131
otherwise return Some info
3232
*)
33-
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config
33+
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config ~warn_as_error
3434
: Bsb_config_types.t option =
3535
let lib_artifacts_dir = Bsb_config.lib_bs in
3636
let lib_bs_dir = per_proj_dir // lib_artifacts_dir in
@@ -58,6 +58,23 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
5858
Bsb_config_parse.interpret_json
5959
~filename:config_filename ~json:config_json ~package_kind ~per_proj_dir
6060
in
61+
62+
let warning = match config.warning with
63+
| None -> (
64+
match warn_as_error with
65+
| Some e -> Some {Bsb_warning.number = Some e; error = Warn_error_number e}
66+
| None -> None)
67+
| Some {error} as t ->
68+
match (warn_as_error, error) with
69+
| (Some error_str, Warn_error_false) ->
70+
Some {number = Some error_str; error = Warn_error_number error_str}
71+
| (Some error_str, Warn_error_number prev) ->
72+
let new_error = prev ^ error_str in
73+
Some {number = Some new_error; error = Warn_error_number new_error}
74+
| _ -> t
75+
in
76+
77+
let config = {config with warning = warning} in
6178
(* create directory, lib/bs, lib/js, lib/es6 etc *)
6279
Bsb_build_util.mkp lib_bs_dir;
6380
Bsb_package_specs.list_dirs_by config.package_specs (fun x ->

jscomp/bsb/bsb_ninja_regen.mli

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ val regenerate_ninja :
2727
forced:bool ->
2828
per_proj_dir:string ->
2929
warn_legacy_config:bool ->
30+
warn_as_error:string option ->
3031
Bsb_config_types.t option
3132
(** Regenerate ninja file by need based on [.bsdeps]
3233
return None if we dont need regenerate

jscomp/bsb/bsb_package_specs.ml

+18-7
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

+1-1
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/bsb/bsb_warning.mli

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
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 t
25+
type warning_error =
26+
| Warn_error_false
27+
(* default [false] to make our changes non-intrusive *)
28+
| Warn_error_true
29+
| Warn_error_number of string
30+
31+
type t0 = { number : string option; error : warning_error }
32+
33+
type nonrec t = t0 option
34+
2635

2736
val to_merlin_string : t -> string
2837
(** Extra work is need to make merlin happy *)

jscomp/bsb/bsb_world.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let ( // ) = Ext_path.combine
2626
let vendor_ninja = Bsb_global_paths.vendor_ninja
2727

2828
let make_world_deps cwd (config : Bsb_config_types.t option)
29-
(ninja_args : string array) =
29+
(ninja_args : string array) warn_as_error =
3030
let package_specs, jsx, uncurried, pinned_dependencies =
3131
match config with
3232
| None ->
@@ -71,6 +71,7 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
7171
else Dependency { package_specs; jsx; uncurried })
7272
~per_proj_dir:proj_dir ~forced:false
7373
~warn_legacy_config:false
74+
~warn_as_error:(if is_pinned then warn_as_error else None)
7475
in
7576
let command =
7677
{ Bsb_unix.cmd = vendor_ninja; cwd = lib_bs_dir; args }

jscomp/bsb/bsb_world.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
val make_world_deps :
26-
string -> Bsb_config_types.t option -> string array -> unit
26+
string -> Bsb_config_types.t option -> string array -> string option -> unit

jscomp/bsb_exe/rescript_main.ml

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ let no_deps_mode = ref false
3030

3131
let do_install = ref false
3232

33+
let warning_as_error = ref None
34+
3335
let force_regenerate = ref false
3436

3537
type spec = Bsb_arg.spec
@@ -40,6 +42,8 @@ let unit_set_spec b : spec = Unit (Unit_set b)
4042

4143
let string_set_spec s : spec = String (String_set s)
4244

45+
let string_call f: spec = String (String_call f)
46+
4347
let failed_annon ~rev_args =
4448
match rev_args with
4549
| x :: _ -> Bsb_arg.bad_arg ("Don't know what to do with " ^ x)
@@ -132,6 +136,7 @@ let build_subcommand ~start argv argv_len =
132136
Always regenerate build.ninja no matter bsconfig.json is changed or \
133137
not" );
134138
("-no-deps", unit_set_spec no_deps_mode, "*internal* Needed for watcher to build without dependencies on file change");
139+
("-warn-error", string_call (fun s -> warning_as_error := Some s), "Warning numbers and whether to turn them into errors, e.g., \"+8+32-102\"")
135140
|]
136141
failed_annon;
137142

@@ -141,14 +146,20 @@ let build_subcommand ~start argv argv_len =
141146
match ninja_args with
142147
| [| "-h" |] -> ninja_command_exit ninja_args
143148
| _ ->
149+
let warn_as_error = match !warning_as_error with
150+
| Some s ->
151+
let () = try Warnings.parse_options true s with Arg.Bad msg -> Bsb_arg.bad_arg (msg ^ "\n") in
152+
Some s
153+
| None -> None in
144154
let config_opt =
145155
Bsb_ninja_regen.regenerate_ninja
146156
~package_kind:Toplevel
147157
~per_proj_dir:Bsb_global_paths.cwd
148158
~forced:!force_regenerate
149159
~warn_legacy_config:true
160+
~warn_as_error
150161
in
151-
if not !no_deps_mode then Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
162+
if not !no_deps_mode then Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args warn_as_error;
152163
if !do_install then install_target ();
153164
ninja_command_exit ninja_args
154165

@@ -180,6 +191,7 @@ let info_subcommand ~start argv =
180191
~per_proj_dir:Bsb_global_paths.cwd
181192
~forced:true
182193
~warn_legacy_config:true
194+
~warn_as_error:None
183195
with
184196
| None -> assert false
185197
| Some { file_groups = { files } } ->
@@ -210,8 +222,9 @@ let () =
210222
~per_proj_dir:Bsb_global_paths.cwd
211223
~forced:false
212224
~warn_legacy_config:true
225+
~warn_as_error:None
213226
in
214-
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
227+
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||] None;
215228
ninja_command_exit [||])
216229
else
217230
match argv.(1) with
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var p = require("child_process");
2+
var assert = require("assert");
3+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
4+
5+
var o = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], {
6+
encoding: "utf8",
7+
cwd: __dirname,
8+
});
9+
10+
var error_message = o.stdout
11+
.split("\n")
12+
.map(s => s.trim())
13+
.includes("Warning number 110 (configured as error)");
14+
15+
if (!error_message) {
16+
assert.fail(o.stdout);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "build_warn_as_error",
3+
"version": "0.1.0",
4+
"sources": ["src"]
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let todo = _ => %todo

jscomp/build_tests/cli_help/input.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ const buildHelp =
3232
"`rescript build -- -h` for Ninja options (internal usage only; unstable)\n" +
3333
"\n" +
3434
"Options:\n" +
35-
" -w Watch mode\n" +
36-
" -ws [host]:port set up host & port for WebSocket build notifications\n" +
37-
" -verbose Set the output to be verbose\n" +
38-
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n";
35+
" -w Watch mode\n" +
36+
" -ws [host]:port set up host & port for WebSocket build notifications\n" +
37+
" -verbose Set the output to be verbose\n" +
38+
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n" +
39+
' -warn-error Warning numbers and whether to turn them into errors, e.g., "+8+32-102"\n';
3940

4041
const cleanHelp =
4142
"Usage: rescript clean <options>\n" +

jscomp/build_tests/cycle1/rescript.json

+1-1
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"
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+
);
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let () = Js.log("Hello, ReScript")

jscomp/build_tests/in_source/rescript.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"in-source": true
88
},
99
{
10-
"module": "es6",
10+
"module": "esmodule",
1111
"in-source": true
1212
}
1313
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/DerivingAccessorsRecordParam.res:2:10-25
4+
5+
1 │ @deriving(accessors)
6+
2 │ type t = Struct({a: int})
7+
3 │
8+
9+
@deriving(accessors) from a variant record argument is unsupported. Either define the record type separately from the variant type or use a positional argument.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
Warning number 110
3+
/.../fixtures/todo_with_no_payload.res:1:38-42
4+
5+
1 │ let implementMeLater = (): string => %todo
6+
2 │
7+
3 │ let x = implementMeLater()
8+
9+
Todo found.
10+
11+
This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
Warning number 110
3+
/.../fixtures/todo_with_payload.res:1:38-85
4+
5+
1 │ let implementMeLater = (): string => %todo("This should return a string 
6+
│ eventually.")
7+
2 │
8+
3 │ let x = implementMeLater()
9+
10+
Todo found: This should return a string eventually.
11+
12+
This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@deriving(accessors)
2+
type t = Struct({a: int})

0 commit comments

Comments
 (0)