Skip to content

Commit

Permalink
BREAKING CHANGE: ret enum value as object (#87)
Browse files Browse the repository at this point in the history
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" }.
  • Loading branch information
Marcos Cáceres committed Oct 17, 2017
1 parent 8360040 commit 9d20714
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -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": []
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/webidl2.js
Expand Up @@ -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: "," });
Expand Down
12 changes: 6 additions & 6 deletions test/syntax/json/enum.json
Expand Up @@ -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": []
},
Expand Down Expand Up @@ -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": []
}
Expand Down

0 comments on commit 9d20714

Please sign in to comment.