1 | import { SourceLocation, SourcePosition } from '../location';
|
2 | import { SourceSlice } from '../slice';
|
3 | import { Source } from '../source';
|
4 | import { MatchFn } from './match';
|
5 | import { AnyPosition, BROKEN, CharPosition, HbsPosition, OffsetKind, SourceOffset } from './offset';
|
6 |
|
7 |
|
8 |
|
9 | interface SpanData {
|
10 | readonly kind: OffsetKind;
|
11 | |
12 |
|
13 |
|
14 | asString(): string;
|
15 | |
16 |
|
17 |
|
18 | getModule(): string;
|
19 | |
20 |
|
21 |
|
22 |
|
23 | getStart(): AnyPosition;
|
24 | |
25 |
|
26 |
|
27 |
|
28 | getEnd(): AnyPosition;
|
29 | |
30 |
|
31 |
|
32 | toHbsSpan(): HbsSpan | null;
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 | locDidUpdate(changes: {
|
39 | start?: SourcePosition;
|
40 | end?: SourcePosition;
|
41 | }): void;
|
42 | |
43 |
|
44 |
|
45 |
|
46 | serialize(): SerializedSourceSpan;
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | export declare class SourceSpan implements SourceLocation {
|
83 | private data;
|
84 | static get NON_EXISTENT(): SourceSpan;
|
85 | static load(source: Source, serialized: SerializedSourceSpan): SourceSpan;
|
86 | static forHbsLoc(source: Source, loc: SourceLocation): SourceSpan;
|
87 | static forCharPositions(source: Source, startPos: number, endPos: number): SourceSpan;
|
88 | static synthetic(chars: string): SourceSpan;
|
89 | static broken(pos?: SourceLocation): SourceSpan;
|
90 | readonly isInvisible: boolean;
|
91 | constructor(data: SpanData & AnySpan);
|
92 | getStart(): SourceOffset;
|
93 | getEnd(): SourceOffset;
|
94 | get loc(): SourceLocation;
|
95 | get module(): string;
|
96 | /**
|
97 | * Get the starting `SourcePosition` for this `SourceSpan`, lazily computing it if needed.
|
98 | */
|
99 | get startPosition(): SourcePosition;
|
100 | /**
|
101 | * Get the ending `SourcePosition` for this `SourceSpan`, lazily computing it if needed.
|
102 | */
|
103 | get endPosition(): SourcePosition;
|
104 | /**
|
105 | * Support converting ASTv1 nodes into a serialized format using JSON.stringify.
|
106 | */
|
107 | toJSON(): SourceLocation;
|
108 | /**
|
109 | * Create a new span with the current span's end and a new beginning.
|
110 | */
|
111 | withStart(other: SourceOffset): SourceSpan;
|
112 | /**
|
113 | * Create a new span with the current span's beginning and a new ending.
|
114 | */
|
115 | withEnd(this: SourceSpan, other: SourceOffset): SourceSpan;
|
116 | asString(): string;
|
117 | /**
|
118 | * Convert this `SourceSpan` into a `SourceSlice`. In debug mode, this method optionally checks
|
119 | * that the byte offsets represented by this `SourceSpan` actually correspond to the expected
|
120 | * string.
|
121 | */
|
122 | toSlice(expected?: string): SourceSlice;
|
123 | /**
|
124 | * For compatibility with SourceLocation in AST plugins
|
125 | *
|
126 | * @deprecated use startPosition instead
|
127 | */
|
128 | get start(): SourcePosition;
|
129 | /**
|
130 | * For compatibility with SourceLocation in AST plugins
|
131 | *
|
132 | * @deprecated use withStart instead
|
133 | */
|
134 | set start(position: SourcePosition);
|
135 | /**
|
136 | * For compatibility with SourceLocation in AST plugins
|
137 | *
|
138 | * @deprecated use endPosition instead
|
139 | */
|
140 | get end(): SourcePosition;
|
141 | /**
|
142 | * For compatibility with SourceLocation in AST plugins
|
143 | *
|
144 | * @deprecated use withEnd instead
|
145 | */
|
146 | set end(position: SourcePosition);
|
147 | /**
|
148 | * For compatibility with SourceLocation in AST plugins
|
149 | *
|
150 | * @deprecated use module instead
|
151 | */
|
152 | get source(): string;
|
153 | collapse(where: 'start' | 'end'): SourceSpan;
|
154 | extend(other: SourceSpan): SourceSpan;
|
155 | serialize(): SerializedSourceSpan;
|
156 | slice({ skipStart, skipEnd }: {
|
157 | skipStart?: number;
|
158 | skipEnd?: number;
|
159 | }): SourceSpan;
|
160 | sliceStartChars({ skipStart, chars }: {
|
161 | skipStart?: number;
|
162 | chars: number;
|
163 | }): SourceSpan;
|
164 | sliceEndChars({ skipEnd, chars }: {
|
165 | skipEnd?: number;
|
166 | chars: number;
|
167 | }): SourceSpan;
|
168 | }
|
169 | declare type AnySpan = HbsSpan | CharPositionSpan | InvisibleSpan;
|
170 | declare class CharPositionSpan implements SpanData {
|
171 | readonly source: Source;
|
172 | readonly charPositions: {
|
173 | start: CharPosition;
|
174 | end: CharPosition;
|
175 | };
|
176 | readonly kind = OffsetKind.CharPosition;
|
177 | _locPosSpan: HbsSpan | BROKEN | null;
|
178 | constructor(source: Source, charPositions: {
|
179 | start: CharPosition;
|
180 | end: CharPosition;
|
181 | });
|
182 | wrap(): SourceSpan;
|
183 | asString(): string;
|
184 | getModule(): string;
|
185 | getStart(): AnyPosition;
|
186 | getEnd(): AnyPosition;
|
187 | locDidUpdate(): void;
|
188 | toHbsSpan(): HbsSpan | null;
|
189 | serialize(): SerializedSourceSpan;
|
190 | toCharPosSpan(): CharPositionSpan;
|
191 | }
|
192 | export declare class HbsSpan implements SpanData {
|
193 | readonly source: Source;
|
194 | readonly hbsPositions: {
|
195 | start: HbsPosition;
|
196 | end: HbsPosition;
|
197 | };
|
198 | readonly kind = OffsetKind.HbsPosition;
|
199 | _charPosSpan: CharPositionSpan | BROKEN | null;
|
200 | _providedHbsLoc: SourceLocation | null;
|
201 | constructor(source: Source, hbsPositions: {
|
202 | start: HbsPosition;
|
203 | end: HbsPosition;
|
204 | }, providedHbsLoc?: SourceLocation | null);
|
205 | serialize(): SerializedConcreteSourceSpan;
|
206 | wrap(): SourceSpan;
|
207 | private updateProvided;
|
208 | locDidUpdate({ start, end }: {
|
209 | start?: SourcePosition;
|
210 | end?: SourcePosition;
|
211 | }): void;
|
212 | asString(): string;
|
213 | getModule(): string;
|
214 | getStart(): AnyPosition;
|
215 | getEnd(): AnyPosition;
|
216 | toHbsLoc(): SourceLocation;
|
217 | toHbsSpan(): HbsSpan;
|
218 | toCharPosSpan(): CharPositionSpan | null;
|
219 | }
|
220 | declare class InvisibleSpan implements SpanData {
|
221 | readonly kind: OffsetKind.Broken | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent;
|
222 | readonly loc: SourceLocation;
|
223 | readonly string: string | null;
|
224 | constructor(kind: OffsetKind.Broken | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent, loc: SourceLocation, string?: string | null);
|
225 | serialize(): SerializedConcreteSourceSpan;
|
226 | wrap(): SourceSpan;
|
227 | asString(): string;
|
228 | locDidUpdate({ start, end }: {
|
229 | start?: SourcePosition;
|
230 | end?: SourcePosition;
|
231 | }): void;
|
232 | getModule(): string;
|
233 | getStart(): AnyPosition;
|
234 | getEnd(): AnyPosition;
|
235 | toCharPosSpan(): InvisibleSpan;
|
236 | toHbsSpan(): null;
|
237 | toHbsLoc(): SourceLocation;
|
238 | }
|
239 | export declare const span: MatchFn<SourceSpan>;
|
240 | export declare type SerializedConcreteSourceSpan = /** collapsed */ number | /** normal */ [start: number, size: number] | /** synthetic */ string;
|
241 | export declare type SerializedSourceSpan = SerializedConcreteSourceSpan | OffsetKind.NonExistent | OffsetKind.Broken;
|
242 | export {};
|
243 |
|
\ | No newline at end of file |