Provide Spelling Suggestions for Named Capture Group References in Regular Expressions (#58613)
This commit is contained in:
Родитель
dc1ffb1648
Коммит
f5238c328e
|
@ -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>/;
|
Загрузка…
Ссылка в новой задаче