@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.
@@ -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
- * 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.
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 (bundle) that this source map applies to.
29
+ * The name of the generated file this source map applies to.
27
30
  *
28
- * @example
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
- * A MappingProvider instance of base64 VLQ-encoded mappings.
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 the sources, if present in the source map.
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
- * A list of symbol names used by the mappings” entry.
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
- * An array of source file paths.
51
+ * Array of source file paths.
52
+ * @since 1.0.0
48
53
  */
49
54
  readonly sources: Array<string>;
50
55
  /**
51
- * An array of source files contents.
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 instance of the `SourceService` class.
61
+ * Creates a new SourceService instance.
56
62
  *
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`.
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
- * @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.
66
+ * @throws Error - When a source map has an invalid format or missing required properties
68
67
  *
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
- * ```
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 current source map data into a plain object format.
73
+ * Converts the source map data to a plain object.
79
74
  *
80
- * @returns The source map json object.
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 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.
87
+ * Concatenates additional source maps into the current instance.
94
88
  *
95
- * @param maps - An array of `SourceMapInterface` or `SourceService` instances to be concatenated.
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 of `SourceService` with concatenated source maps.
103
+ * Creates a new SourceService instance with concatenated source maps.
107
104
  *
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.
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.file); // The file from the new source map
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
- * Retrieves the position information based on the original source line and column.
120
+ * Finds position in generated code based on original source position.
121
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.
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?.line); // The line number in the original source
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
- * Retrieves the position in the original source code based on a given line and column
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 - 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.
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); // The original source file
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 the position and original source content for a given position in the generated code.
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 - Bias used for position matching.
157
- * @returns { PositionWithContentInterface | null } The position and its associated content, or `null` if not found.
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 positionWithContent = sourceService.getPositionWithContent(3, 5);
162
- * console.log(positionWithContent?.sourcesContent); // The source code content
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 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.
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 - 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.
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 positionWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, { linesBefore: 2, linesAfter: 2 });
179
- * console.log(positionWithCode?.code); // The code snippet from the original source
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
- * Converts the current source map object to a JSON string.
193
+ * Serializes the source map to a JSON string.
185
194
  *
186
- * @returns A stringified version of the source map object.
195
+ * @returns JSON string representation of the source map
187
196
  *
188
197
  * @example
189
198
  * ```ts
190
- * console.log(sourceService.toString()); // JSON string of the source map
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 the provided source map object.
207
+ * Validates a source map object has all required properties.
196
208
  *
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.
209
+ * @param input - Source map object to validate
199
210
  *
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.
211
+ * @throws Error - When required properties are missing
203
212
  *
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
- * ```
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.4",
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.13.0",
68
- "typescript-eslint": "^8.11.0",
69
- "eslint-plugin-jsdoc": "^50.4.3",
70
- "@swc/jest": "^0.2.36",
71
- "@types/jest": "^29.5.13",
72
- "@types/node": "^22.7.8",
73
- "@remotex-labs/xbuild": "^1.3.1"
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.6.3"
76
+ "typescript": "^5.8.2"
77
77
  }
78
78
  }