Skip to content

Commit

Permalink
fix(ruby) - fix |= operator false positives (as block arguments) (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
tachyons authored Aug 19, 2024
1 parent 1711895 commit da79da6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Core Grammars:
- enh(erlang) OTP25/27 maybe statement [nixxquality][]
- enh(dart) Support digit-separators in number literals [Sam Rawlins][]
- enh(csharp) add Contextual keywords `file`, `args`, `dynamic`, `record`, `required` and `scoped` [Alvin Joy][]
- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK]

New Grammars:

Expand All @@ -37,6 +38,7 @@ CONTRIBUTORS
[nixxquality]: https://github.com/nixxquality
[srawlins]: https://github.com/srawlins
[Alvin Joy]: https://github.com/alvinsjoy
[Aboobacker MK]: https://github.com/tachyons


## Version 11.10.0
Expand Down
2 changes: 1 addition & 1 deletion src/languages/ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export default function(hljs) {
},
{
className: 'params',
begin: /\|/,
begin: /\|(?!=)/,
end: /\|/,
excludeBegin: true,
excludeEnd: true,
Expand Down
7 changes: 7 additions & 0 deletions test/markup/ruby/blocks.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[<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>|
puts num
<span class="hljs-keyword">end</span>

names |= users.map <span class="hljs-keyword">do</span> |<span class="hljs-params">user</span>|
user.name
<span class="hljs-keyword">end</span>
7 changes: 7 additions & 0 deletions test/markup/ruby/blocks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[1, 2, 3].each do |num|
puts num
end

names |= users.map do |user|
user.name
end

0 comments on commit da79da6

Please sign in to comment.