@remotex-labs/xmap 2.0.4 → 2.1.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 +13 -22
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/index.js.map +4 -4
- package/dist/components/highlighter.component.d.ts +227 -71
- package/dist/components/interfaces/highlighter.interface.d.ts +59 -13
- package/dist/components/interfaces/parse.interface.d.ts +26 -25
- package/dist/components/parser.component.d.ts +212 -5
- package/dist/esm/index.js +7 -7
- package/dist/esm/index.js.map +4 -4
- package/dist/providers/interfaces/mapping.interface.d.ts +111 -22
- package/dist/providers/mapping.provider.d.ts +256 -172
- package/dist/services/source.service.d.ts +94 -95
- package/package.json +9 -9
|
@@ -8,210 +8,209 @@ import type { PositionInterface, SourceMapInterface, SourceOptionsInterface, Pos
|
|
|
8
8
|
import { MappingProvider } from "../providers/mapping.provider";
|
|
9
9
|
import { Bias } from "../providers/interfaces/mapping.interface";
|
|
10
10
|
/**
|
|
11
|
-
* A service for validating and processing source maps
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* A service for validating and processing source maps that provides functionality for parsing,
|
|
12
|
+
* position mapping, concatenation, and code snippet extraction.
|
|
13
|
+
*
|
|
14
|
+
* @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)
|
|
15
|
+
* @param file - Optional file name for the generated bundle
|
|
16
|
+
* @returns A new SourceService instance
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* ```ts
|
|
18
20
|
* const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
|
|
19
21
|
* const sourceService = new SourceService(sourceMapJSON);
|
|
20
|
-
*
|
|
21
|
-
* console.log(sourceService.file); // Outputs: 'bundle.js'
|
|
22
|
+
* console.log(sourceService.file); // 'bundle.js'
|
|
22
23
|
* ```
|
|
24
|
+
*
|
|
25
|
+
* @since 1.0.0
|
|
23
26
|
*/
|
|
24
27
|
export declare class SourceService {
|
|
25
28
|
/**
|
|
26
|
-
* The name of the generated file
|
|
29
|
+
* The name of the generated file this source map applies to.
|
|
27
30
|
*
|
|
28
|
-
* @
|
|
29
|
-
* ```ts
|
|
30
|
-
* console.log(sourceService.file); // 'bundle.js'
|
|
31
|
-
* ```
|
|
31
|
+
* @since 1.0.0
|
|
32
32
|
*/
|
|
33
33
|
readonly file: string | null;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Provider for accessing and manipulating the base64 VLQ-encoded mappings.
|
|
36
|
+
*
|
|
37
|
+
* @since 1.0.0
|
|
36
38
|
*/
|
|
37
39
|
readonly mappings: MappingProvider;
|
|
38
40
|
/**
|
|
39
|
-
* The root URL for
|
|
41
|
+
* The root URL for resolving relative paths in the source files.
|
|
42
|
+
* @since 1.0.0
|
|
40
43
|
*/
|
|
41
44
|
readonly sourceRoot: string | null;
|
|
42
45
|
/**
|
|
43
|
-
*
|
|
46
|
+
* List of symbol names referenced by the mappings.
|
|
47
|
+
* @since 1.0.0
|
|
44
48
|
*/
|
|
45
49
|
readonly names: Array<string>;
|
|
46
50
|
/**
|
|
47
|
-
*
|
|
51
|
+
* Array of source file paths.
|
|
52
|
+
* @since 1.0.0
|
|
48
53
|
*/
|
|
49
54
|
readonly sources: Array<string>;
|
|
50
55
|
/**
|
|
51
|
-
*
|
|
56
|
+
* Array of source file contents.
|
|
57
|
+
* @since 1.0.0
|
|
52
58
|
*/
|
|
53
59
|
readonly sourcesContent: Array<string>;
|
|
54
60
|
/**
|
|
55
|
-
* Creates a new
|
|
61
|
+
* Creates a new SourceService instance.
|
|
56
62
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* It validates the source map and populates its properties such as `file`, `sources`, and `mappings`.
|
|
63
|
+
* @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)
|
|
64
|
+
* @param file - Optional file name for the generated bundle
|
|
60
65
|
*
|
|
61
|
-
* @
|
|
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.
|
|
66
|
+
* @throws Error - When a source map has an invalid format or missing required properties
|
|
68
67
|
*
|
|
69
|
-
* @
|
|
70
|
-
* ```ts
|
|
71
|
-
* const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
|
|
72
|
-
* const sourceService = new SourceService(sourceMapJSON);
|
|
73
|
-
* ```
|
|
68
|
+
* @since 1.0.0
|
|
74
69
|
*/
|
|
75
70
|
constructor(source: SourceService);
|
|
76
71
|
constructor(source: SourceMapInterface | string, file?: string | null);
|
|
77
72
|
/**
|
|
78
|
-
* Converts the
|
|
73
|
+
* Converts the source map data to a plain object.
|
|
79
74
|
*
|
|
80
|
-
* @returns
|
|
75
|
+
* @returns A SourceMapInterface object representing the current state
|
|
81
76
|
*
|
|
82
77
|
* @example
|
|
83
78
|
* ```ts
|
|
84
79
|
* const mapObject = sourceService.getMapObject();
|
|
85
80
|
* console.log(mapObject.file); // 'bundle.js'
|
|
86
81
|
* ```
|
|
82
|
+
*
|
|
83
|
+
* @since 1.0.0
|
|
87
84
|
*/
|
|
88
85
|
getMapObject(): SourceMapInterface;
|
|
89
86
|
/**
|
|
90
|
-
* Concatenates
|
|
91
|
-
*
|
|
92
|
-
* This method merges additional source maps into the current source map,
|
|
93
|
-
* updating the `mappings`, `names`, `sources`, and `sourcesContent` arrays.
|
|
87
|
+
* Concatenates additional source maps into the current instance.
|
|
94
88
|
*
|
|
95
|
-
* @param maps -
|
|
96
|
-
* @throws { Error } If no source maps are provided for concatenation.
|
|
89
|
+
* @param maps - Source maps to concatenate with the current map
|
|
97
90
|
*
|
|
98
91
|
* @example
|
|
99
92
|
* ```ts
|
|
100
93
|
* sourceService.concat(anotherSourceMap);
|
|
101
94
|
* console.log(sourceService.sources); // Updated source paths
|
|
102
95
|
* ```
|
|
96
|
+
*
|
|
97
|
+
* @throws Error - When no maps are provided
|
|
98
|
+
*
|
|
99
|
+
* @since 1.0.0
|
|
103
100
|
*/
|
|
104
101
|
concat(...maps: Array<SourceMapInterface | SourceService>): void;
|
|
105
102
|
/**
|
|
106
|
-
* Creates a new instance
|
|
103
|
+
* Creates a new SourceService instance with concatenated source maps.
|
|
107
104
|
*
|
|
108
|
-
* @param maps -
|
|
109
|
-
* @returns
|
|
110
|
-
* @throws { Error } If no source maps are provided.
|
|
105
|
+
* @param maps - Source maps to concatenate with a copy of the current map
|
|
106
|
+
* @returns A new SourceService instance with the combined maps
|
|
111
107
|
*
|
|
112
108
|
* @example
|
|
113
109
|
* ```ts
|
|
114
110
|
* const newService = sourceService.concatNewMap(anotherSourceMap);
|
|
115
|
-
* console.log(newService.
|
|
111
|
+
* console.log(newService.sources); // Combined sources array
|
|
116
112
|
* ```
|
|
113
|
+
*
|
|
114
|
+
* @throws Error - When no maps are provided
|
|
115
|
+
*
|
|
116
|
+
* @since 1.0.0
|
|
117
117
|
*/
|
|
118
118
|
concatNewMap(...maps: Array<SourceMapInterface | SourceService>): SourceService;
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
120
|
+
* Finds position in generated code based on original source position.
|
|
121
121
|
*
|
|
122
|
-
* @param line -
|
|
123
|
-
* @param column -
|
|
124
|
-
* @param sourceIndex -
|
|
125
|
-
* @param bias -
|
|
126
|
-
* @returns
|
|
122
|
+
* @param line - Line number in the original source
|
|
123
|
+
* @param column - Column number in the original source
|
|
124
|
+
* @param sourceIndex - Index or file path of the original source
|
|
125
|
+
* @param bias - Position matching strategy (default: Bias.BOUND)
|
|
126
|
+
* @returns Position information or null if not found
|
|
127
127
|
*
|
|
128
128
|
* @example
|
|
129
129
|
* ```ts
|
|
130
130
|
* const position = sourceService.getPositionByOriginal(1, 10, 'foo.ts');
|
|
131
|
-
* console.log(position?.
|
|
131
|
+
* console.log(position?.generatedLine); // Line in generated code
|
|
132
132
|
* ```
|
|
133
|
+
*
|
|
134
|
+
* @since 1.0.0
|
|
133
135
|
*/
|
|
134
136
|
getPositionByOriginal(line: number, column: number, sourceIndex: number | string, bias?: Bias): PositionInterface | null;
|
|
135
137
|
/**
|
|
136
|
-
*
|
|
137
|
-
* in the generated code.
|
|
138
|
+
* Finds position in an original source based on generated code position.
|
|
138
139
|
*
|
|
139
|
-
* @param line - Line number in the generated code
|
|
140
|
-
* @param column - Column number in the generated code
|
|
141
|
-
* @param bias -
|
|
142
|
-
* @returns
|
|
140
|
+
* @param line - Line number in the generated code
|
|
141
|
+
* @param column - Column number in the generated code
|
|
142
|
+
* @param bias - Position matching strategy (default: Bias.BOUND)
|
|
143
|
+
* @returns Position information or null if not found
|
|
143
144
|
*
|
|
144
145
|
* @example
|
|
145
146
|
* ```ts
|
|
146
147
|
* const position = sourceService.getPosition(2, 15);
|
|
147
|
-
* console.log(position?.source); //
|
|
148
|
+
* console.log(position?.source); // Original source file
|
|
148
149
|
* ```
|
|
150
|
+
*
|
|
151
|
+
* @since 1.0.0
|
|
149
152
|
*/
|
|
150
153
|
getPosition(line: number, column: number, bias?: Bias): PositionInterface | null;
|
|
151
154
|
/**
|
|
152
|
-
* Retrieves
|
|
155
|
+
* Retrieves position with source content for a location in generated code.
|
|
153
156
|
*
|
|
154
|
-
* @param line - Line number in the generated code
|
|
155
|
-
* @param column - Column number in the generated code
|
|
156
|
-
* @param bias -
|
|
157
|
-
* @returns
|
|
157
|
+
* @param line - Line number in the generated code
|
|
158
|
+
* @param column - Column number in the generated code
|
|
159
|
+
* @param bias - Position matching strategy (default: Bias.BOUND)
|
|
160
|
+
* @returns Position with content information or null if not found
|
|
158
161
|
*
|
|
159
162
|
* @example
|
|
160
163
|
* ```ts
|
|
161
|
-
* const
|
|
162
|
-
* console.log(
|
|
164
|
+
* const posWithContent = sourceService.getPositionWithContent(3, 5);
|
|
165
|
+
* console.log(posWithContent?.sourcesContent); // Original source content
|
|
163
166
|
* ```
|
|
167
|
+
*
|
|
168
|
+
* @since 1.0.0
|
|
164
169
|
*/
|
|
165
170
|
getPositionWithContent(line: number, column: number, bias?: Bias): PositionWithContentInterface | null;
|
|
166
171
|
/**
|
|
167
|
-
* Retrieves
|
|
168
|
-
* generated code position, with additional lines of code around the matching line.
|
|
172
|
+
* Retrieves position with a code snippet from the original source.
|
|
169
173
|
*
|
|
170
|
-
* @param line - Line number in the generated code
|
|
171
|
-
* @param column - Column number in the generated code
|
|
172
|
-
* @param bias -
|
|
173
|
-
* @param options -
|
|
174
|
-
* @returns
|
|
174
|
+
* @param line - Line number in the generated code
|
|
175
|
+
* @param column - Column number in the generated code
|
|
176
|
+
* @param bias - Position matching strategy (default: Bias.BOUND)
|
|
177
|
+
* @param options - Configuration for the amount of surrounding lines
|
|
178
|
+
* @returns Position with code snippet or null if not found
|
|
175
179
|
*
|
|
176
180
|
* @example
|
|
177
181
|
* ```ts
|
|
178
|
-
* const
|
|
179
|
-
*
|
|
182
|
+
* const posWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, {
|
|
183
|
+
* linesBefore: 2,
|
|
184
|
+
* linesAfter: 2
|
|
185
|
+
* });
|
|
186
|
+
* console.log(posWithCode?.code); // Code snippet with context
|
|
180
187
|
* ```
|
|
188
|
+
*
|
|
189
|
+
* @since 1.0.0
|
|
181
190
|
*/
|
|
182
191
|
getPositionWithCode(line: number, column: number, bias?: Bias, options?: SourceOptionsInterface): PositionWithCodeInterface | null;
|
|
183
192
|
/**
|
|
184
|
-
*
|
|
193
|
+
* Serializes the source map to a JSON string.
|
|
185
194
|
*
|
|
186
|
-
* @returns
|
|
195
|
+
* @returns JSON string representation of the source map
|
|
187
196
|
*
|
|
188
197
|
* @example
|
|
189
198
|
* ```ts
|
|
190
|
-
*
|
|
199
|
+
* const jsonString = sourceService.toString();
|
|
200
|
+
* console.log(jsonString); // '{"version":3,"file":"bundle.js",...}'
|
|
191
201
|
* ```
|
|
202
|
+
*
|
|
203
|
+
* @since 1.0.0
|
|
192
204
|
*/
|
|
193
205
|
toString(): string;
|
|
194
206
|
/**
|
|
195
|
-
* Validates
|
|
207
|
+
* Validates a source map object has all required properties.
|
|
196
208
|
*
|
|
197
|
-
*
|
|
198
|
-
* It throws an error if any required keys are missing.
|
|
209
|
+
* @param input - Source map object to validate
|
|
199
210
|
*
|
|
200
|
-
* @
|
|
201
|
-
* @param input - The source map object to be validated.
|
|
202
|
-
* @throws Error If any required key is missing from the source map.
|
|
211
|
+
* @throws Error - When required properties are missing
|
|
203
212
|
*
|
|
204
|
-
* @
|
|
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
|
-
* ```
|
|
213
|
+
* @since 1.0.0
|
|
215
214
|
*/
|
|
216
215
|
private validateSourceMap;
|
|
217
216
|
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
7
7
|
"author": "Garefild",
|
|
8
|
-
"version": "2.0
|
|
8
|
+
"version": "2.1.0",
|
|
9
9
|
"license": "Mozilla Public License Version 2.0",
|
|
10
10
|
"description": "A library with a sourcemap parser and TypeScript code formatter for the CLI",
|
|
11
11
|
"homepage": "https://github.com/remotex-lab/xMap",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"jest": "^29.7.0",
|
|
67
|
-
"eslint": "^9.
|
|
68
|
-
"typescript-eslint": "^8.
|
|
69
|
-
"eslint-plugin-
|
|
70
|
-
"@swc/jest": "^0.2.
|
|
71
|
-
"@types/jest": "^29.5.
|
|
72
|
-
"@types/node": "^22.
|
|
73
|
-
"@remotex-labs/xbuild": "^1.3
|
|
67
|
+
"eslint": "^9.22.0",
|
|
68
|
+
"typescript-eslint": "^8.26.1",
|
|
69
|
+
"eslint-plugin-tsdoc": "^0.4.0",
|
|
70
|
+
"@swc/jest": "^0.2.37",
|
|
71
|
+
"@types/jest": "^29.5.14",
|
|
72
|
+
"@types/node": "^22.13.10",
|
|
73
|
+
"@remotex-labs/xbuild": "^1.5.3"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"typescript": "^5.
|
|
76
|
+
"typescript": "^5.8.2"
|
|
77
77
|
}
|
|
78
78
|
}
|