Open JGreenlee opened 3 months ago
It does seem to make sense to format the docstring in a way that is appropriate for the language. If it's not too messy to do that, it sounds like a good idea. I will just need to see if there are any historical ramifications with changing it from the way it is now.
I was thinking this could be provided as a new option, separate from -d
/ --docat
, so that the existing behavior is not disrupted. Maybe called -jd
/ --jsdoc
I don't think it is too messy to achieve if it's like my example above where the docstring text is taken verbatim, wrapped in /**
and */
, and placed above the JS function.
That much is satisfactory for my use case at least.
If we wanted to actually parse through the docstring and convert Python-style doc into JS-style doc, I think that would get messy, especially because Python has around 3 different major conventions for docstrings and documentation styles.
The repo I am using Transcrypt for (e-mission-common) is a standalone library that gets distributed as both a JS package (npm) and a Python package (pip).
I'm gradually adding inline documentation in the Python source via docstrings so that when people import the library for use in Python projects they can benefit from autocompletion and inline documentation in their IDE. But when imported into JS projects, this doesn't work because Transcrypt doesn't convert docstrings to the JS equivalent (which would be JSDoc)
It's possible to use the
-d
option to get Transcrypt to include the docstrings in the output JS, but doesn't achieve what I want.Example function:
Output JS using
-d
:What I want:
I was actually able to achieve this result by adding this bit of code in
compiler.py
, around line 2664But before I created a PR, I wanted to first file an issue proposing this to see if it would be accepted.