-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathsource-map.d.ts
More file actions
221 lines (218 loc) Β· 8.18 KB
/
Copy pathsource-map.d.ts
File metadata and controls
221 lines (218 loc) Β· 8.18 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
211
212
213
214
215
216
217
218
219
220
221
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<a3a499a683d5ea557e429489802510ae>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro-source-map/src/source-map.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {IConsumer} from './Consumer/types';
import {BundleBuilder, createIndexMap} from './BundleBuilder';
import composeSourceMaps from './composeSourceMaps';
import Consumer from './Consumer';
import normalizeSourcePath from './Consumer/normalizeSourcePath';
import {
functionMapBabelPlugin,
generateFunctionMap,
} from './generateFunctionMap';
import Generator from './Generator';
export type {IConsumer};
type GeneratedCodeMapping = [number, number];
type SourceMapping = [number, number, number, number];
type SourceMappingWithName = [number, number, number, number, string];
export type MetroSourceMapSegmentTuple =
| SourceMappingWithName
| SourceMapping
| GeneratedCodeMapping;
type BabelDecodedMapSegment =
| [number]
| [number, number, number, number]
| [number, number, number, number, number];
export type BabelDecodedMap = {
readonly mappings: ReadonlyArray<ReadonlyArray<BabelDecodedMapSegment>>;
readonly names: ReadonlyArray<string>;
};
export type VlqMap = {
readonly mappings: string;
readonly names: ReadonlyArray<string>;
};
export type HermesFunctionOffsets = {
[$$Key$$: number]: ReadonlyArray<number>;
};
export type FBSourcesArray = ReadonlyArray<null | undefined | FBSourceMetadata>;
export type FBSourceMetadata = [null | undefined | FBSourceFunctionMap];
export type FBSourceFunctionMap = {
readonly names: ReadonlyArray<string>;
readonly mappings: string;
};
export type BabelSourceMapSegment = Readonly<{
generated: Readonly<{column: number; line: number}>;
original?: Readonly<{column: number; line: number}>;
source?: null | undefined | string;
name?: null | undefined | string;
}>;
export type FBSegmentMap = {[id: string]: MixedSourceMap};
export type BasicSourceMap = {
readonly file?: string;
readonly mappings: string;
readonly names: Array<string>;
readonly sourceRoot?: string;
readonly sources: Array<string>;
readonly sourcesContent?: Array<null | undefined | string>;
readonly version: number;
readonly x_facebook_offsets?: Array<number>;
readonly x_metro_module_paths?: Array<string>;
readonly x_facebook_sources?: FBSourcesArray;
readonly x_facebook_segments?: FBSegmentMap;
readonly x_hermes_function_offsets?: HermesFunctionOffsets;
readonly x_google_ignoreList?: Array<number>;
};
export type IndexMapSection = {
map: IndexMap | BasicSourceMap;
offset: {line: number; column: number};
};
export type IndexMap = {
readonly file?: string;
readonly mappings?: void;
readonly sourcesContent?: void;
readonly sections: Array<IndexMapSection>;
readonly version: number;
readonly x_facebook_offsets?: Array<number>;
readonly x_metro_module_paths?: Array<string>;
readonly x_facebook_sources?: void;
readonly x_facebook_segments?: FBSegmentMap;
readonly x_hermes_function_offsets?: HermesFunctionOffsets;
readonly x_google_ignoreList?: void;
};
export type MixedSourceMap = IndexMap | BasicSourceMap;
export type RawMappingsModule = {
readonly map:
| (null | undefined | ReadonlyArray<MetroSourceMapSegmentTuple>)
| VlqMap;
readonly functionMap: null | undefined | FBSourceFunctionMap;
readonly path: string;
readonly source: string;
readonly code: string;
readonly isIgnored: boolean;
readonly lineCount?: number;
};
export interface SourceMapGenerator {
toMap(file?: string, options?: {excludeSource?: boolean}): MixedSourceMap;
toString(file?: string, options?: {excludeSource?: boolean}): string;
}
/**
* Result of `fromRawMappingsIndexed`: a sectioned (indexed) source map where
* each module is one section. VLQ-stored modules pass through verbatim, which is
* why building this is cheap compared to flattening into a single map.
*/
declare class IndexedSourceMapResult implements SourceMapGenerator {
constructor(sections: Array<IndexMapSection>);
toMap(file?: string, options?: {excludeSource?: boolean}): MixedSourceMap;
toString(file?: string, options?: {excludeSource?: boolean}): string;
}
declare function isVlqMap(
map: (null | undefined | ReadonlyArray<MetroSourceMapSegmentTuple>) | VlqMap,
): map is VlqMap;
/**
* Creates a source map from modules with "raw mappings", i.e. an array of
* tuples with either 2, 4, or 5 elements:
* generated line, generated column, source line, source line, symbol name.
* Accepts an `offsetLines` argument in case modules' code is to be offset in
* the resulting bundle, e.g. by some prefix code.
*/
declare function fromRawMappings(
modules: ReadonlyArray<RawMappingsModule>,
offsetLines?: number,
): Generator;
declare function fromRawMappingsNonBlocking(
modules: ReadonlyArray<RawMappingsModule>,
offsetLines?: number,
): Promise<Generator>;
/**
* Like `fromRawMappings`, but produces an indexed (sectioned) source map with
* one section per module. VLQ-stored modules pass through verbatim β no
* decode/re-encode β which is the whole point: it's much cheaper to serialize
* than the flat path, at the cost of emitting an indexed map that consumers must
* understand. Per-module work is trivial, so this runs synchronously.
*/
declare function fromRawMappingsIndexed(
modules: ReadonlyArray<RawMappingsModule>,
offsetLines?: number,
): IndexedSourceMapResult;
/**
* Transforms a standard source map object into a Raw Mappings object, to be
* used across the bundler.
*/
declare function toBabelSegments(
sourceMap: BasicSourceMap,
): Array<BabelSourceMapSegment>;
declare function toSegmentTuple(
mapping: BabelSourceMapSegment,
): MetroSourceMapSegmentTuple;
/**
* Converts a Babel/gen-mapping "decoded" source map (`result.decodedMap` from
* `@babel/generator`) into raw mapping tuples, byte-identical to
* `result.rawMappings.map(toSegmentTuple)`.
*
* Preferred over `result.rawMappings` because `decodedMap` is computed eagerly
* during generation, whereas accessing `rawMappings` triggers a second decode
* (`allMappings`) that allocates ~4-5 objects per segment. No terminating
* mapping is appended (callers that need one use `countLinesAndTerminateMap`).
*/
declare function tuplesFromBabelDecodedMap(
decodedMap: BabelDecodedMap,
): Array<MetroSourceMapSegmentTuple>;
/**
* Encodes raw mapping tuples into a compact VLQ `mappings` string + `names`
* table. Decode the inverse via `decodeVlqMap` (or `toBabelSegments` +
* `toSegmentTuple`). Storing maps in this form uses far less memory than the
* equivalent decoded tuple arrays.
*/
declare function vlqMapFromTuples(
mappings: ReadonlyArray<MetroSourceMapSegmentTuple>,
): VlqMap;
/**
* Encodes a `VlqMap` directly from a Babel/gen-mapping "decoded" source map
* (`result.decodedMap` from `@babel/generator`), without ever materialising the
* intermediate `Array<MetroSourceMapSegmentTuple>`.
*
* `@babel/generator` computes `decodedMap` eagerly while generating, so reusing
* it avoids the separate, more expensive `result.rawMappings` decode (which
* allocates a flat array of segment objects) plus the per-segment tuple
* allocation that `vlqMapFromTuples` would otherwise consume. The result is
* byte-identical to `vlqMapFromTuples(decoded -> tuples)`.
*
* `terminatingMapping` is a `[generatedLine1Based, generatedColumn0Based]`
* generated-only mapping appended at the end (matching the transform worker's
* `countLinesAndTerminateMap`) unless the last real mapping already sits there.
*/
declare function vlqMapFromBabelDecodedMap(
decodedMap: BabelDecodedMap,
terminatingMapping: [number, number],
): VlqMap;
export {
BundleBuilder,
composeSourceMaps,
Consumer,
createIndexMap,
generateFunctionMap,
fromRawMappings,
fromRawMappingsIndexed,
fromRawMappingsNonBlocking,
functionMapBabelPlugin,
isVlqMap,
normalizeSourcePath,
toBabelSegments,
toSegmentTuple,
tuplesFromBabelDecodedMap,
vlqMapFromBabelDecodedMap,
vlqMapFromTuples,
};