Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Fixed a small bug that happened when having a trailing comma in multi…
Browse files Browse the repository at this point in the history
…line array and object literals
  • Loading branch information
matehat committed Mar 26, 2010
1 parent b9b87f7 commit 8f3ea1d
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 107 deletions.
4 changes: 3 additions & 1 deletion lib/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@
// An **AssignList** within a block indentation.
IndentedAssignList: [o("INDENT AssignList OUTDENT", function() {
return $2;
}), o("INDENT AssignList , OUTDENT", function() {
return $2;
})
],
// The three flavors of function call: normal, object instantiation with `new`,
Expand Down Expand Up @@ -352,7 +354,7 @@
return $1.concat([$4]);
}), o("ArgList , INDENT Expression", function() {
return $1.concat([$4]);
}), o("ArgList OUTDENT")
}), o("ArgList OUTDENT"), o("ArgList , OUTDENT")
],
// Just simple, comma-separated, required arguments (no fancy syntax). We need
// this to be separate from the **ArgList** for use in **Switch** blocks, where
Expand Down
210 changes: 107 additions & 103 deletions lib/parser.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/grammar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ grammar: {
# An **AssignList** within a block indentation.
IndentedAssignList: [
o "INDENT AssignList OUTDENT", -> $2
o "INDENT AssignList , OUTDENT", -> $2
]

# The three flavors of function call: normal, object instantiation with `new`,
Expand Down Expand Up @@ -330,6 +331,7 @@ grammar: {
o "ArgList , TERMINATOR Expression", -> $1.concat [$4]
o "ArgList , INDENT Expression", -> $1.concat [$4]
o "ArgList OUTDENT"
o "ArgList , OUTDENT"
]

# Just simple, comma-separated, required arguments (no fancy syntax). We need
Expand Down
2 changes: 1 addition & 1 deletion test/test_functions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ del: -> 5
ok del() is 5

# Ensure that functions can have a trailing comma in their argument list

mult: (x, mids..., y) ->
x: * n for n in mids
x: * y
x

ok mult(1, 2,) is 2
ok mult(1, 2, 3,) is 6
Expand Down
11 changes: 9 additions & 2 deletions test/test_literals.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ ok reg(str) and str is '\\'
trailing_comma: [1, 2, 3,]
ok (trailing_comma[0] is 1) and (trailing_comma[2] is 3) and (trailing_comma.length is 3)

trailing_comma: [
1, 2, 3,
4, 5, 6
7, 8, 9,
]
(sum: (sum or 0) + n) for n in trailing_comma

trailing_comma: {k1: "v1", k2: 4, k3: (-> true),}
ok trailing_comma.k3() and (trailing_comma.k2 is 4) and (trailing_comma.k1 is "v1")

Expand Down Expand Up @@ -60,8 +67,8 @@ ok bob[10] is 'number'


obj: {
'is': -> yes
'not': -> no
'is': -> yes,
'not': -> no,
}

ok obj.is()
Expand Down

0 comments on commit 8f3ea1d

Please sign in to comment.