Skip to content

feat(mongo): allow trailing comma in argument lists#127

Merged
rebelice merged 1 commit intomainfrom
mongo-parser-trailing-comma
May 9, 2026
Merged

feat(mongo): allow trailing comma in argument lists#127
rebelice merged 1 commit intomainfrom
mongo-parser-trailing-comma

Conversation

@h3n4l
Copy link
Copy Markdown
Member

@h3n4l h3n4l commented May 8, 2026

Summary

  • Accept a single trailing comma in function-call argument lists in the mongo parser, matching mongosh / JS ES2017+ behavior.
  • The wild shape — db.coll.find({…},).sort({…}) — comes up in production telemetry from editors and code formatters; previously the parser rejected the trailing , with expected ,, got ")".

Behavior

  • db.coll.find({a: 1},) → ok
  • db.coll.find({}, {a: 1},) → ok
  • db.coll.find({a: 1},).sort({a: 1}) → ok (cursor chain unaffected)
  • db.coll.find().limit(10,) → ok (cursor-method args also tolerate it)
  • db.coll.find(,) / db.coll.find(, {a: 1}) / db.coll.find({a: 1},,) → still error

Test plan

  • New TestTrailingCommaInArguments covers all four success shapes including the exact wild case.
  • New TestArgumentListErrors confirms bare/leading/consecutive commas still fail.
  • Full go test ./mongo/... passes (analysis, catalog, completion, parsertest).

🤖 Generated with Claude Code

mongosh and JavaScript (since ES2017) accept a trailing comma at the end
of a function-call argument list. Production telemetry shows the shape
in the wild — e.g. `db.coll.find({…},).sort({…})` — pasted from editors
or generated by code formatters. The parser previously rejected the
trailing `,` with `expected ,, got ")"`, forcing the caller to fall back
to mongosh.

parseArguments now accepts a single trailing comma after a real argument
while still rejecting bare `(,)`, leading `(,a)`, and consecutive `(a,,)`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rebelice rebelice merged commit 01140a7 into main May 9, 2026
2 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.

2 participants