Skip to content

Commit 9e936d2

Browse files
committed
Capture the arithmetic sign after the variable so that it isnt captured as regex
Fixes #343
1 parent 25fe7b2 commit 9e936d2

File tree

5 files changed

+119
-9
lines changed

5 files changed

+119
-9
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ repository:
1616
statements:
1717
patterns:
1818
- include: '#string'
19-
- include: '#regex'
2019
- include: '#template'
2120
- include: '#comment'
2221
- include: '#literal'
@@ -1509,6 +1508,10 @@ repository:
15091508
match: \+\+
15101509
- name: keyword.operator.arithmetic.ts
15111510
match: '%|\*|/|-|\+'
1511+
# capture the arithmetic sign followed by variable so that it is not interpreted as regex
1512+
- match: (?<=[_$[:alnum:]])\s*(/)(?![/*])
1513+
captures:
1514+
'1': { name: keyword.operator.arithmetic.ts }
15121515

15131516
typeof-operator:
15141517
name: keyword.operator.expression.typeof.ts

TypeScript.tmLanguage

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
<key>include</key>
4444
<string>#string</string>
4545
</dict>
46-
<dict>
47-
<key>include</key>
48-
<string>#regex</string>
49-
</dict>
5046
<dict>
5147
<key>include</key>
5248
<string>#template</string>
@@ -4121,6 +4117,18 @@
41214117
<key>match</key>
41224118
<string>%|\*|/|-|\+</string>
41234119
</dict>
4120+
<dict>
4121+
<key>match</key>
4122+
<string>(?&lt;=[_$[:alnum:]])\s*(/)(?![/*])</string>
4123+
<key>captures</key>
4124+
<dict>
4125+
<key>1</key>
4126+
<dict>
4127+
<key>name</key>
4128+
<string>keyword.operator.arithmetic.ts</string>
4129+
</dict>
4130+
</dict>
4131+
</dict>
41244132
</array>
41254133
</dict>
41264134
<key>typeof-operator</key>

TypeScriptReact.tmLanguage

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
<key>include</key>
4444
<string>#string</string>
4545
</dict>
46-
<dict>
47-
<key>include</key>
48-
<string>#regex</string>
49-
</dict>
5046
<dict>
5147
<key>include</key>
5248
<string>#template</string>
@@ -4103,6 +4099,18 @@
41034099
<key>match</key>
41044100
<string>%|\*|/|-|\+</string>
41054101
</dict>
4102+
<dict>
4103+
<key>match</key>
4104+
<string>(?&lt;=[_$[:alnum:]])\s*(/)(?![/*])</string>
4105+
<key>captures</key>
4106+
<dict>
4107+
<key>1</key>
4108+
<dict>
4109+
<key>name</key>
4110+
<string>keyword.operator.arithmetic.tsx</string>
4111+
</dict>
4112+
</dict>
4113+
</dict>
41064114
</array>
41074115
</dict>
41084116
<key>typeof-operator</key>

tests/baselines/Issue343.baseline.txt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
original file
2+
-----------------------------------
3+
console.log(`${Math.round(responseTime / requests)} ns (${Math.round(requests / ( responseTime / 1e9))}/sec)`);
4+
-----------------------------------
5+
6+
Grammar: TypeScript.tmLanguage
7+
-----------------------------------
8+
>console.log(`${Math.round(responseTime / requests)} ns (${Math.round(requests / ( responseTime / 1e9))}/sec)`);
9+
^^^^^^^
10+
source.ts support.class.console.ts
11+
^
12+
source.ts punctuation.accessor.ts
13+
^^^
14+
source.ts support.function.console.ts
15+
^
16+
source.ts meta.brace.round.ts
17+
^
18+
source.ts string.template.ts punctuation.definition.string.template.begin.ts
19+
^^
20+
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.begin.ts
21+
^^^^
22+
source.ts string.template.ts meta.template.expression.ts support.constant.math.ts
23+
^
24+
source.ts string.template.ts meta.template.expression.ts punctuation.accessor.ts
25+
^^^^^
26+
source.ts string.template.ts meta.template.expression.ts support.function.math.ts
27+
^
28+
source.ts string.template.ts meta.template.expression.ts meta.brace.round.ts
29+
^^^^^^^^^^^^
30+
source.ts string.template.ts meta.template.expression.ts variable.other.readwrite.ts
31+
^
32+
source.ts string.template.ts meta.template.expression.ts
33+
^
34+
source.ts string.template.ts meta.template.expression.ts keyword.operator.arithmetic.ts
35+
^
36+
source.ts string.template.ts meta.template.expression.ts
37+
^^^^^^^^
38+
source.ts string.template.ts meta.template.expression.ts variable.other.readwrite.ts
39+
^
40+
source.ts string.template.ts meta.template.expression.ts meta.brace.round.ts
41+
^
42+
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.end.ts
43+
^^^^^
44+
source.ts string.template.ts
45+
^^
46+
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.begin.ts
47+
^^^^
48+
source.ts string.template.ts meta.template.expression.ts support.constant.math.ts
49+
^
50+
source.ts string.template.ts meta.template.expression.ts punctuation.accessor.ts
51+
^^^^^
52+
source.ts string.template.ts meta.template.expression.ts support.function.math.ts
53+
^
54+
source.ts string.template.ts meta.template.expression.ts meta.brace.round.ts
55+
^^^^^^^^
56+
source.ts string.template.ts meta.template.expression.ts variable.other.readwrite.ts
57+
^
58+
source.ts string.template.ts meta.template.expression.ts
59+
^
60+
source.ts string.template.ts meta.template.expression.ts keyword.operator.arithmetic.ts
61+
^
62+
source.ts string.template.ts meta.template.expression.ts
63+
^
64+
source.ts string.template.ts meta.template.expression.ts meta.brace.round.ts
65+
^
66+
source.ts string.template.ts meta.template.expression.ts
67+
^^^^^^^^^^^^
68+
source.ts string.template.ts meta.template.expression.ts variable.other.readwrite.ts
69+
^
70+
source.ts string.template.ts meta.template.expression.ts
71+
^
72+
source.ts string.template.ts meta.template.expression.ts keyword.operator.arithmetic.ts
73+
^
74+
source.ts string.template.ts meta.template.expression.ts
75+
^^^
76+
source.ts string.template.ts meta.template.expression.ts constant.numeric.decimal.ts
77+
^
78+
source.ts string.template.ts meta.template.expression.ts meta.brace.round.ts
79+
^
80+
source.ts string.template.ts meta.template.expression.ts meta.brace.round.ts
81+
^
82+
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.end.ts
83+
^^^^^
84+
source.ts string.template.ts
85+
^
86+
source.ts string.template.ts punctuation.definition.string.template.end.ts
87+
^
88+
source.ts meta.brace.round.ts
89+
^
90+
source.ts punctuation.terminator.statement.ts

tests/cases/Issue343.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(`${Math.round(responseTime / requests)} ns (${Math.round(requests / ( responseTime / 1e9))}/sec)`);

0 commit comments

Comments
 (0)