p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
119 stars 7 forks source link

Wrong code generated by "Convert if-else into conditional expression" using p42 VSCode plugin v1.163.1 #57

Closed doberkofler closed 1 year ago

doberkofler commented 1 year ago

I just noticed in my code that the following code snipped:

function test(para: string, options?: string): string {
    let url = `url?para=${para}`;

    if (typeof options === 'string' && options.length > 0) {
        url += `&${options}`;
    }

    return url;
}

will be wrongly converted by p42 to:

function test(para: string, options?: string): string {
    return typeof options === 'string' && options.length > 0 ? `&${options}` : `url?para=${para}`;
}
lgrammel commented 1 year ago

Hi @doberkofler - thanks for the bug report! This issue was fixed in v1.163.2. Please try that version and re-open if it still occurs.

Duplicate of #56