mirror of https://github.com/lukechilds/rollup.git
Rich Harris
10 years ago
5 changed files with 34 additions and 3 deletions
@ -0,0 +1,20 @@ |
|||||
|
export default function getLocation ( source, charIndex ) { |
||||
|
const lines = source.split( '\n' ); |
||||
|
const len = lines.length; |
||||
|
|
||||
|
let lineStart = 0; |
||||
|
let i; |
||||
|
|
||||
|
for ( i = 0; i < len; i += 1 ) { |
||||
|
const line = lines[i]; |
||||
|
const lineEnd = lineStart + line.length + 1; // +1 for newline
|
||||
|
|
||||
|
if ( lineEnd > charIndex ) { |
||||
|
return { line: i + 1, column: charIndex - lineStart }; |
||||
|
} |
||||
|
|
||||
|
lineStart = lineEnd; |
||||
|
} |
||||
|
|
||||
|
throw new Error( 'Could not determine location of character' ); |
||||
|
} |
@ -1,2 +1,2 @@ |
|||||
import { a, a } from './exporter'; |
import { a, a } from './foo'; |
||||
assert.equal(a, 1); |
assert.equal(a, 1); |
||||
|
Loading…
Reference in new issue