-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.d.ts
108 lines (101 loc) · 3.24 KB
/
index.d.ts
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
39
40
41
42
43
44
45
46
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* A position for a source mapping. 1-indexed.
*/
export type MappingPosition = {
line: number;
column: number;
};
/**
* An indexed source mapping block
*/
export type IndexedMapping<T> = {
generated: MappingPosition;
original?: MappingPosition;
source?: T;
name?: T;
};
/**
* A source map in VLQ format
*/
export type VLQMap = Readonly<{
sources: ReadonlyArray<string>;
sourcesContent?: ReadonlyArray<string | null>;
names: ReadonlyArray<string>;
mappings: string;
version?: number;
file?: string;
sourceRoot?: string;
}>;
/**
* A parsed source map
*/
export type ParsedMap = {
sources: string[];
names: string[];
mappings: Array<IndexedMapping<number>>;
sourcesContent: Array<string | null>;
};
/**
* Options for stringifying a source map
*/
export type SourceMapStringifyOptions = {
file?: string;
sourceRoot?: string;
rootDir?: string;
inlineSources?: boolean;
fs?: {
readFile(path: string, encoding: string): Promise<string>;
};
format?: 'inline' | 'string' | 'object';
};
/**
* Options for creating an empty source map
*/
export type GenerateEmptyMapOptions = {
projectRoot: string;
sourceName: string;
sourceContent: string;
lineOffset?: number;
};
/**
* A source map to assist in debugging during development
*/
export default class SourceMap {
constructor(projectRoot?: string, buffer?: Buffer);
static generateEmptyMap(opts: GenerateEmptyMapOptions): SourceMap;
addEmptyMap(sourceName: string, sourceContent: string, lineOffset?: number): SourceMap;
addVLQMap(map: VLQMap, lineOffset?: number, columnOffset?: number): SourceMap;
addSourceMap(sourcemap: SourceMap, lineOffset: number): SourceMap;
addBuffer(buffer: Buffer, lineOffset?: number): SourceMap;
addIndexedMapping(mapping: IndexedMapping<string>, lineOffset?: number, columnOffset?: number): void;
addIndexedMappings(mappings: Array<IndexedMapping<string>>, lineOffset?: number, columnOffset?: number): void;
addName(name: string): number;
addNames(names: string[]): number[];
addSource(source: string): number;
addSources(sources: string[]): number[];
getSourceIndex(source: string): number;
getSource(index: number): string;
getSources(): string[];
setSourceContent(sourceName: string, sourceContent: string): void;
getSourceContent(sourceName: string): string;
getSourcesContent(): (string | null)[];
getSourcesContentMap(): { [key: string]: string | null };
getNameIndex(name: string): number;
getName(index: number): string;
getNames(): string[];
getMappings(): IndexedMapping<number>[];
indexedMappingToStringMapping(mapping: IndexedMapping<number> | null | undefined): IndexedMapping<string> | null | undefined;
extends(buffer: Buffer | SourceMap): SourceMap;
getMap(): ParsedMap;
findClosestMapping(line: number, column: number): IndexedMapping<string> | undefined;
offsetLines(line: number, lineOffset: number): IndexedMapping<string> | undefined;
offsetColumns(line: number, column: number, columnOffset: number): IndexedMapping<string> | undefined;
toBuffer(): Buffer;
toVLQ(): VLQMap;
delete(): void;
stringify(options: SourceMapStringifyOptions): Promise<string | VLQMap>;
}
/**
* Only used by the wasm version, await this to ensure the wasm binary is loaded
*/
export const init: Promise<void>