futurGH / ts-to-jsdoc

Transpile TypeScript code to fully compatible JavaScript + JSDoc comments.
MIT License
177 stars 17 forks source link

TSX transpiles into chaos #40

Closed kungfooman closed 7 months ago

kungfooman commented 7 months ago

Test code:

import React from 'react';
import { InfoBox } from 'pcui';
import { ObserverData } from '../types';

// InfoBox that shows an error
const ErrorBox = (props: { observerData: ObserverData }) => {
    return <InfoBox class="pcui-error" title='Error' hidden={!props.observerData.ui.error} text={props.observerData.ui.error} icon='E218'/>;
};

export default ErrorBox;

Output:

// InfoBox that shows an error
/**
 * @param {{ observerData: ObserverData }} props
 * @returns {InfoBox}
 * @type {{ props: any; "": any; }}
 */
const ErrorBox = (props) => {
    return class {
    };
    "pcui-error";
    title = 'Error';
    hidden = {};
    props.observerData.ui.error;
}, text = { props, : .observerData.ui.error }, icon = 'E218' /  > ;
;

export default ErrorBox;
futurGH commented 7 months ago

Fixed in 2.0.0!

kungfooman commented 7 months ago

Sorry, but this isn't fixed - v2.0.0 still outputs the same ASCII code salad.

I tried it like this:

import {transpileFile} from 'ts-to-jsdoc';
import {readFileSync, writeFileSync} from 'fs';
function convert(i, o) {
    const contentTS = readFileSync(i, 'utf8');
    const contentJS = transpileFile({code: contentTS});
    writeFileSync(o, contentJS);
}

(because I don't like how the bin/ts-to-jsdoc command always make an extra dir for every file)

futurGH commented 7 months ago

Ah, should probably document somewhere that you need a .tsx filename for the compiler to recognize it as TSX.

As for the footnote, can you open an issue with a repro? The CLI shouldn't be creating any directories unless you pass -o.