|
1 | 1 | import {Token} from "./tokenizer";
|
| 2 | +import {Position} from "estree"; |
2 | 3 |
|
3 | 4 | /*The offset is calculated as follows:
|
4 | 5 | Current position is one after real position of end of token: 1
|
@@ -30,17 +31,23 @@ function getFullLine(source: string, current: number): string {
|
30 | 31 | return '\n' + source.slice(back, forward);
|
31 | 32 | }
|
32 | 33 |
|
| 34 | +function toEstreeLocation(line: number, column: number, offset: number) { |
| 35 | + return {line, column, offset} |
| 36 | +} |
| 37 | + |
33 | 38 | export namespace TokenizerErrors {
|
34 | 39 | export class BaseTokenizerError extends SyntaxError {
|
35 | 40 | line: number;
|
36 | 41 | col: number;
|
| 42 | + loc: Position; |
37 | 43 |
|
38 | 44 | constructor(message: string, line: number, col: number) {
|
39 | 45 | super(`SyntaxError at line ${line} column ${col-1}
|
40 | 46 | ${message}`);
|
41 | 47 | this.line = line;
|
42 | 48 | this.col = col;
|
43 | 49 | this.name = "BaseTokenizerError";
|
| 50 | + this.loc = toEstreeLocation(line, col, 0); |
44 | 51 | }
|
45 | 52 | }
|
46 | 53 |
|
@@ -103,13 +110,15 @@ export namespace ParserErrors {
|
103 | 110 | export class BaseParserError extends SyntaxError {
|
104 | 111 | line: number;
|
105 | 112 | col: number;
|
| 113 | + loc: Position; |
106 | 114 |
|
107 | 115 | constructor(message: string, line: number, col: number) {
|
108 | 116 | super(`SyntaxError at line ${line} column ${col-1}
|
109 | 117 | ${message}`);
|
110 | 118 | this.line = line;
|
111 | 119 | this.col = col;
|
112 | 120 | this.name = "BaseParserError";
|
| 121 | + this.loc = toEstreeLocation(line, col, 0); |
113 | 122 | }
|
114 | 123 | }
|
115 | 124 | export class ExpectedTokenError extends BaseParserError {
|
@@ -147,13 +156,15 @@ export namespace ResolverErrors {
|
147 | 156 | export class BaseResolverError extends SyntaxError {
|
148 | 157 | line: number;
|
149 | 158 | col: number;
|
| 159 | + loc: Position; |
150 | 160 |
|
151 | 161 | constructor(message: string, line: number, col: number) {
|
152 | 162 | super(`ResolverError at line ${line} column ${col-1}
|
153 | 163 | ${message}`);
|
154 | 164 | this.line = line;
|
155 | 165 | this.col = col;
|
156 | 166 | this.name = "BaseResolverError";
|
| 167 | + this.loc = toEstreeLocation(line, col, 0); |
157 | 168 | }
|
158 | 169 | }
|
159 | 170 | export class NameNotFoundError extends BaseResolverError {
|
|
0 commit comments