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

Incorrect transforming break inside switch-case #49

Closed
Djaler opened this issue Nov 17, 2019 · 3 comments
Closed

Incorrect transforming break inside switch-case #49

Djaler opened this issue Nov 17, 2019 · 3 comments

Comments

@Djaler
Copy link

Djaler commented Nov 17, 2019

I create a repo with reproduction: https://github.com/Djaler/babel-plugin-transform-async-to-promises-switch-bug

Brief comparison of the original code with transformed:

export async function doSomething() {
    await sleep(1000)
    const errorCode = 2; //why not

    let message = 'Something wrong';

    switch (errorCode) {
        case 2:
            message = "Error 2"
            break
    }

    alert(message)
}
var doSomething = _async(function () {
  return _await(sleep(1000), function () {
    var errorCode = 2; //why not

    var message = 'Something wrong';

    switch (errorCode) {
      case 2:
        message = "Error 2";
        return;
    }

    alert(message);
  });
});

As you can see, break turns into return, and because of this alert is never called

@Djaler
Copy link
Author

Djaler commented Dec 9, 2019

Additional info: the issue appears in 0.8.15 version

@agilgur5
Copy link

@rpetrich any word on this? This causes some unexpected and hard to debug issues. We use this inside of TSDX and at least one user downstream is (knowingly) facing this issue jaredpalmer/tsdx#509

I tried to look through the code, but there's a lot of references to switch cases and replaceReturnsAndBreaks etc and I've never written a Babel plugin, so I wasn't really able to figure out where the bug is

@PeterBurner
Copy link

this also happens with continue inside of for-loops
its replaced with return, which breaks the code logic

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

3 participants