@remotex-labs/xmap 3.0.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
+
1
2
  /**
3
+ * This file was automatically generated by xBuild.
4
+ * DO NOT EDIT MANUALLY.
5
+ */
6
+ /**
2
7
  * Represents a source map structure used for mapping code within a file to its original source
3
8
  * @since 1.0.0
4
9
  */
@@ -137,6 +142,7 @@ export interface SourceOptionsInterface {
137
142
  */
138
143
  linesBefore?: number;
139
144
  }
145
+
140
146
  /**
141
147
  * Encodes a given number using Variable-Length Quantity (VLQ) encoding. Negative numbers are encoded by
142
148
  * converting to a non-negative representation and the continuation bit is used to indicate if more bytes follow.
@@ -207,74 +213,13 @@ export declare function encodeArrayVLQ(values: number[]): string;
207
213
  * @since 1.0.0
208
214
  */
209
215
  export declare function decodeVLQ(data: string): number[];
216
+
210
217
  /**
211
- * Represents a source map mapping segment that links positions between original and generated code.
212
- *
213
- * @interface SegmentInterface
214
- *
215
- * @property line - Original line number in the source file
216
- * @property column - Original column number in the source file
217
- * @property nameIndex - Index of the symbol name in the source map's names array (null if no associated name)
218
- * @property sourceIndex - Index of the source file in the source map's sources array
219
- * @property generatedLine - Line number in the generated output code
220
- * @property generatedColumn - Column number in the generated output code
221
- *
222
- * @remarks
223
- * These segments form the core data structure of source maps, providing the necessary
224
- * information to trace locations between original source code and generated output code.
225
- * Each segment represents a single mapping point in the transformation process.
226
- *
227
- * @example
228
- * ```ts
229
- * const segment: SegmentInterface = {
230
- * line: 42,
231
- * column: 10,
232
- * nameIndex: 5,
233
- * sourceIndex: 0,
234
- * generatedLine: 100,
235
- * generatedColumn: 15
236
- * };
237
- * ```
238
- *
239
- * @since 1.0.0
218
+ * Import will remove at compile time
240
219
  */
241
- export interface SegmentInterface {
242
- line: number;
243
- column: number;
244
- nameIndex: number | null;
245
- sourceIndex: number;
246
- generatedLine: number;
247
- generatedColumn: number;
248
- }
249
220
  /**
250
- * A specialized segment interface used during source map offset calculations.
251
- *
252
- * @property nameIndex - Index of the symbol name in the source map's names array (always numeric)
253
- *
254
- * @remarks
255
- * Unlike the base SegmentInterface where nameIndex can be null,
256
- * in offset calculations this value must always be a concrete numeric index.
257
- * This specialized interface ensures type safety during mapping offset operations.
258
- *
259
- * @example
260
- * ```ts
261
- * const offsetSegment: SegmentOffsetInterface = {
262
- * line: 42,
263
- * column: 10,
264
- * nameIndex: 5, // Must be a number, not null
265
- * sourceIndex: 0,
266
- * generatedLine: 100,
267
- * generatedColumn: 15
268
- * };
269
- * ```
270
- *
271
- * @see SegmentInterface
272
- *
273
- * @since 1.0.0
221
+ * Imports
274
222
  */
275
- export interface SegmentOffsetInterface extends SegmentInterface {
276
- nameIndex: number;
277
- }
278
223
  /**
279
224
  * Determines the matching behavior when searching for segments in a source map.
280
225
  *
@@ -296,183 +241,358 @@ export interface SegmentOffsetInterface extends SegmentInterface {
296
241
  *
297
242
  * @since 1.0.0
298
243
  */
