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
90 stars 7 forks source link

JSDoc imported types from namespaced packages do not work #88

Open ekhaled opened 1 year ago

ekhaled commented 1 year ago

This works:

/**
* @type {import(./types).CustomType}
*/
let v1 = "something"

However, this doesn't:

/**
* @type {import(@someNamespace/package).CustomType}
*/
let v1 = "something"

The problem is this line https://github.com/alexprey/sveltedoc-parser/blob/dev/lib/utils.js#L7 That regex fails because of the second @ symbol on that line.

ekhaled commented 1 year ago

A possible fix is:

     const parsedText = text.split(/\n/)
        .map((line) => {
            return line.trim()
                .replace(/^\/\*+/, '').trim()
                .replace(/\s*\*+\/$/, '').trim()
+                .replace(/import\((\s*)(['|"])\@/, "import($1$2").trim()
                .replace(/^\s*\*/, '').trim();
        })
        .join('\n')
        .trim();

Not sure, how open you are to that