Skip to content

Commit 9424a09

Browse files
committed
Fix migration to RegExp.Result.captures
1 parent ac0fc88 commit 9424a09

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

packages/@rescript/runtime/Js_re.res

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,10 @@ type result
4444
An `array` of the match and captures, the first is the full match and the
4545
remaining are the substring captures.
4646
*/
47-
@deprecated({
48-
reason: "Use `RegExp.Result.matches` instead.",
49-
migrate: RegExp.Result.matches(),
50-
})
47+
@deprecated("Use `RegExp.Result.t` instead.")
5148
external captures: result => array<Js_null_undefined.t<string>> = "%identity"
5249

53-
@deprecated({
54-
reason: "Use `RegExp.Result.matches` instead.",
55-
migrate: RegExp.Result.matches(),
56-
})
50+
@deprecated("Use `RegExp.Result.t` instead.")
5751
external matches: result => array<string> = "%identity"
5852

5953
/** 0-based index of the match in the input string. */

packages/@rescript/runtime/Stdlib_RegExp.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Result = {
55
type t = array<option<string>>
66
@get_index external fullMatch: (t, @as(0) _) => string = ""
77
@send external matches: (t, @as(1) _) => array<option<string>> = "slice"
8+
@send external captures: (t, @as(1) _) => array<option<string>> = "slice"
89
@get external index: t => int = "index"
910
@get external input: t => string = "input"
1011
}

packages/@rescript/runtime/Stdlib_RegExp.resi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Result: {
3434
external fullMatch: (t, @as(0) _) => string = ""
3535

3636
/**
37-
`matches(regExpResult)` returns all matches for `regExpResult`.
37+
`captures(regExpResult)` returns all capture groups for `regExpResult`.
3838
3939
## Examples
4040
```rescript
@@ -45,15 +45,23 @@ module Result: {
4545
switch regexp->RegExp.exec("ReScript is pretty cool, right?") {
4646
| None => Console.log("Nope, no match...")
4747
| Some(result) =>
48-
switch result->RegExp.Result.matches->Array.keepSome {
48+
switch result->RegExp.Result.captures->Array.keepSome {
4949
| [firstWord, secondWord] => Console.log2(firstWord, secondWord)
5050
| _ => Console.log("Didn't find exactly two words...")
5151
}
5252
}
5353
```
5454
*/
5555
@send
56+
external captures: (t, @as(1) _) => array<option<string>> = "slice"
57+
58+
@deprecated({
59+
reason: "Use `RegExp.Result.captures` instead.",
60+
migrate: RegExp.Result.captures(),
61+
})
62+
@send
5663
external matches: (t, @as(1) _) => array<option<string>> = "slice"
64+
5765
@get external index: t => int = "index"
5866

5967
/**

0 commit comments

Comments
 (0)