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

types of types #93

Closed
marcoscaceres opened this issue Oct 25, 2017 · 19 comments
Closed

types of types #93

marcoscaceres opened this issue Oct 25, 2017 · 19 comments

Comments

@marcoscaceres
Copy link
Member

For interfaces, const, attributes etc. that define a idlType, those types should themselves have a type: property saying what they are (e.g., "attribute-type", "constant-type").

@saschanaz
Copy link
Member

saschanaz commented Nov 3, 2017

I'm starting to be a bit confused about the hyphening, when we want to use space and when we want to use hyphen for the type name?

@saschanaz
Copy link
Member

saschanaz commented Nov 3, 2017

And what should the name be for return types? Just callback-type or callback-return-type?

@saschanaz
Copy link
Member

saschanaz commented Nov 3, 2017

And BTW, iterable has an idlType or an array of idlTypes. Do we want to make it a consistent array?

@marcoscaceres
Copy link
Member Author

Ok, so the rule appears to be: if the type can match a name for display purpose (e.g., “callback interface”, “interface mixin”) we use space, otherwise use hyphen.

And yeah about iterable, also setlike should be an array with a single item.

@saschanaz
Copy link
Member

Sometimes an idlType has an idlType that includes an idlType with an idlType:

"arguments": [
    {
        "optional": false,
        "variadic": false,
        "extAttrs": [],
        "idlType": {
            "sequence": true,
            "generic": "sequence",
            "nullable": false,
            "union": false,
            "idlType": {
                "sequence": false,
                "generic": "record",
                "nullable": false,
                "union": false,
                "idlType": [
                    {
                        "sequence": false,
                        "generic": null,
                        "nullable": false,
                        "union": false,
                        "idlType": "ByteString"
                    },
                    {
                        "sequence": false,
                        "generic": null,
                        "nullable": false,
                        "union": false,
                        "idlType": "any"
                    }
                ]
            }
        },
        "name": "param"
    }
]

Do we want to also add sequence-type, record-type, etc. for them? How about union-type?

@marcoscaceres
Copy link
Member Author

that would be great, actually. That's part what I'm doing at the moment with my dynamically adding a parent (in ReSpec) to work out the type's type.

@saschanaz
Copy link
Member

That sounds essentially #85 😄. Can you point your related ReSpec commits if you pushed so that I can understand your use case better?

@marcoscaceres
Copy link
Member Author

I've not pushed my local the code up yet, but essentially I am deriving the "type" for a data-attribute. For example:

<a dataset-idl-type="attribute-type">DOMString</a>

So, to do that, I call getTypeFromParent(), which just combines into, for example, "attribute-type":

function getTypeFromParent({ parent }) {
  if (!parent) {
    return "";
  }
  if (parent.hasOwnProperty("type")) {
    return parent.type + "-type";
  }
  return getTypeFromParent(parent);
}

@saschanaz
Copy link
Member

That is helpful, thanks!

@saschanaz
Copy link
Member

Oops, not completely fixed yet.

@saschanaz
Copy link
Member

saschanaz commented Jan 30, 2018

We covered argument-type, attribute-type, const-type, dictionary-type, return-type, and typedef-type. Is there anything still needed before a potential release?

@marcoscaceres
Copy link
Member Author

I think we should be good to go. I'll publish soon.

@marcoscaceres
Copy link
Member Author

@saschanaz, sorry, can you seem to be getting errors locally with npm test:

  1) Parses all of the IDLs to produce the correct ASTs
       should produce the same AST for /Users/marcos/Dropbox/repos/w3c/webidl2.js/test/syntax/idl/record.widl:
     Error: expect(received).toBeFalsy()

Expected value to be falsy, instead received
  {"0": {"members": {"1": {"idlType": {"idlType": {"1": {"idlType": {"0": {"type": ["return-type", null]}, "1": {"type": ["return-type", null]}, "_t": "a"}, "type": [null, "return-type"]}, "_t": "a"}}}, "_t": "a"}}, "_t": "a"}
      at Context.it (test/syntax.js:11:29)

  2) Parses all of the IDLs to produce the correct ASTs
       should produce the same AST for /Users/marcos/Dropbox/repos/w3c/webidl2.js/test/syntax/idl/typedef-union.widl:
     Error: expect(received).toBeFalsy()

Expected value to be falsy, instead received
  {"0": {"idlType": {"idlType": {"0": {"type": ["typedef-type", null]}, "1": {"type": ["typedef-type", null]}, "2": {"type": ["typedef-type", null]}, "3": {"type": ["typedef-type", null]}, "_t": "a"}, "type": [null, "typedef-type"]}}, "_t": "a"}
      at Context.it (test/syntax.js:11:29)

I haven't had a chance to poke around at those. Could you take a look?

@saschanaz
Copy link
Member

Oops, quickly pushed ac7ef08. Sorry!

@marcoscaceres
Copy link
Member Author

No problem :) Thanks for fixing!

@marcoscaceres
Copy link
Member Author

released 10.2.0.

@saschanaz
Copy link
Member

I think this is fixed 👍

@cyraid
Copy link

cyraid commented Sep 7, 2024

Is there anyone that updates the typescript @types/webidl2 ? It seems the typescript side hasn't been updated to include argument-type, const-type etc.

@saschanaz
Copy link
Member

That one is indeed undermaintained and it should ideally be autogenerated: #255

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

No branches or pull requests

3 participants