Skip to content

Commit d720e09

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

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
@@ -1290,7 +1290,7 @@ repository:
12901290
- name: keyword.operator.arithmetic.ts
12911291
match: '%|\*|/|-|\+'
12921292
# capture the arithmetic sign followed by variable or parenthesized expression so that it is not interpreted as regex
1293-
- match: (?<=[_$[:alnum:])])\s*(/)(?![/*])
1293+
- match: (?<=[_$[:alnum:])\]])\s*(/)(?![/*])
12941294
captures:
12951295
'1': { name: keyword.operator.arithmetic.ts }
12961296

@@ -2092,7 +2092,7 @@ repository:
20922092
- include: '#regexp'
20932093
# Check if complete regexp syntax
20942094
- name: string.regexp.ts
2095-
begin: (?<![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
2095+
begin: (?<![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
20962096
beginCaptures:
20972097
'0': {name: punctuation.definition.string.begin.ts}
20982098
end: (/)([gimuy]*)

TypeScript.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,7 +4001,7 @@
40014001
</dict>
40024002
<dict>
40034003
<key>match</key>
4004-
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
4004+
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
40054005
<key>captures</key>
40064006
<dict>
40074007
<key>1</key>
@@ -5906,7 +5906,7 @@
59065906
<key>name</key>
59075907
<string>string.regexp.ts</string>
59085908
<key>begin</key>
5909-
<string>(?&lt;![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
5909+
<string>(?&lt;![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
59105910
<key>beginCaptures</key>
59115911
<dict>
59125912
<key>0</key>

TypeScriptReact.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,7 +3947,7 @@
39473947
</dict>
39483948
<dict>
39493949
<key>match</key>
3950-
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
3950+
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
39513951
<key>captures</key>
39523952
<dict>
39533953
<key>1</key>
@@ -5852,7 +5852,7 @@
58525852
<key>name</key>
58535853
<string>string.regexp.tsx</string>
58545854
<key>begin</key>
5855-
<string>(?&lt;![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
5855+
<string>(?&lt;![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
58565856
<key>beginCaptures</key>
58575857
<dict>
58585858
<key>0</key>
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)