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

False-positive fall-through switch detection, adds unsyntactic break #116

Open
enisdenjo opened this issue Mar 17, 2021 · 0 comments
Open

Comments

@enisdenjo
Copy link

Hello there, seems like async switch cases with curly brackets report false-positives fall-throughs at nodent@3.2.13.

// index.js
// ❌

(async () => {
  switch (true) {
    case true: {
      await Promise.resolve();
      break;
    }
  }
})();
$ ./nodent.js index.js --out

/* /somewhere/index.js: 'use nodent*' directive missing/ignored, assumed 'use nodent;' */
Nodent: /somewhere/index.js(3:4)	switch-case fall-through not supported - added break. See https://github.com/MatAtBread/nodent#differences-from-the-es7-specification
(() => (function ($return, $error) {
    switch (true) {
        case true:
            return Promise.resolve().then((function ($await_2) {
                break; // 👈  Illegal break statement
            }).$asyncbind(this, $error), $error);
    }
    return $return();
}).$asyncbind(this, true))();

My guess is that nodent-transform wrongly reads the consequent end type as a BlockStatement.

Removing the curly brackets from the case in index.js transforms the file correctly. This works:

// index.js
// ✅

(async () => {
  switch (true) {
    case true:
      await Promise.resolve();
      break;
  }
})();
$ ./nodent.js index.js --out

/* /somewhere/index.js: 'use nodent*' directive missing/ignored, assumed 'use nodent;' */
(() => (function ($return, $error) {
    function $Switch_1() {
        return $return();
    }

    switch (true) {
        case true:
            return Promise.resolve().then((function ($await_2) {
                return $Switch_1.call(this);
            }).$asyncbind(this, $error), $error);
    }
    return $Switch_1.call(this);
}).$asyncbind(this, true))();
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

1 participant