Skip to content

Commit

Permalink
feat: type on union types (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz authored Jan 30, 2018
1 parent bde0553 commit f422f2a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/webidl2.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@
function union_type(typeName) {
all_ws();
if (!consume(OTHER, "(")) return;
const ret = { sequence: false, generic: null, nullable: false, union: true, idlType: [] };
const fst = type_with_extended_attributes(typeName) || error("Union type with no content");
const ret = { type: typeName || null, sequence: false, generic: null, nullable: false, union: true, idlType: [] };
const fst = type_with_extended_attributes() || error("Union type with no content");
ret.idlType.push(fst);
while (true) {
all_ws();
if (!consume(ID, "or")) break;
const typ = type_with_extended_attributes(typeName) || error("No type after 'or' in union type");
const typ = type_with_extended_attributes() || error("No type after 'or' in union type");
ret.idlType.push(typ);
}
if (!consume(OTHER, ")")) error("Unterminated union type");
Expand Down
5 changes: 3 additions & 2 deletions test/syntax/json/extended-attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,22 @@
"inherit": false,
"readonly": false,
"idlType": {
"type": "attribute-type",
"sequence": false,
"generic": null,
"nullable": false,
"union": true,
"idlType": [
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "long"
},
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
Expand Down
1 change: 1 addition & 0 deletions test/syntax/json/record.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"idlType": "DOMString"
},
{
"type": null,
"sequence": false,
"generic": null,
"nullable": true,
Expand Down
1 change: 1 addition & 0 deletions test/syntax/json/typedef-union.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"type": "typedef",
"idlType": {
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
Expand Down
18 changes: 11 additions & 7 deletions test/syntax/json/uniontype.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@
"inherit": false,
"readonly": false,
"idlType": {
"type": "attribute-type",
"sequence": false,
"generic": null,
"nullable": false,
"union": true,
"idlType": [
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "float"
},
{
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
"union": true,
"idlType": [
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "Date"
},
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
Expand All @@ -49,21 +51,22 @@
]
},
{
"type": null,
"sequence": false,
"generic": null,
"nullable": true,
"union": true,
"idlType": [
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "Node"
},
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
Expand All @@ -84,13 +87,14 @@
"inherit": false,
"readonly": false,
"idlType": {
"type": "attribute-type",
"sequence": false,
"generic": null,
"nullable": false,
"union": true,
"idlType": [
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
Expand All @@ -106,7 +110,7 @@
]
},
{
"type": "attribute-type",
"type": null,
"sequence": false,
"generic": null,
"nullable": false,
Expand Down

0 comments on commit f422f2a

Please sign in to comment.