sveltedoc-parser icon indicating copy to clipboard operation
sveltedoc-parser copied to clipboard

Add support of TypeScript inside Svelte components

Open alexprey opened this issue 3 years ago • 13 comments

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

Plan

  • [x] Pase variable definitions (private data items)
  • [x] Parse exported variable (public data items)
  • [ ] Parse method declarations (public / private)
  • [ ] Correct comments and description parsing
  • [ ] Parse imported components
  • [ ] Events parsing
  • [ ] Parse event names from objects of current source file
  • [ ] Basic type inferring for variables
  • [ ] Basic type matching based on type declarations (let a: IType to be IType)
  • [ ] Computed (reactive) variables

alexprey avatar Aug 27 '20 13:08 alexprey

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.

alexprey avatar Dec 02 '20 01:12 alexprey

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?

soft-decay avatar Dec 22 '20 22:12 soft-decay

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

alexprey avatar Dec 22 '20 22:12 alexprey

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.

sidharthramesh avatar Jan 15 '21 06:01 sidharthramesh

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

alexprey avatar Jan 15 '21 08:01 alexprey

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

sidharthramesh avatar Jan 15 '21 09:01 sidharthramesh

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

alexprey avatar Jan 25 '21 16:01 alexprey

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.

vezwork avatar Feb 17 '21 16:02 vezwork

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

madeleineostoja avatar May 16 '21 10:05 madeleineostoja

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.

alexprey avatar Dec 17 '21 17:12 alexprey

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?

IanVS avatar Jun 02 '22 17:06 IanVS

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.

Ddupasquier avatar Apr 05 '23 14:04 Ddupasquier