Should attributes with union types should have a type of "attribute-type"?
pyoor opened this issue · 1 comments
pyoor commented
The AST generated by parsing an attribute with a union type has a result idlType.type
of null
. Is there a reason this isn't attribute-type
?
Current Results:
{
"type": "attribute-type",
"extAttrs": [],
"generic": "",
"nullable": false,
"union": true,
"idlType": [
{
"type": null,
"extAttrs": [],
"generic": "",
"nullable": false,
"union": false,
"idlType": "UTF8String"
},
{
"type": null,
"extAttrs": [],
"generic": "",
"nullable": false,
"union": false,
"idlType": "CanvasGradient"
}
]
}
Expected results:
{
"type": "attribute-type",
"extAttrs": [],
"generic": "",
"nullable": false,
"union": true,
"idlType": [
{
"type": "attribute-type",
"extAttrs": [],
"generic": "",
"nullable": false,
"union": false,
"idlType": "UTF8String"
},
{
"type": "attribute-type",
"extAttrs": [],
"generic": "",
"nullable": false,
"union": false,
"idlType": "CanvasGradient"
}
]
}
Suggested fix:
diff --git a/lib/productions/type.js b/lib/productions/type.js
index 728fe6f..3e16e29 100644
--- a/lib/productions/type.js
+++ b/lib/productions/type.js
@@ -129,7 +129,7 @@ function union_type(tokeniser, type) {
ret.type = type || null;
while (true) {
const typ =
- type_with_extended_attributes(tokeniser) ||
+ type_with_extended_attributes(tokeniser, type) ||
tokeniser.error("No type after open parenthesis or 'or' in union type");
if (typ.idlType === "any")
tokeniser.error("Type `any` cannot be included in a union type");
saschanaz commented
This sounds right, except attribute-type
itself is kinda redundant now; you can also do type.parent.type === "attribute"
. Anyway, happy to accept a PR.