codemodsquad / asyncify

Don't keep your promises 😉
MIT License
13 stars 6 forks source link

Unexpected comment placement after transformation #25

Open raphinesse opened 3 years ago

raphinesse commented 3 years ago

Again, thanks for this code mod. It works very well so far!

I just wanted to pass on some examples where comments in the transformed code were not placed like I expected them to be.

Environment

Input

function a (x) {
    // Apply f to x because ...
    return f(x)
        .then(() => x);
}

function b (x) {
    return f(x)
        // Always return true because ...
        .then(() => true);
}

Actual Output

async function a(x) {
    await f(x);
    // Apply f to x because ...
    return x;
}

async function b(x) {
    await // Always return true because ...
    f(x);

    return true;
}

Expected Output

async function a(x) {
    // Apply f to x because ...
    await f(x);
    return x;
}

async function b(x) {
    await f(x);
    // Always return true because ...
    return true;
}
jedwards1211 commented 3 years ago

Yeah, this is a known issue, you can try the --commentWorkarounds=true option, it will usually improve the output but sometimes it will cause an assertion failure inside recast. Dealing with comments in recastseems kinda problematic...

jedwards1211 commented 3 years ago

I can't remember if I had any specific handling for the comment-before-then case, but I'll look into it some more

jedwards1211 commented 3 years ago

ack, I forgot about this. And then, I think I just mindlessly blew away some work in progress that was sitting in my working copy while checking a PR... 😅

I have some memories of what I learned from looking into this, will try to work on it again soon