From f51e9d1dda454b9dce8b8c2179fceacf5236220f Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Tue, 4 Apr 2023 20:34:36 +0000 Subject: [PATCH] Make RegExpMatch.pattern have type RegExp. It's always a RegExp, so it's a safe change. It's also a very, very rarely used property, since nobody ever noticed that it wasn't typed optimally. Tested: Type change of getter to actual type of value. No new test. CoreLibraryReviewExempt: Aske is out. Change-Id: Ifb560a80c3cdb05be0164c593383539dc10ec0dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267961 Reviewed-by: Stephen Adams Reviewed-by: Nate Bosch Commit-Queue: Lasse Nielsen Reviewed-by: Martin Kustermann --- CHANGELOG.md | 1 + sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart | 2 +- sdk/lib/_internal/js_runtime/lib/regexp_helper.dart | 2 +- sdk/lib/_internal/vm/lib/regexp_patch.dart | 2 +- sdk/lib/_internal/wasm/lib/regexp_helper.dart | 2 +- sdk/lib/core/regexp.dart | 2 ++ 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b264b284ad1..91ac0114b37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ #### `dart:core` - Added `bool.parse` and `bool.tryParse` static methods. - Added `DateTime.timestamp()` constructor to get current time as UTC. +- The type of `RegExpMatch.pattern` is now `RegExp`, not just `Pattern`. - **Breaking change** [#49529][]: - Removed the deprecated `List` constructor, as it wasn't null safe. diff --git a/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart b/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart index 73f95fb4460..64af42d3763 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart @@ -180,7 +180,7 @@ class JSSyntaxRegExp implements RegExp { } class _MatchImplementation implements RegExpMatch { - final Pattern pattern; + final RegExp pattern; // Contains a JS RegExp match object that is an Array with extra "index" and // "input" properties. The array contains Strings but the values at indices // related to capture groups can be undefined. diff --git a/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart b/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart index 698d7508afa..4ba4ae51859 100644 --- a/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart +++ b/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart @@ -168,7 +168,7 @@ class JSSyntaxRegExp implements RegExp { } class _MatchImplementation implements RegExpMatch { - final Pattern pattern; + final RegExp pattern; // Contains a JS RegExp match object. // It is an Array of String values with extra 'index' and 'input' properties. // If there were named capture groups, there will also be an extra 'groups' diff --git a/sdk/lib/_internal/vm/lib/regexp_patch.dart b/sdk/lib/_internal/vm/lib/regexp_patch.dart index a729f69f41e..d906954d7c8 100644 --- a/sdk/lib/_internal/vm/lib/regexp_patch.dart +++ b/sdk/lib/_internal/vm/lib/regexp_patch.dart @@ -117,7 +117,7 @@ class _RegExpMatch implements RegExpMatch { int get groupCount => _regexp._groupCount; - Pattern get pattern => _regexp; + RegExp get pattern => _regexp; String? namedGroup(String name) { var idx = _regexp._groupNameIndex(name); diff --git a/sdk/lib/_internal/wasm/lib/regexp_helper.dart b/sdk/lib/_internal/wasm/lib/regexp_helper.dart index 2afc7a6a50c..89e4922ba27 100644 --- a/sdk/lib/_internal/wasm/lib/regexp_helper.dart +++ b/sdk/lib/_internal/wasm/lib/regexp_helper.dart @@ -163,7 +163,7 @@ class JSSyntaxRegExp implements RegExp { } class _MatchImplementation implements RegExpMatch { - final Pattern pattern; + final RegExp pattern; // Contains a JS RegExp match object. // It is an Array of String values with extra 'index' and 'input' properties. // If there were named capture groups, there will also be an extra 'groups' diff --git a/sdk/lib/core/regexp.dart b/sdk/lib/core/regexp.dart index 921af06189c..f8f0efa6581 100644 --- a/sdk/lib/core/regexp.dart +++ b/sdk/lib/core/regexp.dart @@ -483,4 +483,6 @@ abstract interface class RegExpMatch implements Match { /// The names of the named capture groups of [pattern]. Iterable get groupNames; + + RegExp get pattern; }