Skip to content

Commit b9f410d

Browse files
committed
Handle the "/" followed by "]" to ensure it not being treated as regex
Fixes #580
1 parent a7080b7 commit b9f410d

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ repository:
12451245
- name: keyword.operator.arithmetic.ts
12461246
match: '%|\*|/|-|\+'
12471247
# capture the arithmetic sign followed by variable or parenthesized expression so that it is not interpreted as regex
1248-
- match: (?<=[_$[:alnum:])])\s*(/)(?![/*])
1248+
- match: (?<=[_$[:alnum:])\]])\s*(/)(?![/*])
12491249
captures:
12501250
'1': { name: keyword.operator.arithmetic.ts }
12511251

@@ -2033,7 +2033,7 @@ repository:
20332033
- include: '#regexp'
20342034
# Check if complete regexp syntax
20352035
- name: string.regexp.ts
2036-
begin: (?<![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
2036+
begin: (?<![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
20372037
beginCaptures:
20382038
'0': {name: punctuation.definition.string.begin.ts}
20392039
end: (/)([gimuy]*)

TypeScript.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3868,7 +3868,7 @@
38683868
</dict>
38693869
<dict>
38703870
<key>match</key>
3871-
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
3871+
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
38723872
<key>captures</key>
38733873
<dict>
38743874
<key>1</key>
@@ -5738,7 +5738,7 @@
57385738
<key>name</key>
57395739
<string>string.regexp.ts</string>
57405740
<key>begin</key>
5741-
<string>(?&lt;![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
5741+
<string>(?&lt;![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
57425742
<key>beginCaptures</key>
57435743
<dict>
57445744
<key>0</key>

TypeScriptReact.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,7 +3814,7 @@
38143814
</dict>
38153815
<dict>
38163816
<key>match</key>
3817-
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
3817+
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
38183818
<key>captures</key>
38193819
<dict>
38203820
<key>1</key>
@@ -5684,7 +5684,7 @@
56845684
<key>name</key>
56855685
<string>string.regexp.tsx</string>
56865686
<key>begin</key>
5687-
<string>(?&lt;![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
5687+
<string>(?&lt;![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
56885688
<key>beginCaptures</key>
56895689
<dict>
56905690
<key>0</key>

tests/baselines/Issue580.baseline.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
original file
2+
-----------------------------------
3+
(a[0] / 2) / (2)
4+
-----------------------------------
5+
6+
Grammar: TypeScript.tmLanguage
7+
-----------------------------------
8+
>(a[0] / 2) / (2)
9+
^
10+
source.ts meta.brace.round.ts
11+
^
12+
source.ts variable.other.readwrite.ts
13+
^
14+
source.ts meta.array.literal.ts meta.brace.square.ts
15+
^
16+
source.ts meta.array.literal.ts constant.numeric.decimal.ts
17+
^
18+
source.ts meta.array.literal.ts meta.brace.square.ts
19+
^
20+
source.ts
21+
^
22+
source.ts keyword.operator.arithmetic.ts
23+
^
24+
source.ts
25+
^
26+
source.ts constant.numeric.decimal.ts
27+
^
28+
source.ts meta.brace.round.ts
29+
^
30+
source.ts
31+
^
32+
source.ts keyword.operator.arithmetic.ts
33+
^
34+
source.ts
35+
^
36+
source.ts meta.brace.round.ts
37+
^
38+
source.ts constant.numeric.decimal.ts
39+
^
40+
source.ts meta.brace.round.ts

tests/cases/Issue580.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(a[0] / 2) / (2)

0 commit comments

Comments
 (0)