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

Object literals not supported in @type #35

Closed
soft-decay opened this issue Nov 27, 2020 · 4 comments
Closed

Object literals not supported in @type #35

soft-decay opened this issue Nov 27, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@soft-decay
Copy link
Contributor

Adding this to examples/Button.svelte:

/**
 * Additional options for the button.
 * @type {{ rtl: boolean, lang: string }}
 */
export let options = { rtl: false, lang: 'en-us' };

and running yarn generate-examples produces this .json (only showing relevant part) :

// ...
// Last item of data
{   
    "keywords": [
        {
            "name": "type",
            "description": "{{ rtl: boolean, lang: string }}"
        }
    ],
    "visibility": "public",
    "description": "Additional options for the button.",
    "name": "options",
    "kind": "let",
    "static": false,
    "readonly": false,
    "type": {
        "kind": "type",
        "text": "{ rtl: boolean, lang: string",
        "type": "{ rtl: boolean, lang: string"
    }
}
// ...

where type.text and type.type lose the closing curly brace.

I have a fix ready, but it adds a new dependency to the project ("xregexp": "^4.4.0").
If you're open to this idea, I can create a PR.
I also added jsdoc unit tests for Object literals and nested literals, but only for 'Parse type keyword'.

@alexprey
Copy link
Collaborator

Hi! Thanks for the issue, that interesting case, I'm try to think how it can be fixed w/o adding the new dependency

@alexprey alexprey added the bug Something isn't working label Nov 27, 2020
@soft-decay
Copy link
Contributor Author

soft-decay commented Nov 27, 2020

Yes I understand that. My first idea was to solve it with pure regex, but javascript regex does not provide the PCRE recursive parameter (?R) (see Regex Recursion (Matching Nested Constructs)). So you can only match to a predetermined depth of matching things, which could be enough.

But your comment made me realize that the matcher for types does not need to ignore closing } :

- const TYPE = '\\{([^\\}]*)\\}';
+ const TYPE = '\\{(.*)\\}';

It's not perfect but it passes all current tests plus the tests I made for Object literals and nested literals.
Should I create a PR for it?

@alexprey
Copy link
Collaborator

Ok, looks good as a quick fix. Please create PR and I'm merge it and then publish a new version 😄

alexprey added a commit that referenced this issue Nov 28, 2020
fix(jsdoc): Object literals not supported in type annotation (#35)
@alexprey
Copy link
Collaborator

Thanks for a fix!
I'm publish it as a version 3.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants