@remotex-labs/xmap 1.1.0 → 2.0.1
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/README.md +206 -143
- package/dist/{components → cjs/components}/formatter.component.d.ts +2 -2
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/index.js.map +8 -0
- package/dist/cjs/providers/interfaces/mapping.interface.d.ts +52 -0
- package/dist/cjs/providers/mapping.provider.d.ts +229 -0
- package/dist/cjs/services/interfaces/source.interface.d.ts +53 -0
- package/dist/cjs/services/source.service.d.ts +217 -0
- package/dist/esm/components/base64.component.d.ts +26 -0
- package/dist/esm/components/formatter.component.d.ts +66 -0
- package/dist/esm/components/highlighter.component.d.ts +186 -0
- package/dist/esm/components/interfaces/formatter.interface.d.ts +42 -0
- package/dist/esm/components/interfaces/highlighter.interface.d.ts +48 -0
- package/dist/esm/components/interfaces/parse.interface.d.ts +31 -0
- package/dist/esm/components/parser.component.d.ts +11 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +8 -0
- package/dist/esm/providers/interfaces/mapping.interface.d.ts +52 -0
- package/dist/esm/providers/mapping.provider.d.ts +229 -0
- package/dist/esm/services/interfaces/source.interface.d.ts +53 -0
- package/dist/esm/services/source.service.d.ts +217 -0
- package/package.json +24 -9
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -7
- package/dist/services/interfaces/source.interface.d.ts +0 -252
- package/dist/services/source.service.d.ts +0 -478
- /package/dist/{components → cjs/components}/base64.component.d.ts +0 -0
- /package/dist/{components → cjs/components}/highlighter.component.d.ts +0 -0
- /package/dist/{components → cjs/components}/interfaces/formatter.interface.d.ts +0 -0
- /package/dist/{components → cjs/components}/interfaces/highlighter.interface.d.ts +0 -0
- /package/dist/{components → cjs/components}/interfaces/parse.interface.d.ts +0 -0
- /package/dist/{components → cjs/components}/parser.component.d.ts +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import will remove at compile time
|
|
3
|
+
*/
|
|
4
|
+
import { Bias, type MapType, type SegmentInterface } from './interfaces/mapping.interface';
|
|
5
|
+
/**
|
|
6
|
+
* The `MappingProvider` class provides methods to encode and decode mappings
|
|
7
|
+
* from a source map or mapping string to an internal structured representation.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MappingProvider {
|
|
10
|
+
/**
|
|
11
|
+
* The internal mapping representation, where each index represents a frame of segments.
|
|
12
|
+
*/
|
|
13
|
+
private mapping;
|
|
14
|
+
/**
|
|
15
|
+
* Constructor to initialize the `MappingProvider` with a mapping.
|
|
16
|
+
* Can be initialized with either a mapping string or a structured mapping array.
|
|
17
|
+
*
|
|
18
|
+
* @param mapping - The mapping data, either as a string or structured array.
|
|
19
|
+
* @param namesOffset - Optional offset for the names index.
|
|
20
|
+
* @param sourceOffset - Optional offset for the sources index.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const provider = new MappingProvider(";;;AAiBO,SAAS,OAAO;AACnB,UAAQ,IAAI,MAAM;AACtB;;;ACjBA,QAAQ,IAAI,GAAG;AACf,KAAK;", 0, 0);
|
|
25
|
+
* const provider2 = new MappingProvider([
|
|
26
|
+
* null,
|
|
27
|
+
* [
|
|
28
|
+
* {
|
|
29
|
+
* line: 1,
|
|
30
|
+
* column: 1,
|
|
31
|
+
* nameIndex: null,
|
|
32
|
+
* sourceIndex: 0,
|
|
33
|
+
* generatedLine: 2,
|
|
34
|
+
* generatedColumn: 1
|
|
35
|
+
* }
|
|
36
|
+
* ],
|
|
37
|
+
* null
|
|
38
|
+
* ], 0, 0);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
constructor(mapping: string, namesOffset?: number, sourceOffset?: number);
|
|
42
|
+
constructor(mapping: MapType, namesOffset?: number, sourceOffset?: number);
|
|
43
|
+
constructor(mapping: MappingProvider, namesOffset?: number, sourceOffset?: number);
|
|
44
|
+
/**
|
|
45
|
+
* Encodes the internal mapping array back into a mapping string.
|
|
46
|
+
*
|
|
47
|
+
* @returns {string} - The encoded mapping string.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const encoded = provider.encode();
|
|
51
|
+
* console.log(encoded); // Outputs encoded mapping string
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
encode(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Decodes a mapping from either a string or structured array into the internal mapping.
|
|
57
|
+
*
|
|
58
|
+
* @param mapping - The mapping data to decode.
|
|
59
|
+
* @param namesOffset - Offset for the names index.
|
|
60
|
+
* @param sourcesOffset - Offset for the sources index.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* provider.decode(";;;AAiBO,SAAS,OAAO;AACnB,UAAQ,IAAI,MAAM;AACtB;;;ACjBA,QAAQ,IAAI,GAAG;AACf,KAAK;", 0, 0);
|
|
64
|
+
* provider.decode([
|
|
65
|
+
* null,
|
|
66
|
+
* [
|
|
67
|
+
* {
|
|
68
|
+
* line: 1,
|
|
69
|
+
* column: 1,
|
|
70
|
+
* nameIndex: null,
|
|
71
|
+
* sourceIndex: 0,
|
|
72
|
+
* generatedLine: 2,
|
|
73
|
+
* generatedColumn: 1
|
|
74
|
+
* }
|
|
75
|
+
* ],
|
|
76
|
+
* null
|
|
77
|
+
* ], 0, 0);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
decode(mapping: MappingProvider | MapType | string, namesOffset?: number, sourcesOffset?: number): void;
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves a segment based on the provided generated line and column,
|
|
83
|
+
* applying the specified bias when the exact match is not found.
|
|
84
|
+
*
|
|
85
|
+
* This method performs a binary search on the segments of the specified
|
|
86
|
+
* generated line to efficiently locate the segment corresponding to
|
|
87
|
+
* the provided generated column. If an exact match is not found,
|
|
88
|
+
* the method returns the closest segment based on the specified bias:
|
|
89
|
+
* - `Bias.BOUND`: No preference for column matching (returns the closest segment).
|
|
90
|
+
* - `Bias.LOWER_BOUND`: Prefers the closest mapping with a lower column value.
|
|
91
|
+
* - `Bias.UPPER_BOUND`: Prefers the closest mapping with a higher column value.
|
|
92
|
+
*
|
|
93
|
+
* @param generatedLine - The line number of the generated code (1-based index).
|
|
94
|
+
* @param generatedColumn - The column number of the generated code (0-based index).
|
|
95
|
+
* @param bias - The bias to use when the line matches, can be one of:
|
|
96
|
+
* - `Bias.BOUND` (default): No preference for column matching.
|
|
97
|
+
* - `Bias.LOWER_BOUND`: Prefer the closest mapping with a lower column value.
|
|
98
|
+
* - `Bias.UPPER_BOUND`: Prefer the closest mapping with a higher column value.
|
|
99
|
+
* @returns The matching segment if found;
|
|
100
|
+
* returns null if no segments exist for the specified generated line
|
|
101
|
+
* or if the generated line is out of bounds.
|
|
102
|
+
*
|
|
103
|
+
* @throws { Error } - Throws an error if the generated line is invalid
|
|
104
|
+
* (out of bounds).
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const segment = sourceMap.getSegment(5, 10, Bias.UPPER_BOUND);
|
|
109
|
+
* if (segment) {
|
|
110
|
+
* console.log(`Found segment: line ${segment.line}, column ${segment.column}`);
|
|
111
|
+
* } else {
|
|
112
|
+
* console.log('No matching segment found.');
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
getSegment(generatedLine: number, generatedColumn: number, bias?: Bias): SegmentInterface | null;
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves the original segment based on the provided line, column, and source index.
|
|
119
|
+
*
|
|
120
|
+
* This method searches for the original segment that corresponds to the specified
|
|
121
|
+
* line, column, and source index. It uses binary search to find the closest segment
|
|
122
|
+
* based on the provided bias.
|
|
123
|
+
*
|
|
124
|
+
* @param line - The line number of the original code (1-based index).
|
|
125
|
+
* @param column - The column number of the original code (0-based index).
|
|
126
|
+
* @param sourceIndex - The index of the source file in the source map.
|
|
127
|
+
* @param bias - The bias to apply when multiple segments match; defaults to `Bias.BOUND`.
|
|
128
|
+
* @returns {SegmentInterface | null} - The matching original segment if found;
|
|
129
|
+
* returns null if no segments exist for the specified line and source index.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const originalSegment = sourceMap.getOriginalSegment(3, 5, 0, Bias.LOWER_BOUND);
|
|
134
|
+
* if (originalSegment) {
|
|
135
|
+
* console.log(`Found original segment: line ${originalSegment.line}, column ${originalSegment.column}`);
|
|
136
|
+
* } else {
|
|
137
|
+
* console.log('No matching original segment found.');
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
getOriginalSegment(line: number, column: number, sourceIndex: number, bias?: Bias): SegmentInterface | null;
|
|
142
|
+
/**
|
|
143
|
+
* Initializes the segment offsets used to track the current decoding position.
|
|
144
|
+
*
|
|
145
|
+
* @param namesOffset - The offset for the names index.
|
|
146
|
+
* @param sourceIndex - The offset for the source index.
|
|
147
|
+
* @returns { SegmentOffsetInterface } - The initialized segment offset.
|
|
148
|
+
*/
|
|
149
|
+
private initPositionOffsets;
|
|
150
|
+
/**
|
|
151
|
+
* Validates the format of an encoded mapping string.
|
|
152
|
+
*
|
|
153
|
+
* @param encodedSourceMap - The encoded source map string to validate.
|
|
154
|
+
* @returns Returns `true` if the format is valid, otherwise `false`.
|
|
155
|
+
*/
|
|
156
|
+
private validateMappingString;
|
|
157
|
+
/**
|
|
158
|
+
* Validates the properties of a segment to ensure they conform to expected types.
|
|
159
|
+
*
|
|
160
|
+
* This method checks that the segment's properties are finite numbers and that
|
|
161
|
+
* the nameIndex, if provided, is either a finite number or null.
|
|
162
|
+
* An error is thrown if any of the properties do not meet the specified criteria.
|
|
163
|
+
*
|
|
164
|
+
* @param segment - The segment object to validate, which must conform to the
|
|
165
|
+
* SegmentInterface structure, including:
|
|
166
|
+
* - line: number (finite)
|
|
167
|
+
* - column: number (finite)
|
|
168
|
+
* - nameIndex: number | null (if not null, must be finite)
|
|
169
|
+
* - sourceIndex: number (finite)
|
|
170
|
+
* - generatedLine: number (finite)
|
|
171
|
+
* - generatedColumn: number (finite)
|
|
172
|
+
*
|
|
173
|
+
* @throws {Error} - Throws an error if any property of the segment is invalid.
|
|
174
|
+
* The error message will specify which property is invalid
|
|
175
|
+
* and the value that was received.
|
|
176
|
+
*/
|
|
177
|
+
private validateSegment;
|
|
178
|
+
/**
|
|
179
|
+
* Encodes a segment into a VLQ-encoded string based on the segment offsets.
|
|
180
|
+
*
|
|
181
|
+
* @param segmentOffset - The current segment offset.
|
|
182
|
+
* @param segmentObject - The segment to encode.
|
|
183
|
+
* @returns The encoded segment string.
|
|
184
|
+
*/
|
|
185
|
+
private encodeSegment;
|
|
186
|
+
/**
|
|
187
|
+
* Encodes the entire mapping array into a VLQ-encoded mapping string.
|
|
188
|
+
*
|
|
189
|
+
* @param map - The mapping array to encode.
|
|
190
|
+
* @returns The encoded mapping string.
|
|
191
|
+
*/
|
|
192
|
+
private encodeMappings;
|
|
193
|
+
/**
|
|
194
|
+
* Decodes a VLQ-encoded segment into a segment object based on the current offset.
|
|
195
|
+
*
|
|
196
|
+
* @param segmentOffset - The current segment offset.
|
|
197
|
+
* @param decodedSegment - The decoded VLQ segment values.
|
|
198
|
+
* @returns The decoded segment object.
|
|
199
|
+
*/
|
|
200
|
+
private decodedSegment;
|
|
201
|
+
/**
|
|
202
|
+
* Decodes a VLQ-encoded mapping string into the internal mapping representation.
|
|
203
|
+
*
|
|
204
|
+
* @param encodedMap - The VLQ-encoded mapping string.
|
|
205
|
+
* @param namesOffset - Offset for the names index.
|
|
206
|
+
* @param sourceOffset - Offset for the sources index.
|
|
207
|
+
* @throws { Error } - Throws an error if the mapping string is invalid.
|
|
208
|
+
*/
|
|
209
|
+
private decodeMappingString;
|
|
210
|
+
/**
|
|
211
|
+
* Decodes a mapping array into the internal mapping representation, adjusting for offsets.
|
|
212
|
+
*
|
|
213
|
+
* This method processes each frame in the provided structured mapping array,
|
|
214
|
+
* validating each segment within the frame and adjusting the indices based on the
|
|
215
|
+
* specified offsets for names and sources. If a frame is invalid or not an array,
|
|
216
|
+
* an error will be thrown.
|
|
217
|
+
*
|
|
218
|
+
* @param encodedMap - The structured mapping array, which should be an array of frames,
|
|
219
|
+
* where each frame is an array of segments. Each segment must conform
|
|
220
|
+
* to the SegmentInterface.
|
|
221
|
+
* @param namesOffset - Offset for the names index, which will be added to each segment's nameIndex.
|
|
222
|
+
* @param sourceOffset - Offset for the sources index, which will be added to each segment's sourceIndex.
|
|
223
|
+
* @throws { Error } - Throws an error if:
|
|
224
|
+
* - The mapping array is invalid (not an array).
|
|
225
|
+
* - Any frame is not an array.
|
|
226
|
+
* - Any segment does not conform to the SegmentInterface.
|
|
227
|
+
*/
|
|
228
|
+
private decodeMappingArray;
|
|
229
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a source map structure used for mapping code within a file
|
|
3
|
+
* to its original source. Source maps are essential for debugging minified
|
|
4
|
+
* or transpiled code, as they allow developers to trace back to the
|
|
5
|
+
* original source files and understand the context of the code execution.
|
|
6
|
+
*
|
|
7
|
+
* @interface SourceMapInterface
|
|
8
|
+
* @property file - The generated file's name that the source map is associated with.
|
|
9
|
+
* This property is optional and may be null if not specified.
|
|
10
|
+
* @property names - An array of variable/function names that are present in the original source.
|
|
11
|
+
* These names help in mapping the original code context during debugging.
|
|
12
|
+
* @property version - The version of the source map specification.
|
|
13
|
+
* This should be set to `3` for the standard source map version.
|
|
14
|
+
* @property sources - An array of URLs or paths to the original source files.
|
|
15
|
+
* These sources are used to locate the original code that corresponds to the generated code.
|
|
16
|
+
* @property mappings - A VLQ (Variable-Length Quantity) encoded string that describes how to map the
|
|
17
|
+
* generated code back to the original source code. This property is crucial for the correct functioning of the source map.
|
|
18
|
+
* @property sourceRoot - An optional root URL for the sources.
|
|
19
|
+
* It can be used to specify a base path for resolving the sources, which may be null if not applicable.
|
|
20
|
+
* @property sourcesContent - An optional array containing the content of the original source files.
|
|
21
|
+
* This property can be useful when the original files are not available at runtime.
|
|
22
|
+
*/
|
|
23
|
+
export interface SourceMapInterface {
|
|
24
|
+
file?: string | null;
|
|
25
|
+
names: Array<string>;
|
|
26
|
+
version: number;
|
|
27
|
+
sources: Array<string>;
|
|
28
|
+
mappings: string;
|
|
29
|
+
sourceRoot?: string | null;
|
|
30
|
+
sourcesContent?: Array<string>;
|
|
31
|
+
}
|
|
32
|
+
export interface PositionInterface {
|
|
33
|
+
name: string | null;
|
|
34
|
+
line: number;
|
|
35
|
+
column: number;
|
|
36
|
+
source: string;
|
|
37
|
+
sourceRoot: string | null;
|
|
38
|
+
sourceIndex: number;
|
|
39
|
+
generatedLine: number;
|
|
40
|
+
generatedColumn: number;
|
|
41
|
+
}
|
|
42
|
+
export interface PositionWithContentInterface extends PositionInterface {
|
|
43
|
+
sourcesContent: string;
|
|
44
|
+
}
|
|
45
|
+
export interface PositionWithCodeInterface extends PositionInterface {
|
|
46
|
+
code: string;
|
|
47
|
+
endLine: number;
|
|
48
|
+
startLine: number;
|
|
49
|
+
}
|
|
50
|
+
export interface SourceOptionsInterface {
|
|
51
|
+
linesAfter?: number;
|
|
52
|
+
linesBefore?: number;
|
|
53
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import will remove at compile time
|
|
3
|
+
*/
|
|
4
|
+
import type { PositionInterface, SourceMapInterface, SourceOptionsInterface, PositionWithCodeInterface, PositionWithContentInterface } from "./interfaces/source.interface";
|
|
5
|
+
/**
|
|
6
|
+
* Imports
|
|
7
|
+
*/
|
|
8
|
+
import { MappingProvider } from "../providers/mapping.provider";
|
|
9
|
+
import { Bias } from "../providers/interfaces/mapping.interface";
|
|
10
|
+
/**
|
|
11
|
+
* A service for validating and processing source maps.
|
|
12
|
+
* This class allows parsing and manipulation of source maps, providing functionality such as
|
|
13
|
+
* retrieving position mappings between original and generated code, concatenating source maps,
|
|
14
|
+
* and getting code snippets based on mappings.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
|
|
19
|
+
* const sourceService = new SourceService(sourceMapJSON);
|
|
20
|
+
*
|
|
21
|
+
* console.log(sourceService.file); // Outputs: 'bundle.js'
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class SourceService {
|
|
25
|
+
/**
|
|
26
|
+
* The name of the generated file (bundle) that this source map applies to.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* console.log(sourceService.file); // 'bundle.js'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
readonly file: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* A MappingProvider instance of base64 VLQ-encoded mappings.
|
|
36
|
+
*/
|
|
37
|
+
readonly mappings: MappingProvider;
|
|
38
|
+
/**
|
|
39
|
+
* The root URL for the sources, if present in the source map.
|
|
40
|
+
*/
|
|
41
|
+
readonly sourceRoot: string | null;
|
|
42
|
+
/**
|
|
43
|
+
* A list of symbol names used by the “mappings” entry.
|
|
44
|
+
*/
|
|
45
|
+
readonly names: Array<string>;
|
|
46
|
+
/**
|
|
47
|
+
* An array of source file paths.
|
|
48
|
+
*/
|
|
49
|
+
readonly sources: Array<string>;
|
|
50
|
+
/**
|
|
51
|
+
* An array of source files contents.
|
|
52
|
+
*/
|
|
53
|
+
readonly sourcesContent: Array<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new instance of the `SourceService` class.
|
|
56
|
+
*
|
|
57
|
+
* This constructor initializes the class using either a `SourceMapInterface` object,
|
|
58
|
+
* a JSON string representing the source map, or an existing `SourceService` instance.
|
|
59
|
+
* It validates the source map and populates its properties such as `file`, `sources`, and `mappings`.
|
|
60
|
+
*
|
|
61
|
+
* @param source - Can be one of the following:
|
|
62
|
+
* - An object conforming to the `SourceMapInterface`.
|
|
63
|
+
* - A JSON string representing the source map.
|
|
64
|
+
* - A `SourceService` instance to copy the properties.
|
|
65
|
+
* @param file - (Optional) A string representing the file name of the generated bundle.
|
|
66
|
+
* Defaults to `null`. It will overwrite any existing `file` property in the source map.
|
|
67
|
+
* @throws {Error} - If the source map does not contain required properties or has an invalid format.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
|
|
72
|
+
* const sourceService = new SourceService(sourceMapJSON);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
constructor(source: SourceService);
|
|
76
|
+
constructor(source: SourceMapInterface | string, file?: string | null);
|
|
77
|
+
/**
|
|
78
|
+
* Converts the current source map data into a plain object format.
|
|
79
|
+
*
|
|
80
|
+
* @returns The source map json object.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const mapObject = sourceService.getMapObject();
|
|
85
|
+
* console.log(mapObject.file); // 'bundle.js'
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
getMapObject(): SourceMapInterface;
|
|
89
|
+
/**
|
|
90
|
+
* Concatenates one or more source maps to the current source map.
|
|
91
|
+
*
|
|
92
|
+
* This method merges additional source maps into the current source map,
|
|
93
|
+
* updating the `mappings`, `names`, `sources`, and `sourcesContent` arrays.
|
|
94
|
+
*
|
|
95
|
+
* @param maps - An array of `SourceMapInterface` or `SourceService` instances to be concatenated.
|
|
96
|
+
* @throws { Error } If no source maps are provided for concatenation.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* sourceService.concat(anotherSourceMap);
|
|
101
|
+
* console.log(sourceService.sources); // Updated source paths
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
concat(...maps: Array<SourceMapInterface | SourceService>): void;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new instance of `SourceService` with concatenated source maps.
|
|
107
|
+
*
|
|
108
|
+
* @param maps - An array of `SourceMapInterface` or `SourceService` instances to be concatenated.
|
|
109
|
+
* @returns { SourceService } A new `SourceService` instance with the concatenated maps.
|
|
110
|
+
* @throws { Error } If no source maps are provided.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const newService = sourceService.concatNewMap(anotherSourceMap);
|
|
115
|
+
* console.log(newService.file); // The file from the new source map
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
concatNewMap(...maps: Array<SourceMapInterface | SourceService>): SourceService;
|
|
119
|
+
/**
|
|
120
|
+
* Retrieves the position information based on the original source line and column.
|
|
121
|
+
*
|
|
122
|
+
* @param line - The line number in the generated code.
|
|
123
|
+
* @param column - The column number in the generated code.
|
|
124
|
+
* @param sourceIndex - The index or file path of the original source.
|
|
125
|
+
* @param bias - The bias to use when matching positions (`Bias.LOWER_BOUND`, `Bias.UPPER_BOUND`, or `Bias.BOUND`).
|
|
126
|
+
* @returns { PositionInterface | null } The corresponding position in the original source, or `null` if not found.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const position = sourceService.getPositionByOriginal(1, 10, 'foo.ts');
|
|
131
|
+
* console.log(position?.line); // The line number in the original source
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
getPositionByOriginal(line: number, column: number, sourceIndex: number | string, bias?: Bias): PositionInterface | null;
|
|
135
|
+
/**
|
|
136
|
+
* Retrieves the position in the original source code based on a given line and column
|
|
137
|
+
* in the generated code.
|
|
138
|
+
*
|
|
139
|
+
* @param line - Line number in the generated code.
|
|
140
|
+
* @param column - Column number in the generated code.
|
|
141
|
+
* @param bias - The bias to use for matching positions. Defaults to `Bias.BOUND`.
|
|
142
|
+
* @returns {PositionInterface | null} The position in the original source, or null if not found.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const position = sourceService.getPosition(2, 15);
|
|
147
|
+
* console.log(position?.source); // The original source file
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
getPosition(line: number, column: number, bias?: Bias): PositionInterface | null;
|
|
151
|
+
/**
|
|
152
|
+
* Retrieves the position and original source content for a given position in the generated code.
|
|
153
|
+
*
|
|
154
|
+
* @param line - Line number in the generated code.
|
|
155
|
+
* @param column - Column number in the generated code.
|
|
156
|
+
* @param bias - Bias used for position matching.
|
|
157
|
+
* @returns { PositionWithContentInterface | null } The position and its associated content, or `null` if not found.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const positionWithContent = sourceService.getPositionWithContent(3, 5);
|
|
162
|
+
* console.log(positionWithContent?.sourcesContent); // The source code content
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
getPositionWithContent(line: number, column: number, bias?: Bias): PositionWithContentInterface | null;
|
|
166
|
+
/**
|
|
167
|
+
* Retrieves the position and a code snippet from the original source based on the given
|
|
168
|
+
* generated code position, with additional lines of code around the matching line.
|
|
169
|
+
*
|
|
170
|
+
* @param line - Line number in the generated code.
|
|
171
|
+
* @param column - Column number in the generated code.
|
|
172
|
+
* @param bias - Bias used for position matching.
|
|
173
|
+
* @param options - (Optional) Extra options for the amount of surrounding lines to include.
|
|
174
|
+
* @returns { PositionWithCodeInterface | null } The position and code snippet.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* const positionWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, { linesBefore: 2, linesAfter: 2 });
|
|
179
|
+
* console.log(positionWithCode?.code); // The code snippet from the original source
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
getPositionWithCode(line: number, column: number, bias?: Bias, options?: SourceOptionsInterface): PositionWithCodeInterface | null;
|
|
183
|
+
/**
|
|
184
|
+
* Converts the current source map object to a JSON string.
|
|
185
|
+
*
|
|
186
|
+
* @returns A stringified version of the source map object.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* console.log(sourceService.toString()); // JSON string of the source map
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
toString(): string;
|
|
194
|
+
/**
|
|
195
|
+
* Validates the provided source map object.
|
|
196
|
+
*
|
|
197
|
+
* This method checks whether all required keys are present in the source map object.
|
|
198
|
+
* It throws an error if any required keys are missing.
|
|
199
|
+
*
|
|
200
|
+
* @private
|
|
201
|
+
* @param input - The source map object to be validated.
|
|
202
|
+
* @throws Error If any required key is missing from the source map.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* const sourceMap = {
|
|
207
|
+
* version: 3,
|
|
208
|
+
* file: 'example.js',
|
|
209
|
+
* names: ['src', 'maps', 'example', 'function', 'line', 'column'],
|
|
210
|
+
* sources: ['source1.js', 'source2.js'],
|
|
211
|
+
* mappings: 'AAAA,SAASA,CAAC,CAAC,CAAC;AAAA,CAAC,CAAC;AAAC,CAAC',
|
|
212
|
+
* };
|
|
213
|
+
* sourceService['validateSource'](sourceMap); // Throws if invalid
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
private validateSourceMap;
|
|
217
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotex-labs/xmap",
|
|
3
|
-
"main": "dist/index.js",
|
|
4
|
-
"
|
|
3
|
+
"main": "dist/cjs/index.js",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./dist/cjs/index.d.ts",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
5
7
|
"author": "Garefild",
|
|
6
|
-
"version": "
|
|
8
|
+
"version": "2.0.1",
|
|
7
9
|
"license": "Mozilla Public License Version 2.0",
|
|
8
10
|
"description": "A library with a sourcemap parser and TypeScript code formatter for the CLI",
|
|
9
11
|
"homepage": "https://github.com/remotex-lab/xMap",
|
|
@@ -32,6 +34,19 @@
|
|
|
32
34
|
"engines": {
|
|
33
35
|
"node": ">=18"
|
|
34
36
|
},
|
|
37
|
+
"exports": {
|
|
38
|
+
"./package.json": "./package.json",
|
|
39
|
+
".": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/esm/index.d.ts",
|
|
42
|
+
"default": "./dist/esm/index.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/cjs/index.d.ts",
|
|
46
|
+
"default": "./dist/cjs/index.js"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
35
50
|
"files": [
|
|
36
51
|
"dist",
|
|
37
52
|
"LICENSE",
|
|
@@ -40,7 +55,7 @@
|
|
|
40
55
|
"scripts": {
|
|
41
56
|
"dev": "xBuild -w",
|
|
42
57
|
"test": "jest",
|
|
43
|
-
"build": "xBuild",
|
|
58
|
+
"build": "xBuild && xbuild -c xbuild.cjs.ts",
|
|
44
59
|
"test:coverage": "jest --coverage",
|
|
45
60
|
"lint": "xbuild --tc && eslint . -c ./eslint.config.mjs",
|
|
46
61
|
"ci:test": "jest",
|
|
@@ -49,15 +64,15 @@
|
|
|
49
64
|
},
|
|
50
65
|
"devDependencies": {
|
|
51
66
|
"jest": "^29.7.0",
|
|
52
|
-
"eslint": "^9.
|
|
53
|
-
"typescript-eslint": "^8.
|
|
54
|
-
"eslint-plugin-jsdoc": "^50.
|
|
67
|
+
"eslint": "^9.12.0",
|
|
68
|
+
"typescript-eslint": "^8.9.0",
|
|
69
|
+
"eslint-plugin-jsdoc": "^50.4.1",
|
|
55
70
|
"@swc/jest": "^0.2.36",
|
|
56
71
|
"@types/jest": "^29.5.13",
|
|
57
|
-
"@types/node": "^22.7.
|
|
72
|
+
"@types/node": "^22.7.5",
|
|
58
73
|
"@remotex-labs/xbuild": "^1.2.0"
|
|
59
74
|
},
|
|
60
75
|
"dependencies": {
|
|
61
|
-
"typescript": "^5.6.
|
|
76
|
+
"typescript": "^5.6.3"
|
|
62
77
|
}
|
|
63
78
|
}
|
package/dist/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";var P=Object.create;var f=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var D=(i,e)=>{for(var n in e)f(i,n,{get:e[n],enumerable:!0})},b=(i,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of k(e))!$.call(i,r)&&r!==n&&f(i,r,{get:()=>e[r],enumerable:!(t=R(e,r))||t.enumerable});return i};var U=(i,e,n)=>(n=i!=null?P(B(i)):{},b(e||!i||!i.__esModule?f(n,"default",{value:i,enumerable:!0}):n,i)),_=i=>b(f({},"__esModule",{value:!0}),i);var V={};D(V,{CodeHighlighter:()=>S,Colors:()=>O,SourceService:()=>y,decodeVLQ:()=>I,encodeArrayVLQ:()=>x,encodeVLQ:()=>N,formatCode:()=>E,formatErrorCode:()=>j,highlightCode:()=>W,parseErrorStack:()=>F});module.exports=_(V);function F(i){let e=i.split(`
|
|
2
|
-
`).slice(1),n=/^\s*at\s+(.*?)\s+\((.*?):(\d+):(\d+)\)$|^\s*at\s+(.*?):(\d+):(\d+)$/,t=/eval\s+at\s+([^\s(]+).+\((.+):(\d+):(\d+)\),\s(.+)/,r=[];return e.forEach(s=>{let a=s.match(n);if(!a)return;let c=a.slice(1);a[2]||(c=a.slice(4));let[l,d,m,g]=c,p=parseInt(m,10),u=parseInt(g,10);if(s.includes("eval")){let C=d.match(t)?.slice(1);if(C){let[M,A,K,T,w]=C;r.push({at:l,file:w,line:p,column:u,executor:{at:M,file:A,line:parseInt(K,10),column:parseInt(T,10)}});return}}r.push({at:l||"<anonymous>",file:d,line:p,column:u,executor:null})}),r}var v={},L="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");L.forEach((i,e)=>{v[i]=e});function N(i){let e=i<0,n="",t=e?(-i<<1)+1:i<<1;do{let r=t&31;t>>>=5,n+=L[r|(t>0?32:0)]}while(t>0);return n}function x(i){return i.map(N).join("")}function I(i){let e=[],n=0,t=0;for(let r=0;r<i.length;r++){let s=v[i[r]];if(s===void 0)throw new Error(`Invalid Base64 character: ${i[r]}`);let a=s&32;if(t+=(s&31)<<n,a)n+=5;else{let c=(t&1)===1,l=t>>1;e.push(c?-l:l),t=n=0}}return e}function E(i,e={}){let n=i.split(`
|
|
3
|
-
`),t=e.padding??10,r=e.startLine??0;return n.map((s,a)=>{let c=a+r+1,d=`${`${c} | `.padStart(t)}${s}`;return e.action&&c===e.action.triggerLine?e.action.callback(d,t,c):d}).join(`
|
|
4
|
-
`)}function j(i,e){let{code:n,line:t,column:r,startLine:s}=i;if(t<s||r<1)throw new Error("Invalid line or column number.");return E(n,{startLine:s,action:{triggerLine:t,callback:(a,c,l)=>{let d="^",m=c-1,g=">";e&&(d=`${e.color}${d}${e.reset}`,m+=e.color.length+e.reset.length,g=`${e.color}>${e.reset}`);let p=" | ".padStart(c)+" ".repeat(r-1)+`${d}`;return a=`${g} ${l} |`.padStart(m)+a.split("|")[1],a+`
|
|
5
|
-
${p}`}}})}var o=U(require("typescript")),h=require("typescript"),O=(u=>(u.reset="\x1B[0m",u.gray="\x1B[38;5;243m",u.darkGray="\x1B[38;5;238m",u.lightCoral="\x1B[38;5;203m",u.lightOrange="\x1B[38;5;215m",u.oliveGreen="\x1B[38;5;149m",u.burntOrange="\x1B[38;5;208m",u.lightGoldenrodYellow="\x1B[38;5;221m",u.lightYellow="\x1B[38;5;230m",u.canaryYellow="\x1B[38;5;227m",u.deepOrange="\x1B[38;5;166m",u.lightGray="\x1B[38;5;252m",u.brightPink="\x1B[38;5;197m",u))(O||{}),G={enumColor:"\x1B[38;5;208m",typeColor:"\x1B[38;5;221m",classColor:"\x1B[38;5;215m",stringColor:"\x1B[38;5;149m",keywordColor:"\x1B[38;5;203m",commentColor:"\x1B[38;5;238m",functionColor:"\x1B[38;5;215m",variableColor:"\x1B[38;5;208m",interfaceColor:"\x1B[38;5;221m",parameterColor:"\x1B[38;5;166m",getAccessorColor:"\x1B[38;5;230m",numericLiteralColor:"\x1B[38;5;252m",methodSignatureColor:"\x1B[38;5;208m",regularExpressionColor:"\x1B[38;5;149m",propertyAssignmentColor:"\x1B[38;5;227m",propertyAccessExpressionColor:"\x1B[38;5;230m",expressionWithTypeArgumentsColor:"\x1B[38;5;215m"},S=class{constructor(e,n,t){this.sourceFile=e;this.code=n;this.schema=t}segments=new Map;parseNode(e){this.processComments(e),this.processKeywords(e),this.processNode(e)}highlight(){let e=0,n,t=[];return Array.from(this.segments.values()).sort((s,a)=>s.start-a.start||s.end-a.end).forEach(s=>{if(n&&s.start<n.end){let a=t.pop();if(!a)return;let c=this.getSegmentSource(s.start,s.end),l=`${s.color}${c}${n.color}`;t.push(a.replace(c,l));return}t.push(this.getSegmentSource(e,s.start)),t.push(`${s.color}${this.getSegmentSource(s.start,s.end)}${s.reset}`),e=s.end,n=s}),t.join("")+this.getSegmentSource(e)}getSegmentSource(e,n){return this.code.slice(e,n)}addSegment(e,n,t,r="\x1B[0m"){let s=`${e}-${n}`;this.segments.set(s,{start:e,end:n,color:t,reset:r})}processComments(e){[...o.getTrailingCommentRanges(this.sourceFile.getFullText(),e.getFullStart())||[],...o.getLeadingCommentRanges(this.sourceFile.getFullText(),e.getFullStart())||[]].forEach(t=>this.addSegment(t.pos,t.end,this.schema.commentColor))}processKeywords(e){if([h.SyntaxKind.NullKeyword,h.SyntaxKind.VoidKeyword,h.SyntaxKind.StringKeyword,h.SyntaxKind.NumberKeyword,h.SyntaxKind.BooleanKeyword,h.SyntaxKind.UndefinedKeyword].includes(e.kind))return this.addSegment(e.getStart(),e.getEnd(),this.schema.typeColor);e&&e.kind>=o.SyntaxKind.FirstKeyword&&e.kind<=o.SyntaxKind.LastKeyword&&this.addSegment(e.getStart(),e.getEnd(),this.schema.keywordColor)}processIdentifier(e){let n=e.getEnd(),t=e.getStart();switch(e.parent.kind){case o.SyntaxKind.EnumMember:return this.addSegment(t,n,this.schema.enumColor);case o.SyntaxKind.CallExpression:case o.SyntaxKind.EnumDeclaration:case o.SyntaxKind.PropertySignature:case o.SyntaxKind.ModuleDeclaration:return this.addSegment(t,n,this.schema.variableColor);case o.SyntaxKind.InterfaceDeclaration:return this.addSegment(t,n,this.schema.interfaceColor);case o.SyntaxKind.GetAccessor:return this.addSegment(t,n,this.schema.getAccessorColor);case o.SyntaxKind.PropertyAssignment:return this.addSegment(t,n,this.schema.propertyAssignmentColor);case o.SyntaxKind.MethodSignature:return this.addSegment(t,n,this.schema.methodSignatureColor);case o.SyntaxKind.MethodDeclaration:case o.SyntaxKind.FunctionDeclaration:return this.addSegment(t,n,this.schema.functionColor);case o.SyntaxKind.ClassDeclaration:return this.addSegment(t,n,this.schema.classColor);case o.SyntaxKind.Parameter:return this.addSegment(t,n,this.schema.parameterColor);case o.SyntaxKind.VariableDeclaration:return this.addSegment(t,n,this.schema.variableColor);case o.SyntaxKind.PropertyDeclaration:return this.addSegment(t,n,this.schema.variableColor);case o.SyntaxKind.PropertyAccessExpression:return e.parent.getChildAt(0).getText()===e.getText()?this.addSegment(t,n,this.schema.variableColor):this.addSegment(t,n,this.schema.propertyAccessExpressionColor);case o.SyntaxKind.ExpressionWithTypeArguments:return this.addSegment(t,n,this.schema.expressionWithTypeArgumentsColor);case o.SyntaxKind.BreakStatement:case o.SyntaxKind.ShorthandPropertyAssignment:case o.SyntaxKind.BindingElement:return this.addSegment(t,n,this.schema.variableColor);case o.SyntaxKind.BinaryExpression:case o.SyntaxKind.SwitchStatement:case o.SyntaxKind.TemplateSpan:return this.addSegment(t,n,this.schema.variableColor);case o.SyntaxKind.TypeReference:case o.SyntaxKind.TypeAliasDeclaration:return this.addSegment(t,n,this.schema.typeColor);case o.SyntaxKind.NewExpression:return this.addSegment(t,n,this.schema.variableColor)}}processTemplateExpression(e){let n=e.head.getStart(),t=e.head.getEnd();this.addSegment(n,t,this.schema.stringColor),e.templateSpans.forEach(r=>{let s=r.literal.getStart(),a=r.literal.getEnd();this.addSegment(s,a,this.schema.stringColor)})}processNode(e){let n=e.getStart(),t=e.getEnd();switch(e.kind){case o.SyntaxKind.TypeParameter:return this.addSegment(n,n+e.name.text.length,this.schema.typeColor);case o.SyntaxKind.TypeReference:return this.addSegment(n,t,this.schema.typeColor);case o.SyntaxKind.StringLiteral:case o.SyntaxKind.NoSubstitutionTemplateLiteral:return this.addSegment(n,t,this.schema.stringColor);case o.SyntaxKind.RegularExpressionLiteral:return this.addSegment(n,t,this.schema.regularExpressionColor);case o.SyntaxKind.TemplateExpression:return this.processTemplateExpression(e);case o.SyntaxKind.Identifier:return this.processIdentifier(e);case o.SyntaxKind.BigIntLiteral:case o.SyntaxKind.NumericLiteral:return this.addSegment(n,t,this.schema.numericLiteralColor)}}};function W(i,e={}){let n=o.createSourceFile("temp.ts",i,o.ScriptTarget.Latest,!0,o.ScriptKind.TS),t=new S(n,i,Object.assign(G,e));function r(s){t.parseNode(s);for(let a=0;a<s.getChildCount();a++)r(s.getChildAt(a))}return o.forEachChild(n,r),t.highlight()}var y=class{file;sourceRoot;names;sources;mappings;sourcesContent;constructor(e){this.validateSourceMap(e),this.file=e.file??null,this.names=e.names??[],this.sources=e.sources??[],this.mappings=[],this.sourceRoot=e.sourceRoot??null,this.sourcesContent=e.sourcesContent??[],this.decodeMappings(e.mappings)}getMapObject(){let e={version:3,names:this.names,sources:this.sources,mappings:this.encodeMappings(this.mappings),sourcesContent:this.sourcesContent};return this.file&&(e.file=this.file),this.sourceRoot&&(e.sourceRoot=this.sourceRoot),e}getSourceCodeByLocation(e,n,t,r){let s=e;if(typeof e=="string"&&(s=this.sources.findIndex(l=>l.includes(e))),s<0)return null;let a=Object.assign({bias:1,linesAfter:4,linesBefore:3},r),c=this.retrieveMapping(n,t,a.bias,s,"sourceLine","sourceColumn");return this.getPositionWithSource(c,a)}getSourcePosition(e,n,t){let r=Object.assign({bias:1,linesAfter:4,linesBefore:3},t),s=this.retrieveMapping(e,n,r.bias);return this.getPositionWithSource(s,r)}getPosition(e,n,t=1){let r=this.retrieveMapping(e,n,t);return r&&{line:r.sourceLine,name:this.names[r.nameIndex??-1]??null,column:r.sourceColumn,source:this.sources[r.fileIndex],sourceRoot:this.sourceRoot}}concat(...e){if(e.length<1)throw new Error("At least one map must be provided for concatenation.");for(let n of e){this.names.push(...n.names),this.sources.push(...n.sources),this.sourcesContent.push(...n.sourcesContent);let t=this.mappings[this.mappings.length-1],r=this.sourcesContent[t.fileIndex].split(`
|
|
6
|
-
`).length;this.decodeMappings(e[0].mappings,{nameIndex:this.names.length-1,fileIndex:this.sources.length-1,generatedLine:r<2?2:r})}}toString(){return JSON.stringify(this.getMapObject())}getPositionWithSource(e,n){if(!e||isNaN(e.fileIndex))return null;let t=this.sourcesContent[e.fileIndex].split(`
|
|
7
|
-
`),r=(e.sourceLine??1)+n.linesAfter,s=Math.max((e.sourceLine??1)-n.linesBefore,0);return{code:t.slice(s,Math.min(r+1,t.length)).join(`
|
|
8
|
-
`),line:e.sourceLine,name:this.names[e.nameIndex??-1]??null,column:e.sourceColumn,endLine:r,startLine:s,source:this.sources[e.fileIndex],sourceRoot:this.sourceRoot}}validateSourceMap(e){if(!["version","sources","sourcesContent","mappings","names"].every(t=>t in e))throw new Error("Missing required keys in SourceMap.")}decodeMappings(e,n){let t=Object.assign({fileIndex:0,nameIndex:0,sourceLine:1,sourceColumn:1,generatedLine:1,generatedColumn:1},n);try{for(let[r,s]of e.split(";").entries()){if(!s)continue;t.generatedColumn=1;let a=s.split(",");for(let c of a){if(c.length<4)continue;let l=I(c);this.decodedSegment(t,l,r+t.generatedLine)}}}catch(r){throw new Error(`Error decoding mappings: ${r.message}`)}}decodedSegment(e,n,t){let[r,s,a,c,l]=n;e.fileIndex+=s,e.nameIndex+=l??0,e.sourceLine+=a,e.sourceColumn+=c,e.generatedColumn+=r,this.mappings.push({nameIndex:l!==void 0?e.nameIndex:null,fileIndex:e.fileIndex,sourceLine:e.sourceLine,sourceColumn:e.sourceColumn,generatedLine:t,generatedColumn:e.generatedColumn})}encodeMappings(e){let n="",t=[],r={fileIndex:0,nameIndex:0,sourceLine:1,sourceColumn:1,generatedLine:1,generatedColumn:1};r.generatedLine=e[0].generatedLine,n+=";".repeat(r.generatedLine-1);for(let s of e)s.generatedLine!==r.generatedLine&&(n+=t.join(","),n+=";".repeat(Math.max(1,s.generatedLine-r.generatedLine)),t=[],r.generatedLine=s.generatedLine,r.generatedColumn=1),this.encodeSegment(s,t,r);return n+t.join(",")+";"}encodeSegment(e,n,t){let r=[],s=e.fileIndex;if(r[1]=0,r[2]=e.sourceLine-t.sourceLine,r[3]=e.sourceColumn-t.sourceColumn,r[0]=e.generatedColumn-t.generatedColumn,s!==t.fileIndex&&(r[1]=s-t.fileIndex,t.fileIndex=s),e.nameIndex){let a=e.nameIndex;r[4]=a-t.nameIndex,t.nameIndex=a}t.sourceLine=e.sourceLine,t.sourceColumn=e.sourceColumn,t.generatedColumn=e.generatedColumn,n.push(x(r))}shouldSkipMapping(e,n){return n!==-1&&e.fileIndex!==n}retrieveMapping(e,n,t=0,r=-1,s="generatedLine",a="generatedColumn"){let c=0,l=this.mappings.length-1,d=null;for(;c<=l;){let m=Math.floor((c+l)/2),g=this.mappings[m];if(this.shouldSkipMapping(g,r)){c=m+1;continue}let p=g[s],u=g[a];if(p<e)c=m+1;else if(p>e)l=m-1;else if(u<n)d=t===1?g:d,c=m+1;else if(u>n)d=t===2?g:d,l=m-1;else return g}return d&&d[s]===e?d:null}};0&&(module.exports={CodeHighlighter,Colors,SourceService,decodeVLQ,encodeArrayVLQ,encodeVLQ,formatCode,formatErrorCode,highlightCode,parseErrorStack});
|
|
9
|
-
//# sourceMappingURL=index.js.map
|