diff --git a/lib/coffee-script/helpers.js b/lib/coffee-script/helpers.js index 5c72acf2..1b33005d 100644 --- a/lib/coffee-script/helpers.js +++ b/lib/coffee-script/helpers.js @@ -220,7 +220,7 @@ codeLine = this.code.split('\n')[first_line]; start = first_column; end = first_line === last_line ? last_column + 1 : codeLine.length; - marker = repeat(' ', start) + repeat('^', end - start); + marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start); if (typeof process !== "undefined" && process !== null) { colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS; } diff --git a/src/helpers.coffee b/src/helpers.coffee index 98792cd0..4ab4f954 100644 --- a/src/helpers.coffee +++ b/src/helpers.coffee @@ -172,7 +172,7 @@ syntaxErrorToString = -> start = first_column # Show only the first line on multi-line errors. end = if first_line is last_line then last_column + 1 else codeLine.length - marker = repeat(' ', start) + repeat('^', end - start) + marker = codeLine[...start].replace(/[^\s]/g, ' ') + repeat('^', end - start) # Check to see if we're running on a color-enabled TTY. if process? diff --git a/test/error_messages.coffee b/test/error_messages.coffee index 551f3b5e..21886f6a 100644 --- a/test/error_messages.coffee +++ b/test/error_messages.coffee @@ -41,6 +41,17 @@ test "compiler error formatting", -> ^^^^ ''' +test "compiler error formatting with mixed tab and space", -> + assertErrorFormat """ + \t if a + \t test + """, + ''' + [stdin]:1:4: error: unexpected if + \t if a + \t ^^ + ''' + if require? fs = require 'fs'