mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fixed a small bug that happened when having a trailing comma in multiline array and object literals
This commit is contained in:
parent
b9b87f7d8e
commit
8f3ea1d0c5
5 changed files with 122 additions and 107 deletions
|
@ -268,6 +268,8 @@
|
||||||
// An **AssignList** within a block indentation.
|
// An **AssignList** within a block indentation.
|
||||||
IndentedAssignList: [o("INDENT AssignList OUTDENT", function() {
|
IndentedAssignList: [o("INDENT AssignList OUTDENT", function() {
|
||||||
return $2;
|
return $2;
|
||||||
|
}), o("INDENT AssignList , OUTDENT", function() {
|
||||||
|
return $2;
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
// The three flavors of function call: normal, object instantiation with `new`,
|
// The three flavors of function call: normal, object instantiation with `new`,
|
||||||
|
@ -352,7 +354,7 @@
|
||||||
return $1.concat([$4]);
|
return $1.concat([$4]);
|
||||||
}), o("ArgList , INDENT Expression", function() {
|
}), o("ArgList , INDENT Expression", function() {
|
||||||
return $1.concat([$4]);
|
return $1.concat([$4]);
|
||||||
}), o("ArgList OUTDENT")
|
}), o("ArgList OUTDENT"), o("ArgList , OUTDENT")
|
||||||
],
|
],
|
||||||
// Just simple, comma-separated, required arguments (no fancy syntax). We need
|
// Just simple, comma-separated, required arguments (no fancy syntax). We need
|
||||||
// this to be separate from the **ArgList** for use in **Switch** blocks, where
|
// this to be separate from the **ArgList** for use in **Switch** blocks, where
|
||||||
|
|
210
lib/parser.js
210
lib/parser.js
File diff suppressed because one or more lines are too long
|
@ -256,6 +256,7 @@ grammar: {
|
||||||
# An **AssignList** within a block indentation.
|
# An **AssignList** within a block indentation.
|
||||||
IndentedAssignList: [
|
IndentedAssignList: [
|
||||||
o "INDENT AssignList OUTDENT", -> $2
|
o "INDENT AssignList OUTDENT", -> $2
|
||||||
|
o "INDENT AssignList , OUTDENT", -> $2
|
||||||
]
|
]
|
||||||
|
|
||||||
# The three flavors of function call: normal, object instantiation with `new`,
|
# The three flavors of function call: normal, object instantiation with `new`,
|
||||||
|
@ -330,6 +331,7 @@ grammar: {
|
||||||
o "ArgList , TERMINATOR Expression", -> $1.concat [$4]
|
o "ArgList , TERMINATOR Expression", -> $1.concat [$4]
|
||||||
o "ArgList , INDENT Expression", -> $1.concat [$4]
|
o "ArgList , INDENT Expression", -> $1.concat [$4]
|
||||||
o "ArgList OUTDENT"
|
o "ArgList OUTDENT"
|
||||||
|
o "ArgList , OUTDENT"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Just simple, comma-separated, required arguments (no fancy syntax). We need
|
# Just simple, comma-separated, required arguments (no fancy syntax). We need
|
||||||
|
|
|
@ -113,10 +113,10 @@ del: -> 5
|
||||||
ok del() is 5
|
ok del() is 5
|
||||||
|
|
||||||
# Ensure that functions can have a trailing comma in their argument list
|
# Ensure that functions can have a trailing comma in their argument list
|
||||||
|
|
||||||
mult: (x, mids..., y) ->
|
mult: (x, mids..., y) ->
|
||||||
x: * n for n in mids
|
x: * n for n in mids
|
||||||
x: * y
|
x: * y
|
||||||
x
|
|
||||||
|
|
||||||
ok mult(1, 2,) is 2
|
ok mult(1, 2,) is 2
|
||||||
ok mult(1, 2, 3,) is 6
|
ok mult(1, 2, 3,) is 6
|
||||||
|
|
|
@ -28,6 +28,13 @@ ok reg(str) and str is '\\'
|
||||||
trailing_comma: [1, 2, 3,]
|
trailing_comma: [1, 2, 3,]
|
||||||
ok (trailing_comma[0] is 1) and (trailing_comma[2] is 3) and (trailing_comma.length is 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),}
|
trailing_comma: {k1: "v1", k2: 4, k3: (-> true),}
|
||||||
ok trailing_comma.k3() and (trailing_comma.k2 is 4) and (trailing_comma.k1 is "v1")
|
ok trailing_comma.k3() and (trailing_comma.k2 is 4) and (trailing_comma.k1 is "v1")
|
||||||
|
|
||||||
|
@ -60,8 +67,8 @@ ok bob[10] is 'number'
|
||||||
|
|
||||||
|
|
||||||
obj: {
|
obj: {
|
||||||
'is': -> yes
|
'is': -> yes,
|
||||||
'not': -> no
|
'not': -> no,
|
||||||
}
|
}
|
||||||
|
|
||||||
ok obj.is()
|
ok obj.is()
|
||||||
|
|
Loading…
Add table
Reference in a new issue