@remotex-labs/xmap 1.0.4 → 2.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/README.md +206 -143
- package/dist/{components → cjs/components}/formatter.component.d.ts +3 -3
- package/dist/{components → cjs/components}/highlighter.component.d.ts +1 -1
- package/dist/{components → cjs/components}/parser.component.d.ts +1 -1
- package/dist/cjs/index.d.ts +9 -0
- 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 +27 -12
- package/dist/index.d.ts +0 -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 -399
- /package/dist/{components → cjs/components}/base64.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
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface representing a source map object, which is used to map
|
|
3
|
-
* transformed or compiled code back to its original source.
|
|
4
|
-
* This is typically used in debugging to trace errors or logs in the
|
|
5
|
-
* compiled code back to the original source code.
|
|
6
|
-
*/
|
|
7
|
-
export interface SourceMapInterface {
|
|
8
|
-
/**
|
|
9
|
-
* The version of the source map specification.
|
|
10
|
-
* This field is a required number that indicates which version of the source map format is used.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* 3
|
|
14
|
-
*/
|
|
15
|
-
version: number;
|
|
16
|
-
/**
|
|
17
|
-
* The name of the generated file (bundle) that this source map applies to.
|
|
18
|
-
* This field is optional, and it might not always be present in the source map.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* "bundle.js"
|
|
22
|
-
*/
|
|
23
|
-
file?: string | null;
|
|
24
|
-
/**
|
|
25
|
-
* A VLQ (Variable-Length Quantity) encoded string representing the mapping information
|
|
26
|
-
* between the transformed code and the original source code. This field is mandatory
|
|
27
|
-
* and stores the actual mapping data in a compact format.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* "AAAA,QAASA,IAAIC;..."
|
|
31
|
-
*/
|
|
32
|
-
mappings: string;
|
|
33
|
-
/**
|
|
34
|
-
* A list of variable or function names used in the transformed code,
|
|
35
|
-
* corresponding to their references in the source code.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ["myFunction", "myVariable", "otherSymbol"]
|
|
39
|
-
*/
|
|
40
|
-
names: Array<string>;
|
|
41
|
-
/**
|
|
42
|
-
* An array of source file paths. Each path corresponds to a source file that was part of the original code,
|
|
43
|
-
* allowing for a reverse mapping to the source files.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ["src/file1.ts", "src/file2.ts"]
|
|
47
|
-
*/
|
|
48
|
-
sources: Array<string>;
|
|
49
|
-
/**
|
|
50
|
-
* An array of the contents of the source files, corresponding to the paths in the `sources` array.
|
|
51
|
-
* If available, this field allows viewing the original source code within the source map file.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ["function myFunction() {...}", "const myVariable = 10;"]
|
|
55
|
-
*/
|
|
56
|
-
sourcesContent: Array<string>;
|
|
57
|
-
/**
|
|
58
|
-
* An optional prefix that is added to the source file paths in the `sources` array.
|
|
59
|
-
* This is useful when the paths in the `sources` field are relative and need to be resolved
|
|
60
|
-
* against a common root directory. It helps organize and locate the original source files.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* "/source/root"
|
|
64
|
-
*/
|
|
65
|
-
sourceRoot?: string | null;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Interface representing a mapping between generated and original source code.
|
|
69
|
-
* This is used to connect positions in the compiled/generated code to their
|
|
70
|
-
* corresponding positions in the original source code, allowing for debugging
|
|
71
|
-
* and error tracking.
|
|
72
|
-
*/
|
|
73
|
-
export interface MappingInterface {
|
|
74
|
-
/**
|
|
75
|
-
* The index in the `names` array that refers to a symbol (such as a function or variable name)
|
|
76
|
-
* in the original source. If there is no corresponding name, this will be `null`.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* 3
|
|
80
|
-
*/
|
|
81
|
-
nameIndex: number | null;
|
|
82
|
-
/**
|
|
83
|
-
* The index in the `sources` array that refers to the file in which the original code is located.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* 1
|
|
87
|
-
*/
|
|
88
|
-
fileIndex: number;
|
|
89
|
-
/**
|
|
90
|
-
* The line number in the original source code (1-based index).
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* 25
|
|
94
|
-
*/
|
|
95
|
-
sourceLine: number;
|
|
96
|
-
/**
|
|
97
|
-
* The column number in the original source code (0-based index).
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* 12
|
|
101
|
-
*/
|
|
102
|
-
sourceColumn: number;
|
|
103
|
-
/**
|
|
104
|
-
* The line number in the generated (compiled/transpiled) code (1-based index).
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* 32
|
|
108
|
-
*/
|
|
109
|
-
generatedLine: number;
|
|
110
|
-
/**
|
|
111
|
-
* The column number in the generated (compiled/transpiled) code (0-based index).
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* 8
|
|
115
|
-
*/
|
|
116
|
-
generatedColumn: number;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Internal interface used to track the current state during decoding and encoding mappings.
|
|
120
|
-
* This interface keeps track of the current mapping segment and is primarily used in the
|
|
121
|
-
* process of transforming source maps. Not intended for external use.
|
|
122
|
-
*/
|
|
123
|
-
export interface ShiftSegmentInterface {
|
|
124
|
-
/**
|
|
125
|
-
* The index of the source file in the `sources` array.
|
|
126
|
-
*/
|
|
127
|
-
fileIndex: number;
|
|
128
|
-
/**
|
|
129
|
-
* The index of the name in the `names` array. May be `null` if there is no associated name.
|
|
130
|
-
*/
|
|
131
|
-
nameIndex: number;
|
|
132
|
-
/**
|
|
133
|
-
* The line number in the original source code.
|
|
134
|
-
*/
|
|
135
|
-
sourceLine: number;
|
|
136
|
-
/**
|
|
137
|
-
* The column number in the original source code.
|
|
138
|
-
*/
|
|
139
|
-
sourceColumn: number;
|
|
140
|
-
/**
|
|
141
|
-
* The line number in the generated code.
|
|
142
|
-
*/
|
|
143
|
-
generatedLine: number;
|
|
144
|
-
/**
|
|
145
|
-
* The column number in the generated code.
|
|
146
|
-
*/
|
|
147
|
-
generatedColumn: number;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Internal interface used to track offsets during source map concatenation.
|
|
151
|
-
* This interface helps handle transitions between different source maps
|
|
152
|
-
* and offsets. Not intended for external use.
|
|
153
|
-
*/
|
|
154
|
-
export interface ThresholdSegmentInterface {
|
|
155
|
-
/**
|
|
156
|
-
* Optional index of the source file in the `sources` array, used for tracking offsets.
|
|
157
|
-
*/
|
|
158
|
-
fileIndex?: number;
|
|
159
|
-
/**
|
|
160
|
-
* Optional index of the name in the `names` array, used for tracking name offsets.
|
|
161
|
-
*/
|
|
162
|
-
nameIndex?: number;
|
|
163
|
-
/**
|
|
164
|
-
* Optional line number in the generated code, used for tracking line offsets.
|
|
165
|
-
*/
|
|
166
|
-
generatedLine?: number;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Interface representing a position in the source code.
|
|
170
|
-
* This is used to pinpoint an exact location in the source code (line, column),
|
|
171
|
-
* along with the name and the file path (source) where the position occurs.
|
|
172
|
-
*/
|
|
173
|
-
export interface PositionInterface {
|
|
174
|
-
/**
|
|
175
|
-
* The line number in the source code (1-based index).
|
|
176
|
-
*/
|
|
177
|
-
line: number;
|
|
178
|
-
/**
|
|
179
|
-
* The column number in the source code (0-based index).
|
|
180
|
-
*/
|
|
181
|
-
column: number;
|
|
182
|
-
/**
|
|
183
|
-
* The name associated with this position, if any.
|
|
184
|
-
* If no name is associated, this will be `null`.
|
|
185
|
-
*/
|
|
186
|
-
name: string | null;
|
|
187
|
-
/**
|
|
188
|
-
* The path or name of the source file.
|
|
189
|
-
*/
|
|
190
|
-
source: string;
|
|
191
|
-
/**
|
|
192
|
-
* The root URL for the sources, if present in the source map.
|
|
193
|
-
*/
|
|
194
|
-
sourceRoot: string | null;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Interface representing a position in the source code with additional context.
|
|
198
|
-
* Extends `PositionInterface` by adding the actual code snippet and range information.
|
|
199
|
-
*/
|
|
200
|
-
export interface PositionSourceInterface extends PositionInterface {
|
|
201
|
-
/**
|
|
202
|
-
* A snippet of the actual code at this position.
|
|
203
|
-
*/
|
|
204
|
-
code: string;
|
|
205
|
-
/**
|
|
206
|
-
* The ending line number (1-based index) of the code range.
|
|
207
|
-
*/
|
|
208
|
-
endLine: number;
|
|
209
|
-
/**
|
|
210
|
-
* The starting line number (0-based index) of the code range.
|
|
211
|
-
*/
|
|
212
|
-
startLine: number;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Interface representing options for retrieving source positions.
|
|
216
|
-
* This interface defines options that can modify how source positions
|
|
217
|
-
* are retrieved, including bias settings and surrounding line context.
|
|
218
|
-
*/
|
|
219
|
-
export interface SourceOptionsInterface {
|
|
220
|
-
/**
|
|
221
|
-
* The bias option for controlling how mappings are searched.
|
|
222
|
-
* This determines how to handle ambiguities in the source map (e.g., when multiple mappings exist).
|
|
223
|
-
*/
|
|
224
|
-
bias?: Bias;
|
|
225
|
-
/**
|
|
226
|
-
* The number of lines after the target position to include for additional context.
|
|
227
|
-
*/
|
|
228
|
-
linesAfter?: number;
|
|
229
|
-
/**
|
|
230
|
-
* The number of lines before the target position to include for additional context.
|
|
231
|
-
*/
|
|
232
|
-
linesBefore?: number;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Enumeration representing bias options for searching in mappings.
|
|
236
|
-
* This can control whether the search favors the closest lower-bound or upper-bound
|
|
237
|
-
* mapping when looking for a corresponding position in the source map.
|
|
238
|
-
*/
|
|
239
|
-
export declare const enum Bias {
|
|
240
|
-
/**
|
|
241
|
-
* No specific bias is applied when searching for a mapping.
|
|
242
|
-
*/
|
|
243
|
-
BOUND = 0,
|
|
244
|
-
/**
|
|
245
|
-
* Search for the closest lower-bound mapping.
|
|
246
|
-
*/
|
|
247
|
-
LOWER_BOUND = 1,
|
|
248
|
-
/**
|
|
249
|
-
* Search for the closest upper-bound mapping.
|
|
250
|
-
*/
|
|
251
|
-
UPPER_BOUND = 2
|
|
252
|
-
}
|
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Import will remove at compile time
|
|
3
|
-
*/
|
|
4
|
-
import type { PositionInterface, SourceMapInterface, SourceOptionsInterface, PositionSourceInterface } from "./interfaces/source.interface.ts";
|
|
5
|
-
/**
|
|
6
|
-
* Imports
|
|
7
|
-
*/
|
|
8
|
-
import { Bias } from "./interfaces/source.interface.ts";
|
|
9
|
-
/**
|
|
10
|
-
* A service for validating and processing source maps.
|
|
11
|
-
*/
|
|
12
|
-
export declare class SourceService {
|
|
13
|
-
/**
|
|
14
|
-
* The name of the generated file (bundle) that this source map applies to.
|
|
15
|
-
*/
|
|
16
|
-
readonly file: string | null;
|
|
17
|
-
/**
|
|
18
|
-
* The root URL for the sources, if present in the source map.
|
|
19
|
-
*/
|
|
20
|
-
readonly sourceRoot: string | null;
|
|
21
|
-
/**
|
|
22
|
-
* A list of symbol names used by the “mappings” entry.
|
|
23
|
-
*/
|
|
24
|
-
private readonly names;
|
|
25
|
-
/**
|
|
26
|
-
* An array of source file paths.
|
|
27
|
-
*/
|
|
28
|
-
private readonly sources;
|
|
29
|
-
/**
|
|
30
|
-
* A string of base64 VLQ-encoded mappings.
|
|
31
|
-
*/
|
|
32
|
-
private readonly mappings;
|
|
33
|
-
/**
|
|
34
|
-
* An array of source files contents.
|
|
35
|
-
*/
|
|
36
|
-
private readonly sourcesContent;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new instance of the SourceService class.
|
|
39
|
-
*
|
|
40
|
-
* This constructor initializes a `SourceService` instance using the provided source map object.
|
|
41
|
-
* It performs validation to ensure that the source map contains all required properties.
|
|
42
|
-
*
|
|
43
|
-
* @param source - An object conforming to the `SourceMapInterface` representing the source map to be validated and processed.
|
|
44
|
-
* @throws Error If any required property is missing from the source map object.
|
|
45
|
-
*/
|
|
46
|
-
constructor(source: SourceMapInterface);
|
|
47
|
-
/**
|
|
48
|
-
* Returns a plain object representation of the source map data.
|
|
49
|
-
*
|
|
50
|
-
* This method constructs and returns an object that includes key properties of the source map:
|
|
51
|
-
* - `version`: The version of the source map specification (typically 3).
|
|
52
|
-
* - `file`: The name of the generated file (optional).
|
|
53
|
-
* - `names`: An array of function or variable names extracted from the original source code.
|
|
54
|
-
* - `sources`: An array of file paths for the source files referenced in the mappings.
|
|
55
|
-
* - `sourceRoot`: An optional root URL for resolving source file paths.
|
|
56
|
-
* - `mappings`: A base64 VLQ-encoded string representing the source map mappings, generated by `encodeMappings`.
|
|
57
|
-
* - `sourcesContent`: An optional array containing the content of the source files. This property may not be present in all source maps.
|
|
58
|
-
*
|
|
59
|
-
* @returns A plain object conforming to the `SourceMapInterface` structure,
|
|
60
|
-
* representing the source map data.
|
|
61
|
-
*/
|
|
62
|
-
getMapObject(): SourceMapInterface;
|
|
63
|
-
/**
|
|
64
|
-
* Retrieves information about the original source code for a given line and column in the generated code.
|
|
65
|
-
*
|
|
66
|
-
* This method looks up the source code mappings to find the corresponding source location and provides additional context based on the provided options.
|
|
67
|
-
* It can choose to retrieve either the original mapping or the generated mapping based on the `useSource` flag.
|
|
68
|
-
*
|
|
69
|
-
* @param line - The line number in the generated code.
|
|
70
|
-
* @param column - The column number in the generated code.
|
|
71
|
-
* @param options - Optional configuration for retrieving source information.
|
|
72
|
-
* - `linesBefore` (default: 3): Number of lines before the matching source line to include in the context.
|
|
73
|
-
* - `linesAfter` (default: 4): Number of lines after the matching source line to include in the context.
|
|
74
|
-
* - `includeSourceContent` (default: false): Flag indicating whether to include the relevant source code snippet.
|
|
75
|
-
* @param useSource - A boolean flag indicating whether to retrieve the original mapping (`true`) or the generated mapping (`false`). Defaults to `false`.
|
|
76
|
-
* @returns An object containing source location information including:
|
|
77
|
-
* - `line`: The line number in the original source code.
|
|
78
|
-
* - `column`: The column number in the original source code.
|
|
79
|
-
* - `endLine`: The end line number of the included source code snippet.
|
|
80
|
-
* - `startLine`: The start line number of the included source code snippet.
|
|
81
|
-
* - `name`: The function or variable name at the source position, or null if not available.
|
|
82
|
-
* - `source`: The file name of the source code.
|
|
83
|
-
* - `code` (if `includeSourceContent` is true): A snippet of the source code surrounding the specified line.
|
|
84
|
-
*
|
|
85
|
-
* @returns Null if no matching mapping is found.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* const position = getSourcePosition(10, 5, { linesBefore: 2, linesAfter: 2 }, true);
|
|
89
|
-
* console.log(position); // Outputs the source position information or null if not found
|
|
90
|
-
*/
|
|
91
|
-
getSourcePosition(line: number, column: number, options?: SourceOptionsInterface, useSource?: boolean): PositionSourceInterface | null;
|
|
92
|
-
/**
|
|
93
|
-
* Retrieves the position information in the original source code for a given line and column in the generated code.
|
|
94
|
-
*
|
|
95
|
-
* This method locates the corresponding source code position based on the provided line and column in the generated code.
|
|
96
|
-
* It uses the specified bias to determine the best match when multiple mappings are possible.
|
|
97
|
-
*
|
|
98
|
-
* @param line - The line number in the generated code.
|
|
99
|
-
* @param column - The column number in the generated code.
|
|
100
|
-
* @param bias - Optional parameter specifying how to handle cases where only the line number matches:
|
|
101
|
-
* - `Bias.LOWER_BOUND` (default): If the line number matches but the column is less, returns the closest mapping with a lower column.
|
|
102
|
-
* - `Bias.UPPER_BOUND`: If the line number matches but the column is greater, returns the closest mapping with a higher column.
|
|
103
|
-
* - `Bias.BOUND`: If the line number matches but the column doesn't, returns null (default behavior).
|
|
104
|
-
* @param useSource - Optional parameter that determines whether to use original source mappings (true) or generated mappings (false). Default is false.
|
|
105
|
-
* @returns A `PositionInterface` object representing the position in the original source code, including:
|
|
106
|
-
* - `line`: The line number in the original source code.
|
|
107
|
-
* - `column`: The column number in the original source code.
|
|
108
|
-
* - `name`: The function or variable name at the source position, or null if not available.
|
|
109
|
-
* - `source`: The file name of the original source code.
|
|
110
|
-
* - `sourceRoot`: The root path of the source.
|
|
111
|
-
* Returns null if no matching position is found.
|
|
112
|
-
*/
|
|
113
|
-
getPosition(line: number, column: number, bias?: Bias, useSource?: boolean): PositionInterface | null;
|
|
114
|
-
/**
|
|
115
|
-
* Merges multiple source maps into this source map object.
|
|
116
|
-
* The order of the provided source maps must correspond to the order in which the source files were concatenated.
|
|
117
|
-
*
|
|
118
|
-
* This method appends the names, sources, and source contents from each provided source map to the current source map.
|
|
119
|
-
* It also adjusts the mappings to account for the concatenation of the source files.
|
|
120
|
-
*
|
|
121
|
-
* @param maps - An array of `SourceMapInterface` instances representing the source maps to be merged.
|
|
122
|
-
* @throws Error If no source maps are provided for concatenation.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* // Merging two source maps
|
|
126
|
-
* const map1: SourceMapInterface = { /* ... *\/ };
|
|
127
|
-
* const map2: SourceMapInterface = { /* ... *\/ };
|
|
128
|
-
* sourceMapService.concat(map1, map2);
|
|
129
|
-
*/
|
|
130
|
-
concat(...maps: Array<SourceMapInterface>): void;
|
|
131
|
-
/**
|
|
132
|
-
* Converts the source map object to a JSON string representation.
|
|
133
|
-
*
|
|
134
|
-
* This method performs the following steps:
|
|
135
|
-
* 1. Creates a plain object representation of the source map using the `getMapObject` method.
|
|
136
|
-
* 2. Converts the plain object to a JSON string using `JSON.stringify`.
|
|
137
|
-
*
|
|
138
|
-
* @returns A JSON string representation of the source map.
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* const sourceMapString = sourceMapService.toString();
|
|
142
|
-
* // sourceMapString contains the JSON string representation of the source map.
|
|
143
|
-
*/
|
|
144
|
-
toString(): string;
|
|
145
|
-
/**
|
|
146
|
-
* Validates the provided source map object.
|
|
147
|
-
*
|
|
148
|
-
* This method checks whether all required keys are present in the source map object.
|
|
149
|
-
* It throws an error if any required keys are missing.
|
|
150
|
-
*
|
|
151
|
-
* @private
|
|
152
|
-
* @param input - The source map object to be validated.
|
|
153
|
-
* @throws Error If any required key is missing from the source map.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* const sourceMap = {
|
|
157
|
-
* version: 3,
|
|
158
|
-
* file: 'example.js',
|
|
159
|
-
* names: ['src', 'maps', 'example', 'function', 'line', 'column'],
|
|
160
|
-
* sources: ['source1.js', 'source2.js'],
|
|
161
|
-
* mappings: 'AAAA,SAASA,CAAC,CAAC,CAAC;AAAA,CAAC,CAAC;AAAC,CAAC',
|
|
162
|
-
* sourcesContent: ['console.log("Hello world");', 'console.log("Another file");']
|
|
163
|
-
* };
|
|
164
|
-
*
|
|
165
|
-
* try {
|
|
166
|
-
* validateSourceMap(sourceMap);
|
|
167
|
-
* console.log('Source map is valid.');
|
|
168
|
-
* } catch (error) {
|
|
169
|
-
* console.error('Invalid source map:', error.message);
|
|
170
|
-
* }
|
|
171
|
-
*/
|
|
172
|
-
private validateSourceMap;
|
|
173
|
-
/**
|
|
174
|
-
* Decodes and processes the base64 VLQ-encoded mappings from a source map.
|
|
175
|
-
*
|
|
176
|
-
* This method interprets the encoded mappings from the `mappings` property of a source map. It adjusts
|
|
177
|
-
* the shift state for both generated and original positions in the source code, and processes each
|
|
178
|
-
* decoded mapping segment using the `decodedSegment` method.
|
|
179
|
-
*
|
|
180
|
-
* The decoding process involves:
|
|
181
|
-
* 1. Parsing the base64 VLQ-encoded mappings.
|
|
182
|
-
* 2. Adjusting the shift state based on the provided `thresholdSegment` or default values.
|
|
183
|
-
* 3. Handling each decoded mapping segment with the `decodedSegment` method.
|
|
184
|
-
*
|
|
185
|
-
* @param encodedMappings - A string representing the encoded mappings in base64 VLQ format. This string
|
|
186
|
-
* is typically found in the `mappings` property of a source map.
|
|
187
|
-
* @param thresholdSegment - Optional. An object containing offset information that adjusts the starting
|
|
188
|
-
* point for decoding. This can include offsets for line, column, or file index.
|
|
189
|
-
* If not provided, default values are used.
|
|
190
|
-
* @throws Error - Throws an error if the decoding process encounters an issue, such as an invalid
|
|
191
|
-
* encoding or unexpected format.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* const encodedMappings = 'AAAA,CAAC,CAAC,CAAC,CAAC;AAAA,CAAC,CAAC,CAAC,CAAC';
|
|
195
|
-
* const threshold = {
|
|
196
|
-
* fileIndex: 0,
|
|
197
|
-
* nameIndex: 0,
|
|
198
|
-
* sourceLine: 1,
|
|
199
|
-
* sourceColumn: 1,
|
|
200
|
-
* generatedLine: 1,
|
|
201
|
-
* generatedColumn: 1
|
|
202
|
-
* };
|
|
203
|
-
* try {
|
|
204
|
-
* decodeMappings(encodedMappings, threshold);
|
|
205
|
-
* } catch (error) {
|
|
206
|
-
* console.error('Failed to decode mappings:', error.message);
|
|
207
|
-
* }
|
|
208
|
-
*/
|
|
209
|
-
private decodeMappings;
|
|
210
|
-
/**
|
|
211
|
-
* Processes a decoded VLQ segment and updates the mapping information.
|
|
212
|
-
*
|
|
213
|
-
* This method adjusts the current mapping state based on the decoded VLQ segment and the current
|
|
214
|
-
* line in the generated code. It then updates the internal mappings list with the new information.
|
|
215
|
-
*
|
|
216
|
-
* The decoding process involves:
|
|
217
|
-
* 1. Extracting the mapping details from the `decodedSegment` array.
|
|
218
|
-
* 2. Updating the shift values for file index, name index, source line, source column, and generated column.
|
|
219
|
-
* 3. Adding the processed mapping to the internal `mappings` array.
|
|
220
|
-
*
|
|
221
|
-
* @param shift - The current state of mapping information. This object tracks the cumulative state
|
|
222
|
-
* of file index, name index, source line, source column, and generated column.
|
|
223
|
-
* @param decodedSegment - An array representing the decoded VLQ segment, containing:
|
|
224
|
-
* - `generatedColumn`: The column number in the generated code.
|
|
225
|
-
* - `fileIndex`: The index in the sources array.
|
|
226
|
-
* - `sourceLine`: The line number in the original source code.
|
|
227
|
-
* - `sourceColumn`: The column number in the original source code.
|
|
228
|
-
* - `nameIndex`: The index in the names array.
|
|
229
|
-
* @param generatedLine - The line index in the generated code where this segment applies.
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* const shift = {
|
|
233
|
-
* fileIndex: 0,
|
|
234
|
-
* nameIndex: 0,
|
|
235
|
-
* sourceLine: 1,
|
|
236
|
-
* sourceColumn: 1,
|
|
237
|
-
* generatedLine: 1,
|
|
238
|
-
* generatedColumn: 1
|
|
239
|
-
* };
|
|
240
|
-
* const decodedSegment = [2, 1, 3, 4, 5];
|
|
241
|
-
* const generatedLine = 1;
|
|
242
|
-
* this.decodedSegment(shift, decodedSegment, generatedLine);
|
|
243
|
-
*
|
|
244
|
-
* @see ShiftSegmentInterface for details on the `shift` parameter.
|
|
245
|
-
* @see SourceMapInterface for details on the mapping properties.
|
|
246
|
-
*/
|
|
247
|
-
private decodedSegment;
|
|
248
|
-
/**
|
|
249
|
-
* Encodes an array of mappings into a VLQ-encoded string representation.
|
|
250
|
-
*
|
|
251
|
-
* This method converts an array of `MappingInterface` objects into a base64 VLQ-encoded string,
|
|
252
|
-
* which is used in source maps to represent the mapping between generated and original source code positions.
|
|
253
|
-
*
|
|
254
|
-
* The encoding process involves:
|
|
255
|
-
* 1. Initializing the shift state to track the current line and column in the generated code.
|
|
256
|
-
* 2. Iterating through the mappings to group them by line number and encode each segment.
|
|
257
|
-
* 3. Concatenating encoded segments with the appropriate separator characters (`,` and `;`).
|
|
258
|
-
*
|
|
259
|
-
* @param mappings - An array of `MappingInterface` objects representing the mappings to encode. Each mapping object contains:
|
|
260
|
-
* - `nameIndex`: The index in the names array.
|
|
261
|
-
* - `fileIndex`: The index in the sources array.
|
|
262
|
-
* - `sourceLine`: The line number in the original source code.
|
|
263
|
-
* - `sourceColumn`: The column number in the original source code.
|
|
264
|
-
* - `generatedLine`: The line number in the generated code.
|
|
265
|
-
* - `generatedColumn`: The column number in the generated code.
|
|
266
|
-
* @returns A VLQ-encoded string representing the mappings, with segments separated by commas and lines by semicolons.
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* const mappings = [
|
|
270
|
-
* { nameIndex: 0, fileIndex: 1, sourceLine: 2, sourceColumn: 3, generatedLine: 1, generatedColumn: 4 },
|
|
271
|
-
* { nameIndex: 1, fileIndex: 1, sourceLine: 3, sourceColumn: 4, generatedLine: 2, generatedColumn: 5 }
|
|
272
|
-
* ];
|
|
273
|
-
* const encodedMappings = this.encodeMappings(mappings);
|
|
274
|
-
* console.log(encodedMappings); // Outputs the VLQ-encoded string
|
|
275
|
-
*
|
|
276
|
-
* @see MappingInterface for details on the mapping properties.
|
|
277
|
-
*/
|
|
278
|
-
private encodeMappings;
|
|
279
|
-
/**
|
|
280
|
-
* Encodes a single segment of the mappings into VLQ format.
|
|
281
|
-
*
|
|
282
|
-
* This method processes a `MappingInterface` object and updates the list of encoded segments. It calculates the differences
|
|
283
|
-
* between the current and previous mapping states, then encodes these differences using VLQ (Variable-Length Quantity) encoding.
|
|
284
|
-
* The encoded segment is added to the provided `segments` array.
|
|
285
|
-
*
|
|
286
|
-
* The encoding process involves:
|
|
287
|
-
* 1. Calculating the delta values for the file index, source line, source column, and generated column.
|
|
288
|
-
* 2. Updating the `shift` state to reflect the current mapping information.
|
|
289
|
-
* 3. Encoding the segment using VLQ and adding it to the `segments` array.
|
|
290
|
-
*
|
|
291
|
-
* @param map - The `MappingInterface` object representing a single mapping to encode. This object contains:
|
|
292
|
-
* - `nameIndex`: The index in the names array.
|
|
293
|
-
* - `fileIndex`: The index in the sources array.
|
|
294
|
-
* - `sourceLine`: The line number in the original source code.
|
|
295
|
-
* - `sourceColumn`: The column number in the original source code.
|
|
296
|
-
* - `generatedColumn`: The column number in the generated code.
|
|
297
|
-
* @param segments - An array of encoded segments that will be updated with the new encoded segment.
|
|
298
|
-
* @param shift - The current state of the mapping information, including the latest file index, name index, source line,
|
|
299
|
-
* source column, and generated column. This state is updated as new mappings are processed.
|
|
300
|
-
*
|
|
301
|
-
* @example
|
|
302
|
-
* const map: MappingInterface = { nameIndex: 0, fileIndex: 1, sourceLine: 2, sourceColumn: 3, generatedLine: 1, generatedColumn: 4 };
|
|
303
|
-
* const segments: Array<string> = [];
|
|
304
|
-
* const shift: ShiftSegmentInterface = { fileIndex: 0, nameIndex: 0, sourceLine: 1, sourceColumn: 1, generatedLine: 1, generatedColumn: 1 };
|
|
305
|
-
* this.encodeSegment(map, segments, shift);
|
|
306
|
-
* console.log(segments); // Outputs the encoded VLQ segment
|
|
307
|
-
*
|
|
308
|
-
* @see MappingInterface for details on the mapping properties.
|
|
309
|
-
* @see encodeArrayVLQ for the encoding function used.
|
|
310
|
-
*/
|
|
311
|
-
private encodeSegment;
|
|
312
|
-
/**
|
|
313
|
-
* Performs a binary search on the internal `mappings` array to locate a mapping based on the specified line and column information.
|
|
314
|
-
* This method efficiently searches for a mapping corresponding to a specific line and column, using binary search for improved performance.
|
|
315
|
-
*
|
|
316
|
-
* The method supports optional biasing to refine the search when an exact match is not found:
|
|
317
|
-
* - **Bias.LOWER_BOUND**: If the line number matches but the column is less, returns the closest mapping with a lower column.
|
|
318
|
-
* - **Bias.UPPER_BOUND**: If the line number matches but the column is greater, returns the closest mapping with a higher column.
|
|
319
|
-
* - **Bias.BOUND**: If the line number matches but the column doesn't, returns null. This is the default behavior.
|
|
320
|
-
*
|
|
321
|
-
* @param targetLine - The line number to search for. This is the primary criterion for locating the mapping.
|
|
322
|
-
* @param targetColumn - The column number to search for. This is used in conjunction with the line number.
|
|
323
|
-
* @param bias - An optional bias value to handle cases where only the line number matches. It influences how the column mismatch
|
|
324
|
-
* is resolved.
|
|
325
|
-
* - `Bias.LOWER_BOUND`: Return the closest mapping with a lower column if the exact column is not found.
|
|
326
|
-
* - `Bias.UPPER_BOUND`: Return the closest mapping with a higher column if the exact column is not found.
|
|
327
|
-
* - `Bias.BOUND`: Return null if no exact column match is found. (Default behavior)
|
|
328
|
-
* @param lineAccessor - A function that retrieves the line property from the mapping being examined, allowing for flexibility
|
|
329
|
-
* in accessing either generated or original lines.
|
|
330
|
-
* @param columnAccessor - A function that retrieves the column property from the mapping being examined, allowing for flexibility
|
|
331
|
-
* in accessing either generated or original columns.
|
|
332
|
-
* @returns A `MappingInterface` object representing the found mapping if an exact or biased match is found, or null if no
|
|
333
|
-
* appropriate mapping is located.
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* const targetLine = 10;
|
|
337
|
-
* const targetColumn = 5;
|
|
338
|
-
* const bias = Bias.UPPER_BOUND;
|
|
339
|
-
* const result = this.findMappingGeneric(targetLine, targetColumn, bias,
|
|
340
|
-
* (mapping) => mapping.generatedLine,
|
|
341
|
-
* (mapping) => mapping.generatedColumn);
|
|
342
|
-
* console.log(result); // Outputs the found mapping or null if not found
|
|
343
|
-
*/
|
|
344
|
-
private findMappingGeneric;
|
|
345
|
-
/**
|
|
346
|
-
* Searches for a mapping in the internal `mappings` array based on the specified line and column information in the generated code.
|
|
347
|
-
* This method utilizes the `findMappingGeneric` function to perform the search, leveraging its binary search mechanism for efficiency.
|
|
348
|
-
*
|
|
349
|
-
* The method supports optional biasing to refine the search when an exact match is not found:
|
|
350
|
-
* - **Bias.LOWER_BOUND**: If the line number matches but the column is less, returns the closest mapping with a lower column.
|
|
351
|
-
* - **Bias.UPPER_BOUND**: If the line number matches but the column is greater, returns the closest mapping with a higher column.
|
|
352
|
-
* - **Bias.BOUND**: If the line number matches but the column doesn't, returns null. This is the default behavior.
|
|
353
|
-
*
|
|
354
|
-
* @param targetLine - The line number in the generated code to search for. This is the primary criterion for locating the mapping.
|
|
355
|
-
* @param targetColumn - The column number in the generated code to search for. This is used in conjunction with the line number.
|
|
356
|
-
* @param bias - An optional bias value to handle cases where only the line number matches. It influences how the column mismatch
|
|
357
|
-
* is resolved.
|
|
358
|
-
* - `Bias.LOWER_BOUND`: Return the closest mapping with a lower column if the exact column is not found.
|
|
359
|
-
* - `Bias.UPPER_BOUND`: Return the closest mapping with a higher column if the exact column is not found.
|
|
360
|
-
* - `Bias.BOUND`: Return null if no exact column match is found. (Default behavior)
|
|
361
|
-
* @returns A `MappingInterface` object representing the found mapping if an exact or biased match is found, or null if no
|
|
362
|
-
* appropriate mapping is located.
|
|
363
|
-
*
|
|
364
|
-
* @example
|
|
365
|
-
* const targetLine = 10;
|
|
366
|
-
* const targetColumn = 5;
|
|
367
|
-
* const bias = Bias.UPPER_BOUND;
|
|
368
|
-
* const result = this.findMapping(targetLine, targetColumn, bias);
|
|
369
|
-
* console.log(result); // Outputs the found mapping or null if not found
|
|
370
|
-
*/
|
|
371
|
-
private findMapping;
|
|
372
|
-
/**
|
|
373
|
-
* Searches for a mapping in the internal `mappings` array based on the specified line and column information in the original source code.
|
|
374
|
-
* This method utilizes the `findMappingGeneric` function to perform the search, leveraging its binary search mechanism for efficiency.
|
|
375
|
-
*
|
|
376
|
-
* The method supports optional biasing to refine the search when an exact match is not found:
|
|
377
|
-
* - **Bias.LOWER_BOUND**: If the line number matches but the column is less, returns the closest mapping with a lower column.
|
|
378
|
-
* - **Bias.UPPER_BOUND**: If the line number matches but the column is greater, returns the closest mapping with a higher column.
|
|
379
|
-
* - **Bias.BOUND**: If the line number matches but the column doesn't, returns null. This is the default behavior.
|
|
380
|
-
*
|
|
381
|
-
* @param targetLine - The line number in the original source code to search for. This is the primary criterion for locating the mapping.
|
|
382
|
-
* @param targetColumn - The column number in the original source code to search for. This is used in conjunction with the line number.
|
|
383
|
-
* @param bias - An optional bias value to handle cases where only the line number matches. It influences how the column mismatch
|
|
384
|
-
* is resolved.
|
|
385
|
-
* - `Bias.LOWER_BOUND`: Return the closest mapping with a lower column if the exact column is not found.
|
|
386
|
-
* - `Bias.UPPER_BOUND`: Return the closest mapping with a higher column if the exact column is not found.
|
|
387
|
-
* - `Bias.BOUND`: Return null if no exact column match is found. (Default behavior)
|
|
388
|
-
* @returns A `MappingInterface` object representing the found mapping if an exact or biased match is found, or null if no
|
|
389
|
-
* appropriate mapping is located.
|
|
390
|
-
*
|
|
391
|
-
* @example
|
|
392
|
-
* const targetLine = 15;
|
|
393
|
-
* const targetColumn = 10;
|
|
394
|
-
* const bias = Bias.LOWER_BOUND;
|
|
395
|
-
* const result = this.findOriginalMapping(targetLine, targetColumn, bias);
|
|
396
|
-
* console.log(result); // Outputs the found mapping or null if not found
|
|
397
|
-
*/
|
|
398
|
-
private findOriginalMapping;
|
|
399
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|