Permalink
Browse files

Add *leading* comma tests.

Really interesting -- turns out leading commas *in arrays* are valid JS too.

    > eval('[]').length
    0
    > eval('[,]').length
    1
    > eval('[,,]').length
    2
    > eval('[,,,]').length
    3
    > eval('[,,true]').length
    3

It seems that commas are always considered trailing, and if they have no value
preceding them, undefined is used for that value. After that, the standard
rule of optional trailing commas applies.
  • Loading branch information...
1 parent bf8d1c9 commit 215e8a8f1290a3876d9cd013cc9261aba64abaab @aseemk aseemk committed May 27, 2012
Showing with 6 additions and 0 deletions.
  1. +3 −0 test/cases/leading-comma-array.json5
  2. +3 −0 test/cases/leading-comma-object.json5
@@ -0,0 +1,3 @@
+[
+ ,null
+]
@@ -0,0 +1,3 @@
+{
+ ,"foo": "bar"
+}

0 comments on commit 215e8a8

Please sign in to comment.