Skip to content

make bsb the source of truth for error/warning reporting #4650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions jscomp/bsb/bsb_templates.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ let root = OCamlRes.Res.([
\ \"suffix\": \".bs.js\",\n\
\ \"bs-dependencies\": [\n\
\ ],\n\
\ \"warnings\": {\n\
\ \"error\" : \"+101\"\n\
\ },\n\
\ \"refmt\": 3\n\
}\n\
") ;
Expand Down
49 changes: 10 additions & 39 deletions jscomp/bsb/bsb_warning.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)


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
}
number : string option;
} [@@ocaml.unboxed]

type nonrec t = t0 option

Expand Down Expand Up @@ -70,27 +64,13 @@ let to_merlin_string x =

let from_map (m : Ext_json_types.t Map_string.t) =
let number_opt = Map_string.find_opt m Bsb_build_schemas.number in
let error_opt = Map_string.find_opt m Bsb_build_schemas.error in
match number_opt, error_opt with
| None, None -> None
| _, _ ->
let error =
match error_opt with
| Some (True _) -> Warn_error_true
| Some (False _) -> Warn_error_false
| Some (Str {str ; })
-> Warn_error_number str
| Some x -> Bsb_exception.config_error x "expect true/false or string"
| None -> Warn_error_false
(** To make it less intrusive : warning error has to be enabled*)
in
let number =
match number_opt with
| Some (Str { str = number}) -> Some number
| None -> None
| Some x -> Bsb_exception.config_error x "expect a string"
in
Some {number; error }
let number =
match number_opt with
| Some (Str { str = number}) -> Some number
| None -> None
| Some x -> Bsb_exception.config_error x "expect a string"
in
Some {number }


let to_bsb_string ~toplevel warning =
Expand All @@ -103,15 +83,6 @@ let to_bsb_string ~toplevel warning =
Ext_string.empty
| Some x ->
prepare_warning_concat ~beg:true x
) ^
(
match warning.error with
| Warn_error_true ->
" -warn-error A"
| Warn_error_number y ->
" -warn-error " ^ y
| Warn_error_false ->
Ext_string.empty
)
)
else " -w a"
(* TODO: this is the current default behavior *)
3 changes: 0 additions & 3 deletions jscomp/bsb/templates/basic/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@
"suffix": ".bs.js",
"bs-dependencies": [
],
"warnings": {
"error" : "+101"
},
"refmt": 3
}
5 changes: 2 additions & 3 deletions jscomp/build_tests/bucklescript-tea/input.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var p = require("child_process");
const { assert } = require("console");

var o = p.spawnSync(`bsb`);

console.log(o.stderr + "");
console.log("-----");
console.log(o.stdout + "");
if (o.error) {
throw o.error;
}
assert(o.status === 0)
18 changes: 9 additions & 9 deletions jscomp/build_tests/bucklescript-tea/src/tea_app.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ let programLoop update view subscriptions initModel initCmd = function
(* We own the passed in node, clear it out TODO: Clear it out properly *)
(* let () = Js.log ("Blah", Web.Node.firstChild parentNode, Js.Null.test (Web.Node.firstChild parentNode), false, true) in *)
let clearPnode () = while (Js.Array.length (Web.Node.childNodes parentNode)) > 0 do
match Js.Null.to_opt (Web.Node.firstChild parentNode) with
match Js.Null.toOption (Web.Node.firstChild parentNode) with
| None -> ()
| Some firstChild -> let _removedChild = Web.Node.removeChild parentNode firstChild in ()
done in
Expand Down Expand Up @@ -256,7 +256,7 @@ let program : ('flags, 'model, 'msg) program -> Web.Node.t Js.null_undefined ->
fun {init; update; view; subscriptions; shutdown} pnode flags ->
let () = Web.polyfills () in
let initModel, initCmd = init flags in
let opnode = Js.Null_undefined.to_opt pnode in
let opnode = Js.Null_undefined.toOption pnode in
let pumpInterface = programLoop update view subscriptions initModel initCmd opnode in
programStateWrapper initModel pumpInterface shutdown

Expand Down Expand Up @@ -286,7 +286,7 @@ let map func vnode =
Vdom.map func vnode

(* let fullProgram program pnode flags =
match Js.Null_undefined.to_opt pnode with
match Js.Null_undefined.toOption pnode with
| None -> Web.Document.body ()
| Some parentNode -> parentNode *)

Expand Down Expand Up @@ -346,7 +346,7 @@ let programLoop = function

let program {init; update; view} pnode flags =
let initModel, initCmd = init flags in
let opnode = Js.Null_undefined.to_opt pnode in
let opnode = Js.Null_undefined.toOption pnode in
let modelState = programStateWrapperInit initModel in
let rec viewState msgHandler = programLoopInit msgHandler view initModel opnode
and pump_unfixed msgHandler = programLoop viewState update view initModel msgHandler in
Expand All @@ -360,17 +360,17 @@ let program {init; update; view} pnode flags =
initModel
initCmds
view
(Js.Null_undefined.to_opt pnode) *)
(Js.Null_undefined.toOption pnode) *)

