AuthorOfTheSurf/KobraScript

Allow string and numeric literals to be object keys in object literals

AuthorOfTheSurf opened this issue · 1 comments

Title, to be included in #58

Currently only names can be keys e.g.

{
  x: 10
}

It is possible to use then between [ ]'s as expressions: ob[10], ob["age"]. This fix is aimed at values used as property keys within object literals.

http://stackoverflow.com/questions/6066846/keys-in-javascript-objects-can-only-be-strings
This means that numeric literals are interpreted as strings. See this REPL experiment:

> var a = {}
undefined
> a[10] = true
true
> a
{ '10': true }
> var b = {
...   10: true
... }
undefined
> b
{ '10': true }
> var c = {
... 3.14159265: true
... }
{ '3.14159265': true }
> 

Edit: works for floats too, nice