1 | export default (source, filename, err) ->
|
2 |
|
3 | {first_line, last_line, first_column, last_column} = err.location
|
4 |
|
5 |
|
6 | last_line = first_line unless last_line?
|
7 |
|
8 |
|
9 | lines = source.split '\n'
|
10 |
|
11 |
|
12 | l = lines[first_line]
|
13 | lines[first_line] = (l.substring 0, first_column) + '\x1B[91m' + l.substring first_column
|
14 |
|
15 |
|
16 |
|
17 | l = lines[last_line]
|
18 |
|
19 | if first_line is last_line
|
20 |
|
21 |
|
22 | col = last_column + 6
|
23 | else
|
24 | col = last_column
|
25 |
|
26 |
|
27 | lines[last_line] = (l.substring 0, col) + '\x1B[39m' + (l.substring col)
|
28 |
|
29 |
|
30 | lines = lines.slice first_line, last_line + 1
|
31 |
|
32 |
|
33 | carets = Array(first_column+1).join(' ') +
|
34 | "\x1B[91m#{Array(last_column + 2 - first_column).join('^')}\x1B[39m"
|
35 |
|
36 | lines.push carets
|
37 |
|
38 | """
|
39 | #{filename}:#{first_line+1}:#{first_column+1}: #{err.name}: #{err.message}
|
40 | #{lines.join '\n'}\n
|
41 | """ |
\ | No newline at end of file |