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

Add support of TypeScript inside Svelte components #34

Open alexprey opened 3 years ago

alexprey commented 3 years ago

Use the native typescript package AST Viewer: https://ts-ast-viewer.com

Plan

alexprey commented 3 years ago

Looking for this task I found the Babel Parser. This parser used by all babel eco-system and actually used in most of project build systems. Also this compiler output API looks very similar with espree parser that used in this project to parse scripts. The babel parser API allows parse not only code blocks, also that support parsing of simple expressions that can be usuful for template inline expressions. So, I think that it is a good idea to look into this parser to use it for the next versions.

Before parser will be changed it is a good idea to done refactoring around V3 parser and split logic on multiple files.

soft-decay commented 3 years ago

I was wondering if you were planning on including typescript support in v4 or rather do a v4 release while working on typescript support in a separate branch?

alexprey commented 3 years ago

I plan to release v4 tomorrow if all works well, and start playing around TS support in a new branch for v5 release

sidharthramesh commented 3 years ago

Thank you for the great work! As of now, can I use the parser with my svelte-typescript project? I want to extract the exported props and their types into JSON. Is this supported? The current version on npm gave me an Unexpected token error.

alexprey commented 3 years ago

Hi @sidharthramesh thanks! For now, typescript is not supported yet by this library, but I'm already start working on it. I hope that I can provide some workaround soon

sidharthramesh commented 3 years ago

Thank you @alexprey. For now, I guess I'll just use regex to extract out and parse the JSDocs in a svelte file.

alexprey commented 3 years ago

Ok, that time is come. I'm create a branch for typescript support (ref:typescript-support) by this library. I'm start with duplicating integration tests with small changes to make it writen with typescript.

The next step is provide the special API that can transpile typescript code to ES, which we can use later for parsing. This API should be similar with svelte.preprocess option for better integration with existing transpilers

vezwork commented 3 years ago

Want to express that I'm looking forward to this! I'm building my svelte app with Typescript using both rollup and webpack right now and they both work, but I get complaints from sveltedoc-parser in the console.

madeleineostoja commented 3 years ago

This would be a big win for the new Storybook svelte story formats as well, since it currently can't infer prop types in the auto generated documentation

alexprey commented 2 years ago

Hi, everyone! I'm back to work on that library and start intensive work with typescript parsing. I'm update initial task description to track progress of typescript parser implementation.

IanVS commented 2 years ago

I wonder, could it be possible to use https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx to get you at least part of the way to typescript support?

Ddupasquier commented 1 year ago

Would love to find out if anything ever came of this. Just discovered Storybook and am very excited to use it, but if it can't handle svelte/ts then I'm just going to have to remove it.

fkrauthan commented 4 months ago

Any news on this? would also love to have proper type support in storybook. And it seems like storybook uses this library for that.