Repository: w3c/webidl2.js (js)

Issue:
Enum values should be objects
Given:

```JS
enum Things {
    "foo",
    "bar"
};
```

Enum values current result in, 

```js
[
  {
    "type": "ws",
    "value": "\n          "
  },
  "foo",
  {
    "type": ","
  },
  {
    "type": "ws",
    "value": "\n          "
  },
  "bar",
  {
    "type": "ws",
    "value": "\n        "
  }
]
```

This switching of types makes things really inconsistent. Would have expected an Object like:

```js
  {
    "type": "enum-value",
    "value": "foo",
  }
```

And maybe, for compat:

```js
  {
    "type": "enum-value",
    "value": "foo",
    toString(){
       return this.value;
    }
  }
```


Pull request description:
BREAKING CHANGE: ret enum value as object
* closes #86 

This changes the return type of parsed `emum.values` from strings to objects. The Objects have two members, `type` and `value`: `{type: "string", value: "value" }`.  


Patch:
diff --git a/README.md b/README.md
index a40d62c..180a7f0 100644
--- a/README.md
+++ b/README.md
@@ -279,9 +279,9 @@ An enum looks like this:
   "type": "enum",
   "name": "MealType",
   "values": [
-    "rice",
-    "noodles",
-    "other"
+    { "type": "string", "value": "rice" },
+    { "type": "string", "value": "noodles" },
+    { "type": "string", "value": "other" }
   ],
   "extAttrs": []
 }
@@ -291,7 +291,7 @@ The fields are as follows:
 
 * `type`: Always "enum".
 * `name`: The enum's name.
-* `value`: An array of values (strings).
+* `value`: An array of values.
 * `extAttrs`: A list of [extended attributes](#extended-attributes).
 
 ### Typedef
@@ -327,7 +327,7 @@ The fields are as follows:
 * `name`: The typedef's name.
 * `idlType`: An [IDL Type](#idl-type) describing what typedef's type.
 * `extAttrs`: A list of [extended attributes](#extended-attributes).
-* `typeExtAttrs`: A list of [extended attributes](#extended-attributes) that apply to the 
+* `typeExtAttrs`: A list of [extended attributes](#extended-attributes) that apply to the
 type rather than to the typedef as a whole.
 
 ### Implements
diff --git a/lib/webidl2.js b/lib/webidl2.js
index cb375f2..fd562f7 100644
--- a/lib/webidl2.js
+++ b/lib/webidl2.js
@@ -885,7 +885,8 @@
           return ret;
         }
         const val = consume(STR) || error("Unexpected value in enum");
-        ret.values.push(val.value.replace(/"/g, ""));
+        val.value = val.value.replace(/"/g, "");
+        ret.values.push( val );
         all_ws(store ? vals : null);
         if (consume(OTHER, ",")) {
           if (store) vals.push({ type: "," });


Test patch:
diff --git a/test/syntax/json/enum.json b/test/syntax/json/enum.json
index d9abab7..27c7afc 100644
--- a/test/syntax/json/enum.json
+++ b/test/syntax/json/enum.json
@@ -3,9 +3,9 @@
         "type": "enum",
         "name": "MealType",
         "values": [
-            "rice",
-            "noodles",
-            "other"
+            { "type": "string", "value": "rice" },
+            { "type": "string", "value": "noodles" },
+            { "type": "string", "value": "other" }
         ],
         "extAttrs": []
     },
@@ -100,9 +100,9 @@
         "type": "enum",
         "name": "AltMealType",
         "values": [
-            "rice",
-            "noodles",
-            "other"
+            { "type": "string", "value": "rice" },
+            { "type": "string", "value": "noodles" },
+            { "type": "string", "value": "other" }
         ],
         "extAttrs": []
     }