Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/scanner/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ func (p *regExpParser) scanClassSetExpression() {
operand = p.text()[start:p.pos()]
default:
operand = p.scanClassSetOperand()
if isCharacterComplement && p.mayContainStrings {
p.error(diagnostics.Anything_that_would_possibly_match_more_than_a_single_character_is_invalid_inside_a_negated_character_class, start, p.pos()-start)
}
expressionMayContainStrings = expressionMayContainStrings || p.mayContainStrings
}
}
p.mayContainStrings = !isCharacterComplement && expressionMayContainStrings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
negatedUnicodeSetUnionMayContainStrings.ts(1,14): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
negatedUnicodeSetUnionMayContainStrings.ts(2,15): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.


==== negatedUnicodeSetUnionMayContainStrings.ts (2 errors) ====
const a = /[^\q{xy}b]/v;
~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
const b = /[^b\q{xy}]/v;
~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/negatedUnicodeSetUnionMayContainStrings.ts] ////

//// [negatedUnicodeSetUnionMayContainStrings.ts]
const a = /[^\q{xy}b]/v;
const b = /[^b\q{xy}]/v;


//// [negatedUnicodeSetUnionMayContainStrings.js]
"use strict";
const a = /[^\q{xy}b]/v;
const b = /[^b\q{xy}]/v;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/compiler/negatedUnicodeSetUnionMayContainStrings.ts] ////

=== negatedUnicodeSetUnionMayContainStrings.ts ===
const a = /[^\q{xy}b]/v;
>a : Symbol(a, Decl(negatedUnicodeSetUnionMayContainStrings.ts, 0, 5))

const b = /[^b\q{xy}]/v;
>b : Symbol(b, Decl(negatedUnicodeSetUnionMayContainStrings.ts, 1, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/negatedUnicodeSetUnionMayContainStrings.ts] ////

=== negatedUnicodeSetUnionMayContainStrings.ts ===
const a = /[^\q{xy}b]/v;
>a : RegExp
>/[^\q{xy}b]/v : RegExp

const b = /[^b\q{xy}]/v;
>b : RegExp
>/[^b\q{xy}]/v : RegExp

Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,23 @@ regularExpressionScanning.ts(38,87): error TS1501: This regular expression flag
regularExpressionScanning.ts(39,56): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(39,67): error TS1005: '&&' expected.
regularExpressionScanning.ts(39,77): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
regularExpressionScanning.ts(40,14): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(40,83): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
regularExpressionScanning.ts(41,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(41,30): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(41,83): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
regularExpressionScanning.ts(42,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,18): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,28): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,53): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,77): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
regularExpressionScanning.ts(43,14): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(43,95): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
regularExpressionScanning.ts(44,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(44,34): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(44,95): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
regularExpressionScanning.ts(45,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,22): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,32): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,61): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,89): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
Expand All @@ -219,7 +223,7 @@ regularExpressionScanning.ts(47,89): error TS1518: Anything that would possibly
regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.


==== regularExpressionScanning.ts (219 errors) ====
==== regularExpressionScanning.ts (223 errors) ====
const regexes: RegExp[] = [
// Flags
/foo/visualstudiocode,
Expand Down Expand Up @@ -654,6 +658,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
~
!!! error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
/[^\p{Emoji}\p{RGI_Emoji}][^\p{Emoji}--\p{RGI_Emoji}][^\p{Emoji}&&\p{RGI_Emoji}]/v,
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~
!!! error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
/[^\p{RGI_Emoji}\p{Emoji}][^\p{RGI_Emoji}--\p{Emoji}][^\p{RGI_Emoji}&&\p{Emoji}]/v,
Expand All @@ -665,6 +671,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
/[^\p{RGI_Emoji}\q{foo}][^\p{RGI_Emoji}--\q{foo}][^\p{RGI_Emoji}&&\q{foo}]/v,
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
Expand All @@ -673,6 +681,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
~
!!! error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
/[^\p{Emoji}[[\p{RGI_Emoji}]]][^\p{Emoji}--[[\p{RGI_Emoji}]]][^\p{Emoji}&&[[\p{RGI_Emoji}]]]/v,
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~
!!! error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
/[^[[\p{RGI_Emoji}]]\p{Emoji}][^[[\p{RGI_Emoji}]]--\p{Emoji}][^[[\p{RGI_Emoji}]]&&\p{Emoji}]/v,
Expand All @@ -684,6 +694,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1501: This regular expression flag is only available when targeting 'es2024' or later.
/[^[[\p{RGI_Emoji}]]\q{foo}][^[[\p{RGI_Emoji}]]--\q{foo}][^[[\p{RGI_Emoji}]]&&\q{foo}]/v,
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,18 @@ regularExpressionScanning.ts(38,75): error TS1508: Unexpected '&'. Did you mean
regularExpressionScanning.ts(38,85): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(39,56): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(39,67): error TS1005: '&&' expected.
regularExpressionScanning.ts(40,14): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(41,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(41,30): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,18): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,28): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(42,53): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(43,14): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(44,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(44,34): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,22): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,32): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(45,61): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
regularExpressionScanning.ts(46,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
Expand All @@ -193,7 +197,7 @@ regularExpressionScanning.ts(47,5): error TS1518: Anything that would possibly m
regularExpressionScanning.ts(47,89): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.


==== regularExpressionScanning.ts (193 errors) ====
==== regularExpressionScanning.ts (197 errors) ====
const regexes: RegExp[] = [
// Flags
/foo/visualstudiocode,
Expand Down Expand Up @@ -592,26 +596,34 @@ regularExpressionScanning.ts(47,89): error TS1518: Anything that would possibly

!!! error TS1005: '&&' expected.
/[^\p{Emoji}\p{RGI_Emoji}][^\p{Emoji}--\p{RGI_Emoji}][^\p{Emoji}&&\p{RGI_Emoji}]/v,
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
/[^\p{RGI_Emoji}\p{Emoji}][^\p{RGI_Emoji}--\p{Emoji}][^\p{RGI_Emoji}&&\p{Emoji}]/v,
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
/[^\p{RGI_Emoji}\q{foo}][^\p{RGI_Emoji}--\q{foo}][^\p{RGI_Emoji}&&\q{foo}]/v,
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
/[^\p{Emoji}[[\p{RGI_Emoji}]]][^\p{Emoji}--[[\p{RGI_Emoji}]]][^\p{Emoji}&&[[\p{RGI_Emoji}]]]/v,
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
/[^[[\p{RGI_Emoji}]]\p{Emoji}][^[[\p{RGI_Emoji}]]--\p{Emoji}][^[[\p{RGI_Emoji}]]&&\p{Emoji}]/v,
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
/[^[[\p{RGI_Emoji}]]\q{foo}][^[[\p{RGI_Emoji}]]--\q{foo}][^[[\p{RGI_Emoji}]]&&\q{foo}]/v,
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
~~~~~~~~~~~~~~~~~
!!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
Expand Down
Loading