299
- export declare const enum Bias {
244
+ declare const enum Bias {
300
245
  BOUND = 0,
301
246
  LOWER_BOUND = 1,
302
247
  UPPER_BOUND = 2
303
248
  }
304
249
  /**
305
- * Represents a collection of mapping segments for a single line in generated code.
306
- *
307
- * @remarks
308
- * A frame contains all the segments that map to a particular line of generated code.
309
- * Each segment within the frame provides mapping information for a specific range
310
- * of columns within that line.
311
- *
312
- * @example
313
- * ```ts
314
- * const lineFrame: FrameType = [
315
- * { line: 10, column: 0, nameIndex: null, sourceIndex: 0, generatedLine: 5, generatedColumn: 0 },
316
- * { line: 10, column: 5, nameIndex: 3, sourceIndex: 0, generatedLine: 5, generatedColumn: 10 }
317
- * ];
318
- * ```
319
- *
320
- * @see SegmentInterface
321
- *
322
- * @since 1.0.0
323
- */
324
- export type FrameType = Array<SegmentInterface>;
325
- /**
326
- * Represents the complete mapping structure of a source map.
327
- *
328
- * @remarks
329
- * A source map contains an array where each index corresponds to a line in the generated code.
330
- * Each entry is either:
331
- * - A frame (array of segments) containing mappings for that line
332
- * - Null, indicating the line has no mappings (represented by a semicolon in the source map)
333
- *
334
- * The array index corresponds directly to the line number in generated code (0-based).
335
- *
336
- * @example
337
- * ```ts
338
- * const sourceMap: MapType = [
339
- * [{ line: 1, column: 0, nameIndex: null, sourceIndex: 0, generatedLine: 0, generatedColumn: 0 }], // Line 0
340
- * null, // Line 1 has no mappings
341
- * [{ line: 2, column: 0, nameIndex: 1, sourceIndex: 0, generatedLine: 2, generatedColumn: 0 }] // Line 2
342
- * ];
343
- * ```
344
- *
345
- * @see FrameType
346
- * @see SegmentInterface
347
- *
348
- * @since 1.0.0
349
- */
350
- export type MapType = Array<null | FrameType>;
351
- /**
352
- * Provides functionality for encoding and decoding source map mappings.
353
- *
354
- * The MappingProvider class handles the conversion between various mapping representations:
355
- * - String format (VLQ-encoded mappings)
356
- * - Structured array format (MapType)
357
- * - Internal structured representation
250
+ * A service for validating and processing source maps that provides functionality for parsing,
251
+ * position mapping, concatenation, and code snippet extraction.
358
252
  *
359
- * It also provides methods to query and retrieve source map segments based on
360
- * generated or original source positions.
253
+ * @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)
254
+ * @param file - Optional file name for the generated bundle
255
+ * @returns A new SourceService instance
361
256
  *
362
257
  * @example
363
258
  * ```ts
364
- * // Create from VLQ-encoded mapping string
365
- * const provider = new MappingProvider(mappingString);
366
- *
367
- * // Get a segment by generated position
368
- * const segment = provider.getSegment(10, 15);
369
- *
370
- * // Convert back to mapping string
371
- * const encoded = provider.encode();
259
+ * const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
260
+ * const sourceService = new SourceService(sourceMapJSON);
261
+ * console.log(sourceService.file); // 'bundle.js'
372
262
  * ```
373
263
  *
374
264
  * @since 1.0.0
375
265
  */
376
- export declare class MappingProvider {
377
- private mapping;
266
+ export declare class SourceService {
378
267
  /**
379
- * Creates a new MappingProvider instance.
380
- *
381
- * @param mapping - Source map mapping data in one of three formats:
382
- * - VLQ-encoded string
383
- * - Structured array (MapType)
384
- * - Another MappingProvider instance (copy constructor)
385
- * @param namesOffset - Optional offset to apply to name indices (default: 0)
386
- * @param sourceOffset - Optional offset to apply to source indices (default: 0)
387
- *
388
- * @remarks
389
- * The constructor automatically detects the mapping format and decodes it accordingly.
390
- * When providing offsets, these values will be added to the corresponding indices
391
- * in the decoded mapping data, which is useful when concatenating multiple source maps.
268
+ * The name of the generated file this source map applies to.
392
269
  *
393
270
  * @since 1.0.0
394
271
  */
395
- constructor(mapping: string, namesOffset?: number, sourceOffset?: number);
396
- constructor(mapping: MapType, namesOffset?: number, sourceOffset?: number);
397
- constructor(mapping: MappingProvider, namesOffset?: number, sourceOffset?: number);
272
+ readonly file: string | null;
398
273
  /**
399
- * Encodes the internal mapping representation to a VLQ-encoded mapping string.
400
- *
401
- * @returns VLQ-encoded mapping string compatible with the source map format specification
274
+ * Provider for accessing and manipulating the base64 VLQ-encoded mappings.
402
275
  *
403
- * @remarks
404
- * This method converts the internal structured mapping representation into a compact
405
- * string format using Variable Length Quantity (VLQ) encoding.
406
- * The resulting string follows the source map v3 format for the 'mappings' field.
276
+ * @since 1.0.0
277
+ */
278
+ readonly mappings: MappingProvider;
279
+ /**
280
+ * The root URL for resolving relative paths in the source files.
281
+ * @since 1.0.0
282
+ */
283
+ readonly sourceRoot: string | null;
284
+ /**
285
+ * List of symbol names referenced by the mappings.
286
+ * @since 1.0.0
287
+ */
288
+ readonly names: Array<string>;
289
+ /**
290
+ * Array of source file paths.
291
+ * @since 1.0.0
292
+ */
293
+ readonly sources: Array<string>;
294
+ /**
295
+ * Array of source file contents.
296
+ * @since 1.0.0
297
+ */
298
+ readonly sourcesContent: Array<string>;
299
+ /**
300
+ * Creates a new SourceService instance.
407
301
  *
408
- * @see https://sourcemaps.info/spec.html
302
+ * @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)
303
+ * @throws Error - When a source map has an invalid format or missing required properties
409
304
  *
410
305
  * @since 1.0.0
411
306
  */
412
- encode(): string;
307
+ constructor(source: SourceService);
413
308
  /**
414
- * Decodes mapping data into the internal representation.
415
- *
416
- * @param mapping - Mapping data to decode in one of three formats:
417
- * - VLQ-encoded string
418
- * - Structured array (MapType)
419
- * - Another MappingProvider instance
420
- * @param namesOffset - Optional offset for name indices (default: 0)
421
- * @param sourcesOffset - Optional offset for source indices (default: 0)
309
+ * Creates a new SourceService instance.
422
310
  *
423
- * @remarks
424
- * This method replaces the current internal mapping data with the newly decoded mapping.
425
- * The format of the input mapping is automatically detected and processed accordingly.
311
+ * @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)
312
+ * @param file - Optional file name for the generated bundle
426
313
  *
427
- * @see MapType
428
- * @see MappingProvider
314
+ * @throws Error - When a source map has an invalid format or missing required properties
429
315
  *
430
316
  * @since 1.0.0
431
317
  */
432
- decode(mapping: MappingProvider | MapType | string, namesOffset?: number, sourcesOffset?: number): void;
318
+ constructor(source: SourceMapInterface | string, file?: string | null);
433
319
  /**
434
- * Retrieves a segment based on a position in the generated code.
320
+ * Converts the source map data to a plain object.
435
321
  *
436
- * @param generatedLine - Line number in generated code (1-based)
437
- * @param generatedColumn - Column number in generated code (0-based)
438
- * @param bias - Controls matching behavior when exact position not found:
439
- * - BOUND: No preference (default)
440
- * - LOWER_BOUND: Prefer segment with lower column
441
- * - UPPER_BOUND: Prefer segment with higher column
442
- * @returns Matching segment or null if not found
322
+ * @returns A SourceMapInterface object representing the current state
443
323
  *
444
- * @remarks
445
- * Uses binary search to efficiently locate matching segments.
446
- * When no exact match is found, the bias parameter determines which nearby segment to return.
324
+ * @example
325
+ * ```ts
326
+ * const mapObject = sourceService.getMapObject();
327
+ * console.log(mapObject.file); // 'bundle.js'
328
+ * ```
447
329
  *
448
330
  * @since 1.0.0
449
331
  */
450
- getSegment(generatedLine: number, generatedColumn: number, bias?: Bias): SegmentInterface | null;
332
+ getMapObject(): SourceMapInterface;
451
333
  /**
452
- * Retrieves a segment based on a position in the original source code.
334
+ * Concatenates additional source maps into the current instance.
453
335
  *
454
- * @param line - Line number in original source (1-based)
455
- * @param column - Column number in original source (0-based)
456
- * @param sourceIndex - Index of source file in the sources array
457
- * @param bias - Controls matching behavior when exact position not found:
458
- * - BOUND: No preference (default)
459
- * - LOWER_BOUND: Prefer segment with lower column
460
- * - UPPER_BOUND: Prefer segment with higher column
461
- * @returns Matching segment or null if not found
336
+ * @param maps - Source maps to concatenate with the current map
462
337
  *
463
- * @remarks
464
- * Searches across all mapping segments to find those matching the specified original source position.
465
- * When multiple matches are possible, the bias
466
- * parameter determines which segment to return.
338
+ * @example
339
+ * ```ts
340
+ * sourceService.concat(anotherSourceMap);
341
+ * console.log(sourceService.sources); // Updated source paths
342
+ * ```
467
343
  *
468
- * This operation is more expensive than getSegment as it must potentially
469
- * scan the entire mapping structure.
344
+ * @throws Error - When no maps are provided
470
345
  *
471
346
  * @since 1.0.0
472
347
  */
473
- getOriginalSegment(line: number, column: number, sourceIndex: number, bias?: Bias): SegmentInterface | null;
348
+ concat(...maps: Array<SourceMapInterface | SourceService>): void;
474
349
  /**
475
- * Initializes a new segment offset object with default values.
350
+ * Creates a new SourceService instance with concatenated source maps.
351
+ *
352
+ * @param maps - Source maps to concatenate with a copy of the current map
353
+ * @returns A new SourceService instance with the combined maps
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * const newService = sourceService.concatNewMap(anotherSourceMap);
358
+ * console.log(newService.sources); // Combined sources array
359
+ * ```
360
+ *
361
+ * @throws Error - When no maps are provided
362
+ *
363
+ * @since 1.0.0
364
+ */
365
+ concatNewMap(...maps: Array<SourceMapInterface | SourceService>): SourceService;
366
+ /**
367
+ * Finds position in generated code based on original source position.
368
+ *
369
+ * @param line - Line number in the original source
370
+ * @param column - Column number in the original source
371
+ * @param sourceIndex - Index or file path of the original source
372
+ * @param bias - Position matching strategy (default: Bias.BOUND)
373
+ * @returns Position information or null if not found
374
+ *
375
+ * @example
376
+ * ```ts
377
+ * const position = sourceService.getPositionByOriginal(1, 10, 'foo.ts');
378
+ * console.log(position?.generatedLine); // Line in generated code
379
+ * ```
380
+ *
381
+ * @since 1.0.0
382
+ */
383
+ getPositionByOriginal(line: number, column: number, sourceIndex: number | string, bias?: Bias): PositionInterface | null;
384
+ /**
385
+ * Finds position in an original source based on generated code position.
386
+ *
387
+ * @param line - Line number in the generated code
388
+ * @param column - Column number in the generated code
389
+ * @param bias - Position matching strategy (default: Bias.BOUND)
390
+ * @returns Position information or null if not found
391
+ *
392
+ * @example
393
+ * ```ts
394
+ * const position = sourceService.getPosition(2, 15);
395
+ * console.log(position?.source); // Original source file
396
+ * ```
397
+ *
398
+ * @since 1.0.0
399
+ */
400
+ getPosition(line: number, column: number, bias?: Bias): PositionInterface | null;
401
+ /**
402
+ * Retrieves position with source content for a location in generated code.
403
+ *
404
+ * @param line - Line number in the generated code
405
+ * @param column - Column number in the generated code
406
+ * @param bias - Position matching strategy (default: Bias.BOUND)
407
+ * @returns Position with content information or null if not found
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * const posWithContent = sourceService.getPositionWithContent(3, 5);
412
+ * console.log(posWithContent?.sourcesContent); // Original source content
413
+ * ```
414
+ *
415
+ * @since 1.0.0
416
+ */
417
+ getPositionWithContent(line: number, column: number, bias?: Bias): PositionWithContentInterface | null;
418
+ /**
419
+ * Retrieves position with a code snippet from the original source.
420
+ *
421
+ * @param line - Line number in the generated code
422
+ * @param column - Column number in the generated code
423
+ * @param bias - Position matching strategy (default: Bias.BOUND)
424
+ * @param options - Configuration for the amount of surrounding lines
425
+ * @returns Position with code snippet or null if not found
426
+ *
427
+ * @example
428
+ * ```ts
429
+ * const posWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, {
430
+ * linesBefore: 2,
431
+ * linesAfter: 2
432
+ * });
433
+ * console.log(posWithCode?.code); // Code snippet with context
434
+ * ```
435
+ *
436
+ * @since 1.0.0
437
+ */
438
+ getPositionWithCode(line: number, column: number, bias?: Bias, options?: SourceOptionsInterface): PositionWithCodeInterface | null;
439
+ /**
440
+ * Serializes the source map to a JSON string.
441
+ *
442
+ * @returns JSON string representation of the source map
443
+ *
444
+ * @example
445
+ * ```ts
446
+ * const jsonString = sourceService.toString();
447
+ * console.log(jsonString); // '{"version":3,"file":"bundle.js",...}'
448
+ * ```
449
+ *
450
+ * @since 1.0.0
451
+ */
452
+ toString(): string;
453
+ /**
454
+ * Validates a source map object has all required properties.
455
+ *
456
+ * @param input - Source map object to validate
457
+ *
458
+ * @throws Error - When required properties are missing
459
+ *
460
+ * @since 1.0.0
461
+ */
462
+ private validateSourceMap;
463
+ }
464
+
465
+ /**
466
+ * Import will remove at compile time
467
+ */
468
+ /**
469
+ * Imports
470
+ */
471
+ /**
472
+ * Provides functionality for encoding and decoding source map mappings.
473
+ *
474
+ * The MappingProvider class handles the conversion between various mapping representations:
475
+ * - String format (VLQ-encoded mappings)
476
+ * - Structured array format (MapType)
477
+ * - Internal structured representation
478
+ *
479
+ * It also provides methods to query and retrieve source map segments based on
480
+ * generated or original source positions.
481
+ *
482
+ * @example
483
+ * ```ts
484
+ * // Create from VLQ-encoded mapping string
485
+ * const provider = new MappingProvider(mappingString);
486
+ *
487
+ * // Get a segment by generated position
488
+ * const segment = provider.getSegment(10, 15);
489
+ *
490
+ * // Convert back to mapping string
491
+ * const encoded = provider.encode();
492
+ * ```
493
+ *
494
+ * @since 1.0.0
495
+ */
496
+ declare class MappingProvider {
497
+ private mapping;
498
+ /**
499
+ * Creates a new MappingProvider instance.
500
+ *
501
+ * @param mapping - Source map mapping data in one of three formats:
502
+ * - VLQ-encoded string
503
+ * - Structured array (MapType)
504
+ * - Another MappingProvider instance (copy constructor)
505
+ * @param namesOffset - Optional offset to apply to name indices (default: 0)
506
+ * @param sourceOffset - Optional offset to apply to source indices (default: 0)
507
+ *
508
+ * @remarks
509
+ * The constructor automatically detects the mapping format and decodes it accordingly.
510
+ * When providing offsets, these values will be added to the corresponding indices
511
+ * in the decoded mapping data, which is useful when concatenating multiple source maps.
512
+ *
513
+ * @since 1.0.0
514
+ */
515
+ constructor(mapping: string, namesOffset?: number, sourceOffset?: number);
516
+ constructor(mapping: MapType, namesOffset?: number, sourceOffset?: number);
517
+ constructor(mapping: MappingProvider, namesOffset?: number, sourceOffset?: number);
518
+ /**
519
+ * Encodes the internal mapping representation to a VLQ-encoded mapping string.
520
+ *
521
+ * @returns VLQ-encoded mapping string compatible with the source map format specification
522
+ *
523
+ * @remarks
524
+ * This method converts the internal structured mapping representation into a compact
525
+ * string format using Variable Length Quantity (VLQ) encoding.
526
+ * The resulting string follows the source map v3 format for the 'mappings' field.
527
+ *
528
+ * @see https://sourcemaps.info/spec.html
529
+ *
530
+ * @since 1.0.0
531
+ */
532
+ encode(): string;
533
+ /**
534
+ * Decodes mapping data into the internal representation.
535
+ *
536
+ * @param mapping - Mapping data to decode in one of three formats:
537
+ * - VLQ-encoded string
538
+ * - Structured array (MapType)
539
+ * - Another MappingProvider instance
540
+ * @param namesOffset - Optional offset for name indices (default: 0)
541
+ * @param sourcesOffset - Optional offset for source indices (default: 0)
542
+ *
543
+ * @remarks
544
+ * This method replaces the current internal mapping data with the newly decoded mapping.
545
+ * The format of the input mapping is automatically detected and processed accordingly.
546
+ *
547
+ * @see MapType
548
+ * @see MappingProvider
549
+ *
550
+ * @since 1.0.0
551
+ */
552
+ decode(mapping: MappingProvider | MapType | string, namesOffset?: number, sourcesOffset?: number): void;
553
+ /**
554
+ * Retrieves a segment based on a position in the generated code.
555
+ *
556
+ * @param generatedLine - Line number in generated code (1-based)
557
+ * @param generatedColumn - Column number in generated code (0-based)
558
+ * @param bias - Controls matching behavior when exact position not found:
559
+ * - BOUND: No preference (default)
560
+ * - LOWER_BOUND: Prefer segment with lower column
561
+ * - UPPER_BOUND: Prefer segment with higher column
562
+ * @returns Matching segment or null if not found
563
+ *
564
+ * @remarks
565
+ * Uses binary search to efficiently locate matching segments.
566
+ * When no exact match is found, the bias parameter determines which nearby segment to return.
567
+ *
568
+ * @since 1.0.0
569
+ */
570
+ getSegment(generatedLine: number, generatedColumn: number, bias?: Bias): SegmentInterface | null;
571
+ /**
572
+ * Retrieves a segment based on a position in the original source code.
573
+ *
574
+ * @param line - Line number in original source (1-based)
575
+ * @param column - Column number in original source (0-based)
576
+ * @param sourceIndex - Index of source file in the sources array
577
+ * @param bias - Controls matching behavior when exact position not found:
578
+ * - BOUND: No preference (default)
579
+ * - LOWER_BOUND: Prefer segment with lower column
580
+ * - UPPER_BOUND: Prefer segment with higher column
581
+ * @returns Matching segment or null if not found
582
+ *
583
+ * @remarks
584
+ * Searches across all mapping segments to find those matching the specified original source position.
585
+ * When multiple matches are possible, the bias
586
+ * parameter determines which segment to return.
587
+ *
588
+ * This operation is more expensive than getSegment as it must potentially
589
+ * scan the entire mapping structure.
590
+ *
591
+ * @since 1.0.0
592
+ */
593
+ getOriginalSegment(line: number, column: number, sourceIndex: number, bias?: Bias): SegmentInterface | null;
594
+ /**
595
+ * Initializes a new segment offset object with default values.
476
596
  *
477
597
  * @param namesOffset - Initial name index offset value (default: 0)
478
598
  * @param sourceIndex - Initial source index offset value (default: 0)
@@ -657,210 +777,119 @@ export declare class MappingProvider {
657
777
  */
658
778
  private decodeMappingArray;
659
779
  }
780
+
660
781
  /**
661
- * A service for validating and processing source maps that provides functionality for parsing,
662
- * position mapping, concatenation, and code snippet extraction.
663
- *
664
- * @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)
665
- * @param file - Optional file name for the generated bundle
666
- * @returns A new SourceService instance
782
+ * Represents a source map mapping segment that links positions between original and generated code.
667
783
  *
668
- * @example
669
- * ```ts
670
- * const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
671
- * const sourceService = new SourceService(sourceMapJSON);
672
- * console.log(sourceService.file); // 'bundle.js'
673
- * ```
784
+ * @interface SegmentInterface
674
785
  *
675
- * @since 1.0.0
786
+ * @property line - Original line number in the source file
787
+ * @property column - Original column number in the source file
788
+ * @property nameIndex - Index of the symbol name in the source map's names array (null if no associated name)
789
+ * @property sourceIndex - Index of the source file in the source map's sources array
790
+ * @property generatedLine - Line number in the generated output code
791
+ * @property generatedColumn - Column number in the generated output code
792
+ *
793
+ * @remarks
794
+ * These segments form the core data structure of source maps, providing the necessary
795
+ * information to trace locations between original source code and generated output code.
796
+ * Each segment represents a single mapping point in the transformation process.
797
+ *
798
+ * @example
799
+ * ```ts
800
+ * const segment: SegmentInterface = {
801
+ * line: 42,
802
+ * column: 10,
803
+ * nameIndex: 5,
804
+ * sourceIndex: 0,
805
+ * generatedLine: 100,
806
+ * generatedColumn: 15
807
+ * };
808
+ * ```
809
+ *
810
+ * @since 1.0.0
676
811
  */
677
- export declare class SourceService {
678
- /**
679
- * The name of the generated file this source map applies to.
680
- *
681
- * @since 1.0.0
682
- */
683
- readonly file: string | null;
684
- /**
685
- * Provider for accessing and manipulating the base64 VLQ-encoded mappings.
686
- *
687
- * @since 1.0.0
688
- */
689
- readonly mappings: MappingProvider;
690
- /**
691
- * The root URL for resolving relative paths in the source files.
692
- * @since 1.0.0
693
- */
694
- readonly sourceRoot: string | null;
695
- /**
696
- * List of symbol names referenced by the mappings.
697
- * @since 1.0.0
698
- */
699
- readonly names: Array<string>;
700
- /**
701
- * Array of source file paths.
702
- * @since 1.0.0
703
- */
704
- readonly sources: Array<string>;
705
- /**
706
- * Array of source file contents.
707
- * @since 1.0.0
708
- */
709
- readonly sourcesContent: Array<string>;
710
- /**
711
- * Creates a new SourceService instance.
712
- *
713
- * @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)
714
- * @param file - Optional file name for the generated bundle
715
- *
716
- * @throws Error - When a source map has an invalid format or missing required properties
717
- *
718
- * @since 1.0.0
719
- */
720
- constructor(source: SourceService);
721
- constructor(source: SourceMapInterface | string, file?: string | null);
722
- /**
723
- * Converts the source map data to a plain object.
724
- *
725
- * @returns A SourceMapInterface object representing the current state
726
- *
727
- * @example
728
- * ```ts
729
- * const mapObject = sourceService.getMapObject();
730
- * console.log(mapObject.file); // 'bundle.js'
731
- * ```
732
- *
733
- * @since 1.0.0
734
- */
735
- getMapObject(): SourceMapInterface;
736
- /**
737
- * Concatenates additional source maps into the current instance.
738
- *
739
- * @param maps - Source maps to concatenate with the current map
740
- *
741
- * @example
742
- * ```ts
743
- * sourceService.concat(anotherSourceMap);
744
- * console.log(sourceService.sources); // Updated source paths
745
- * ```
746
- *
747
- * @throws Error - When no maps are provided
748
- *
749
- * @since 1.0.0
750
- */
751
- concat(...maps: Array<SourceMapInterface | SourceService>): void;
752
- /**
753
- * Creates a new SourceService instance with concatenated source maps.
754
- *
755
- * @param maps - Source maps to concatenate with a copy of the current map
756
- * @returns A new SourceService instance with the combined maps
757
- *
758
- * @example
759
- * ```ts
760
- * const newService = sourceService.concatNewMap(anotherSourceMap);
761
- * console.log(newService.sources); // Combined sources array
762
- * ```
763
- *
764
- * @throws Error - When no maps are provided
765
- *
766
- * @since 1.0.0
767
- */
768
- concatNewMap(...maps: Array<SourceMapInterface | SourceService>): SourceService;
769
- /**
770
- * Finds position in generated code based on original source position.
771
- *
772
- * @param line - Line number in the original source
773
- * @param column - Column number in the original source
774
- * @param sourceIndex - Index or file path of the original source
775
- * @param bias - Position matching strategy (default: Bias.BOUND)
776
- * @returns Position information or null if not found
777
- *
778
- * @example
779
- * ```ts
780
- * const position = sourceService.getPositionByOriginal(1, 10, 'foo.ts');
781
- * console.log(position?.generatedLine); // Line in generated code
782
- * ```
783
- *
784
- * @since 1.0.0
785
- */
786
- getPositionByOriginal(line: number, column: number, sourceIndex: number | string, bias?: Bias): PositionInterface | null;
787
- /**
788
- * Finds position in an original source based on generated code position.
789
- *
790
- * @param line - Line number in the generated code
791
- * @param column - Column number in the generated code
792
- * @param bias - Position matching strategy (default: Bias.BOUND)
793
- * @returns Position information or null if not found
794
- *
795
- * @example
796
- * ```ts
797
- * const position = sourceService.getPosition(2, 15);
798
- * console.log(position?.source); // Original source file
799
- * ```
800
- *
801
- * @since 1.0.0
802
- */
803
- getPosition(line: number, column: number, bias?: Bias): PositionInterface | null;
804
- /**
805
- * Retrieves position with source content for a location in generated code.
806
- *
807
- * @param line - Line number in the generated code
808
- * @param column - Column number in the generated code
809
- * @param bias - Position matching strategy (default: Bias.BOUND)
810
- * @returns Position with content information or null if not found
811
- *
812
- * @example
813
- * ```ts
814
- * const posWithContent = sourceService.getPositionWithContent(3, 5);
815
- * console.log(posWithContent?.sourcesContent); // Original source content
816
- * ```
817
- *
818
- * @since 1.0.0
819
- */
820
- getPositionWithContent(line: number, column: number, bias?: Bias): PositionWithContentInterface | null;
821
- /**
822
- * Retrieves position with a code snippet from the original source.
823
- *
824
- * @param line - Line number in the generated code
825
- * @param column - Column number in the generated code
826
- * @param bias - Position matching strategy (default: Bias.BOUND)
827
- * @param options - Configuration for the amount of surrounding lines
828
- * @returns Position with code snippet or null if not found
829
- *
830
- * @example
831
- * ```ts
832
- * const posWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, {
833
- * linesBefore: 2,
834
- * linesAfter: 2
835
- * });
836
- * console.log(posWithCode?.code); // Code snippet with context
837
- * ```
838
- *
839
- * @since 1.0.0
840
- */
841
- getPositionWithCode(line: number, column: number, bias?: Bias, options?: SourceOptionsInterface): PositionWithCodeInterface | null;
842
- /**
843
- * Serializes the source map to a JSON string.
844
- *
845
- * @returns JSON string representation of the source map
846
- *
847
- * @example
848
- * ```ts
849
- * const jsonString = sourceService.toString();
850
- * console.log(jsonString); // '{"version":3,"file":"bundle.js",...}'
851
- * ```
852
- *
853
- * @since 1.0.0
854
- */
855
- toString(): string;
856
- /**
857
- * Validates a source map object has all required properties.
858
- *
859
- * @param input - Source map object to validate
860
- *
861
- * @throws Error - When required properties are missing
862
- *
863
- * @since 1.0.0
864
- */
865
- private validateSourceMap;
812
+ interface SegmentInterface {
813
+ line: number;
814
+ column: number;
815
+ nameIndex: number | null;
816
+ sourceIndex: number;
817
+ generatedLine: number;
818
+ generatedColumn: number;
866
819
  }
820
+ /**
821
+ * A specialized segment interface used during source map offset calculations.
822
+ *
823
+ * @property nameIndex - Index of the symbol name in the source map's names array (always numeric)
824
+ *
825
+ * @remarks
826
+ * Unlike the base SegmentInterface where nameIndex can be null,
827
+ * in offset calculations this value must always be a concrete numeric index.
828
+ * This specialized interface ensures type safety during mapping offset operations.
829
+ *
830
+ * @example
831
+ * ```ts
832
+ * const offsetSegment: SegmentOffsetInterface = {
833
+ * line: 42,
834
+ * column: 10,
835
+ * nameIndex: 5, // Must be a number, not null
836
+ * sourceIndex: 0,
837
+ * generatedLine: 100,
838
+ * generatedColumn: 15
839
+ * };
840
+ * ```
841
+ *
842
+ * @see SegmentInterface
843
+ *
844
+ * @since 1.0.0
845
+ */
846
+ interface SegmentOffsetInterface extends SegmentInterface {
847
+ nameIndex: number;
848
+ }
849
+ /**
850
+ * Represents a collection of mapping segments for a single line in generated code.
851
+ *
852
+ * @remarks
853
+ * A frame contains all the segments that map to a particular line of generated code.
854
+ * Each segment within the frame provides mapping information for a specific range
855
+ * of columns within that line.
856
+ *
857
+ * @example
858
+ * ```ts
859
+ * const lineFrame: FrameType = [
860
+ * { line: 10, column: 0, nameIndex: null, sourceIndex: 0, generatedLine: 5, generatedColumn: 0 },
861
+ * { line: 10, column: 5, nameIndex: 3, sourceIndex: 0, generatedLine: 5, generatedColumn: 10 }
862
+ * ];
863
+ * ```
864
+ *
865
+ * @see SegmentInterface
866
+ *
867
+ * @since 1.0.0
868
+ */
869
+ type FrameType = Array<SegmentInterface>;
870
+ /**
871
+ * Represents the complete mapping structure of a source map.
872
+ *
873
+ * @remarks
874
+ * A source map contains an array where each index corresponds to a line in the generated code.
875
+ * Each entry is either:
876
+ * - A frame (array of segments) containing mappings for that line
877
+ * - Null, indicating the line has no mappings (represented by a semicolon in the source map)
878
+ *
879
+ * The array index corresponds directly to the line number in generated code (0-based).
880
+ *
881
+ * @example
882
+ * ```ts
883
+ * const sourceMap: MapType = [
884
+ * [{ line: 1, column: 0, nameIndex: null, sourceIndex: 0, generatedLine: 0, generatedColumn: 0 }], // Line 0
885
+ * null, // Line 1 has no mappings
886
+ * [{ line: 2, column: 0, nameIndex: 1, sourceIndex: 0, generatedLine: 2, generatedColumn: 0 }] // Line 2
887
+ * ];
888
+ * ```
889
+ *
890
+ * @see FrameType
891
+ * @see SegmentInterface
892
+ *
893
+ * @since 1.0.0
894
+ */
895
+ type MapType = Array<null | FrameType>;