| 1 | // Type definitions for source-map 0.7
|
|---|
| 2 | // Project: https://github.com/mozilla/source-map
|
|---|
| 3 | // Definitions by: Morten Houston Ludvigsen <https://github.com/MortenHoustonLudvigsen>,
|
|---|
| 4 | // Ron Buckton <https://github.com/rbuckton>,
|
|---|
| 5 | // John Vilk <https://github.com/jvilk>
|
|---|
| 6 | // Definitions: https://github.com/mozilla/source-map
|
|---|
| 7 | export type SourceMapUrl = string;
|
|---|
| 8 |
|
|---|
| 9 | export interface StartOfSourceMap {
|
|---|
| 10 | file?: string;
|
|---|
| 11 | sourceRoot?: string;
|
|---|
| 12 | skipValidation?: boolean;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | export interface RawSourceMap {
|
|---|
| 16 | version: number;
|
|---|
| 17 | sources: string[];
|
|---|
| 18 | names: string[];
|
|---|
| 19 | sourceRoot?: string;
|
|---|
| 20 | sourcesContent?: string[];
|
|---|
| 21 | mappings: string;
|
|---|
| 22 | file: string;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | export interface RawIndexMap extends StartOfSourceMap {
|
|---|
| 26 | version: number;
|
|---|
| 27 | sections: RawSection[];
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | export interface RawSection {
|
|---|
| 31 | offset: Position;
|
|---|
| 32 | map: RawSourceMap;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | export interface Position {
|
|---|
| 36 | line: number;
|
|---|
| 37 | column: number;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | export interface NullablePosition {
|
|---|
| 41 | line: number | null;
|
|---|
| 42 | column: number | null;
|
|---|
| 43 | lastColumn: number | null;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | export interface MappedPosition {
|
|---|
| 47 | source: string;
|
|---|
| 48 | line: number;
|
|---|
| 49 | column: number;
|
|---|
| 50 | name?: string;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | export interface NullableMappedPosition {
|
|---|
| 54 | source: string | null;
|
|---|
| 55 | line: number | null;
|
|---|
| 56 | column: number | null;
|
|---|
| 57 | name: string | null;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | export interface MappingItem {
|
|---|
| 61 | source: string;
|
|---|
| 62 | generatedLine: number;
|
|---|
| 63 | generatedColumn: number;
|
|---|
| 64 | lastGeneratedColumn: number | null;
|
|---|
| 65 | originalLine: number;
|
|---|
| 66 | originalColumn: number;
|
|---|
| 67 | name: string;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | export interface Mapping {
|
|---|
| 71 | generated: Position;
|
|---|
| 72 | original: Position;
|
|---|
| 73 | source: string;
|
|---|
| 74 | name?: string;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | export interface CodeWithSourceMap {
|
|---|
| 78 | code: string;
|
|---|
| 79 | map: SourceMapGenerator;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | export interface SourceMappings {
|
|---|
| 83 | "lib/mappings.wasm": SourceMapUrl | ArrayBuffer;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | export interface SourceMapConsumer {
|
|---|
| 87 | /**
|
|---|
| 88 | * When using SourceMapConsumer outside of node.js, for example on the Web, it
|
|---|
| 89 | * needs to know from what URL to load lib/mappings.wasm. You must inform it
|
|---|
| 90 | * by calling initialize before constructing any SourceMapConsumers.
|
|---|
| 91 | *
|
|---|
| 92 | * @param mappings an object with the following property:
|
|---|
| 93 | * - "lib/mappings.wasm": A String containing the URL of the
|
|---|
| 94 | * lib/mappings.wasm file, or an ArrayBuffer with the contents of
|
|---|
| 95 | * lib/mappings.wasm.
|
|---|
| 96 | */
|
|---|
| 97 | initialize(mappings: SourceMappings): void;
|
|---|
| 98 |
|
|---|
| 99 | /**
|
|---|
| 100 | * Compute the last column for each generated mapping. The last column is
|
|---|
| 101 | * inclusive.
|
|---|
| 102 | */
|
|---|
| 103 | computeColumnSpans(): void;
|
|---|
| 104 |
|
|---|
| 105 | /**
|
|---|
| 106 | * Returns the original source, line, and column information for the generated
|
|---|
| 107 | * source's line and column positions provided. The only argument is an object
|
|---|
| 108 | * with the following properties:
|
|---|
| 109 | *
|
|---|
| 110 | * - line: The line number in the generated source.
|
|---|
| 111 | * - column: The column number in the generated source.
|
|---|
| 112 | * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
|
|---|
| 113 | * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
|
|---|
| 114 | * closest element that is smaller than or greater than the one we are
|
|---|
| 115 | * searching for, respectively, if the exact element cannot be found.
|
|---|
| 116 | * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
|
|---|
| 117 | *
|
|---|
| 118 | * and an object is returned with the following properties:
|
|---|
| 119 | *
|
|---|
| 120 | * - source: The original source file, or null.
|
|---|
| 121 | * - line: The line number in the original source, or null.
|
|---|
| 122 | * - column: The column number in the original source, or null.
|
|---|
| 123 | * - name: The original identifier, or null.
|
|---|
| 124 | */
|
|---|
| 125 | originalPositionFor(
|
|---|
| 126 | generatedPosition: Position & { bias?: number }
|
|---|
| 127 | ): NullableMappedPosition;
|
|---|
| 128 |
|
|---|
| 129 | /**
|
|---|
| 130 | * Returns the generated line and column information for the original source,
|
|---|
| 131 | * line, and column positions provided. The only argument is an object with
|
|---|
| 132 | * the following properties:
|
|---|
| 133 | *
|
|---|
| 134 | * - source: The filename of the original source.
|
|---|
| 135 | * - line: The line number in the original source.
|
|---|
| 136 | * - column: The column number in the original source.
|
|---|
| 137 | * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
|
|---|
| 138 | * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
|
|---|
| 139 | * closest element that is smaller than or greater than the one we are
|
|---|
| 140 | * searching for, respectively, if the exact element cannot be found.
|
|---|
| 141 | * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
|
|---|
| 142 | *
|
|---|
| 143 | * and an object is returned with the following properties:
|
|---|
| 144 | *
|
|---|
| 145 | * - line: The line number in the generated source, or null.
|
|---|
| 146 | * - column: The column number in the generated source, or null.
|
|---|
| 147 | */
|
|---|
| 148 | generatedPositionFor(
|
|---|
| 149 | originalPosition: MappedPosition & { bias?: number }
|
|---|
| 150 | ): NullablePosition;
|
|---|
| 151 |
|
|---|
| 152 | /**
|
|---|
| 153 | * Returns all generated line and column information for the original source,
|
|---|
| 154 | * line, and column provided. If no column is provided, returns all mappings
|
|---|
| 155 | * corresponding to a either the line we are searching for or the next
|
|---|
| 156 | * closest line that has any mappings. Otherwise, returns all mappings
|
|---|
| 157 | * corresponding to the given line and either the column we are searching for
|
|---|
| 158 | * or the next closest column that has any offsets.
|
|---|
| 159 | *
|
|---|
| 160 | * The only argument is an object with the following properties:
|
|---|
| 161 | *
|
|---|
| 162 | * - source: The filename of the original source.
|
|---|
| 163 | * - line: The line number in the original source.
|
|---|
| 164 | * - column: Optional. the column number in the original source.
|
|---|
| 165 | *
|
|---|
| 166 | * and an array of objects is returned, each with the following properties:
|
|---|
| 167 | *
|
|---|
| 168 | * - line: The line number in the generated source, or null.
|
|---|
| 169 | * - column: The column number in the generated source, or null.
|
|---|
| 170 | */
|
|---|
| 171 | allGeneratedPositionsFor(
|
|---|
| 172 | originalPosition: MappedPosition
|
|---|
| 173 | ): NullablePosition[];
|
|---|
| 174 |
|
|---|
| 175 | /**
|
|---|
| 176 | * Return true if we have the source content for every source in the source
|
|---|
| 177 | * map, false otherwise.
|
|---|
| 178 | */
|
|---|
| 179 | hasContentsOfAllSources(): boolean;
|
|---|
| 180 |
|
|---|
| 181 | /**
|
|---|
| 182 | * Returns the original source content. The only argument is the url of the
|
|---|
| 183 | * original source file. Returns null if no original source content is
|
|---|
| 184 | * available.
|
|---|
| 185 | */
|
|---|
| 186 | sourceContentFor(
|
|---|
| 187 | source: string,
|
|---|
| 188 | returnNullOnMissing?: boolean
|
|---|
| 189 | ): string | null;
|
|---|
| 190 |
|
|---|
| 191 | /**
|
|---|
| 192 | * Iterate over each mapping between an original source/line/column and a
|
|---|
| 193 | * generated line/column in this source map.
|
|---|
| 194 | *
|
|---|
| 195 | * @param callback
|
|---|
| 196 | * The function that is called with each mapping.
|
|---|
| 197 | * @param context
|
|---|
| 198 | * Optional. If specified, this object will be the value of `this` every
|
|---|
| 199 | * time that `aCallback` is called.
|
|---|
| 200 | * @param order
|
|---|
| 201 | * Either `SourceMapConsumer.GENERATED_ORDER` or
|
|---|
| 202 | * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
|
|---|
| 203 | * iterate over the mappings sorted by the generated file's line/column
|
|---|
| 204 | * order or the original's source/line/column order, respectively. Defaults to
|
|---|
| 205 | * `SourceMapConsumer.GENERATED_ORDER`.
|
|---|
| 206 | */
|
|---|
| 207 | eachMapping(
|
|---|
| 208 | callback: (mapping: MappingItem) => void,
|
|---|
| 209 | context?: any,
|
|---|
| 210 | order?: number
|
|---|
| 211 | ): void;
|
|---|
| 212 | /**
|
|---|
| 213 | * Free this source map consumer's associated wasm data that is manually-managed.
|
|---|
| 214 | * Alternatively, you can use SourceMapConsumer.with to avoid needing to remember to call destroy.
|
|---|
| 215 | */
|
|---|
| 216 | destroy(): void;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | export interface SourceMapConsumerConstructor {
|
|---|
| 220 | prototype: SourceMapConsumer;
|
|---|
| 221 |
|
|---|
| 222 | GENERATED_ORDER: number;
|
|---|
| 223 | ORIGINAL_ORDER: number;
|
|---|
| 224 | GREATEST_LOWER_BOUND: number;
|
|---|
| 225 | LEAST_UPPER_BOUND: number;
|
|---|
| 226 |
|
|---|
| 227 | new (
|
|---|
| 228 | rawSourceMap: RawSourceMap,
|
|---|
| 229 | sourceMapUrl?: SourceMapUrl
|
|---|
| 230 | ): Promise<BasicSourceMapConsumer>;
|
|---|
| 231 | new (
|
|---|
| 232 | rawSourceMap: RawIndexMap,
|
|---|
| 233 | sourceMapUrl?: SourceMapUrl
|
|---|
| 234 | ): Promise<IndexedSourceMapConsumer>;
|
|---|
| 235 | new (
|
|---|
| 236 | rawSourceMap: RawSourceMap | RawIndexMap | string,
|
|---|
| 237 | sourceMapUrl?: SourceMapUrl
|
|---|
| 238 | ): Promise<BasicSourceMapConsumer | IndexedSourceMapConsumer>;
|
|---|
| 239 |
|
|---|
| 240 | /**
|
|---|
| 241 | * Create a BasicSourceMapConsumer from a SourceMapGenerator.
|
|---|
| 242 | *
|
|---|
| 243 | * @param sourceMap
|
|---|
| 244 | * The source map that will be consumed.
|
|---|
| 245 | */
|
|---|
| 246 | fromSourceMap(
|
|---|
| 247 | sourceMap: SourceMapGenerator,
|
|---|
| 248 | sourceMapUrl?: SourceMapUrl
|
|---|
| 249 | ): Promise<BasicSourceMapConsumer>;
|
|---|
| 250 |
|
|---|
| 251 | /**
|
|---|
| 252 | * Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl`
|
|---|
| 253 | * (see the `SourceMapConsumer` constructor for details. Then, invoke the `async
|
|---|
| 254 | * function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait
|
|---|
| 255 | * for `f` to complete, call `destroy` on the consumer, and return `f`'s return
|
|---|
| 256 | * value.
|
|---|
| 257 | *
|
|---|
| 258 | * You must not use the consumer after `f` completes!
|
|---|
| 259 | *
|
|---|
| 260 | * By using `with`, you do not have to remember to manually call `destroy` on
|
|---|
| 261 | * the consumer, since it will be called automatically once `f` completes.
|
|---|
| 262 | *
|
|---|
| 263 | * ```js
|
|---|
| 264 | * const xSquared = await SourceMapConsumer.with(
|
|---|
| 265 | * myRawSourceMap,
|
|---|
| 266 | * null,
|
|---|
| 267 | * async function (consumer) {
|
|---|
| 268 | * // Use `consumer` inside here and don't worry about remembering
|
|---|
| 269 | * // to call `destroy`.
|
|---|
| 270 | *
|
|---|
| 271 | * const x = await whatever(consumer);
|
|---|
| 272 | * return x * x;
|
|---|
| 273 | * }
|
|---|
| 274 | * );
|
|---|
| 275 | *
|
|---|
| 276 | * // You may not use that `consumer` anymore out here; it has
|
|---|
| 277 | * // been destroyed. But you can use `xSquared`.
|
|---|
| 278 | * console.log(xSquared);
|
|---|
| 279 | * ```
|
|---|
| 280 | */
|
|---|
| 281 | with<T>(
|
|---|
| 282 | rawSourceMap: RawSourceMap | RawIndexMap | string,
|
|---|
| 283 | sourceMapUrl: SourceMapUrl | null | undefined,
|
|---|
| 284 | callback: (
|
|---|
| 285 | consumer: BasicSourceMapConsumer | IndexedSourceMapConsumer
|
|---|
| 286 | ) => Promise<T> | T
|
|---|
| 287 | ): Promise<T>;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | export const SourceMapConsumer: SourceMapConsumerConstructor;
|
|---|
| 291 |
|
|---|
| 292 | export interface BasicSourceMapConsumer extends SourceMapConsumer {
|
|---|
| 293 | file: string;
|
|---|
| 294 | sourceRoot: string;
|
|---|
| 295 | sources: string[];
|
|---|
| 296 | sourcesContent: string[];
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | export interface BasicSourceMapConsumerConstructor {
|
|---|
| 300 | prototype: BasicSourceMapConsumer;
|
|---|
| 301 |
|
|---|
| 302 | new (rawSourceMap: RawSourceMap | string): Promise<BasicSourceMapConsumer>;
|
|---|
| 303 |
|
|---|
| 304 | /**
|
|---|
| 305 | * Create a BasicSourceMapConsumer from a SourceMapGenerator.
|
|---|
| 306 | *
|
|---|
| 307 | * @param sourceMap
|
|---|
| 308 | * The source map that will be consumed.
|
|---|
| 309 | */
|
|---|
| 310 | fromSourceMap(sourceMap: SourceMapGenerator): Promise<BasicSourceMapConsumer>;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | export const BasicSourceMapConsumer: BasicSourceMapConsumerConstructor;
|
|---|
| 314 |
|
|---|
| 315 | export interface IndexedSourceMapConsumer extends SourceMapConsumer {
|
|---|
| 316 | sources: string[];
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | export interface IndexedSourceMapConsumerConstructor {
|
|---|
| 320 | prototype: IndexedSourceMapConsumer;
|
|---|
| 321 |
|
|---|
| 322 | new (rawSourceMap: RawIndexMap | string): Promise<IndexedSourceMapConsumer>;
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | export const IndexedSourceMapConsumer: IndexedSourceMapConsumerConstructor;
|
|---|
| 326 |
|
|---|
| 327 | export class SourceMapGenerator {
|
|---|
| 328 | constructor(startOfSourceMap?: StartOfSourceMap);
|
|---|
| 329 |
|
|---|
| 330 | /**
|
|---|
| 331 | * Creates a new SourceMapGenerator based on a SourceMapConsumer
|
|---|
| 332 | *
|
|---|
| 333 | * @param sourceMapConsumer The SourceMap.
|
|---|
| 334 | */
|
|---|
| 335 | static fromSourceMap(
|
|---|
| 336 | sourceMapConsumer: SourceMapConsumer
|
|---|
| 337 | ): SourceMapGenerator;
|
|---|
| 338 |
|
|---|
| 339 | /**
|
|---|
| 340 | * Add a single mapping from original source line and column to the generated
|
|---|
| 341 | * source's line and column for this source map being created. The mapping
|
|---|
| 342 | * object should have the following properties:
|
|---|
| 343 | *
|
|---|
| 344 | * - generated: An object with the generated line and column positions.
|
|---|
| 345 | * - original: An object with the original line and column positions.
|
|---|
| 346 | * - source: The original source file (relative to the sourceRoot).
|
|---|
| 347 | * - name: An optional original token name for this mapping.
|
|---|
| 348 | */
|
|---|
| 349 | addMapping(mapping: Mapping): void;
|
|---|
| 350 |
|
|---|
| 351 | /**
|
|---|
| 352 | * Set the source content for a source file.
|
|---|
| 353 | */
|
|---|
| 354 | setSourceContent(sourceFile: string, sourceContent: string): void;
|
|---|
| 355 |
|
|---|
| 356 | /**
|
|---|
| 357 | * Applies the mappings of a sub-source-map for a specific source file to the
|
|---|
| 358 | * source map being generated. Each mapping to the supplied source file is
|
|---|
| 359 | * rewritten using the supplied source map. Note: The resolution for the
|
|---|
| 360 | * resulting mappings is the minimium of this map and the supplied map.
|
|---|
| 361 | *
|
|---|
| 362 | * @param sourceMapConsumer The source map to be applied.
|
|---|
| 363 | * @param sourceFile Optional. The filename of the source file.
|
|---|
| 364 | * If omitted, SourceMapConsumer's file property will be used.
|
|---|
| 365 | * @param sourceMapPath Optional. The dirname of the path to the source map
|
|---|
| 366 | * to be applied. If relative, it is relative to the SourceMapConsumer.
|
|---|
| 367 | * This parameter is needed when the two source maps aren't in the same
|
|---|
| 368 | * directory, and the source map to be applied contains relative source
|
|---|
| 369 | * paths. If so, those relative source paths need to be rewritten
|
|---|
| 370 | * relative to the SourceMapGenerator.
|
|---|
| 371 | */
|
|---|
| 372 | applySourceMap(
|
|---|
| 373 | sourceMapConsumer: SourceMapConsumer,
|
|---|
| 374 | sourceFile?: string,
|
|---|
| 375 | sourceMapPath?: string
|
|---|
| 376 | ): void;
|
|---|
| 377 |
|
|---|
| 378 | toString(): string;
|
|---|
| 379 |
|
|---|
| 380 | toJSON(): RawSourceMap;
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | export class SourceNode {
|
|---|
| 384 | children: SourceNode[];
|
|---|
| 385 | sourceContents: any;
|
|---|
| 386 | line: number;
|
|---|
| 387 | column: number;
|
|---|
| 388 | source: string;
|
|---|
| 389 | name: string;
|
|---|
| 390 |
|
|---|
| 391 | constructor();
|
|---|
| 392 | constructor(
|
|---|
| 393 | line: number | null,
|
|---|
| 394 | column: number | null,
|
|---|
| 395 | source: string | null,
|
|---|
| 396 | chunks?: Array<string | SourceNode> | SourceNode | string,
|
|---|
| 397 | name?: string
|
|---|
| 398 | );
|
|---|
| 399 |
|
|---|
| 400 | static fromStringWithSourceMap(
|
|---|
| 401 | code: string,
|
|---|
| 402 | sourceMapConsumer: SourceMapConsumer,
|
|---|
| 403 | relativePath?: string
|
|---|
| 404 | ): SourceNode;
|
|---|
| 405 |
|
|---|
| 406 | add(chunk: Array<string | SourceNode> | SourceNode | string): SourceNode;
|
|---|
| 407 |
|
|---|
| 408 | prepend(chunk: Array<string | SourceNode> | SourceNode | string): SourceNode;
|
|---|
| 409 |
|
|---|
| 410 | setSourceContent(sourceFile: string, sourceContent: string): void;
|
|---|
| 411 |
|
|---|
| 412 | walk(fn: (chunk: string, mapping: MappedPosition) => void): void;
|
|---|
| 413 |
|
|---|
| 414 | walkSourceContents(fn: (file: string, content: string) => void): void;
|
|---|
| 415 |
|
|---|
| 416 | join(sep: string): SourceNode;
|
|---|
| 417 |
|
|---|
| 418 | replaceRight(pattern: string, replacement: string): SourceNode;
|
|---|
| 419 |
|
|---|
| 420 | toString(): string;
|
|---|
| 421 |
|
|---|
| 422 | toStringWithSourceMap(startOfSourceMap?: StartOfSourceMap): CodeWithSourceMap;
|
|---|
| 423 | }
|
|---|