Provide Spelling Suggestions for Named Capture Group References in Regular Expressions (#58613)

This commit is contained in:
graphemecluster 2024-06-05 04:47:58 +08:00 коммит произвёл GitHub
Родитель dc1ffb1648
Коммит f5238c328e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
6 изменённых файлов: 42 добавлений и 0 удалений

Просмотреть файл

@ -3568,6 +3568,12 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
forEach(groupNameReferences, reference => {
if (!groupSpecifiers?.has(reference.name)) {
error(Diagnostics.There_is_no_capturing_group_named_0_in_this_regular_expression, reference.pos, reference.end - reference.pos, reference.name);
if (groupSpecifiers) {
const suggestion = getSpellingSuggestion(reference.name, groupSpecifiers, identity);
if (suggestion) {
error(Diagnostics.Did_you_mean_0, reference.pos, reference.end - reference.pos, suggestion);
}
}
}
});
forEach(decimalEscapes, escape => {

Просмотреть файл

@ -0,0 +1,12 @@
regularExpressionGroupNameSuggestions.ts(1,18): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionGroupNameSuggestions.ts(1,27): error TS1532: There is no capturing group named 'Foo' in this regular expression.
==== regularExpressionGroupNameSuggestions.ts (2 errors) ====
const regex = /(?<foo>)\k<Foo>/;
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
!!! error TS1532: There is no capturing group named 'Foo' in this regular expression.
!!! related TS1369: Did you mean 'foo'?

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/regularExpressionGroupNameSuggestions.ts] ////
//// [regularExpressionGroupNameSuggestions.ts]
const regex = /(?<foo>)\k<Foo>/;
//// [regularExpressionGroupNameSuggestions.js]
var regex = /(?<foo>)\k<Foo>/;

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/regularExpressionGroupNameSuggestions.ts] ////
=== regularExpressionGroupNameSuggestions.ts ===
const regex = /(?<foo>)\k<Foo>/;
>regex : Symbol(regex, Decl(regularExpressionGroupNameSuggestions.ts, 0, 5))

Просмотреть файл

@ -0,0 +1,9 @@
//// [tests/cases/compiler/regularExpressionGroupNameSuggestions.ts] ////
=== regularExpressionGroupNameSuggestions.ts ===
const regex = /(?<foo>)\k<Foo>/;
>regex : RegExp
> : ^^^^^^
>/(?<foo>)\k<Foo>/ : RegExp
> : ^^^^^^

Просмотреть файл

@ -0,0 +1 @@
const regex = /(?<foo>)\k<Foo>/;