Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: account for trailing commas in nested calls
Fixes #2413 When there was an implicit object as the sole argument to a nested function application that ended with a trailing comma, the normalize stage would fail to generate corect CoffeeScript. The normalize stage would insert the opening and closing parentheses, but also attempt to remove the trailing comma as it was "unnecessary". Normally this doesn't cause a problem because the comma is removed and then the closing parenthesis is added after it. However, because there are two nested function applications, we end up with these operations: 1. insert opening parenthesis for outer function application 2. remove comma after last argument of inner function appliication 3. insert opening parenthesis for inner function application 4. remove same comma again for outer function application, removing the newly-inserted parenthesis from step 3 5. insert closing parenthesis for outer function application Thus, only 1 closing parenthesis is added and there is a mismatch causing a syntax error. The simplest fix seems to be to not remove the comma if it attached to the last node in the list (i.e. of arguments, in this case). This does change the behavior to preserve trailing commas in some cases where they were previously removed, but that's probably a good thing.
- Loading branch information