Skip to content
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@

- 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

# 11.1.0-rc.8

#### :rocket: New Feature

- Add `%todo` extension for leaving implementation for later. https://github.com/rescript-lang/rescript-compiler/pull/6713
- Add `-warn-error` argument for generating errors in CI. Useful for `%todo` extension. https://github.com/rescript-lang/rescript-compiler/pull/6717

#### :bug: Bug Fix

- Improve error when using `@deriving(accessors)` on a variant with record arguments. https://github.com/rescript-lang/rescript-compiler/pull/6712
- Stop escaping JSX prop names with hyphens. https://github.com/rescript-lang/rescript-compiler/pull/6705
- Fix trailing undefined for optional parameters not omitted with `@send` and `@new`. https://github.com/rescript-lang/rescript-compiler/pull/6716
- Fix JSX4 adding the incorrect type annotation for the prop `ref` in `React.forwardRef` component. https://github.com/rescript-lang/rescript-compiler/pull/6718
- Fix description for warning number 110. https://github.com/rescript-lang/rescript-compiler/pull/6725

#### :nail_care: Polish

- Module spec `es6` and `es6-global` is deprecated in favor of `esmodule`. https://github.com/rescript-lang/rescript-compiler/pull/6709

# 11.1.0-rc.7

#### :bug: Bug Fix
Expand Down
4 changes: 2 additions & 2 deletions docs/docson/build-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"module-format": {
"enum": ["commonjs", "es6", "es6-global"],
"description": "es6-global generate relative `require` paths instead of relying on NodeJS' module resolution. Default: commonjs."
"enum": ["esmodule", "commonjs", "es6", "es6-global"],
"description": "es6 and es6-global are deprecated. Default: commonjs."
},
"suffix-spec": {
"type": "string",
Expand Down
8 changes: 5 additions & 3 deletions jscomp/bsb/bsb_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ let rev_lib_bs = ".." // ".."

(* access the js directory from "lib/bs",
it would be '../js'

TODO: should be renamed, js -> cjs, es6 -> mjs in v12
*)
let lib_bs_prefix_of_format (x : Ext_module_system.t) =
".."
// match x with NodeJS -> "js" | Es6 -> "es6" | Es6_global -> "es6_global"
// match x with Commonjs -> "js" | Esmodule -> "es6" | Es6_global -> "es6_global"

(* lib/js, lib/es6, lib/es6_global *)
let top_prefix_of_format (x : Ext_module_system.t) =
match x with
| NodeJS -> lib_js
| Es6 -> lib_es6
| Commonjs -> lib_js
| Esmodule -> lib_es6
| Es6_global -> lib_es6_global

let rev_lib_bs_prefix p = rev_lib_bs // p
Expand Down
2 changes: 2 additions & 0 deletions jscomp/bsb/bsb_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ val lib_js : string
val lib_bs : string

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

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

val lib_ocaml : string

Expand Down
19 changes: 18 additions & 1 deletion jscomp/bsb/bsb_ninja_regen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let ( // ) = Ext_path.combine
return None if we dont need regenerate
otherwise return Some info
*)
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config ~warn_as_error
: Bsb_config_types.t option =
let lib_artifacts_dir = Bsb_config.lib_bs in
let lib_bs_dir = per_proj_dir // lib_artifacts_dir in
Expand Down Expand Up @@ -58,6 +58,23 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
Bsb_config_parse.interpret_json
~filename:config_filename ~json:config_json ~package_kind ~per_proj_dir
in

let warning = match config.warning with
| None -> (
match warn_as_error with
| Some e -> Some {Bsb_warning.number = Some e; error = Warn_error_number e}
| None -> None)
| Some {error} as t ->
match (warn_as_error, error) with
| (Some error_str, Warn_error_false) ->
Some {number = Some error_str; error = Warn_error_number error_str}
| (Some error_str, Warn_error_number prev) ->
let new_error = prev ^ error_str in
Some {number = Some new_error; error = Warn_error_number new_error}
| _ -> t
in

let config = {config with warning = warning} in
(* create directory, lib/bs, lib/js, lib/es6 etc *)
Bsb_build_util.mkp lib_bs_dir;
Bsb_package_specs.list_dirs_by config.package_specs (fun x ->
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_ninja_regen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ val regenerate_ninja :
forced:bool ->
per_proj_dir:string ->
warn_legacy_config:bool ->
warn_as_error:string option ->
Bsb_config_types.t option
(** Regenerate ninja file by need based on [.bsdeps]
return None if we dont need regenerate
Expand Down
25 changes: 18 additions & 7 deletions jscomp/bsb/bsb_package_specs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,29 @@ let ( .?() ) = Map_string.find_opt
let bad_module_format_message_exn ~loc format =
Bsb_exception.errorf ~loc
"package-specs: `%s` isn't a valid output module format. It has to be one \
of: %s, %s or %s"
format Literals.commonjs Literals.es6 Literals.es6_global
of: %s or %s"
format Literals.esmodule Literals.commonjs

let supported_format (x : string) loc : Ext_module_system.t =
if x = Literals.commonjs then NodeJS
else if x = Literals.es6 then Es6
let _ =
if x = Literals.es6 || x = Literals.es6_global then
let loc_end =
{loc with Lexing.pos_cnum = loc.Lexing.pos_cnum + String.length x}
in
let loc = {Warnings.loc_start = loc; loc_end; loc_ghost = false} in
Location.deprecated loc
(Printf.sprintf "Option \"%s\" is deprecated. Use \"%s\" instead." x
Literals.esmodule)
in
if x = Literals.es6 || x = Literals.esmodule then Esmodule
else if x = Literals.commonjs then Commonjs
else if x = Literals.es6_global then Es6_global
else bad_module_format_message_exn ~loc x

let string_of_format (x : Ext_module_system.t) =
match x with
| NodeJS -> Literals.commonjs
| Es6 -> Literals.es6
| Commonjs -> Literals.commonjs
| Esmodule -> Literals.esmodule
| Es6_global -> Literals.es6_global

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

let default_package_specs suffix =
Spec_set.singleton { format = NodeJS; in_source = false; suffix }
(* TODO: swap default to Esmodule in v12 *)
Spec_set.singleton { format = Commonjs; in_source = false; suffix }

(**
[get_list_of_output_js specs "src/hi/hello"]
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_spec_set.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[@@@warning "+9"]

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

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

Expand Down
11 changes: 10 additions & 1 deletion jscomp/bsb/bsb_warning.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

type t
type warning_error =
| Warn_error_false
(* default [false] to make our changes non-intrusive *)
| Warn_error_true
| Warn_error_number of string

type t0 = { number : string option; error : warning_error }

type nonrec t = t0 option


val to_merlin_string : t -> string
(** Extra work is need to make merlin happy *)
Expand Down
3 changes: 2 additions & 1 deletion jscomp/bsb/bsb_world.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let ( // ) = Ext_path.combine
let vendor_ninja = Bsb_global_paths.vendor_ninja

let make_world_deps cwd (config : Bsb_config_types.t option)
(ninja_args : string array) =
(ninja_args : string array) warn_as_error =
let package_specs, jsx, uncurried, pinned_dependencies =
match config with
| None ->
Expand Down Expand Up @@ -71,6 +71,7 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
else Dependency { package_specs; jsx; uncurried })
~per_proj_dir:proj_dir ~forced:false
~warn_legacy_config:false
~warn_as_error:(if is_pinned then warn_as_error else None)
in
let command =
{ Bsb_unix.cmd = vendor_ninja; cwd = lib_bs_dir; args }
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_world.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val make_world_deps :
string -> Bsb_config_types.t option -> string array -> unit
string -> Bsb_config_types.t option -> string array -> string option -> unit
17 changes: 15 additions & 2 deletions jscomp/bsb_exe/rescript_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ let no_deps_mode = ref false

let do_install = ref false

let warning_as_error = ref None

let force_regenerate = ref false

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

let string_set_spec s : spec = String (String_set s)

let string_call f: spec = String (String_call f)

let failed_annon ~rev_args =
match rev_args with
| x :: _ -> Bsb_arg.bad_arg ("Don't know what to do with " ^ x)
Expand Down Expand Up @@ -132,6 +136,7 @@ let build_subcommand ~start argv argv_len =
Always regenerate build.ninja no matter bsconfig.json is changed or \
not" );
("-no-deps", unit_set_spec no_deps_mode, "*internal* Needed for watcher to build without dependencies on file change");
("-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\"")
|]
failed_annon;

Expand All @@ -141,14 +146,20 @@ let build_subcommand ~start argv argv_len =
match ninja_args with
| [| "-h" |] -> ninja_command_exit ninja_args
| _ ->
let warn_as_error = match !warning_as_error with
| Some s ->
let () = try Warnings.parse_options true s with Arg.Bad msg -> Bsb_arg.bad_arg (msg ^ "\n") in
Some s
| None -> None in
let config_opt =
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~per_proj_dir:Bsb_global_paths.cwd
~forced:!force_regenerate
~warn_legacy_config:true
~warn_as_error
in
if not !no_deps_mode then Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
if not !no_deps_mode then Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args warn_as_error;
if !do_install then install_target ();
ninja_command_exit ninja_args

Expand Down Expand Up @@ -180,6 +191,7 @@ let info_subcommand ~start argv =
~per_proj_dir:Bsb_global_paths.cwd
~forced:true
~warn_legacy_config:true
~warn_as_error:None
with
| None -> assert false
| Some { file_groups = { files } } ->
Expand Down Expand Up @@ -210,8 +222,9 @@ let () =
~per_proj_dir:Bsb_global_paths.cwd
~forced:false
~warn_legacy_config:true
~warn_as_error:None
in
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||] None;
ninja_command_exit [||])
else
match argv.(1) with
Expand Down
17 changes: 17 additions & 0 deletions jscomp/build_tests/build_warn_as_error/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var p = require("child_process");
var assert = require("assert");
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;

var o = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], {
encoding: "utf8",
cwd: __dirname,
});

