Skip to content

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

Open
@enisdenjo

Description

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))();

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions