-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCodeLocation.mjs
38 lines (33 loc) · 953 Bytes
/
CodeLocation.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import CodePosition from "./CodePosition.mjs";
/**
* A location in code.
* @kind class
* @name CodeLocation
* @param {CodePosition} start Start code position.
* @param {CodePosition} [end] End code position.
* @ignore
*/
export default class CodeLocation {
constructor(start, end) {
if (!(start instanceof CodePosition))
throw new TypeError(
"Argument 1 `start` must be a `CodePosition` instance."
);
if (arguments.length > 1) {
if (!(end instanceof CodePosition))
throw new TypeError(
"Argument 2 `end` must be a `CodePosition` instance."
);
if (
start.line > end.line ||
(start.line === end.line && start.column > end.column)
)
throw new TypeError(
"Argument 2 `end` must be a code position at or beyond the start code position."
);
}
this.start = start;
if (end) this.end = end;
Object.freeze(this);
}
}