Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should attributes with union types should have a type of "attribute-type"? #751

Closed
pyoor opened this issue Jul 7, 2023 · 1 comment · Fixed by #752
Closed

Should attributes with union types should have a type of "attribute-type"? #751

pyoor opened this issue Jul 7, 2023 · 1 comment · Fixed by #752

Comments

@pyoor
Copy link
Contributor

pyoor commented Jul 7, 2023

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants