Skip to content

fix(ruby) do not read Name::method as a Name: symbol - #4573

Open
clark719664 wants to merge 1 commit into
highlightjs:mainfrom
clark719664:fix/ruby-scope-resolution-symbols
Open

clark719664 wants to merge 1 commit into
highlightjs:mainfrom
clark719664:fix/ruby-scope-resolution-symbols

Conversation

@clark719664

Copy link
Copy Markdown

Resolves #4516

Changes

Confirms the report: on main, A::a_method(sym: 1) and an_alias::a_method(sym: 5) highlight A: / an_alias: and :a_method as symbols, and A::B::C.new gives A: + :B. The :: swallow rule added in #4463 only helps when the left-hand side is consumed first by the CamelCase class-reference rule (Foo::Bar); for a single capital letter or a lowercase receiver, the identifier: symbol rule matches one character earlier and wins.

  • ruby.js: the identifier(!|?)?: symbol rule now requires that the colon is not followed by another colon (:(?!:)), so hash-key symbols (name:, sym:) still match and Name::method falls through to the existing :: rule.
  • test/markup/ruby/symbols: three added cases (A::a_method(sym: 1), an_alias::a_method(sym: 5), A::B::C.new). All previous expectations in that file are unchanged.
  • CHANGES.md entry.

Verification (Node 24, Windows):

  • npm run build && mocha test: the extended should markup symbols test fails on main and passes with this change; the full suite is 1650 passing, 3 pending.
  • Checked that real symbols and ternaries are unaffected: a = :symbol, { hash_key: 1 }, b[:hash_key], def m(sym: 123), cond ? a : b, a ? :yes : :no, { "k": 1, k2: 2 } all highlight as before.
  • eslint src/languages/ruby.js reports the same single parsing error as on main (pre-existing, unrelated to this change).

Note: the CHANGES.md hunk sits next to the one in #4572; whichever lands second will need a trivial rebase.

Assisted-by: Claude Fable 5.1 (high). This change was developed with an AI coding assistant (Claude Code) and reviewed by Clark.

Checklist

  • Added markup tests, or they don't apply here because...
  • I have read and followed our AI-assisted contributions policy (human review, no slop)

🤖 Generated with Claude Code

The `identifier:` symbol rule matched the first colon of a scope
resolution operator whenever the left-hand side was not a CamelCase
class reference, so `A::a_method` and `an_alias::a_method` were
highlighted as the symbols `A:` + `:a_method`. The existing `::`
swallow rule never got a chance because the symbol match started one
character earlier.

Require that the colon is not followed by another colon, so hash-key
symbols (`name:`) still match and `Name::method` falls through to the
`::` rule.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Assisted-by: Claude Fable 5.1 (high)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Again: Ruby syntax: Wrong recognition of symbols at the place of calling a class methods. Now in v11.12.0

1 participant