Trailing commas in function parameter lists and calls S4
- Stage: Stage 4
- Status: Finished
- ECMAScript edition: ES2017
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
This proposal addresses the problem where adding a parameter to a multiline function definition or call requires modifying both the previous last line (adding a comma) and adding a new line, which affects version control blame information. The solution is to allow a trailing comma in function parameter lists and calls, matching features in other languages.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
Proposal to allow trailing commas in function parameter lists
In some codebases/style guides there are scenarios that arise where function calls and definitions are split across multiple lines in the style of:
In these cases, when some other code contributor comes along and adds another parameter to one of these parameter lists, they must make two line updates:
In the process of doing this change on code managed by a version control system (git, subversion, mercurial, etc), the blame/annotation code history information for lines 3 and 9 get updated to point at the person who added the comma (rather than the person who originally added the parameter).
To help mitigate this problem, some other languages (Python, D, Hack, ...probably others...) have added grammar support to allow a trailing comma in these parameter lists. This allows code contributors to always end a parameter addition with a trailing comma in one of these per-line parameter lists and never have to worry about the code attribution problem again:
Note that this proposal is exclusively about grammar and makes no changes to semantics, therefore the presence of a trailing comma has no effect on things like <<function>>.length.
This repo contains the proposal slides, a version of esprima hacked to allow trailing commas in parameter lists, and a very simple CLI utility to show that it's possible (and easy) to transpile trailing commas to ES5-compatible non-trailing commas in a build step.
For the CLI, you can either give it a single filename argument to read from disk, or you can pipe source text in to it.