Skip to content

Commit d3c203d

Browse files
committed
Correct the comound arithmetic assignment detection with /=
Fixes #850
1 parent 74f669d commit d3c203d

File tree

5 files changed

+69
-15
lines changed

5 files changed

+69
-15
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,10 +1706,11 @@ repository:
17061706
match: ===|!==|==|!=
17071707
- name: keyword.operator.relational.ts
17081708
match: <=|>=|<>|<|>
1709-
- match: (?<=[_$[:alnum:]])(\!)\s*(/)(?![/*])
1709+
- match: (?<=[_$[:alnum:]])(\!)\s*(?:(/=)|(?:(/)(?![/*])))
17101710
captures:
17111711
'1': { name: keyword.operator.logical.ts }
1712-
'2': { name: keyword.operator.arithmetic.ts }
1712+
'2': { name: keyword.operator.assignment.compound.ts }
1713+
'3': { name: keyword.operator.arithmetic.ts }
17131714
- name: keyword.operator.logical.ts
17141715
match: \!|&&|\|\||\?\?
17151716
- name: keyword.operator.bitwise.ts
@@ -1723,15 +1724,17 @@ repository:
17231724
- name: keyword.operator.arithmetic.ts
17241725
match: '%|\*|/|-|\+'
17251726
# capture the arithmetic sign followed by variable or parenthesized expression so that it is not interpreted as regex
1726-
- begin: (?<=[_$[:alnum:])\]])\s*(?=({{inlineComment}}\s*)+(/)(?![/*]))
1727-
end: (/)(?!\*([^\*]|(\*[^\/]))*\*\/)
1727+
- begin: (?<=[_$[:alnum:])\]])\s*(?=({{inlineComment}}\s*)+(?:(/=)|(?:(/)(?![/*]))))
1728+
end: (?:(/=)|(?:(/)(?!\*([^\*]|(\*[^\/]))*\*\/)))
17281729
endCaptures:
1729-
'1': { name: keyword.operator.arithmetic.ts }
1730+
'1': { name: keyword.operator.assignment.compound.ts }
1731+
'2': { name: keyword.operator.arithmetic.ts }
17301732
patterns:
17311733
- include: '#comment'
1732-
- match: (?<=[_$[:alnum:])\]])\s*(/)(?![/*])
1734+
- match: (?<=[_$[:alnum:])\]])\s*(?:(/=)|(?:(/)(?![/*])))
17331735
captures:
1734-
'1': { name: keyword.operator.arithmetic.ts }
1736+
'1': { name: keyword.operator.assignment.compound.ts }
1737+
'2': { name: keyword.operator.arithmetic.ts }
17351738

17361739
typeof-operator:
17371740
begin: '{{startOfIdentifier}}typeof{{endOfIdentifier}}'

TypeScript.tmLanguage

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5534,7 +5534,7 @@
55345534
</dict>
55355535
<dict>
55365536
<key>match</key>
5537-
<string>(?&lt;=[_$[:alnum:]])(\!)\s*(/)(?![/*])</string>
5537+
<string>(?&lt;=[_$[:alnum:]])(\!)\s*(?:(/=)|(?:(/)(?![/*])))</string>
55385538
<key>captures</key>
55395539
<dict>
55405540
<key>1</key>
@@ -5543,6 +5543,11 @@
55435543
<string>keyword.operator.logical.ts</string>
55445544
</dict>
55455545
<key>2</key>
5546+
<dict>
5547+
<key>name</key>
5548+
<string>keyword.operator.assignment.compound.ts</string>
5549+
</dict>
5550+
<key>3</key>
55465551
<dict>
55475552
<key>name</key>
55485553
<string>keyword.operator.arithmetic.ts</string>
@@ -5587,12 +5592,17 @@
55875592
</dict>
55885593
<dict>
55895594
<key>begin</key>
5590-
<string>(?&lt;=[_$[:alnum:])\]])\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)+(/)(?![/*]))</string>
5595+
<string>(?&lt;=[_$[:alnum:])\]])\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)+(?:(/=)|(?:(/)(?![/*]))))</string>
55915596
<key>end</key>
5592-
<string>(/)(?!\*([^\*]|(\*[^\/]))*\*\/)</string>
5597+
<string>(?:(/=)|(?:(/)(?!\*([^\*]|(\*[^\/]))*\*\/)))</string>
55935598
<key>endCaptures</key>
55945599
<dict>
55955600
<key>1</key>
5601+
<dict>
5602+
<key>name</key>
5603+
<string>keyword.operator.assignment.compound.ts</string>
5604+
</dict>
5605+
<key>2</key>
55965606
<dict>
55975607
<key>name</key>
55985608
<string>keyword.operator.arithmetic.ts</string>
@@ -5608,10 +5618,15 @@
56085618
</dict>
56095619
<dict>
56105620
<key>match</key>
5611-
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
5621+
<string>(?&lt;=[_$[:alnum:])\]])\s*(?:(/=)|(?:(/)(?![/*])))</string>
56125622
<key>captures</key>
56135623
<dict>
56145624
<key>1</key>
5625+
<dict>
5626+
<key>name</key>
5627+
<string>keyword.operator.assignment.compound.ts</string>
5628+
</dict>
5629+
<key>2</key>
56155630
<dict>
56165631
<key>name</key>
56175632
<string>keyword.operator.arithmetic.ts</string>

TypeScriptReact.tmLanguage

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5480,7 +5480,7 @@
54805480
</dict>
54815481
<dict>
54825482
<key>match</key>
5483-
<string>(?&lt;=[_$[:alnum:]])(\!)\s*(/)(?![/*])</string>
5483+
<string>(?&lt;=[_$[:alnum:]])(\!)\s*(?:(/=)|(?:(/)(?![/*])))</string>
54845484
<key>captures</key>
54855485
<dict>
54865486
<key>1</key>
@@ -5489,6 +5489,11 @@
54895489
<string>keyword.operator.logical.tsx</string>
54905490
</dict>
54915491
<key>2</key>
5492+
<dict>
5493+
<key>name</key>
5494+
<string>keyword.operator.assignment.compound.tsx</string>
5495+
</dict>
5496+
<key>3</key>
54925497
<dict>
54935498
<key>name</key>
54945499
<string>keyword.operator.arithmetic.tsx</string>
@@ -5533,12 +5538,17 @@
55335538
</dict>
55345539
<dict>
55355540
<key>begin</key>
5536-
<string>(?&lt;=[_$[:alnum:])\]])\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)+(/)(?![/*]))</string>
5541+
<string>(?&lt;=[_$[:alnum:])\]])\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)+(?:(/=)|(?:(/)(?![/*]))))</string>
55375542
<key>end</key>
5538-
<string>(/)(?!\*([^\*]|(\*[^\/]))*\*\/)</string>
5543+
<string>(?:(/=)|(?:(/)(?!\*([^\*]|(\*[^\/]))*\*\/)))</string>
55395544
<key>endCaptures</key>
55405545
<dict>
55415546
<key>1</key>
5547+
<dict>
5548+
<key>name</key>
5549+
<string>keyword.operator.assignment.compound.tsx</string>
5550+
</dict>
5551+
<key>2</key>
55425552
<dict>
55435553
<key>name</key>
55445554
<string>keyword.operator.arithmetic.tsx</string>
@@ -5554,10 +5564,15 @@
55545564
</dict>
55555565
<dict>
55565566
<key>match</key>
5557-
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
5567+
<string>(?&lt;=[_$[:alnum:])\]])\s*(?:(/=)|(?:(/)(?![/*])))</string>
55585568
<key>captures</key>
55595569
<dict>
55605570
<key>1</key>
5571+
<dict>
5572+
<key>name</key>
5573+
<string>keyword.operator.assignment.compound.tsx</string>
5574+
</dict>
5575+
<key>2</key>
55615576
<dict>
55625577
<key>name</key>
55635578
<string>keyword.operator.arithmetic.tsx</string>

tests/baselines/Issue850.baseline.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
original file
2+
-----------------------------------
3+
x /= 2;
4+
-----------------------------------
5+
6+
Grammar: TypeScript.tmLanguage
7+
-----------------------------------
8+
>x /= 2;
9+
^
10+
source.ts variable.other.readwrite.ts
11+
^
12+
source.ts
13+
^^
14+
source.ts keyword.operator.assignment.compound.ts
15+
^
16+
source.ts
17+
^
18+
source.ts constant.numeric.decimal.ts
19+
^
20+
source.ts punctuation.terminator.statement.ts

tests/cases/Issue850.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x /= 2;

0 commit comments

Comments
 (0)