Skip to content

Commit 3ee427b

Browse files
committed
/ followed by parenthesized expression is arithmetic division instead of start of regexp
Fixes #377
1 parent e7aa4da commit 3ee427b

File tree

5 files changed

+127
-4
lines changed

5 files changed

+127
-4
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,8 @@ repository:
15641564
match: \+\+
15651565
- name: keyword.operator.arithmetic.ts
15661566
match: '%|\*|/|-|\+'
1567-
# capture the arithmetic sign followed by variable so that it is not interpreted as regex
1568-
- match: (?<=[_$[:alnum:]])\s*(/)(?![/*])
1567+
# capture the arithmetic sign followed by variable or parenthesized expression so that it is not interpreted as regex
1568+
- match: (?<=[_$[:alnum:])])\s*(/)(?![/*])
15691569
captures:
15701570
'1': { name: keyword.operator.arithmetic.ts }
15711571

TypeScript.tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4356,7 +4356,7 @@
43564356
</dict>
43574357
<dict>
43584358
<key>match</key>
4359-
<string>(?&lt;=[_$[:alnum:]])\s*(/)(?![/*])</string>
4359+
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
43604360
<key>captures</key>
43614361
<dict>
43624362
<key>1</key>

TypeScriptReact.tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4338,7 +4338,7 @@
43384338
</dict>
43394339
<dict>
43404340
<key>match</key>
4341-
<string>(?&lt;=[_$[:alnum:]])\s*(/)(?![/*])</string>
4341+
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
43424342
<key>captures</key>
43434343
<dict>
43444344
<key>1</key>

tests/baselines/Issue377.baseline.txt

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
original file
2+
-----------------------------------
3+
dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';
4+
5+
-----------------------------------
6+
7+
Grammar: TypeScript.tmLanguage
8+
-----------------------------------
9+
>dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';
10+
^^
11+
source.ts variable.other.readwrite.ts
12+
^
13+
source.ts
14+
^
15+
source.ts keyword.operator.assignment.ts
16+
^
17+
source.ts
18+
^
19+
source.ts meta.brace.round.ts
20+
^
21+
source.ts meta.brace.round.ts
22+
^^
23+
source.ts variable.other.readwrite.ts
24+
^
25+
source.ts meta.array.literal.ts meta.brace.square.ts
26+
^
27+
source.ts meta.array.literal.ts constant.numeric.decimal.ts
28+
^
29+
source.ts meta.array.literal.ts meta.brace.square.ts
30+
^
31+
source.ts
32+
^
33+
source.ts keyword.operator.arithmetic.ts
34+
^
35+
source.ts
36+
^^^
37+
source.ts constant.numeric.decimal.ts
38+
^
39+
source.ts
40+
^
41+
source.ts keyword.operator.arithmetic.ts
42+
^
43+
source.ts
44+
^^
45+
source.ts variable.other.readwrite.ts
46+
^
47+
source.ts meta.array.literal.ts meta.brace.square.ts
48+
^
49+
source.ts meta.array.literal.ts constant.numeric.decimal.ts
50+
^
51+
source.ts meta.array.literal.ts meta.brace.square.ts
52+
^
53+
source.ts meta.brace.round.ts
54+
^
55+
source.ts
56+
^
57+
source.ts keyword.operator.arithmetic.ts
58+
^
59+
source.ts
60+
^^^
61+
source.ts constant.numeric.decimal.ts
62+
^
63+
source.ts meta.brace.round.ts
64+
^
65+
source.ts punctuation.accessor.ts
66+
^^^^^^^
67+
source.ts entity.name.function.ts
68+
^
69+
source.ts meta.brace.round.ts
70+
^
71+
source.ts constant.numeric.decimal.ts
72+
^
73+
source.ts meta.brace.round.ts
74+
^
75+
source.ts punctuation.accessor.ts
76+
^^^^^^^
77+
source.ts support.function.ts
78+
^
79+
source.ts meta.brace.round.ts
80+
^
81+
source.ts string.regex.ts punctuation.definition.string.begin.ts
82+
^^
83+
source.ts string.regex.ts constant.character.escape.backslash.regexp
84+
^
85+
source.ts string.regex.ts keyword.operator.quantifier.regexp
86+
^
87+
source.ts string.regex.ts
88+
^
89+
source.ts string.regex.ts keyword.operator.quantifier.regexp
90+
^
91+
source.ts string.regex.ts keyword.control.anchor.regexp
92+
^
93+
source.ts string.regex.ts punctuation.definition.string.end.ts
94+
^
95+
source.ts punctuation.separator.comma.ts
96+
^
97+
source.ts
98+
^
99+
source.ts string.quoted.single.ts punctuation.definition.string.begin.ts
100+
^
101+
source.ts string.quoted.single.ts punctuation.definition.string.end.ts
102+
^
103+
source.ts meta.brace.round.ts
104+
^
105+
source.ts
106+
^
107+
source.ts keyword.operator.arithmetic.ts
108+
^
109+
source.ts
110+
^
111+
source.ts string.quoted.single.ts punctuation.definition.string.begin.ts
112+
^^
113+
source.ts string.quoted.single.ts
114+
^
115+
source.ts string.quoted.single.ts punctuation.definition.string.end.ts
116+
^
117+
source.ts punctuation.terminator.statement.ts
118+
^^
119+
source.ts
120+
>
121+
^
122+
source.ts

tests/cases/Issue377.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';

0 commit comments

Comments
 (0)