-
Notifications
You must be signed in to change notification settings - Fork 452
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
Fix Js.String.match_ return type #5070
Fix Js.String.match_ return type #5070
Conversation
I also mentioned that, there are a few files that have been modified, but I'm not sure if I should commit that also. And I don't know how I add the test case above to the codebase (neither if I should). |
hi @renatoalencar , thanks your contribution.
Feel free to skip it |
4f3126c
to
0ae1f60
Compare
Sure. Done that. The new test case I wrote for this: let m = Js.String.match_ [%re "/hello (world)?/"] "hello word";;
let n =
match m with
| Some(n) -> Js.Array.filter Js.Option.isSome n
| None -> [||];;
Js.log n;;
let o = Js.String2.match_ "hello word" [%re "/hello (world)?/"];;
let p =
match o with
| Some(q) -> Js.Array.filter Js.Option.isSome q
| None -> [||];;
Js.log p;; |
can you add the test case in |
Sure |
Error message:
For the record, for CI, we should set -k 1 |
Yeah, I fixed that changed the following test case From "match", (fun _ ->
Eq(Some [| "na"; "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"])
); To "match", (fun _ ->
Eq(Some [| Some "na"; Some "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"])
); And added another one: "match - not found capture groups", (fun _ ->
Eq(Some [| Some "hello "; None |], "hello word" |. Js.String2.match_ [%re "/hello (world)?/"])
); But I'm getting the following error
The MDN docs mention extra properties for some cases, I think that's something special for groups. |
That's harsh! I can't think of anything else that would make it possible to bind those extra properties in the array while keeping the zero cost. Maybe just ignore them for now. |
Javscript String.prototype.match function can return undefined values for optional capture groups that are not found, which breaks the type annotations since this is not added as a Js.nullable or an option, it's not possible to deal with those. Added an option type for array values.
0ae1f60
to
5ae4b1b
Compare
I passed the result of the match through another step like this "hello word" |. Js.String2.match_ [%re "/hello (world)?/"] |. Belt.Option.map Js.Array.copy So the runtime extra props are removed and the test passes. I'm not sure if this is the best solution, but let me know if there's anything I can do in order to improve that. |
@renatoalencar That's expected, since polymorphic comparision is best effort. I will merge it after we roll out 9.1, thanks |
Ok, thanks. |
`Js.String2.match_` and `Js.String.match_` return type was changed in rescript-lang/rescript#5070 and released on 10.0.0. This commit updates the API documentation. close rescript-lang#551
`Js.String2.match_` and `Js.String.match_` return type was changed in rescript-lang/rescript#5070 and released on 10.0.0. This commit updates the API documentation. close #551
Javscript String.prototype.match function can return
undefined
for optional capture groups that are not found, which breaks the type annotations since this is not added as aJs.nullable
, it's not possible to deal with those undefined values since it can't be passed toJs.Nullable.isNullable
.Fixes #5066.
I used the following code to test this.