@remotex-labs/xmap 2.0.3 → 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
- package/dist/components/base64.component.js +0 -2
- package/dist/components/base64.component.js.map +0 -8
- package/dist/components/formatter.component.js +0 -5
- package/dist/components/formatter.component.js.map +0 -8
- package/dist/components/highlighter.component.js +0 -2
- package/dist/components/highlighter.component.js.map +0 -8
- package/dist/components/parser.component.js +0 -3
- package/dist/components/parser.component.js.map +0 -8
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -8
- package/dist/package.json +0 -1
- package/dist/providers/interfaces/mapping.interface.js +0 -2
- package/dist/providers/interfaces/mapping.interface.js.map +0 -8
- package/dist/providers/mapping.provider.js +0 -2
- package/dist/providers/mapping.provider.js.map +0 -8
- package/dist/services/source.service.js +0 -4
- package/dist/services/source.service.js.map +0 -8
|
@@ -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
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const u=31,d=32,I={},N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");N.forEach((e,t)=>{I[e]=t});function T(e){const t=e<0;let o="",n=t?(-e<<1)+1:e<<1;do{const r=n&31;n>>>=5,o+=N[r|(n>0?32:0)]}while(n>0);return o}function l(e){return e.map(T).join("")}function _(e){const t=[];let o=0,n=0;for(let r=0;r<e.length;r++){const i=I[e[r]];if(i===void 0)throw new Error(`Invalid Base64 character: ${e[r]}`);const c=i&32;if(n+=(i&31)<<o,c)o+=5;else{const O=(n&1)===1,s=n>>1;t.push(O?-s:s),n=o=0}}return t}export{_ as decodeVLQ,l as encodeArrayVLQ,T as encodeVLQ};
|
|
2
|
-
//# sourceMappingURL=base64.component.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/components/base64.component.ts"],
|
|
4
|
-
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/2.0.3/",
|
|
5
|
-
"sourcesContent": ["// Bitmask to extract the lower 5 bits (continuation bit removed) - 0b11111\nconst CONTINUATION_BIT_REMOVE = 0x1F;\n\n// Bitmask to set the continuation bit - 0b100000\nconst CONTINUATION_BIT_POSITION = 0x20;\n\n// Mapping of Base64 characters to their indices\nconst base64Map: { [key: string]: number } = {};\n\n// Array of Base64 characters\nconst base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');\n\n// Populate the base64Map with characters and their corresponding indices\nbase64Chars.forEach((char, index) => {\n base64Map[char] = index;\n});\n\n/**\n * Encodes a given number using Variable-Length Quantity (VLQ) encoding.\n * Negative numbers are encoded by converting to a non-negative representation.\n * The continuation bit is used to indicate if more bytes follow.\n *\n * @param value - The number to be encoded.\n * @returns The VLQ encoded string.\n */\n\nexport function encodeVLQ(value: number): string {\n const isNegative = value < 0;\n\n /**\n * Bit Structure Representation:\n *\n * +--------------------------+\n * | C | Value | Sign |\n * +---+---+---+---+---+------+\n * | 1 | 1 | 0 | 0 | 1 | 0 |\n * +---+---+---+---+---+------+\n */\n\n let encoded = '';\n let vlq = isNegative ? ((-value) << 1) + 1 : (value << 1); // Shift left by 1 bit to encode the sign bit\n\n do {\n const digit = vlq & CONTINUATION_BIT_REMOVE; // Extract lower 5 bits\n vlq >>>= 5; // Right shift by 5 bits to process next chunk\n encoded += base64Chars[digit | (vlq > 0 ? CONTINUATION_BIT_POSITION : 0)]; // Combine digit and continuation bit\n } while (vlq > 0);\n\n return encoded;\n}\n\n/**\n * Encodes an array of numbers using VLQ encoding.\n * Each number in the array is individually encoded and the results are concatenated.\n *\n * @param values - The array of numbers to be encoded.\n * @returns The concatenated VLQ encoded string.\n */\n\nexport function encodeArrayVLQ(values: number[]): string {\n return values.map(encodeVLQ).join('');\n}\n\n/**\n * Decodes a VLQ encoded string back into an array of numbers.\n * Each character is decoded using the Base64 map and continuation bits are processed.\n *\n * @param data - The VLQ encoded string.\n * @returns The array of decoded numbers.\n * @throws Error If the string contains invalid Base64 characters.\n */\n\nexport function decodeVLQ(data: string): number[] {\n const result = [];\n let shift = 0;\n let value = 0;\n\n for (let i = 0; i < data.length; i++) {\n const digit = base64Map[data[i]];\n if (digit === undefined) {\n throw new Error(`Invalid Base64 character: ${data[i]}`);\n }\n\n const continuation = digit & CONTINUATION_BIT_POSITION; // Check if continuation bit is set\n value += (digit & CONTINUATION_BIT_REMOVE) << shift; // Add lower 5 bits to value\n if (continuation) {\n shift += 5; // Shift left by 5 for next chunk\n } else {\n const isNegative = (value & 1) === 1; // Check if the number is negative\n const shifted = value >> 1; // Remove the sign bit\n\n result.push(isNegative ? -shifted : shifted); // Convert back to signed integer\n value = shift = 0; // Reset for next number\n }\n }\n\n return result;\n}\n"],
|
|
6
|
-
"mappings": "AACA,MAAMA,EAA0B,GAG1BC,EAA4B,GAG5BC,EAAuC,CAAC,EAGxCC,EAAc,mEAAmE,MAAM,EAAE,EAG/FA,EAAY,QAAQ,CAACC,EAAMC,IAAU,CACjCH,EAAUE,CAAI,EAAIC,CACtB,CAAC,EAWM,SAASC,EAAUC,EAAuB,CAC7C,MAAMC,EAAaD,EAAQ,EAY3B,IAAIE,EAAU,GACVC,EAAMF,GAAe,CAACD,GAAU,GAAK,EAAKA,GAAS,EAEvD,EAAG,CACC,MAAMI,EAAQD,EAAM,GACpBA,KAAS,EACTD,GAAWN,EAAYQ,GAASD,EAAM,EAAI,GAA4B,EAAE,CAC5E,OAASA,EAAM,GAEf,OAAOD,CACX,CAUO,SAASG,EAAeC,EAA0B,CACrD,OAAOA,EAAO,IAAIP,CAAS,EAAE,KAAK,EAAE,CACxC,CAWO,SAASQ,EAAUC,EAAwB,CAC9C,MAAMC,EAAS,CAAC,EAChB,IAAIC,EAAQ,EACRV,EAAQ,EAEZ,QAASW,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAAK,CAClC,MAAMP,EAAQT,EAAUa,EAAKG,CAAC,CAAC,EAC/B,GAAIP,IAAU,OACV,MAAM,IAAI,MAAM,6BAA6BI,EAAKG,CAAC,CAAC,EAAE,EAG1D,MAAMC,EAAeR,EAAQ,GAE7B,GADAJ,IAAUI,EAAQ,KAA4BM,EAC1CE,EACAF,GAAS,MACN,CACH,MAAMT,GAAcD,EAAQ,KAAO,EAC7Ba,EAAUb,GAAS,EAEzBS,EAAO,KAAKR,EAAa,CAACY,EAAUA,CAAO,EAC3Cb,EAAQU,EAAQ,CACpB,CACJ,CAEA,OAAOD,CACX",
|
|
7
|
-
"names": ["CONTINUATION_BIT_REMOVE", "CONTINUATION_BIT_POSITION", "base64Map", "base64Chars", "char", "index", "encodeVLQ", "value", "isNegative", "encoded", "vlq", "digit", "encodeArrayVLQ", "values", "decodeVLQ", "data", "result", "shift", "i", "continuation", "shifted"]
|
|
8
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
function u(a,r={}){const f=a.split(`
|
|
2
|
-
`),n=r.padding??10,c=r.startLine??0;return f.map((i,o)=>{const e=o+c+1,t=`${`${e} | `.padStart(n)}${i}`;return r.action&&e===r.action.triggerLine?r.action.callback(t,n,e):t}).join(`
|
|
3
|
-
`)}function $(a,r){const{code:f,line:n,column:c,startLine:i}=a;if(n<i||c<1)throw new Error("Invalid line or column number.");return u(f,{startLine:i,action:{triggerLine:n,callback:(o,e,s)=>{let t="^",l=e-1,d=">";r&&(t=`${r.color}${t}${r.reset}`,l+=r.color.length+r.reset.length,d=`${r.color}>${r.reset}`);const m=" | ".padStart(e)+" ".repeat(c-1)+`${t}`;return o=`${d} ${s} |`.padStart(l)+o.split("|")[1],o+`
|
|
4
|
-
${m}`}}})}export{u as formatCode,$ as formatErrorCode};
|
|
5
|
-
//# sourceMappingURL=formatter.component.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/components/formatter.component.ts"],
|
|
4
|
-
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/2.0.3/",
|
|
5
|
-
"sourcesContent": ["/**\n * Import will remove at compile time\n */\n\nimport type { PositionWithCodeInterface } from '../services/interfaces/source.interface.js';\nimport type { AnsiOptionInterface, FormatCodeInterface } from './/interfaces/formatter.interface.js';\n\n/**\n * Formats a code snippet with optional line padding and custom actions.\n *\n * This function takes a code string and an options object to format the code snippet.\n * It applies padding to line numbers and can trigger custom actions for specific lines.\n *\n * @param code - The source code | stack to be formatted.\n * @param options - Configuration options for formatting the code.\n * - `padding` (number, optional): Number of characters for line number padding. Defaults to 10.\n * - `startLine` (number, optional): The starting line number for formatting. Defaults to 1.\n * - `action` (object, optional): Custom actions to apply to specific lines.\n * - `triggerLine` (number): The line number where the action should be triggered.\n * - `callback` (function): A callback function to format the line string when `triggerLine` is matched.\n * The callback receives the formatted line string, the padding value, and the current line number as arguments.\n *\n * @returns A formatted string of the code snippet with applied padding and custom actions.\n *\n * @example\n * ```typescript\n * const formattedCode = formatCode(code, {\n * padding: 8,\n * startLine: 5,\n * action: {\n * triggerLine: 7,\n * callback: (lineString, padding, lineNumber) => {\n * return `Custom formatting for line ${lineNumber}: ${lineString}`;\n * }\n * }\n * });\n * console.log(formattedCode);\n * ```\n */\n\nexport function formatCode(code: string, options: FormatCodeInterface = {}): string {\n const lines = code.split('\\n');\n const padding = options.padding ?? 10;\n const startLine = options.startLine ?? 0;\n\n return lines.map((lineContent, index) => {\n const currentLineNumber = index + startLine + 1;\n const prefix = `${ currentLineNumber} | `;\n const string = `${ prefix.padStart(padding) }${ lineContent }`;\n\n if (options.action && currentLineNumber === options.action.triggerLine) {\n return options.action.callback(string, padding, currentLineNumber);\n }\n\n return string;\n }).join('\\n');\n}\n\n/**\n * Formats a code snippet around an error location with special highlighting.\n *\n * This function takes a `sourcePosition` object containing information about the source code\n * and error location, then uses `formatCode` to format and highlight the relevant code snippet.\n *\n * @param sourcePosition - An object containing information about the source code and error location.\n * - `code` (string): The entire source code content.\n * - `line` (number): The line number where the error occurred (1-based indexing).\n * - `column` (number): The column number within the line where the error occurred (1-based indexing).\n * - `startLine` (number, optional): The starting line number of the code snippet (defaults to 1).\n * @param ansiOption - Optional configuration for ANSI color codes.\n * - `color` (string): The ANSI escape sequence to colorize the error marker and prefix (e.g., `'\\x1b[38;5;160m'`).\n * - `reset` (string): The ANSI escape sequence to reset the color (e.g., `'\\x1b[0m'`).\n *\n * @throws Error - If the provided `sourcePosition` object has invalid line or column numbers,\n * or if the error line is outside the boundaries of the provided code content.\n *\n * @returns A formatted string representing the relevant code snippet around the error location,\n * including special highlighting for the error line and column.\n *\n * @example\n * ```typescript\n * const formattedErrorCode = formatErrorCode(sourcePosition);\n * console.log(formattedErrorCode);\n * ```\n */\n\nexport function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string {\n const { code, line: errorLine, column: errorColumn, startLine } = sourcePosition;\n\n // Validate line and column numbers\n if (errorLine < startLine || errorColumn < 1) {\n throw new Error('Invalid line or column number.');\n }\n\n return formatCode(code, {\n startLine,\n action: {\n triggerLine: errorLine,\n callback: (lineString, padding, line) => {\n let pointer = '^';\n let ansiPadding = padding - 1; // 1 size of the char we added\n let prefixPointer = '>';\n\n if (ansiOption) {\n pointer = `${ ansiOption.color }${ pointer }${ ansiOption.reset }`;\n ansiPadding += (ansiOption.color.length + ansiOption.reset.length);\n prefixPointer = `${ ansiOption.color }>${ ansiOption.reset }`;\n }\n\n const errorMarker = ' | '.padStart(padding) + ' '.repeat(errorColumn - 1) + `${ pointer }`;\n lineString = `${ prefixPointer } ${ line } |`.padStart(ansiPadding) + lineString.split('|')[1];\n\n return lineString + `\\n${ errorMarker }`;\n }\n }\n });\n}\n"],
|
|
6
|
-
"mappings": "AAwCO,SAASA,EAAWC,EAAcC,EAA+B,CAAC,EAAW,CAChF,MAAMC,EAAQF,EAAK,MAAM;AAAA,CAAI,EACvBG,EAAUF,EAAQ,SAAW,GAC7BG,EAAYH,EAAQ,WAAa,EAEvC,OAAOC,EAAM,IAAI,CAACG,EAAaC,IAAU,CACrC,MAAMC,EAAoBD,EAAQF,EAAY,EAExCI,EAAS,GADA,GAAID,CAAiB,MACV,SAASJ,CAAO,CAAE,GAAIE,CAAY,GAE5D,OAAIJ,EAAQ,QAAUM,IAAsBN,EAAQ,OAAO,YAChDA,EAAQ,OAAO,SAASO,EAAQL,EAASI,CAAiB,EAG9DC,CACX,CAAC,EAAE,KAAK;AAAA,CAAI,CAChB,CA8BO,SAASC,EAAgBC,EAA2CC,EAA0C,CACjH,KAAM,CAAE,KAAAX,EAAM,KAAMY,EAAW,OAAQC,EAAa,UAAAT,CAAU,EAAIM,EAGlE,GAAIE,EAAYR,GAAaS,EAAc,EACvC,MAAM,IAAI,MAAM,gCAAgC,EAGpD,OAAOd,EAAWC,EAAM,CACpB,UAAAI,EACA,OAAQ,CACJ,YAAaQ,EACb,SAAU,CAACE,EAAYX,EAASY,IAAS,CACrC,IAAIC,EAAU,IACVC,EAAcd,EAAU,EACxBe,EAAgB,IAEhBP,IACAK,EAAU,GAAIL,EAAW,KAAM,GAAIK,CAAQ,GAAIL,EAAW,KAAM,GAChEM,GAAgBN,EAAW,MAAM,OAASA,EAAW,MAAM,OAC3DO,EAAgB,GAAIP,EAAW,KAAM,IAAKA,EAAW,KAAM,IAG/D,MAAMQ,EAAc,MAAM,SAAShB,CAAO,EAAI,IAAI,OAAOU,EAAc,CAAC,EAAI,GAAIG,CAAQ,GACxF,OAAAF,EAAa,GAAII,CAAc,IAAKH,CAAK,KAAK,SAASE,CAAW,EAAIH,EAAW,MAAM,GAAG,EAAE,CAAC,EAEtFA,EAAa;AAAA,EAAMK,CAAY,EAC1C,CACJ,CACJ,CAAC,CACL",
|
|
7
|
-
"names": ["formatCode", "code", "options", "lines", "padding", "startLine", "lineContent", "index", "currentLineNumber", "string", "formatErrorCode", "sourcePosition", "ansiOption", "errorLine", "errorColumn", "lineString", "line", "pointer", "ansiPadding", "prefixPointer", "errorMarker"]
|
|
8
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import*as t from"typescript";import{SyntaxKind as l}from"typescript";var g=(a=>(a.reset="\x1B[0m",a.gray="\x1B[38;5;243m",a.darkGray="\x1B[38;5;238m",a.lightCoral="\x1B[38;5;203m",a.lightOrange="\x1B[38;5;215m",a.oliveGreen="\x1B[38;5;149m",a.burntOrange="\x1B[38;5;208m",a.lightGoldenrodYellow="\x1B[38;5;221m",a.lightYellow="\x1B[38;5;230m",a.canaryYellow="\x1B[38;5;227m",a.deepOrange="\x1B[38;5;166m",a.lightGray="\x1B[38;5;252m",a.brightPink="\x1B[38;5;197m",a))(g||{});const m={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"};class S{constructor(e,r,n){this.sourceFile=e;this.code=r;this.schema=n}segments=new Map;parseNode(e){this.processComments(e),this.processKeywords(e),this.processNode(e)}highlight(){let e=0,r;const n=[];return Array.from(this.segments.values()).sort((s,i)=>s.start-i.start||s.end-i.end).forEach(s=>{if(r&&s.start<r.end){const i=n.pop();if(!i)return;const h=this.getSegmentSource(s.start,s.end),d=`${s.color}${h}${r.color}`;n.push(i.replace(h,d));return}n.push(this.getSegmentSource(e,s.start)),n.push(`${s.color}${this.getSegmentSource(s.start,s.end)}${s.reset}`),e=s.end,r=s}),n.join("")+this.getSegmentSource(e)}getSegmentSource(e,r){return this.code.slice(e,r)}addSegment(e,r,n,o="\x1B[0m"){const s=`${e}-${r}`;this.segments.set(s,{start:e,end:r,color:n,reset:o})}processComments(e){[...t.getTrailingCommentRanges(this.sourceFile.getFullText(),e.getFullStart())||[],...t.getLeadingCommentRanges(this.sourceFile.getFullText(),e.getFullStart())||[]].forEach(n=>this.addSegment(n.pos,n.end,this.schema.commentColor))}processKeywords(e){if([l.NullKeyword,l.VoidKeyword,l.StringKeyword,l.NumberKeyword,l.BooleanKeyword,l.UndefinedKeyword].includes(e.kind))return this.addSegment(e.getStart(),e.getEnd(),this.schema.typeColor);e&&e.kind>=t.SyntaxKind.FirstKeyword&&e.kind<=t.SyntaxKind.LastKeyword&&this.addSegment(e.getStart(),e.getEnd(),this.schema.keywordColor)}processIdentifier(e){const r=e.getEnd(),n=e.getStart();switch(e.parent.kind){case t.SyntaxKind.EnumMember:return this.addSegment(n,r,this.schema.enumColor);case t.SyntaxKind.CallExpression:case t.SyntaxKind.EnumDeclaration:case t.SyntaxKind.PropertySignature:case t.SyntaxKind.ModuleDeclaration:return this.addSegment(n,r,this.schema.variableColor);case t.SyntaxKind.InterfaceDeclaration:return this.addSegment(n,r,this.schema.interfaceColor);case t.SyntaxKind.GetAccessor:return this.addSegment(n,r,this.schema.getAccessorColor);case t.SyntaxKind.PropertyAssignment:return this.addSegment(n,r,this.schema.propertyAssignmentColor);case t.SyntaxKind.MethodSignature:return this.addSegment(n,r,this.schema.methodSignatureColor);case t.SyntaxKind.MethodDeclaration:case t.SyntaxKind.FunctionDeclaration:return this.addSegment(n,r,this.schema.functionColor);case t.SyntaxKind.ClassDeclaration:return this.addSegment(n,r,this.schema.classColor);case t.SyntaxKind.Parameter:return this.addSegment(n,r,this.schema.parameterColor);case t.SyntaxKind.VariableDeclaration:return this.addSegment(n,r,this.schema.variableColor);case t.SyntaxKind.PropertyDeclaration:return this.addSegment(n,r,this.schema.variableColor);case t.SyntaxKind.PropertyAccessExpression:return e.parent.getChildAt(0).getText()===e.getText()?this.addSegment(n,r,this.schema.variableColor):this.addSegment(n,r,this.schema.propertyAccessExpressionColor);case t.SyntaxKind.ExpressionWithTypeArguments:return this.addSegment(n,r,this.schema.expressionWithTypeArgumentsColor);case t.SyntaxKind.BreakStatement:case t.SyntaxKind.ShorthandPropertyAssignment:case t.SyntaxKind.BindingElement:return this.addSegment(n,r,this.schema.variableColor);case t.SyntaxKind.BinaryExpression:case t.SyntaxKind.SwitchStatement:case t.SyntaxKind.TemplateSpan:return this.addSegment(n,r,this.schema.variableColor);case t.SyntaxKind.TypeReference:case t.SyntaxKind.TypeAliasDeclaration:return this.addSegment(n,r,this.schema.typeColor);case t.SyntaxKind.NewExpression:return this.addSegment(n,r,this.schema.variableColor)}}processTemplateExpression(e){const r=e.head.getStart(),n=e.head.getEnd();this.addSegment(r,n,this.schema.stringColor),e.templateSpans.forEach(o=>{const s=o.literal.getStart(),i=o.literal.getEnd();this.addSegment(s,i,this.schema.stringColor)})}processNode(e){const r=e.getStart(),n=e.getEnd();switch(e.kind){case t.SyntaxKind.TypeParameter:return this.addSegment(r,r+e.name.text.length,this.schema.typeColor);case t.SyntaxKind.TypeReference:return this.addSegment(r,n,this.schema.typeColor);case t.SyntaxKind.StringLiteral:case t.SyntaxKind.NoSubstitutionTemplateLiteral:return this.addSegment(r,n,this.schema.stringColor);case t.SyntaxKind.RegularExpressionLiteral:return this.addSegment(r,n,this.schema.regularExpressionColor);case t.SyntaxKind.TemplateExpression:return this.processTemplateExpression(e);case t.SyntaxKind.Identifier:return this.processIdentifier(e);case t.SyntaxKind.BigIntLiteral:case t.SyntaxKind.NumericLiteral:return this.addSegment(r,n,this.schema.numericLiteralColor)}}}function u(c,e={}){const r=t.createSourceFile("temp.ts",c,t.ScriptTarget.Latest,!0,t.ScriptKind.TS),n=new S(r,c,Object.assign(m,e));function o(s){n.parseNode(s);for(let i=0;i<s.getChildCount();i++)o(s.getChildAt(i))}return t.forEachChild(r,o),n.highlight()}export{S as CodeHighlighter,g as Colors,u as highlightCode};
|
|
2
|
-
//# sourceMappingURL=highlighter.component.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/components/highlighter.component.ts"],
|
|
4
|
-
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/2.0.3/",
|
|
5
|
-
"sourcesContent": ["/**\n * Import will remove at compile time\n */\n\nimport type { HighlightSchemeInterface, HighlightNodeSegmentInterface } from './/interfaces/highlighter.interface.js';\n\n/**\n * Imports\n */\n\nimport * as ts from 'typescript';\nimport { SyntaxKind } from 'typescript';\n\n/**\n * An enum containing ANSI escape sequences for various colors.\n *\n * This enum is primarily intended for terminal output and won't work directly in JavaScript for web development.\n * It defines color codes for various colors and a reset code to return to\n * the default text color.\n *\n * @example\n * ```typescript\n * console.log(`${Colors.red}This the text will be red in the terminal.${Colors.reset}`);\n * ```\n *\n * This functionality is limited to terminal environments.\n * Consider alternative methods\n * for color highlighting in web development contexts, such as CSS classes.\n */\n\nexport const enum Colors {\n reset = '\\x1b[0m',\n gray = '\\x1b[38;5;243m',\n darkGray = '\\x1b[38;5;238m',\n lightCoral = '\\x1b[38;5;203m',\n lightOrange = '\\x1b[38;5;215m',\n oliveGreen = '\\x1b[38;5;149m',\n burntOrange = '\\x1b[38;5;208m',\n lightGoldenrodYellow = '\\x1b[38;5;221m',\n lightYellow = '\\x1b[38;5;230m',\n canaryYellow = '\\x1b[38;5;227m',\n deepOrange = '\\x1b[38;5;166m',\n lightGray = '\\x1b[38;5;252m',\n brightPink = '\\x1b[38;5;197m'\n}\n\n/**\n * Default color scheme for semantic highlighting.\n * This scheme uses red color for all code elements.\n *\n * @example\n * const scheme = defaultScheme;\n * console.log(scheme.typeColor); // Outputs: the red color code\n */\n\n\nconst defaultScheme: HighlightSchemeInterface = {\n enumColor: Colors.burntOrange,\n typeColor: Colors.lightGoldenrodYellow,\n classColor: Colors.lightOrange,\n stringColor: Colors.oliveGreen,\n keywordColor: Colors.lightCoral,\n commentColor: Colors.darkGray,\n functionColor: Colors.lightOrange,\n variableColor: Colors.burntOrange,\n interfaceColor: Colors.lightGoldenrodYellow,\n parameterColor: Colors.deepOrange,\n getAccessorColor: Colors.lightYellow,\n numericLiteralColor: Colors.lightGray,\n methodSignatureColor: Colors.burntOrange,\n regularExpressionColor: Colors.oliveGreen,\n propertyAssignmentColor: Colors.canaryYellow,\n propertyAccessExpressionColor: Colors.lightYellow,\n expressionWithTypeArgumentsColor: Colors.lightOrange\n};\n\n/**\n * Class responsible for applying semantic highlighting to a source code string based on a given color scheme.\n *\n * @class\n *\n * @param sourceFile - The TypeScript AST node representing the source file.\n * @param code - The source code string to be highlighted.\n * @param schema - The color scheme used for highlighting different elements in the code.\n *\n * const highlighter = new CodeHighlighter(sourceFile, code, schema);\n */\n\nexport class CodeHighlighter {\n\n /**\n * A Map of segments where the key is a combination of start and end positions,\n * and the value is an object containing the color and reset code.\n * This structure ensures unique segments and allows for fast lookups and updates.\n *\n * @example\n * this.segments = new Map([\n * ['0-10', { start: 1, end: 11, color: '\\x1b[31m', reset: '\\x1b[0m' }],\n * ['11-20', { start: 12, end: 20, color: '\\x1b[32m', reset: '\\x1b[0m' }]\n * ]);\n */\n\n private segments: Map<string, HighlightNodeSegmentInterface> = new Map();\n\n /**\n * Creates an instance of the CodeHighlighter class.\n *\n * @param sourceFile - The TypeScript AST node representing the source file.\n * @param code - The source code string to be highlighted.\n * @param schema - The color scheme used for highlighting different elements in the code.\n */\n\n constructor(private sourceFile: ts.Node, private code: string, private schema: HighlightSchemeInterface) {\n }\n\n /**\n * Parses a TypeScript AST node and processes its comments to identify segments that need highlighting.\n *\n * @param node - The TypeScript AST node to be parsed.\n */\n\n parseNode(node: ts.Node): void {\n this.processComments(node);\n this.processKeywords(node);\n this.processNode(node);\n }\n\n /**\n * Generates a string with highlighted code segments based on the provided color scheme.\n *\n * This method processes the stored segments, applies the appropriate colors to each segment,\n * and returns the resulting highlighted code as a single string.\n *\n * @returns The highlighted code as a string, with ANSI color codes applied to the segments.\n */\n\n highlight(): string {\n let previousSegmentEnd = 0;\n let parent: HighlightNodeSegmentInterface | undefined;\n\n const result: Array<string> = [];\n const segments = Array.from(\n this.segments.values()\n ).sort((a, b) => a.start - b.start || a.end - b.end);\n\n segments.forEach((segment) => {\n if (parent && segment.start < parent.end) {\n const lastSegment = result.pop();\n if (!lastSegment) return;\n\n const source = this.getSegmentSource(segment.start, segment.end);\n const combinedSource = `${ segment.color }${ source }${ parent.color }`;\n result.push(lastSegment.replace(source, combinedSource));\n\n return;\n }\n\n result.push(this.getSegmentSource(previousSegmentEnd, segment.start));\n result.push(`${ segment.color }${ this.getSegmentSource(segment.start, segment.end) }${ segment.reset }`);\n previousSegmentEnd = segment.end;\n parent = segment;\n });\n\n return result.join('') + this.getSegmentSource(previousSegmentEnd);\n }\n\n /**\n * Extracts a substring from the code based on the specified start and end positions.\n *\n * This method is used to retrieve the source code segment that corresponds to the\n * given start and end positions. It is primarily used for highlighting specific\n * segments of the code.\n *\n * @param start - The starting index of the segment to be extracted.\n * @param end - The ending index of the segment to be extracted.\n * @returns The extracted substring from the code.\n */\n\n private getSegmentSource(start: number, end?: number): string {\n return this.code.slice(start, end);\n }\n\n /**\n * Adds a new segment to the list of segments to be highlighted.\n * The segment is defined by its start and end positions, the color to apply, and an optional reset code.\n *\n * @param start - The starting index of the segment in the code string.\n * @param end - The ending index of the segment in the code string.\n * @param color - The color code to apply to the segment.\n * @param reset - The color reset code to apply after the segment, Defaults to the reset code defined in `Colors.reset`.\n */\n\n private addSegment(start: number, end: number, color: string, reset: string = Colors.reset) {\n const key = `${ start }-${ end }`;\n this.segments.set(key, { start, end, color, reset });\n }\n\n /**\n * Processes comments within a TypeScript AST node and adds segments for highlighting.\n * Extracts trailing and leading comments from the node and adds them as segments using the color defined in `this.colorSchema.comments`.\n *\n * @param node - The TypeScript AST node whose comments are to be processed.\n */\n\n private processComments(node: ts.Node): void {\n const comments = [\n ...ts.getTrailingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || [],\n ...ts.getLeadingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || []\n ];\n\n comments.forEach(comment => this.addSegment(comment.pos, comment.end, this.schema.commentColor));\n }\n\n /**\n * Processes the keywords within a TypeScript AST node and adds them as segments for highlighting.\n *\n * This method identifies potential keyword tokens within the provided node and adds them to the\n * list of segments with the color defined in `this.schema.keywordColor`.\n * The method considers the current node, its first token, and its last token to determine if they should be highlighted\n * as keywords.\n *\n * The method checks if the node's kind falls within the range of keyword kinds defined by TypeScript.\n * If the node or any of its tokens are identified as keywords, a segment is added to `this.segments`\n * with the start and end positions of the node and the specified color for keywords.\n *\n * @param node - The TypeScript AST node to be processed for keywords.\n */\n\n private processKeywords(node: ts.Node): void {\n if ([\n SyntaxKind.NullKeyword,\n SyntaxKind.VoidKeyword,\n SyntaxKind.StringKeyword,\n SyntaxKind.NumberKeyword,\n SyntaxKind.BooleanKeyword,\n SyntaxKind.UndefinedKeyword\n ].includes(node.kind)) {\n return this.addSegment(node.getStart(), node.getEnd(), this.schema.typeColor);\n }\n\n if (node && node.kind >= ts.SyntaxKind.FirstKeyword && node.kind <= ts.SyntaxKind.LastKeyword) {\n this.addSegment(node.getStart(), node.getEnd(), this.schema.keywordColor);\n }\n }\n\n /**\n * Processes identifiers within a TypeScript AST node and adds them as segments for highlighting\n * based on the node's parent type.\n *\n * This method determines the appropriate color for an identifier based on its parent node's kind.\n * If the parent node matches one of the specified kinds, the identifier is highlighted with a cyan color.\n * Supported parent kinds include various declarations, expressions, and signatures.\n *\n * @param node - The TypeScript AST node representing the identifier to be processed.\n */\n\n private processIdentifier(node: ts.Node): void {\n const end = node.getEnd();\n const start = node.getStart();\n\n switch (node.parent.kind) {\n case ts.SyntaxKind.EnumMember:\n return this.addSegment(start, end, this.schema.enumColor);\n case ts.SyntaxKind.CallExpression:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.PropertySignature:\n case ts.SyntaxKind.ModuleDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.InterfaceDeclaration:\n return this.addSegment(start, end, this.schema.interfaceColor);\n case ts.SyntaxKind.GetAccessor:\n return this.addSegment(start, end, this.schema.getAccessorColor);\n case ts.SyntaxKind.PropertyAssignment:\n return this.addSegment(start, end, this.schema.propertyAssignmentColor);\n case ts.SyntaxKind.MethodSignature:\n return this.addSegment(start, end, this.schema.methodSignatureColor);\n case ts.SyntaxKind.MethodDeclaration:\n case ts.SyntaxKind.FunctionDeclaration:\n return this.addSegment(start, end, this.schema.functionColor);\n case ts.SyntaxKind.ClassDeclaration:\n return this.addSegment(start, end, this.schema.classColor);\n case ts.SyntaxKind.Parameter:\n return this.addSegment(start, end, this.schema.parameterColor);\n case ts.SyntaxKind.VariableDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyAccessExpression: {\n if (node.parent.getChildAt(0).getText() === node.getText()) {\n return this.addSegment(start, end, this.schema.variableColor);\n }\n\n return this.addSegment(start, end, this.schema.propertyAccessExpressionColor);\n }\n case ts.SyntaxKind.ExpressionWithTypeArguments:\n return this.addSegment(start, end, this.schema.expressionWithTypeArgumentsColor);\n case ts.SyntaxKind.BreakStatement:\n case ts.SyntaxKind.ShorthandPropertyAssignment:\n case ts.SyntaxKind.BindingElement:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.BinaryExpression:\n case ts.SyntaxKind.SwitchStatement:\n case ts.SyntaxKind.TemplateSpan:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.TypeReference:\n case ts.SyntaxKind.TypeAliasDeclaration:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.NewExpression:\n return this.addSegment(start, end, this.schema.variableColor);\n }\n }\n\n /**\n * Processes a TypeScript template expression and adds segments for highlighting its literal parts.\n *\n * This method adds a segment for the head of the template expression with the color specified in `this.schema.stringColor`.\n * It also processes each template span within the expression, adding\n * segments for each span's literal part.\n *\n * @param templateExpression - The TypeScript template expression to be processed.\n */\n\n private processTemplateExpression(templateExpression: ts.TemplateExpression): void {\n const start = templateExpression.head.getStart();\n const end = templateExpression.head.getEnd();\n this.addSegment(start, end, this.schema.stringColor);\n\n templateExpression.templateSpans.forEach(span => {\n const spanStart = span.literal.getStart();\n const spanEnd = span.literal.getEnd();\n this.addSegment(spanStart, spanEnd, this.schema.stringColor);\n });\n }\n\n /**\n * Processes a TypeScript AST node and adds segments for highlighting based on the node's kind.\n *\n * This method identifies the kind of the node and determines the appropriate color for highlighting.\n * It handles various node kinds including string literals, regular expressions, template expressions, and identifiers.\n * Specific methods are invoked for more complex node kinds, such as template expressions and identifiers.\n *\n * @param node - The TypeScript AST node to be processed.\n */\n\n private processNode(node: ts.Node): void {\n const start = node.getStart();\n const end = node.getEnd();\n\n switch (node.kind) {\n case ts.SyntaxKind.TypeParameter:\n return this.addSegment(start, start + (node as ts.TypeParameterDeclaration).name.text.length, this.schema.typeColor);\n case ts.SyntaxKind.TypeReference:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.StringLiteral:\n case ts.SyntaxKind.NoSubstitutionTemplateLiteral:\n return this.addSegment(start, end, this.schema.stringColor);\n case ts.SyntaxKind.RegularExpressionLiteral:\n return this.addSegment(start, end, this.schema.regularExpressionColor);\n case ts.SyntaxKind.TemplateExpression:\n return this.processTemplateExpression(node as ts.TemplateExpression);\n case ts.SyntaxKind.Identifier:\n return this.processIdentifier(node);\n case ts.SyntaxKind.BigIntLiteral:\n case ts.SyntaxKind.NumericLiteral:\n return this.addSegment(start, end, this.schema.numericLiteralColor);\n }\n }\n}\n\n/**\n * Applies semantic highlighting to the provided code string using the specified color scheme.\n *\n * @param code - The source code to be highlighted.\n * @param schema - An optional partial schema defining the color styles for various code elements.\n * Defaults to an empty object, which means no specific highlighting will be applied.\n *\n * @returns A string with the code elements wrapped in the appropriate color styles as specified by the schema.\n *\n * @example\n * const code = 'const x: number = 42;';\n * const schema = {\n * keywordColor: '\\x1b[34m', // Blue\n * stringColor: '\\x1b[32m', // Green\n * numberColor: '\\x1b[31m', // Red\n * reset: '\\x1b[0m' // Reset\n * };\n * const highlightedCode = highlightCode(code, schema);\n * console.log(highlightedCode);\n */\n\nexport function highlightCode(code: string, schema: Partial<HighlightSchemeInterface> = {}) {\n const sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const codeHighlighter = new CodeHighlighter(sourceFile, code, Object.assign(defaultScheme, schema));\n\n function walk(node: ts.Node): void {\n codeHighlighter.parseNode(node);\n\n for (let i = 0; i < node.getChildCount(); i++) {\n walk(node.getChildAt(i));\n }\n } ts.forEachChild(sourceFile, walk);\n\n return codeHighlighter.highlight();\n}\n"],
|
|
6
|
-
"mappings": "AAUA,UAAYA,MAAQ,aACpB,OAAS,cAAAC,MAAkB,aAmBpB,IAAWC,OACdA,EAAA,MAAQ,UACRA,EAAA,KAAO,iBACPA,EAAA,SAAW,iBACXA,EAAA,WAAa,iBACbA,EAAA,YAAc,iBACdA,EAAA,WAAa,iBACbA,EAAA,YAAc,iBACdA,EAAA,qBAAuB,iBACvBA,EAAA,YAAc,iBACdA,EAAA,aAAe,iBACfA,E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nB,KAAKA,EAAG,WAAW,8BACf,OAAO,KAAK,WAAWkB,EAAOC,EAAK,KAAK,OAAO,WAAW,EAC9D,KAAKnB,EAAG,WAAW,yBACf,OAAO,KAAK,WAAWkB,EAAOC,EAAK,KAAK,OAAO,sBAAsB,EACzE,KAAKnB,EAAG,WAAW,mBACf,OAAO,KAAK,0BAA0BQ,CAA6B,EACvE,KAAKR,EAAG,WAAW,WACf,OAAO,KAAK,kBAAkBQ,CAAI,EACtC,KAAKR,EAAG,WAAW,cACnB,KAAKA,EAAG,WAAW,eACf,OAAO,KAAK,WAAWkB,EAAOC,EAAK,KAAK,OAAO,mBAAmB,CAC1E,CACJ,CACJ,CAuBO,SAASS,EAActB,EAAcC,EAA4C,CAAC,EAAG,CACxF,MAAMF,EAAaL,EAAG,iBAAiB,UAAWM,EAAMN,EAAG,aAAa,OAAQ,GAAMA,EAAG,WAAW,EAAE,EAChG6B,EAAkB,IAAIzB,EAAgBC,EAAYC,EAAM,OAAO,OAAOH,EAAeI,CAAM,CAAC,EAElG,SAASuB,EAAKtB,EAAqB,CAC/BqB,EAAgB,UAAUrB,CAAI,EAE9B,QAAS,EAAI,EAAG,EAAIA,EAAK,cAAc,EAAG,IACtCsB,EAAKtB,EAAK,WAAW,CAAC,CAAC,CAE/B,CAAE,OAAAR,EAAG,aAAaK,EAAYyB,CAAI,EAE3BD,EAAgB,UAAU,CACrC",
|
|
7
|
-
"names": ["ts", "SyntaxKind", "Colors", "defaultScheme", "CodeHighlighter", "sourceFile", "code", "schema", "node", "previousSegmentEnd", "parent", "result", "a", "b", "segment", "lastSegment", "source", "combinedSource", "start", "end", "color", "reset", "key", "comment", "templateExpression", "span", "spanStart", "spanEnd", "highlightCode", "codeHighlighter", "walk"]
|
|
8
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
function g(o){const u=o.split(`
|
|
2
|
-
`).slice(1),m=/^\s*at\s+(.*?)\s+\((.*?):(\d+):(\d+)\)$|^\s*at\s+(.*?):(\d+):(\d+)$/,f=/eval\s+at\s+([^\s(]+).+\((.+):(\d+):(\d+)\),\s(.+)/,t=[];return u.forEach(n=>{const e=n.match(m);if(!e)return;let a=e.slice(1);e[2]||(a=e.slice(4));const[r,s,p,v]=a,c=parseInt(p,10),l=parseInt(v,10);if(n.includes("eval")){const i=s.match(f)?.slice(1);if(i){const[y,d,h,I,N]=i;t.push({at:r,file:N,line:c,column:l,executor:{at:y,file:d,line:parseInt(h,10),column:parseInt(I,10)}});return}}t.push({at:r||"<anonymous>",file:s,line:c,column:l,executor:null})}),t}export{g as parseErrorStack};
|
|
3
|
-
//# sourceMappingURL=parser.component.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/components/parser.component.ts"],
|
|
4
|
-
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/2.0.3/",
|
|
5
|
-
"sourcesContent": ["/**\n * Import will remove at compile time\n */\n\nimport type { StackEntryInterface } from './/interfaces/parse.interface.js';\n\n/**\n * Parses an error stack trace and returns an object with a message and an array of stack entries.\n *\n * @param stackString - The error stack trace.\n * @returns The parsed stack trace object.\n */\n\nexport function parseErrorStack(stackString: string): Array<StackEntryInterface> {\n const lines = stackString.split('\\n').slice(1);\n const regex = /^\\s*at\\s+(.*?)\\s+\\((.*?):(\\d+):(\\d+)\\)$|^\\s*at\\s+(.*?):(\\d+):(\\d+)$/;\n const evalRegex = /eval\\s+at\\s+([^\\s(]+).+\\((.+):(\\d+):(\\d+)\\),\\s(.+)/;\n const stack: Array<StackEntryInterface> = [];\n\n lines.forEach((line) => {\n const match = line.match(regex);\n if (!match) return;\n\n let args: Array<string> = match.slice(1);\n if(!match[2]) {\n args = match.slice(4);\n }\n\n const [ at, file, lineNum, colNum ] = args;\n const lineNumber = parseInt(lineNum, 10);\n const columnNumber = parseInt(colNum, 10);\n\n if (line.includes('eval')) {\n const evalMatch = file.match(evalRegex)?.slice(1);\n if (evalMatch) {\n const [ evalAt, evalFile, evalLineNum, evalColNum, evalAnonFile ] = evalMatch;\n stack.push({\n at,\n file: evalAnonFile,\n line: lineNumber,\n column: columnNumber,\n executor: {\n at: evalAt,\n file: evalFile,\n line: parseInt(evalLineNum, 10),\n column: parseInt(evalColNum, 10)\n }\n });\n\n return;\n }\n }\n\n stack.push({\n at: at || '<anonymous>',\n file,\n line: lineNumber,\n column: columnNumber,\n executor: null\n });\n });\n\n return stack;\n}\n"],
|
|
6
|
-
"mappings": "AAaO,SAASA,EAAgBC,EAAiD,CAC7E,MAAMC,EAAQD,EAAY,MAAM;AAAA,CAAI,EAAE,MAAM,CAAC,EACvCE,EAAQ,sEACRC,EAAY,qDACZC,EAAoC,CAAC,EAE3C,OAAAH,EAAM,QAASI,GAAS,CACpB,MAAMC,EAAQD,EAAK,MAAMH,CAAK,EAC9B,GAAI,CAACI,EAAO,OAEZ,IAAIC,EAAsBD,EAAM,MAAM,CAAC,EACnCA,EAAM,CAAC,IACPC,EAAOD,EAAM,MAAM,CAAC,GAGxB,KAAM,CAAEE,EAAIC,EAAMC,EAASC,CAAO,EAAIJ,EAChCK,EAAa,SAASF,EAAS,EAAE,EACjCG,EAAe,SAASF,EAAQ,EAAE,EAExC,GAAIN,EAAK,SAAS,MAAM,EAAG,CACvB,MAAMS,EAAYL,EAAK,MAAMN,CAAS,GAAG,MAAM,CAAC,EAChD,GAAIW,EAAW,CACX,KAAM,CAAEC,EAAQC,EAAUC,EAAaC,EAAYC,CAAa,EAAIL,EACpEV,EAAM,KAAK,CACP,GAAAI,EACA,KAAMW,EACN,KAAMP,EACN,OAAQC,EACR,SAAU,CACN,GAAIE,EACJ,KAAMC,EACN,KAAM,SAASC,EAAa,EAAE,EAC9B,OAAQ,SAASC,EAAY,EAAE,CACnC,CACJ,CAAC,EAED,MACJ,CACJ,CAEAd,EAAM,KAAK,CACP,GAAII,GAAM,cACV,KAAAC,EACA,KAAMG,EACN,OAAQC,EACR,SAAU,IACd,CAAC,CACL,CAAC,EAEMT,CACX",
|
|
7
|
-
"names": ["parseErrorStack", "stackString", "lines", "regex", "evalRegex", "stack", "line", "match", "args", "at", "file", "lineNum", "colNum", "lineNumber", "columnNumber", "evalMatch", "evalAt", "evalFile", "evalLineNum", "evalColNum", "evalAnonFile"]
|
|
8
|
-
}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/2.0.3/",
|
|
5
|
-
"sourcesContent": ["// export components interfaces\nexport type * from './components/interfaces/parse.interface.js';\nexport type * from './components/interfaces/formatter.interface.js';\nexport type * from './components/interfaces/highlighter.interface.js';\n\n// export services interfaces\nexport type * from './services/interfaces/source.interface.js';\n\n// Export components\nexport * from './components/parser.component.js';\nexport * from './components/base64.component.js';\nexport * from './components/formatter.component.js';\nexport * from './components/highlighter.component.js';\n\n// export service\nexport * from './services/source.service.js';\n"],
|
|
6
|
-
"mappings": "AASA,WAAc,mCACd,WAAc,mCACd,WAAc,sCACd,WAAc,wCAGd,WAAc",
|
|
7
|
-
"names": []
|
|
8
|
-
}
|
package/dist/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type": "module"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/providers/interfaces/mapping.interface.ts"],
|
|
4
|
-
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/2.0.3/",
|
|
5
|
-
"sourcesContent": ["/**\n * Represents a mapping segment that corresponds to a position in the source map.\n *\n * @property line - The original line number in the source file.\n * @property column - The original column number in the source file.\n * @property nameIndex - The index of the symbol name in the source map, or `null` if there is no associated name.\n * @property sourceIndex - The index of the source file in the source map.\n * @property generatedLine - The line number in the generated code.\n * @property generatedColumn - The column number in the generated code.\n */\n\nexport interface SegmentInterface {\n line: number;\n column: number;\n nameIndex: number | null;\n sourceIndex: number;\n generatedLine: number;\n generatedColumn: number;\n}\n\n/**\n * Extends the `SegmentInterface` to represent an offset segment used during mapping calculations.\n * The main difference is that `nameIndex` is always a number.\n *\n * @augments { SegmentInterface }\n * @property nameIndex - The index of the symbol name in the source map (cannot be null in this context).\n */\n\nexport interface SegmentOffsetInterface extends SegmentInterface {\n nameIndex: number;\n}\n\n/**\n * Represents the bias used when searching for segments in the source map.\n * This enum is useful for determining the preferred matching behavior\n * when the exact line and column cannot be found.\n *\n * @property BOUND - No preference for column matching; returns the first match found.\n * @property LOWER_BOUND - Prefer the closest mapping with a lower column value.\n * @property UPPER_BOUND - Prefer the closest mapping with a higher column value.\n */\n\nexport const enum Bias {\n BOUND,\n LOWER_BOUND,\n UPPER_BOUND\n}\n\n/**\n * A type alias for a frame in the source map, representing an array of segments.\n * Each frame consists of multiple mapping segments for a given line in the generated code.\n */\n\nexport type FrameType = Array<SegmentInterface>;\n\n/**\n * A type alias for the source map, where each entry represents a frame of mappings.\n * A frame can either be an array of segments (frame) or `null` if the line has no mappings (represented by a semicolon in the mapping string).\n */\n\nexport type MapType = Array<null | FrameType>;\n"],
|
|
6
|
-
"mappings": "AA0CO,IAAWA,OACdA,IAAA,iBACAA,IAAA,6BACAA,IAAA,6BAHcA,OAAA",
|
|
7
|
-
"names": ["Bias"]
|
|
8
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{Bias as c}from"./interfaces/mapping.interface.js";import{decodeVLQ as p,encodeArrayVLQ as g}from"../components/base64.component.js";class l{mapping=[];constructor(e,r=0,t=0){e=e instanceof l?e.mapping:e,Array.isArray(e)?this.decodeMappingArray(e,r,t):this.decodeMappingString(e,r,t)}encode(){return this.encodeMappings(this.mapping)}decode(e,r=0,t=0){e=e instanceof l?e.mapping:e,Array.isArray(e)?this.decodeMappingArray(e,r,t):this.decodeMappingString(e,r,t)}getSegment(e,r,t=c.BOUND){const d=this.mapping[e-1];if(!d||d.length===0)return null;let n=0,o=d.length-1,i=null;for(;n<=o;){const a=Math.floor((n+o)/2),u=d[a];if(u.generatedColumn<r)n=a+1,i=t===c.LOWER_BOUND?u:i;else if(u.generatedColumn>r)o=a-1,i=t===c.UPPER_BOUND?u:i;else return u}return i}getOriginalSegment(e,r,t,d=c.BOUND){let n=null;for(const o of this.mapping){if(!o)continue;let i=0,a=o.length-1;for(;i<=a;){const u=Math.floor((i+a)/2),s=o[u];if(s.sourceIndex<t||s.line<e)i=u+1;else if(s.sourceIndex>t||s.line>e)a=u-1;else if(s.column<r)i=u+1,n=d===c.LOWER_BOUND?s:n;else if(s.column>r)a=u-1,n=d===c.UPPER_BOUND?s:n;else return s}}return n}initPositionOffsets(e=0,r=0){return{line:0,column:0,nameIndex:e,sourceIndex:r,generatedLine:0,generatedColumn:0}}validateMappingString(e){return/^[a-zA-Z0-9+/,;]+$/.test(e)}validateSegment(e){if(!Number.isFinite(e.line))throw new Error(`Invalid segment: line must be a finite number, received ${e.line}`);if(!Number.isFinite(e.column))throw new Error(`Invalid segment: column must be a finite number, received ${e.column}`);if(e.nameIndex!==null&&!Number.isFinite(e.nameIndex))throw new Error(`Invalid segment: nameIndex must be a number or null, received ${e.nameIndex}`);if(!Number.isFinite(e.sourceIndex))throw new Error(`Invalid segment: sourceIndex must be a finite number, received ${e.sourceIndex}`);if(!Number.isFinite(e.generatedLine))throw new Error(`Invalid segment: generatedLine must be a finite number, received ${e.generatedLine}`);if(!Number.isFinite(e.generatedColumn))throw new Error(`Invalid segment: generatedColumn must be a finite number, received ${e.generatedColumn}`)}encodeSegment(e,r){const{line:t,column:d,generatedColumn:n,nameIndex:o,sourceIndex:i}=r,a=t-1,u=d-1,s=n-1,m=[s-e.generatedColumn,i!==e.sourceIndex?i-e.sourceIndex:0,a-e.line,u-e.column];return o!=null&&(m[4]=o-e.nameIndex,e.nameIndex=o),e.line=a,e.column=u,e.generatedColumn=s,e.sourceIndex=i,g(m)}encodeMappings(e){const r=this.initPositionOffsets();return e.map(t=>t?(r.generatedColumn=0,t.map(n=>this.encodeSegment(r,n)).join(",")):"").join(";")}decodedSegment(e,r){const[t,d,n,o,i]=r;return e.line+=n,e.column+=o,e.nameIndex+=i??0,e.sourceIndex+=d,e.generatedColumn+=t,{line:e.line+1,column:e.column+1,nameIndex:i!==void 0?e.nameIndex:null,sourceIndex:e.sourceIndex,generatedLine:e.generatedLine+1,generatedColumn:e.generatedColumn+1}}decodeMappingString(e,r,t){if(!this.validateMappingString(e))throw new Error("Invalid Mappings string format: the provided string does not conform to expected VLQ format.");const d=e.split(";"),n=this.mapping.length,o=this.initPositionOffsets(r,t);try{d.forEach((i,a)=>{if(!i){this.mapping.push(null);return}o.generatedColumn=0,o.generatedLine=n+a;const u=i.split(",").map(s=>this.decodedSegment(o,p(s)));this.mapping.push(u)})}catch(i){throw new Error(`Error decoding mappings at frame index ${d.length}: ${i.message}`)}}decodeMappingArray(e,r,t){const d=this.mapping.length;if(!Array.isArray(e))throw new Error("Invalid encoded map: expected an array of frames.");try{e.forEach((n,o)=>{if(!n){this.mapping.push(n);return}if(!Array.isArray(n))throw new Error(`Invalid Mappings array format at frame index ${o}: expected an array, received ${typeof n}.`);const i=n.map(a=>(this.validateSegment(a),{...a,nameIndex:typeof a.nameIndex=="number"?a.nameIndex+r:null,sourceIndex:a.sourceIndex+t,generatedLine:a.generatedLine+d}));this.mapping.push(i)})}catch(n){const o=n instanceof Error?n.message:"Unknown error";throw new Error(`Error decoding mappings: ${o}`)}}}export{l as MappingProvider};
|
|
2
|
-
//# sourceMappingURL=mapping.provider.js.map
|