var error_message = o.stdout
.split("\n")
.map(s => s.trim())
.includes("Warning number 110 (configured as error)");

if (!error_message) {
assert.fail(o.stdout);
}
5 changes: 5 additions & 0 deletions jscomp/build_tests/build_warn_as_error/rescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "build_warn_as_error",
"version": "0.1.0",
"sources": ["src"]
}
1 change: 1 addition & 0 deletions jscomp/build_tests/build_warn_as_error/src/Demo.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let todo = _ => %todo
9 changes: 5 additions & 4 deletions jscomp/build_tests/cli_help/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ const buildHelp =
"`rescript build -- -h` for Ninja options (internal usage only; unstable)\n" +
"\n" +
"Options:\n" +
" -w Watch mode\n" +
" -ws [host]:port set up host & port for WebSocket build notifications\n" +
" -verbose Set the output to be verbose\n" +
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n";
" -w Watch mode\n" +
" -ws [host]:port set up host & port for WebSocket build notifications\n" +
" -verbose Set the output to be verbose\n" +
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n" +
' -warn-error Warning numbers and whether to turn them into errors, e.g., "+8+32-102"\n';

const cleanHelp =
"Usage: rescript clean <options>\n" +
Expand Down
2 changes: 1 addition & 1 deletion jscomp/build_tests/cycle1/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"subdirs": true
},
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".bs.js"
Expand Down
9 changes: 9 additions & 0 deletions jscomp/build_tests/deprecated-package-specs/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const child_process = require("child_process");
const assert = require("assert");
const rescript_exe = require("../../../scripts/bin_path").rescript_exe;

