js2coffee / js2coffee

Compile JavaScript to CoffeeScript

Home Page:http://js2.coffee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect indent bug

rmuratov opened this issue · comments

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

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

@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.

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

Fixed as I see.