From f422f2a6f5659c1afae9fb3698ee23922cbcbf00 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Tue, 30 Jan 2018 12:22:13 +0900 Subject: [PATCH] feat: type on union types (#135) --- lib/webidl2.js | 6 +++--- test/syntax/json/extended-attributes.json | 5 +++-- test/syntax/json/record.json | 1 + test/syntax/json/typedef-union.json | 1 + test/syntax/json/uniontype.json | 18 +++++++++++------- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/webidl2.js b/lib/webidl2.js index 4f3240ce..ab9a4d1f 100644 --- a/lib/webidl2.js +++ b/lib/webidl2.js @@ -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"); diff --git a/test/syntax/json/extended-attributes.json b/test/syntax/json/extended-attributes.json index 7597d8d6..e0dc2360 100644 --- a/test/syntax/json/extended-attributes.json +++ b/test/syntax/json/extended-attributes.json @@ -182,13 +182,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, @@ -196,7 +197,7 @@ "idlType": "long" }, { - "type": "attribute-type", + "type": null, "sequence": false, "generic": null, "nullable": false, diff --git a/test/syntax/json/record.json b/test/syntax/json/record.json index 5e020d85..7f4585f9 100644 --- a/test/syntax/json/record.json +++ b/test/syntax/json/record.json @@ -85,6 +85,7 @@ "idlType": "DOMString" }, { + "type": null, "sequence": false, "generic": null, "nullable": true, diff --git a/test/syntax/json/typedef-union.json b/test/syntax/json/typedef-union.json index 5c155d4e..b80eb457 100644 --- a/test/syntax/json/typedef-union.json +++ b/test/syntax/json/typedef-union.json @@ -2,6 +2,7 @@ { "type": "typedef", "idlType": { + "type": null, "sequence": false, "generic": null, "nullable": false, diff --git a/test/syntax/json/uniontype.json b/test/syntax/json/uniontype.json index bb173f2c..87735c7f 100644 --- a/test/syntax/json/uniontype.json +++ b/test/syntax/json/uniontype.json @@ -11,13 +11,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, @@ -25,13 +26,14 @@ "idlType": "float" }, { + "type": null, "sequence": false, "generic": null, "nullable": false, "union": true, "idlType": [ { - "type": "attribute-type", + "type": null, "sequence": false, "generic": null, "nullable": false, @@ -39,7 +41,7 @@ "idlType": "Date" }, { - "type": "attribute-type", + "type": null, "sequence": false, "generic": null, "nullable": false, @@ -49,13 +51,14 @@ ] }, { + "type": null, "sequence": false, "generic": null, "nullable": true, "union": true, "idlType": [ { - "type": "attribute-type", + "type": null, "sequence": false, "generic": null, "nullable": false, @@ -63,7 +66,7 @@ "idlType": "Node" }, { - "type": "attribute-type", + "type": null, "sequence": false, "generic": null, "nullable": false, @@ -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, @@ -106,7 +110,7 @@ ] }, { - "type": "attribute-type", + "type": null, "sequence": false, "generic": null, "nullable": false,