hegemonic / catharsis

A JavaScript parser for Google Closure Compiler and JSDoc type expressions.
MIT License
54 stars 14 forks source link

Improve parser to support more typescript syntax #64

Open simonseyock opened 3 years ago

simonseyock commented 3 years ago

Hi! I wanted to ask if you are open to accept PRs that would enable JSDoc to parse more typescript specific types. For example the intersection types (See https://github.com/hegemonic/catharsis/issues/62). I think this would be good because more and more projects are using JSDoc together with the typescript parser.

hegemonic commented 3 years ago

Yes, that would be terrific! It would be ideal if Catharsis supported all TypeScript types.

I'd prefer to make users specify whether they're passing in a TypeScript type expression; a Closure Compiler type expression; or a JSDoc type expression, which is basically Closure Compiler + a few extras. (I don't want to fool anyone into thinking that Closure Compiler supports TypeScript syntax, or vice-versa.) So it might make sense to write a separate PEG grammar for TypeScript type expressions, rather than trying to shoehorn TypeScript support into the existing grammar.

Similarly, it might make sense to write a separate stringifier for TypeScript types. In contrast, the parse tree should use the same format as for Closure Compiler types.

If you think any of that doesn't make sense, let me know. If that all sounds good, I'd welcome a PR!

simonseyock commented 3 years ago

I would be interested to add support for typescript syntax, but I don't think I would want to write a whole new part of the software.

The main thing why I want to do this, is that I do a little work for an open source project (https://github.com/openlayers/openlayers) that uses jsdoc for the documentation but uses more complex types that are checked by typescript. At the moment we have rewriting step before the jsdoc processing that rewrites crucial types. That is suboptimal at least.

For us it would be great if there was a route where we could gradually add changes to feel the benefits in a reasonable amount of time.