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

Unreachable break in switch #931

Closed
smokku opened this Issue Oct 20, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@smokku

smokku commented Oct 20, 2016

The following snippets generate unreachable code (break;) in switch:
JS linter running on compiled code is complaining on these.

foo = switch bar
| \a =>
  if baz then 1 else 2
| \b => 3
var foo;
foo = (function(){
  switch (bar) {
  case 'a':
    if (baz) {
      return 1;
    } else {
      return 2;
    }
    break;    // <-- HERE
  case 'b':
    return 3;
  }
}());
foo = switch bar
| \a =>
  switch baz
  | \1 => 1
  | \2 => 2
| \b => 3
var foo;
foo = (function(){
  switch (bar) {
  case 'a':
    switch (baz) {
    case '1':
      return 1;
    case '2':
      return 2;
    }
    break;    // <-- HERE
  case 'b':
    return 3;
  }
}());
@determin1st

This comment has been minimized.

determin1st commented Nov 17, 2016

Well, it's more like a style problem, not the code. It only affects the size of bytes transmitted and not the speed of processing resulting JS. LiveScript, i believe, is a "filter" which produces nice JS code already with no need in additional lint.

@smokku

This comment has been minimized.

smokku commented Nov 17, 2016

My point is that this produced code could be nicer.

And you would be surprised how many programming errors can eslint catch on LiveScript generated code. I sure was.
With this generated code I cannot enable the rule catching unreachable code written by my programmers, because lsc itself is generating unreachable code.

@rhendric

This comment has been minimized.

Collaborator

rhendric commented Apr 4, 2017

Isn't your linter wrong about the second example? If baz takes a value other than '1' or '2', the break is reached, right?

@rhendric rhendric self-assigned this May 4, 2017

rhendric added a commit to rhendric/LiveScript that referenced this issue May 15, 2017

rhendric added a commit that referenced this issue May 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment