diff --git a/jscomp/others/js_string.ml b/jscomp/others/js_string.ml index 8220603a83..02680c0960 100644 --- a/jscomp/others/js_string.ml +++ b/jscomp/others/js_string.ml @@ -274,7 +274,7 @@ external localeCompare : t -> float = "localeCompare" [@@bs.send.pipe: t] ]} *) -external match_ : Js_re.t -> t array option = "match" [@@bs.send.pipe: t] [@@bs.return {null_to_opt}] +external match_ : Js_re.t -> t option array option = "match" [@@bs.send.pipe: t] [@@bs.return {null_to_opt}] (** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. diff --git a/jscomp/others/js_string2.ml b/jscomp/others/js_string2.ml index 179eb87236..fd1b636af1 100644 --- a/jscomp/others/js_string2.ml +++ b/jscomp/others/js_string2.ml @@ -273,7 +273,7 @@ external localeCompare : t -> t -> float = "localeCompare" [@@bs.send] ]} *) -external match_ : t -> Js_re.t -> t array option = "match" [@@bs.send] [@@bs.return {null_to_opt}] +external match_ : t -> Js_re.t -> t option array option = "match" [@@bs.send] [@@bs.return {null_to_opt}] (** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. diff --git a/jscomp/test/js_string_test.ml b/jscomp/test/js_string_test.ml index a2fac5977e..190b7d75ee 100644 --- a/jscomp/test/js_string_test.ml +++ b/jscomp/test/js_string_test.ml @@ -84,11 +84,14 @@ let suites = Mt.[ ); "match", (fun _ -> - Eq(Some [| "na"; "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"]) + Eq(Some [| Some "na"; Some "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"]) ); "match - no match", (fun _ -> Eq(None, "banana" |. Js.String2.match_ [%re "/nanana+/g"]) ); + "match - not found capture groups", (fun _ -> + Eq(Some [| Some "hello "; None |], "hello word" |. Js.String2.match_ [%re "/hello (world)?/"] |. Belt.Option.map Js.Array.copy ) + ); (* es2015 *) "normalize", (fun _ ->