(* {
internal = (fun () -> Js.log "internal update");
init = init;
update = update;
view = view;
} (Js.Null_undefined.to_opt pnode) flags *)
} (Js.Null_undefined.toOption pnode) flags *)


(* match Js.Null_undefined.to_opt pnode with
(* match Js.Null_undefined.toOption pnode with
| None -> Web.Document.body ()
| Some parentNode -> parentNode *)

Expand All @@ -379,11 +379,11 @@ let program {init; update; view} pnode flags =
| None -> Js.log 42
| Some parentNode -> Js.log 84 *)

(* let beginnerProgram program pnode = match Js.Null_undefined.to_opt pnode with
(* let beginnerProgram program pnode = match Js.Null_undefined.toOption pnode with
| None -> Web.Document.body ()
| Some node -> node *)

(* let beginnerPrograms pnode = match Js.Null_undefined.to_opt pnode with
(* let beginnerPrograms pnode = match Js.Null_undefined.toOption pnode with
| None -> Web.Document.body ()
| Some node -> Web.Node.style node *)

Expand Down
12 changes: 6 additions & 6 deletions jscomp/build_tests/bucklescript-tea/src/tea_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ let onMsg eventName msg = onMsg eventName msg
let onInputOpt ?(key="") msg =
onCB "input" key
(fun ev ->
match Js.Undefined.to_opt ev##target with
match Js.Undefined.toOption ev##target with
| None -> None
| Some target -> match Js.Undefined.to_opt target##value with
| Some target -> match Js.Undefined.toOption target##value with
| None -> None
| Some value -> msg value
)
Expand All @@ -182,9 +182,9 @@ let onInput ?(key="") msg = onInputOpt ~key:key (fun ev -> Some (msg ev))
let onChangeOpt ?(key="") msg =
onCB "change" key
(fun ev ->
match Js.Undefined.to_opt ev##target with
match Js.Undefined.toOption ev##target with
| None -> None
| Some target -> match Js.Undefined.to_opt target##value with
| Some target -> match Js.Undefined.toOption target##value with
| None -> None
| Some value -> msg value
)
Expand All @@ -206,9 +206,9 @@ let onFocus msg =
let onCheckOpt ?(key="") msg =
onCB "change" key
(fun ev ->
match Js.Undefined.to_opt ev##target with
match Js.Undefined.toOption ev##target with
| None -> None
| Some target -> match Js.Undefined.to_opt target##checked with
| Some target -> match Js.Undefined.toOption target##checked with
| None -> None
| Some value -> msg value
)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/build_tests/bucklescript-tea/src/tea_html_cmds.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

let focus id =
Tea_cmd.call (fun _enqueue -> match Js.Null_undefined.to_opt (Web.Document.getElementById id) with
Tea_cmd.call (fun _enqueue -> match Js.Null_undefined.toOption (Web.Document.getElementById id) with
| None -> Js.log ("Attempted to focus a non-existant element of: ", id)
| Some elem ->
(* let () = Js.log ("Focusing element", id, elem) in *)
Expand Down
4 changes: 2 additions & 2 deletions jscomp/build_tests/bucklescript-tea/src/tea_http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ let send resultToMessage (Request (request, maybeEvents)) =
()
)

external encodeURIComponent : string -> string = "" [@@bs.val]
external encodeURIComponent : string -> string = "encodeURIComponent" [@@bs.val]

let encodeUri str =
encodeURIComponent str

external decodeURIComponent : string -> string = "" [@@bs.val]
external decodeURIComponent : string -> string = "decodeURIComponent" [@@bs.val]

let decodeUri str =
try Some (decodeURIComponent str)
Expand Down
4 changes: 2 additions & 2 deletions jscomp/build_tests/bucklescript-tea/src/tea_result.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


(* TODO: Remove this when Bucklescript is updated to OCaml 4.03 as it includes result *)
type ('a, 'b) t (* result *) =
type ('a, 'b) t (* result *) = ('a,'b) result =
| Ok of 'a
| Error of 'b

Expand Down Expand Up @@ -55,6 +55,6 @@ let rec error_of_any = function
| Error e -> Some e
| Ok _ -> error_of_any tl

let rec error_of_first fst = function
let error_of_first fst = function
| Error e -> Some e
| Ok _ -> error fst
6 changes: 3 additions & 3 deletions jscomp/build_tests/bucklescript-tea/src/tea_task.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ let testing () =
let () = doTest (Ok 42) e0 in
let e1 = fail "file not found" |> onError (fun _msg -> fail 42) in
let () = doTest (Error 42) e1 in
let n0 = sequence [ mapError string_of_int (fail 42); mapError string_of_float (fail 3.14) ] in
let n0 = sequence [ mapError string_of_int (fail 42); mapError Js.Float.toString (fail 3.14) ] in
let () = doTest (Error "42") n0 in
let n1 = sequence [ mapError string_of_int (succeed 1); mapError string_of_float (fail 3.14)] in
let n1 = sequence [ mapError string_of_int (succeed 1); mapError Js.Float.toString (fail 3.14)] in
let () = doTest (Error "3.14") n1 in
let n2 = sequence [ mapError string_of_int (succeed 1); mapError string_of_float (succeed 2)] in
let n2 = sequence [ mapError string_of_int (succeed 1); mapError Js.Float.toString (succeed 2)] in
let () = doTest (Ok [1;2]) n2 in
let _c0 = perform (fun _ -> 42) (succeed 18) in
(* (\* Should not compile *\) let _c1 = perform (fun _ -> 42) (fail 18) in *)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/build_tests/bucklescript-tea/src/tea_time.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type 'msg myCmd =

let every interval tagger =
let open Vdom in
let key = string_of_float interval in
let key = Js.Float.toString interval in
let enableCall callbacks =
let id = (Web.Window.setInterval (fun () -> callbacks.enqueue (tagger (Web.Date.now ())) ) interval) in
(* let () = Js.log ("Time.every", "enable", interval, tagger, callbacks) in *)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/build_tests/bucklescript-tea/src/web_json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type nothingYet
external stringify : 't -> nothingYet Js.null -> int -> string = "JSON.stringify" [@@bs.val]

let string_of_json ?(indent=2) value =
match Js.Undefined.to_opt value with
match Js.Undefined.toOption value with
| None -> "undefined"
| Some v ->
try stringify v Js.Null.empty indent
Expand Down
2 changes: 1 addition & 1 deletion jscomp/build_tests/bucklescript-tea/src/web_node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let setStyle n key value = setStyle n##style key value

let setStyleProperty n ?(priority=false) key value =
let style = n##style in
match Js.Undefined.to_opt style##setProperty with
match Js.Undefined.toOption style##setProperty with
| None -> setStyle n key value (* TODO: Change this to setAttribute sometime, maybe... *)
| Some _valid -> style##setProperty__ key value (if priority then (Js.Null.return "important") else Js.Null.empty)

Expand Down
14 changes: 7 additions & 7 deletions jscomp/build_tests/bucklescript-tea/src/web_window_history.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ type t = <
> Js.t


let length window = match Js.Undefined.to_opt window##history with
let length window = match Js.Undefined.toOption window##history with
| None -> -1
| Some history -> history##length

let back window = match Js.Undefined.to_opt window##history with
let back window = match Js.Undefined.toOption window##history with
| None -> ()
| Some history -> history##back

let forward window = match Js.Undefined.to_opt window##history with
let forward window = match Js.Undefined.toOption window##history with
| None -> ()
| Some history -> history##forward

let go window to' = match Js.Undefined.to_opt window##history with
let go window to' = match Js.Undefined.toOption window##history with
| None -> ()
| Some history -> history##go to'

let pushState window state title url = match Js.Undefined.to_opt window##history with
let pushState window state title url = match Js.Undefined.toOption window##history with
| None -> ()
| Some history -> history##pushState state title url

let replaceState window state title url = match Js.Undefined.to_opt window##history with
let replaceState window state title url = match Js.Undefined.toOption window##history with
| None -> ()
| Some history -> history##replaceState state title url

let state window = match Js.Undefined.to_opt window##history with
let state window = match Js.Undefined.toOption window##history with
| None -> Js.Undefined.empty
| Some history -> history##state
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ type t = <
setItem : string -> string -> unit [@bs.meth];
> Js.t

let length window = match Js.Undefined.to_opt window##localStorage with
let length window = match Js.Undefined.toOption window##localStorage with
| None -> None
| Some localStorage -> Some (localStorage##length)


let clear window = match Js.Undefined.to_opt window##localStorage with
let clear window = match Js.Undefined.toOption window##localStorage with
| None -> None
| Some localStorage -> Some (localStorage##clear ())


let key window idx = match Js.Undefined.to_opt window##localStorage with
let key window idx = match Js.Undefined.toOption window##localStorage with
| None -> None
| Some localStorage -> Some (localStorage##key idx)


let getItem window key = match Js.Undefined.to_opt window##localStorage with
let getItem window key = match Js.Undefined.toOption window##localStorage with
| None -> None
| Some localStorage ->
try Some (localStorage##getItem key)
with _ -> None


let removeItem window key = match Js.Undefined.to_opt window##localStorage with
let removeItem window key = match Js.Undefined.toOption window##localStorage with
| None -> None
| Some localStorage -> Some (localStorage##removeItem key)


let setItem window key value = match Js.Undefined.to_opt window##localStorage with
let setItem window key value = match Js.Undefined.toOption window##localStorage with
| None -> None
| Some localStorage -> Some (localStorage##setItem key value)
Loading