alexprey / sveltedoc-parser

Generate a JSON documentation for a Svelte (https://github.com/sveltejs/svelte) component
https://www.npmjs.com/package/sveltedoc-parser
MIT License
89 stars 7 forks source link

Support for ES6 assignment pattern #75

Closed ekhaled closed 2 years ago

ekhaled commented 2 years ago

This works awesome:

<script>
    /**
     * The method comment.
     * @param {string} param1 - the first parameter
     * @param {boolean} [param2=false] - the second parameter
     * @returns {number} - return value description
     */
    export function publicMethod(param1, param2) {
        return 0;
    };
</script>

But having this auto-documentation will be even more awesome:

<script>
    /**
     * The method comment.
     * @param param2 - description of the second param
     * @returns {number} - return value description
     */
    export function publicMethod(param1 = "a", param2 = 1) {
        return 0;
    };
</script>

Here we can infer the parameter type as well as the default value because of the ES6 assignment pattern. And all we have to do is supply a description in the comments