Skip to content

Commit b525837

Browse files
authored
Merge pull request #5070 from renatoalencar/fix/js_string-match_
Fix Js.String.match_ return type
2 parents 100da8a + 5ae4b1b commit b525837

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

jscomp/others/js_string.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ external localeCompare : t -> float = "localeCompare" [@@bs.send.pipe: t]
276276
]}
277277
278278
*)
279-
external match_ : Js_re.t -> t array option = "match" [@@bs.send.pipe: t] [@@bs.return {null_to_opt}]
279+
external match_ : Js_re.t -> t option array option = "match" [@@bs.send.pipe: t] [@@bs.return {null_to_opt}]
280280

281281
(** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition.
282282

jscomp/others/js_string2.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ external localeCompare : t -> t -> float = "localeCompare" [@@bs.send]
273273
]}
274274
275275
*)
276-
external match_ : t -> Js_re.t -> t array option = "match" [@@bs.send] [@@bs.return {null_to_opt}]
276+
external match_ : t -> Js_re.t -> t option array option = "match" [@@bs.send] [@@bs.return {null_to_opt}]
277277

278278
(** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition.
279279

jscomp/test/js_string_test.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ let suites = Mt.[
8484
);
8585

8686
"match", (fun _ ->
87-
Eq(Some [| "na"; "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"])
87+
Eq(Some [| Some "na"; Some "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"])
8888
);
8989
"match - no match", (fun _ ->
9090
Eq(None, "banana" |. Js.String2.match_ [%re "/nanana+/g"])
9191
);
92+
"match - not found capture groups", (fun _ ->
93+
Eq(Some [| Some "hello "; None |], "hello word" |. Js.String2.match_ [%re "/hello (world)?/"] |. Belt.Option.map Js.Array.copy )
94+
);
9295

9396
(* es2015 *)
9497
"normalize", (fun _ ->

0 commit comments

Comments
 (0)