Skip to content

Commit da79da6

Browse files
authored
fix(ruby) - fix |= operator false positives (as block arguments) (#4093)
* Fix block parameter handling ruby in ruby block parameter can be enclosed with |. But ruby also has builtin operator |=. This PR ensure that |= is not marked as be the beginning of the block parameter.
1 parent 1711895 commit da79da6

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Core Grammars:
1515
- enh(erlang) OTP25/27 maybe statement [nixxquality][]
1616
- enh(dart) Support digit-separators in number literals [Sam Rawlins][]
1717
- enh(csharp) add Contextual keywords `file`, `args`, `dynamic`, `record`, `required` and `scoped` [Alvin Joy][]
18+
- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK]
1819

1920
New Grammars:
2021

@@ -37,6 +38,7 @@ CONTRIBUTORS
3738
[nixxquality]: https://github.com/nixxquality
3839
[srawlins]: https://github.com/srawlins
3940
[Alvin Joy]: https://github.com/alvinsjoy
41+
[Aboobacker MK]: https://github.com/tachyons
4042

4143

4244
## Version 11.10.0

src/languages/ruby.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export default function(hljs) {
350350
},
351351
{
352352
className: 'params',
353-
begin: /\|/,
353+
begin: /\|(?!=)/,
354354
end: /\|/,
355355
excludeBegin: true,
356356
excludeEnd: true,

test/markup/ruby/blocks.expect.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].each <span class="hljs-keyword">do</span> |<span class="hljs-params">num</span>|
2+
puts num
3+
<span class="hljs-keyword">end</span>
4+
5+
names |= users.map <span class="hljs-keyword">do</span> |<span class="hljs-params">user</span>|
6+
user.name
7+
<span class="hljs-keyword">end</span>

test/markup/ruby/blocks.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[1, 2, 3].each do |num|
2+
puts num
3+
end
4+
5+
names |= users.map do |user|
6+
user.name
7+
end

0 commit comments

Comments
 (0)