| 70 | } |
| 71 | |
| 72 | const location = (source: string, offset: number, file: string, line: number): string => { |
| 73 | let localLine = 1 |
| 74 | let column = 1 |
| 75 | for (let index = 0; index < offset; index++) { |
| 76 | if (source.charCodeAt(index) === 10) { |
| 77 | localLine++ |
| 78 | column = 1 |
| 79 | } else { |
| 80 | column++ |
| 81 | } |
| 82 | } |
| 83 | return `${file}:${line + localLine}:${column}` |
| 84 | } |
| 85 | |
| 86 | const fail = (source: string, offset: number, file: string, line: number, message: string): never => { |
| 87 | throw new Error(`${location(source, offset, file, line)} ${message}`) |