Skip to content

Commit

Permalink
feat(runtime): drop unit arguments and embrace t-last (#963)
Browse files Browse the repository at this point in the history
* feat(runtime): drop `unit` arguments and embrace `t-last`

* chore: update changelog entry
  • Loading branch information
anmonteiro authored Dec 6, 2023
1 parent f2075ec commit 2cd6be0
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 216 deletions.
9 changes: 6 additions & 3 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ Unreleased
([#731](https://github.com/melange-re/melange/issues/731),
[#893](https://github.com/melange-re/melange/pull/893),
[#895](https://github.com/melange-re/melange/pull/895),
[#899](https://github.com/melange-re/melange/pull/899))
[#899](https://github.com/melange-re/melange/pull/899),
[#963](https://github.com/melange-re/melange/pull/963))
- Modules ending with `2` (e.g. `Js.String2`, `Js.Array2`,
`Js.TypedArray2`) are no longer available in Melange
- The functions in their corresponding modules now take labeled arguments,
allowing them to be used with both `|.` and `|>`.
- The functions in their corresponding modules now take labeled arguments
and one positional argument, prioritizing the usage of `|>` but still
allowing `|.` (`->` in Reason) when optionally labeled arguments aren't
omitted.
- BREAKING(runtime): remove deprecated functions from `Js.*` modules
([#897](https://github.com/melange-re/melange/pull/897))
- Consistently handle empty payloads in externals:
Expand Down
354 changes: 173 additions & 181 deletions jscomp/runtime/js_string.ml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jscomp/test/bs_string_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let eq loc x y =
let () =
eq __LOC__
("ghso ghso g"
|. Js.String.split ~sep:" " ()
|. Js.String.split ~sep:" "
|. Js.Array.reduce ~f:(fun x y -> x ^ "-" ^ y) ~init:""
) "-ghso-ghso-g"

Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/dist/jscomp/test/re_or_res/reactTestUtils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jscomp/test/exception_repr_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exception AAA = Exception_def.A
let () =
eq __LOC__ "hey" (Printexc.to_string Hi);
eq __LOC__ "A(1)" (Printexc.to_string (A 1));
eq __LOC__ (Js.String.startsWith (Printexc.to_string Hello) ~prefix:"Exception_repr_test.Hello" ()) true;
eq __LOC__ (Js.String.startsWith (Printexc.to_string Hello) ~prefix:"Exception_repr_test.Hello") true;
eq __LOC__ "A" (Printexc.to_string @@ AAA 3)

;; Mt.from_pair_suites __MODULE__ !suites
46 changes: 23 additions & 23 deletions jscomp/test/js_string_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,32 @@ let suites = Mt.[

(* es2015 *)
"endsWith", (fun _ ->
Eq(true, "foobar" |. Js.String.endsWith ~suffix:"bar" ())
Eq(true, "foobar" |. Js.String.endsWith ~suffix:"bar")
);
"endsWithFrom", (fun _ ->
Eq(false, "foobar" |. Js.String.endsWith ~suffix:"bar" ~len:1 ())
Eq(false, "foobar" |. Js.String.endsWith ~suffix:"bar" ~len:1)
);

(* es2015 *)
"includes", (fun _ ->
Eq(true, "foobarbaz" |. Js.String.includes ~search:"bar" ())
Eq(true, "foobarbaz" |. Js.String.includes ~search:"bar")
);
"includesFrom", (fun _ ->
Eq(false, "foobarbaz" |. Js.String.includes ~search:"bar" ~start:4 ())
Eq(false, "foobarbaz" |. Js.String.includes ~search:"bar" ~start:4)
);

"indexOf", (fun _ ->
Eq(3, "foobarbaz" |. Js.String.indexOf ~search:"bar" ())
Eq(3, "foobarbaz" |. Js.String.indexOf ~search:"bar")
);
"indexOfFrom", (fun _ ->
Eq((-1), "foobarbaz" |. Js.String.indexOf ~search:"bar" ~start:4 ())
Eq((-1), "foobarbaz" |. Js.String.indexOf ~search:"bar" ~start:4)
);

"lastIndexOf", (fun _ ->
Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~search:"bar" ())
Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~search:"bar")
);
"lastIndexOfFrom", (fun _ ->
Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~search:"bar" ~start:4 ())
Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~search:"bar" ~start:4)
);

"localeCompare", (fun _ ->
Expand All @@ -99,10 +99,10 @@ let suites = Mt.[

(* es2015 *)
"normalize", (fun _ ->
Eq("foo", Js.String.normalize "foo" ())
Eq("foo", Js.String.normalize "foo")
);
"normalizeByForm", (fun _ ->
Eq("foo", Js.String.normalize ~form:`NFKD "foo" ())
Eq("foo", Js.String.normalize ~form:`NFKD "foo")
);

(* es2015 *)
Expand Down Expand Up @@ -150,49 +150,49 @@ let suites = Mt.[
);

"slice", (fun _ ->
Eq("bar", "foobarbaz" |. Js.String.slice ~start:3 ~end_:6 ())
Eq("bar", "foobarbaz" |. Js.String.slice ~start:3 ~end_:6)
);
"sliceToEnd", (fun _ ->
Eq("barbaz", "foobarbaz" |. Js.String.slice ~start:3 ())
Eq("barbaz", "foobarbaz" |. Js.String.slice ~start:3)
);

"split", (fun _ ->
Eq([| "foo"; "bar"; "baz" |], "foo bar baz" |. Js.String.split ~sep:" " ())
Eq([| "foo"; "bar"; "baz" |], "foo bar baz" |. Js.String.split ~sep:" ")
);
"splitAtMost", (fun _ ->
Eq([| "foo"; "bar" |], "foo bar baz" |. Js.String.split ~sep:" " ~limit:2 ())
Eq([| "foo"; "bar" |], "foo bar baz" |. Js.String.split ~sep:" " ~limit:2)
);
"splitByRe", (fun _ ->
Eq(
[| Some "a"; Some "#"; None; Some "b"; Some "#"; Some ":"; Some "c" |],
"a#b#:c" |. Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"] ())
"a#b#:c" |. Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"])
);
"splitByReAtMost", (fun _ ->
Eq(
[| Some "a"; Some "#"; None |],
"a#b#:c" |. Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"] ~limit:3 ())
"a#b#:c" |. Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"] ~limit:3)
);

(* es2015 *)
"startsWith", (fun _ ->
Eq(true, "foobarbaz" |. Js.String.startsWith ~prefix:"foo" ())
Eq(true, "foobarbaz" |. Js.String.startsWith ~prefix:"foo")
);
"startsWithFrom", (fun _ ->
Eq(false, "foobarbaz" |. Js.String.startsWith ~prefix:"foo" ~start:1 ())
Eq(false, "foobarbaz" |. Js.String.startsWith ~prefix:"foo" ~start:1)
);

"substr", (fun _ ->
Eq("barbaz", "foobarbaz" |. Js.String.substr ~start:3 ())
Eq("barbaz", "foobarbaz" |. Js.String.substr ~start:3)
);
"substrAtMost", (fun _ ->
Eq("bar", "foobarbaz" |. Js.String.substr ~start:3 ~len:3 ())
Eq("bar", "foobarbaz" |. Js.String.substr ~start:3 ~len:3)
);

"substring", (fun _ ->
Eq("bar", "foobarbaz" |. Js.String.substring ~start:3 ~end_:6 ())
Eq("bar", "foobarbaz" |. Js.String.substring ~start:3 ~end_:6)
);
"substringToEnd", (fun _ ->
Eq("barbaz", "foobarbaz" |. Js.String.substring ~start:3 ())
Eq("barbaz", "foobarbaz" |. Js.String.substring ~start:3)
);

"toLowerCase", (fun _ ->
Expand All @@ -219,6 +219,6 @@ let suites = Mt.[
"link", (fun _ ->
Eq("<a href=\"https://reason.ml\">foo</a>", "foo" |. Js.String.link ~href:"https://reason.ml")
);
__LOC__ , (fun _ -> Ok (Js.String.includes "ab" ~search:"a" ()))
__LOC__ , (fun _ -> Ok (Js.String.includes "ab" ~search:"a"))
]
;; Mt.from_pair_suites __MODULE__ suites
2 changes: 1 addition & 1 deletion jscomp/test/re_or_res/reactTestUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module DOM = {
let findBySelectorAndPartialTextContent = (element, selector, content) =>
querySelectorAll(element, selector)
->Array.getBy(node =>
node->textContent->Js.String.includes(~search=content, ())
node->textContent->Js.String.includes(~search=content)
);
};

Expand Down
10 changes: 5 additions & 5 deletions jscomp/test/re_or_res/reasonReactRouter.re
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ let path = () =>
| "/" => []
| raw =>
/* remove the preceeding /, which every pathname seems to have */
let raw = Js.String.slice(~start=1, raw, ());
let raw = Js.String.slice(~start=1, raw);
/* remove the trailing /, which some pathnames might have. Ugh */
let raw =
switch (Js.String.get(raw, Js.String.length(raw) - 1)) {
| "/" => Js.String.slice(~start=0, ~end_=-1, raw, ())
| "/" => Js.String.slice(~start=0, ~end_=-1, raw)
| _ => raw
};
raw->(Js.String.split(~sep="/", ())) |> arrayToList;
raw->(Js.String.split(~sep="/")) |> arrayToList;
}
};
let hash = () =>
Expand All @@ -96,7 +96,7 @@ let hash = () =>
| raw =>
/* remove the preceeding #, which every hash seems to have.
Why is this even included in location.hash?? */
raw->(Js.String.slice(~start=1, ()))
raw->(Js.String.slice(~start=1))
}
};
let search = () =>
Expand All @@ -108,7 +108,7 @@ let search = () =>
| "?" => ""
| raw =>
/* remove the preceeding ?, which every search seems to have. */
raw->Js.String.slice(~start=1, ())
raw |> Js.String.slice(~start=1)
}
};
let push = path =>
Expand Down

0 comments on commit 2cd6be0

Please sign in to comment.