index.d.ts
6.71 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Type definitions for webpack-sources 1.4
// Project: https://github.com/webpack/webpack-sources
// Definitions by: e-cloud <https://github.com/e-cloud>
// Chris Eppstein <https://github.com/chriseppstein>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { Hash } from 'crypto';
import { SourceNode, RawSourceMap, SourceMapGenerator } from '@umijs/deps/types/webpack-sources/source-map';
import { SourceListMap } from '@umijs/deps/types/webpack-sources/source-list-map';
export interface MapOptions {
/**
* If set to false the implementation may omit mappings for columns
* @default true
*/
columns?: boolean;
/**
* If set to false the implementation may omit inner mappings for modules.
* @default true
*/
module?: boolean;
}
export interface SourceAndMapResult {
source: string;
map: RawSourceMap | null;
}
/**
* Base class for all sources.
* A Source can be asked for source code, size, source map and hash.
*/
export abstract class Source {
/**
* Returns the represented source code as string.
*/
source(): string | ArrayBuffer;
/**
* Returns the size in chars of the represented source code.
*/
size(): number;
/**
* Returns the SourceMap of the represented source code as JSON.
* May return `null` if no SourceMap is available.
*/
map(options?: MapOptions): RawSourceMap | null;
/**
* Returns both, source code (like `Source.prototype.source()` and SourceMap (like `Source.prototype.map()`).
* This method could have better performance than calling `source()` and `map()` separately.
*/
sourceAndMap(options?: MapOptions): SourceAndMapResult;
/**
* This is an optional method. It may be null if not implemented.
* Returns a SourceNode (see source-map library) for the represented source code.
*/
node(options: MapOptions): SourceNode;
/**
* This is an optional method. It may be null if not implemented.
* Returns a SourceListMap (see source-list-map library) for the represented source code.
*/
listNode(options: MapOptions): SourceListMap;
/**
* Updates the provided Hash object with the content of the represented source code.
* (Hash is an object with an update method, which is called with string values)
*/
updateHash(hash: Hash): void;
}
export interface SourceAndMapMixin {
/**
* Returns the SourceMap of the represented source code as JSON.
* May return `null` if no SourceMap is available.
*/
map(options?: MapOptions): RawSourceMap | null;
/**
* Returns both, source code (like `Source.prototype.source()` and SourceMap (like `Source.prototype.map()`).
* This method could have better performance than calling `source()` and `map()` separately.
*/
sourceAndMap(options?: MapOptions): SourceAndMapResult;
}
/**
* Decorates a Source and caches returned results of map, source, size and sourceAndMap in memory.
* Every other operation is delegated to the wrapped Source.
*/
export class CachedSource extends Source {
constructor(source: Source);
map(options?: MapOptions): RawSourceMap;
}
/**
* Concatenate multiple Sources or strings to a single source.
*/
export class ConcatSource extends Source implements SourceAndMapMixin {
children: Array<string | Source>;
constructor(...args: Array<string | Source>);
/**
* Adds an item to the source.
*/
add(item: string | Source): void;
source(): string;
node(options: MapOptions): SourceNode;
listMap(options: MapOptions): SourceListMap;
}
export class LineToLineMappedSource extends Source implements SourceAndMapMixin {
constructor(sourceCode: string, name: string, originalSource: string);
source(): string;
node(options: MapOptions): SourceNode;
listMap(options: MapOptions): SourceListMap;
}
/**
* Represents source code, which is a copy of the original file
*/
export class OriginalSource extends Source implements SourceAndMapMixin {
/**
* OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (;, {, }).
*/
constructor(sourceCode: string, name: string);
source(): string;
node(options: MapOptions): SourceNode;
listMap(options: MapOptions): SourceListMap;
}
/**
* Prefix every line of the decorated Source with a provided string.
*/
export class PrefixSource extends Source implements SourceAndMapMixin {
constructor(prefix: Source | string, source: Source | string);
source(): string;
node(options: MapOptions): SourceNode;
listMap(options: MapOptions): SourceListMap;
}
/**
* Represents source code without SourceMap
*/
export class RawSource extends Source {
constructor(value: string);
source(): string;
map(options: MapOptions): null;
node(options: MapOptions): SourceNode;
listMap(options: MapOptions): SourceListMap;
}
export interface Replacement {
readonly start: number;
readonly end: number;
readonly content: string;
readonly insertIndex: number;
readonly name: string;
}
/**
* Decorates a Source with replacements and insertions of source code.
*
*/
export class ReplaceSource extends Source implements SourceAndMapMixin {
replacements: Replacement[];
/**
* The ReplaceSource supports "identity" mappings for child source.
* When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to split mappings at replacements/insertions.
*/
constructor(source: Source, name?: string);
/**
* Replaces chars from start (0-indexed, inclusive) to end (0-indexed, inclusive) with replacement.
*/
replace(start: number, end: number, newValue: string, name?: string): void;
/**
* Inserts the insertion before char pos (0-indexed).
*/
insert(pos: number, newValue: string, name?: string): void;
/**
* Get decorated Source.
*/
original(): Source;
source(): string;
node(options: MapOptions): SourceNode;
listMap(options: MapOptions): SourceListMap;
}
/**
* Represents source code with SourceMap, optionally having an additional SourceMap for the original source.
*/
export class SourceMapSource extends Source implements SourceAndMapMixin {
constructor(
sourceCode: string,
name: string,
sourceMap: SourceMapGenerator | RawSourceMap,
originalSource?: string,
innerSourceMap?: RawSourceMap | string,
removeOriginalSource?: boolean,
);
source(): string;
node(options: MapOptions): SourceNode;
listMap(options: MapOptions): SourceListMap;
}