Skip to content

Preserve keyword argument semantics through AST transformation#10

Merged
JPDuchesne merged 1 commit intomasterfrom
jpd/kwargs-preservation
Feb 25, 2026
Merged

Preserve keyword argument semantics through AST transformation#10
JPDuchesne merged 1 commit intomasterfrom
jpd/kwargs-preservation

Conversation

@JPDuchesne
Copy link
Contributor

@JPDuchesne JPDuchesne commented Feb 25, 2026

Summary

  • The upstream Parser::Builders::Default#associate emits :hash nodes for both bare keyword arguments (foo(bar: 1)) and explicit hash literals (foo({ bar: 1 })). Unparser uses the node type to decide whether to emit braces, so kwargs were round-tripping as positional hashes — breaking Ruby 3.0+ strict keyword/positional separation.
  • Introduces KwargsBuilder which overrides associate to emit :kwargs nodes when no brace tokens are present, which Unparser already handles correctly.
  • Adds unit tests for KwargsBuilder and regression tests in TransformationTest for keyword argument preservation through transform!.

Test plan

  • KwargsBuilder unit tests (7 tests): bare kwargs, explicit hash, mixed positional+kwargs, standalone hash literals, pair preservation, constructor calls, double-splat
  • TransformationTest regression tests (2 tests): kwargs and mixed kwargs survive a transform! round-trip
  • CI passes on Ruby 3.2, 3.3, and 4.0

Made with Cursor

The upstream parser builder emits :hash nodes for both bare keyword
arguments and explicit hash literals. Unparser uses node type to decide
whether to emit braces, so kwargs were round-tripping as positional
hashes — breaking Ruby 3.0+ strict keyword/positional separation.

KwargsBuilder overrides associate to emit :kwargs nodes when no brace
tokens are present, which Unparser already handles correctly.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@JPDuchesne JPDuchesne merged commit 31271df into master Feb 25, 2026
4 checks passed
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.

1 participant