tamzinblake / js3-mode

A chimeric fork of js2-mode and js-mode
GNU General Public License v3.0
181 stars 13 forks source link

Switch label indentation off inside anonymous functions #99

Closed vthunder closed 10 years ago

vthunder commented 10 years ago

I was excited when I saw #90, but I think it's still broken in the second case below:

function() foo {
  switch (bar) {
  case "1":
  case "2":
  }
}

function() qux {
  doSomething(function() {
    switch (bar) {
  case "1":
  case "2":
    }
  });
}

I want the label to align with the switch statement (or be indented one level in from there, I don't actually care so much). It ends up aligning with the scope outside the anonymous function, which is wrong.

vthunder commented 10 years ago

To drive the point home, here is what happens if you play around with the anonymous function definition so it ends up indented further:

function() foo {
  doSomething(
    function() {
      switch (bar) {
  case "1":
        blah();
        break;
  case "2":
        blah();
        break;
      }
    });
}

Or even the hilarious:

function() foo {
  doSomething(function()
              {
                switch (bar) {
  case "1":
                  blah();
                  break;
  case "2":
                  blah();
                  break;
                }
              });
}
tamzinblake commented 10 years ago

See, this is why one shouldn't merge code without tests.

tamzinblake commented 10 years ago

By the way, function() foo { is totally not JavaScript.

vthunder commented 10 years ago

omg, what a horrible typo. But thanks for fixing so quickly! I just updated, and it works great.