Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected comment placement after transformation #25

Open
raphinesse opened this issue Nov 24, 2020 · 3 comments
Open

Unexpected comment placement after transformation #25

raphinesse opened this issue Nov 24, 2020 · 3 comments

Comments

@raphinesse
Copy link

raphinesse commented Nov 24, 2020

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

  • @codemodsquad/asyncify: 2.0.5
  • jscodeshift: 0.11.0
    • babel: 7.10.2
    • babylon: 7.10.2
    • flow: 0.138.0
    • recast: 0.20.4

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

jedwards1211 commented Aug 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants