Incorrect indent bug #414

Open
rmuratov opened this Issue Nov 12, 2015 · 3 comments

Projects

None yet

3 participants

@rmuratov

Here is code I want to convert using http://js2.coffee/:

function someFunc(data, n) {
  var localSum = 0;
  for (var i = data.length - 1; i >= n; i--) {
    for (var j = i; j > i - n; j--) {
      localSum += data[j];
    }
  }
}

It produces:

someFunc = (data, n) ->
  localSum = 0
  i = data.length - 1
  while i >= n
        j = i
    while j > i - n
      localSum += data[j]
      j--
    i--
  return

Please, take a look at the line 5 of result - indent incorrect. Back to javascript there are 2 same level while instead of nested:

  while (i >= n) {
    j = i;
  }
  while (j > i - n) {
    localSum += data[j];
    j--;
  }

So j = i should be on the same level as second while:

  while i >= n
    j = i
    while j > i - n
@Dunky13
Dunky13 commented Feb 5, 2016

It is because enter adds spaces, whilst you are probably are working with tabs

@rmuratov
rmuratov commented Feb 5, 2016

@Dunky13 I am not sure I understand what are you talking about. Ok, change tabs to spaces, spaces to tabs in input - the same result.

@flying-sheep
Collaborator

@Dunky13 yeah, try pasting things in before you assume stuff, it’s like 5 seconds of work 😉

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