const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" });
assert.match(
out.stderr,
/deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./
);
8 changes: 8 additions & 0 deletions jscomp/build_tests/deprecated-package-specs/rescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "deprecated-package-specs",
"version": "0.1.0",
"sources": "src",
"package-specs": {
"module": "es6-global"
}
}
1 change: 1 addition & 0 deletions jscomp/build_tests/deprecated-package-specs/src/Index.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = Js.log("Hello, ReScript")
2 changes: 1 addition & 1 deletion jscomp/build_tests/in_source/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"in-source": true
},
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

We've found a bug for you!
/.../fixtures/DerivingAccessorsRecordParam.res:2:10-25

1 │ @deriving(accessors)
2 │ type t = Struct({a: int})
3 │

@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 number Diff line number Diff line change
@@ -0,0 +1,11 @@

Warning number 110
/.../fixtures/todo_with_no_payload.res:1:38-42

1 │ let implementMeLater = (): string => %todo
2 │
3 │ let x = implementMeLater()

Todo found.

This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

Warning number 110
/.../fixtures/todo_with_payload.res:1:38-85

1 │ let implementMeLater = (): string => %todo("This should return a string 
│ eventually.")
2 │
3 │ let x = implementMeLater()

Todo found: This should return a string eventually.

This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@deriving(accessors)
type t = Struct({a: int})
Loading