1 | import type { SourcePosition } from '../location';
|
2 | import type { Source } from '../source';
|
3 | import type { BrokenKind, InternalSyntheticKind, NonExistentKind, OffsetKind } from './kinds';
|
4 | import type { SourceSpan } from './span';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export interface PositionData {
|
10 | readonly kind: OffsetKind;
|
11 | toCharPos(): CharPosition | null;
|
12 | toJSON(): SourcePosition;
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export declare const BROKEN = "BROKEN";
|
20 | export type BROKEN = 'BROKEN';
|
21 | export type AnyPosition = HbsPosition | CharPosition | InvisiblePosition;
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | export declare class SourceOffset {
|
33 | readonly data: PositionData & AnyPosition;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | static forHbsPos(source: Source, pos: SourcePosition): SourceOffset;
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | static broken(pos?: SourcePosition): SourceOffset;
|
46 | constructor(data: PositionData & AnyPosition);
|
47 | /**
|
48 | * Get the character offset for this `SourceOffset`, if possible.
|
49 | */
|
50 | get offset(): number | null;
|
51 | /**
|
52 | * Compare this offset with another one.
|
53 | *
|
54 | * If both offsets are `HbsPosition`s, they're equivalent as long as their lines and columns are
|
55 | * the same. This avoids computing offsets unnecessarily.
|
56 | *
|
57 | * Otherwise, two `SourceOffset`s are equivalent if their successfully computed character offsets
|
58 | * are the same.
|
59 | */
|
60 | eql(right: SourceOffset): boolean;
|
61 | /**
|
62 | * Create a span that starts from this source offset and ends with another source offset. Avoid
|
63 | * computing character offsets if both `SourceOffset`s are still lazy.
|
64 | */
|
65 | until(other: SourceOffset): SourceSpan;
|
66 | /**
|
67 | * Create a `SourceOffset` by moving the character position represented by this source offset
|
68 | * forward or backward (if `by` is negative), if possible.
|
69 | *
|
70 | * If this `SourceOffset` can't compute a valid character offset, `move` returns a broken offset.
|
71 | *
|
72 | * If the resulting character offset is less than 0 or greater than the size of the source, `move`
|
73 | * returns a broken offset.
|
74 | */
|
75 | move(by: number): SourceOffset;
|
76 | /**
|
77 | * Create a new `SourceSpan` that represents a collapsed range at this source offset. Avoid
|
78 | * computing the character offset if it has not already been computed.
|
79 | */
|
80 | collapsed(): SourceSpan;
|
81 | /**
|
82 | * Convert this `SourceOffset` into a Handlebars {@see SourcePosition} for compatibility with
|
83 | * existing plugins.
|
84 | */
|
85 | toJSON(): SourcePosition;
|
86 | }
|
87 | export declare class CharPosition implements PositionData {
|
88 | readonly source: Source;
|
89 | readonly charPos: number;
|
90 | readonly kind: "CharPosition";
|
91 |
|
92 | _locPos: HbsPosition | BROKEN | null;
|
93 | constructor(source: Source, charPos: number);
|
94 | /**
|
95 | * This is already a `CharPosition`.
|
96 | *
|
97 | * {@see HbsPosition} for the alternative.
|
98 | */
|
99 | toCharPos(): this;
|
100 | |
101 |
|
102 |
|
103 |
|
104 | toJSON(): SourcePosition;
|
105 | wrap(): SourceOffset;
|
106 | |
107 |
|
108 |
|
109 | get offset(): number;
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | toHbsPos(): HbsPosition | null;
|
117 | }
|
118 | export declare class HbsPosition implements PositionData {
|
119 | readonly source: Source;
|
120 | readonly hbsPos: SourcePosition;
|
121 | readonly kind: "HbsPosition";
|
122 | _charPos: CharPosition | BROKEN | null;
|
123 | constructor(source: Source, hbsPos: SourcePosition, charPos?: number | null);
|
124 | /**
|
125 | * Lazily compute the character offset from the {@see SourcePosition}. Once an `HbsPosition` has
|
126 | * computed its `CharPosition`, it will not need to do compute it again, and the same
|
127 | * `HbsPosition` is retained when used as one of the ends of a `SourceSpan`, so computing the
|
128 | * `CharPosition` should be a one-time operation.
|
129 | */
|
130 | toCharPos(): CharPosition | null;
|
131 | |
132 |
|
133 |
|
134 |
|
135 | toJSON(): SourcePosition;
|
136 | wrap(): SourceOffset;
|
137 | |
138 |
|
139 |
|
140 |
|
141 |
|
142 | toHbsPos(): this;
|
143 | }
|
144 | export declare class InvisiblePosition implements PositionData {
|
145 | readonly kind: BrokenKind | InternalSyntheticKind | NonExistentKind;
|
146 | readonly pos: SourcePosition;
|
147 | constructor(kind: BrokenKind | InternalSyntheticKind | NonExistentKind, pos: SourcePosition);
|
148 | /**
|
149 | * A broken position cannot be turned into a {@see CharacterPosition}.
|
150 | */
|
151 | toCharPos(): null;
|
152 | |
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | toJSON(): SourcePosition;
|
160 | wrap(): SourceOffset;
|
161 | get offset(): null;
|
162 | }
|