Skip to content

Commit d86597d

Browse files
zdenkoGeoffreyBooth
authored andcommitted
Fix #3306: trailing comma in a function call in the last line throws a syntax error (#4860)
* fix #3306 * added test
1 parent bf91781 commit d86597d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/coffeescript/rewriter.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rewriter.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ exports.Rewriter = class Rewriter
364364
while inImplicit()
365365
[stackTag, stackIdx, {sameLine, startsLine}] = stackTop()
366366
# Close implicit calls when reached end of argument list
367-
if inImplicitCall() and prevTag isnt ','
367+
if inImplicitCall() and prevTag isnt ',' or
368+
(prevTag is ',' and tag is 'TERMINATOR' and not nextTag?)
368369
endImplicitCall()
369370
# Close implicit objects such as:
370371
# return a: 1, b: 2 unless true

test/compilation.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,10 @@ test "using transpile from the Node API requires an object", ->
170170
test "transpile option applies to imported .coffee files", ->
171171
return if global.testingBrowser
172172
doesNotThrow -> transpile 'run', "import { getSep } from './test/importing/transpile_import'\ngetSep()"
173+
174+
test "#3306: trailing comma in a function call in the last line", ->
175+
eqJS '''
176+
foo bar,
177+
''', '''
178+
foo(bar);
179+
'''

0 commit comments

Comments
 (0)