@remotex-labs/xmap 3.0.1 → 3.0.3
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/dist/cjs/formatter.component.js.map +3 -3
- package/dist/cjs/highlighter.component.js.map +3 -3
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/parser.component.js +2 -2
- package/dist/cjs/parser.component.js.map +4 -4
- package/dist/esm/formatter.component.js.map +3 -3
- package/dist/esm/highlighter.component.js.map +3 -3
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/parser.component.js +2 -2
- package/dist/esm/parser.component.js.map +4 -4
- package/dist/formatter.component.d.ts +258 -0
- package/dist/{components/highlighter.component.d.ts → highlighter.component.d.ts} +94 -11
- package/dist/index.d.ts +866 -3
- package/dist/{components/parser.component.d.ts → parser.component.d.ts} +58 -14
- package/package.json +22 -18
- package/dist/components/base64.component.d.ts +0 -70
- package/dist/components/formatter.component.d.ts +0 -68
- package/dist/components/interfaces/formatter-component.interface.d.ts +0 -60
- package/dist/components/interfaces/highlighter-component.interface.d.ts +0 -94
- package/dist/components/interfaces/parse-component.interface.d.ts +0 -52
- package/dist/providers/interfaces/mapping-provider.interface.d.ts +0 -141
- package/dist/providers/mapping.provider.d.ts +0 -317
- package/dist/services/interfaces/source-service.interface.d.ts +0 -139
- package/dist/services/source.service.d.ts +0 -216
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A callback function for formatting code lines
|
|
3
|
+
*
|
|
4
|
+
* @param lineString - The content of the line to be formatted
|
|
5
|
+
* @param padding - The amount of padding to be applied to the line
|
|
6
|
+
* @param line - The line number of the line to be formatted
|
|
7
|
+
* @returns Formatted line string
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
export type FormatCodeCallbackType = (lineString: string, padding: number, line: number) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for formatting code
|
|
14
|
+
*
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
export interface FormatCodeInterface {
|
|
18
|
+
/**
|
|
19
|
+
* The amount of padding to be applied to each line
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
padding?: number;
|
|
23
|
+
/**
|
|
24
|
+
* The starting line number for formatting
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
startLine?: number;
|
|
28
|
+
/**
|
|
29
|
+
* An optional action object specifying a line where a callback function should be triggered.
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
*/
|
|
32
|
+
action?: {
|
|
33
|
+
/**
|
|
34
|
+
* The line number at which the callback function should be triggered.
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
*/
|
|
37
|
+
triggerLine: number;
|
|
38
|
+
/**
|
|
39
|
+
* The callback function to be executed when the trigger line is encountered.
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
*/
|
|
42
|
+
callback: FormatCodeCallbackType;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Configuration for ANSI color styling of error pointers
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
49
|
+
export interface AnsiOptionInterface {
|
|
50
|
+
/**
|
|
51
|
+
* ANSI color code to apply to the error pointer
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
*/
|
|
54
|
+
color: string;
|
|
55
|
+
/**
|
|
56
|
+
* ANSI reset code to restore default styling after the error pointer
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
*/
|
|
59
|
+
reset: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Represents a source map structure used for mapping code within a file to its original source
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
*/
|
|
65
|
+
export interface SourceMapInterface {
|
|
66
|
+
/**
|
|
67
|
+
* The generated file's name that the source map is associated with
|
|
68
|
+
* @since 1.0.0
|
|
69
|
+
*/
|
|
70
|
+
file?: string | null;
|
|
71
|
+
/**
|
|
72
|
+
* An array of variable/function names present in the original source
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
*/
|
|
75
|
+
names: Array<string>;
|
|
76
|
+
/**
|
|
77
|
+
* The version of the source map specification (standard is 3)
|
|
78
|
+
* @since 1.0.0
|
|
79
|
+
*/
|
|
80
|
+
version: number;
|
|
81
|
+
/**
|
|
82
|
+
* An array of URLs or paths to the original source files
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
*/
|
|
85
|
+
sources: Array<string>;
|
|
86
|
+
/**
|
|
87
|
+
* VLQ encoded string that maps generated code back to original source code
|
|
88
|
+
* @since 1.0.0
|
|
89
|
+
*/
|
|
90
|
+
mappings: string;
|
|
91
|
+
/**
|
|
92
|
+
* Root URL for resolving the sources
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
95
|
+
sourceRoot?: string | null;
|
|
96
|
+
/**
|
|
97
|
+
* Array containing the content of the original source files
|
|
98
|
+
* @since 1.0.0
|
|
99
|
+
*/
|
|
100
|
+
sourcesContent?: Array<string>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Represents a position in source code with mapping information
|
|
104
|
+
* @since 1.0.0
|
|
105
|
+
*/
|
|
106
|
+
export interface PositionInterface {
|
|
107
|
+
/**
|
|
108
|
+
* Name of the identifier at this position
|
|
109
|
+
* @since 1.0.0
|
|
110
|
+
*/
|
|
111
|
+
name: string | null;
|
|
112
|
+
/**
|
|
113
|
+
* Line number in the original source
|
|
114
|
+
* @since 1.0.0
|
|
115
|
+
*/
|
|
116
|
+
line: number;
|
|
117
|
+
/**
|
|
118
|
+
* Column number in the original source
|
|
119
|
+
* @since 1.0.0
|
|
120
|
+
*/
|
|
121
|
+
column: number;
|
|
122
|
+
/**
|
|
123
|
+
* Path or URL to the original source file
|
|
124
|
+
* @since 1.0.0
|
|
125
|
+
*/
|
|
126
|
+
source: string;
|
|
127
|
+
/**
|
|
128
|
+
* Root URL for resolving the source
|
|
129
|
+
* @since 1.0.0
|
|
130
|
+
*/
|
|
131
|
+
sourceRoot: string | null;
|
|
132
|
+
/**
|
|
133
|
+
* Index of the source in the sources array
|
|
134
|
+
* @since 1.0.0
|
|
135
|
+
*/
|
|
136
|
+
sourceIndex: number;
|
|
137
|
+
/**
|
|
138
|
+
* Line number in the generated code
|
|
139
|
+
* @since 1.0.0
|
|
140
|
+
*/
|
|
141
|
+
generatedLine: number;
|
|
142
|
+
/**
|
|
143
|
+
* Column number in the generated code
|
|
144
|
+
* @since 1.0.0
|
|
145
|
+
*/
|
|
146
|
+
generatedColumn: number;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Position in source code including the original source content
|
|
150
|
+
*
|
|
151
|
+
* @see PositionInterface
|
|
152
|
+
* @since 1.0.0
|
|
153
|
+
*/
|
|
154
|
+
export interface PositionWithContentInterface extends PositionInterface {
|
|
155
|
+
/**
|
|
156
|
+
* Content of the original source file
|
|
157
|
+
* @since 1.0.0
|
|
158
|
+
*/
|
|
159
|
+
sourcesContent: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Position in source code including code fragment information
|
|
163
|
+
*
|
|
164
|
+
* @see PositionInterface
|
|
165
|
+
* @since 1.0.0
|
|
166
|
+
*/
|
|
167
|
+
export interface PositionWithCodeInterface extends PositionInterface {
|
|
168
|
+
/**
|
|
169
|
+
* Code fragment from the original source
|
|
170
|
+
* @since 1.0.0
|
|
171
|
+
*/
|
|
172
|
+
code: string;
|
|
173
|
+
/**
|
|
174
|
+
* Ending line number of the code fragment
|
|
175
|
+
* @since 1.0.0
|
|
176
|
+
*/
|
|
177
|
+
endLine: number;
|
|
178
|
+
/**
|
|
179
|
+
* Starting line number of the code fragment
|
|
180
|
+
* @since 1.0.0
|
|
181
|
+
*/
|
|
182
|
+
startLine: number;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Options for retrieving source code context
|
|
186
|
+
* @since 1.0.0
|
|
187
|
+
*/
|
|
188
|
+
export interface SourceOptionsInterface {
|
|
189
|
+
/**
|
|
190
|
+
* Number of lines to include after the target line
|
|
191
|
+
* @since 1.0.0
|
|
192
|
+
*/
|
|
193
|
+
linesAfter?: number;
|
|
194
|
+
/**
|
|
195
|
+
* Number of lines to include before the target line
|
|
196
|
+
* @since 1.0.0
|
|
197
|
+
*/
|
|
198
|
+
linesBefore?: number;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Formats a code snippet with optional line padding and custom actions
|
|
202
|
+
*
|
|
203
|
+
* @param code - The source code | stack to be formatted
|
|
204
|
+
* @param options - Configuration options for formatting the code
|
|
205
|
+
* @returns A formatted string of the code snippet with applied padding and custom actions
|
|
206
|
+
*
|
|
207
|
+
* @remarks
|
|
208
|
+
* This function takes a code string and an options object to format the code snippet.
|
|
209
|
+
* It applies padding to line numbers and can trigger custom actions for specific lines.
|
|
210
|
+
* Options include padding (default 10), startLine (default 0), and custom actions for specific lines.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* const formattedCode = formatCode(code, {
|
|
215
|
+
* padding: 8,
|
|
216
|
+
* startLine: 5,
|
|
217
|
+
* action: {
|
|
218
|
+
* triggerLine: 7,
|
|
219
|
+
* callback: (lineString, padding, lineNumber) => {
|
|
220
|
+
* return `Custom formatting for line ${lineNumber}: ${lineString}`;
|
|
221
|
+
* }
|
|
222
|
+
* }
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @since 1.0.0
|
|
227
|
+
*/
|
|
228
|
+
export function formatCode(code: string, options?: FormatCodeInterface): string;
|
|
229
|
+
/**
|
|
230
|
+
* Formats a code snippet around an error location with special highlighting
|
|
231
|
+
*
|
|
232
|
+
* @param sourcePosition - An object containing information about the source code and error location
|
|
233
|
+
* @param ansiOption - Optional configuration for ANSI color codes
|
|
234
|
+
* @returns A formatted string representing the relevant code snippet with error highlighting
|
|
235
|
+
*
|
|
236
|
+
* @throws Error - If the provided sourcePosition object has invalid line or column numbers
|
|
237
|
+
*
|
|
238
|
+
* @remarks
|
|
239
|
+
* This function takes a sourcePosition object with code content and error location information,
|
|
240
|
+
* then uses formatCode to format and highlight the relevant code snippet around the error.
|
|
241
|
+
* The sourcePosition object should contain code (string), line (number), column (number),
|
|
242
|
+
* and optional startLine (number, defaults to 1).
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* const formattedErrorCode = formatErrorCode({
|
|
247
|
+
* code: "const x = 1;\nconst y = x.undefined;\n",
|
|
248
|
+
* line: 2,
|
|
249
|
+
* column: 15,
|
|
250
|
+
* startLine: 1
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @see formatCode - The underlying function used for basic code formatting
|
|
255
|
+
*
|
|
256
|
+
* @since 1.0.0
|
|
257
|
+
*/
|
|
258
|
+
export function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string;
|
|
@@ -1,15 +1,98 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
3
|
+
* Defines the color scheme for syntax highlighting different code elements.
|
|
4
|
+
*
|
|
5
|
+
* @interface HighlightSchemeInterface
|
|
6
|
+
*
|
|
7
|
+
* @property enumColor - Color code for enum declarations and references
|
|
8
|
+
* @property typeColor - Color code for type annotations and primitive types
|
|
9
|
+
* @property classColor - Color code for class declarations and references
|
|
10
|
+
* @property stringColor - Color code for string literals and template strings
|
|
11
|
+
* @property keywordColor - Color code for language keywords
|
|
12
|
+
* @property commentColor - Color code for comments (single-line and multi-line)
|
|
13
|
+
* @property functionColor - Color code for function declarations and calls
|
|
14
|
+
* @property variableColor - Color code for variable declarations and references
|
|
15
|
+
* @property interfaceColor - Color code for interface declarations and references
|
|
16
|
+
* @property parameterColor - Color code for function and method parameters
|
|
17
|
+
* @property getAccessorColor - Color code for getter accessor methods
|
|
18
|
+
* @property numericLiteralColor - Color code for numeric literals
|
|
19
|
+
* @property methodSignatureColor - Color code for method signatures in interfaces
|
|
20
|
+
* @property regularExpressionColor - Color code for regular expression literals
|
|
21
|
+
* @property propertyAssignmentColor - Color code for property assignments in object literals
|
|
22
|
+
* @property propertyAccessExpressionColor - Color code for property access expressions
|
|
23
|
+
* @property expressionWithTypeArgumentsColor - Color code for type arguments in expressions
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const darkTheme: HighlightSchemeInterface = {
|
|
28
|
+
* enumColor: Colors.cyan,
|
|
29
|
+
* typeColor: Colors.blue,
|
|
30
|
+
* classColor: Colors.yellow,
|
|
31
|
+
* // ...other color definitions
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @since 1.0.0
|
|
7
36
|
*/
|
|
8
|
-
|
|
37
|
+
export interface HighlightSchemeInterface {
|
|
38
|
+
enumColor: string;
|
|
39
|
+
typeColor: string;
|
|
40
|
+
classColor: string;
|
|
41
|
+
stringColor: string;
|
|
42
|
+
keywordColor: string;
|
|
43
|
+
commentColor: string;
|
|
44
|
+
functionColor: string;
|
|
45
|
+
variableColor: string;
|
|
46
|
+
interfaceColor: string;
|
|
47
|
+
parameterColor: string;
|
|
48
|
+
getAccessorColor: string;
|
|
49
|
+
numericLiteralColor: string;
|
|
50
|
+
methodSignatureColor: string;
|
|
51
|
+
regularExpressionColor: string;
|
|
52
|
+
propertyAssignmentColor: string;
|
|
53
|
+
propertyAccessExpressionColor: string;
|
|
54
|
+
expressionWithTypeArgumentsColor: string;
|
|
55
|
+
}
|
|
9
56
|
/**
|
|
10
|
-
*
|
|
57
|
+
* Represents a segment of source code to be highlighted with specific styling.
|
|
58
|
+
*
|
|
59
|
+
* @interface HighlightNodeSegmentInterface
|
|
60
|
+
*
|
|
61
|
+
* @property start - The starting character position of the segment in the source text
|
|
62
|
+
* @property end - The ending character position of the segment in the source text
|
|
63
|
+
* @property color - The color or style code to apply to this segment
|
|
64
|
+
* @property reset - The reset code that returns formatting to normal after this segment
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Segments are the fundamental units of the highlighting system.
|
|
68
|
+
* Each segment represents a portion of text that should receive specific styling.
|
|
69
|
+
* When the source code is processed for display,
|
|
70
|
+
* these segments are used to insert the appropriate color/style codes at the correct positions.
|
|
71
|
+
*
|
|
72
|
+
* The highlighter maintains a collection of these segments and applies them
|
|
73
|
+
* in position order to create the complete highlighted output.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const keywordSegment: HighlightNodeSegmentInterface = {
|
|
78
|
+
* start: 0,
|
|
79
|
+
* end: 6,
|
|
80
|
+
* color: '\x1b[34m', // Blue for the keyword "import"
|
|
81
|
+
* reset: '\x1b[0m' // Reset to default
|
|
82
|
+
* };
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @see HighlightSchemeInterface
|
|
86
|
+
* @see addSegment
|
|
87
|
+
*
|
|
88
|
+
* @since 1.0.0
|
|
11
89
|
*/
|
|
12
|
-
|
|
90
|
+
export interface HighlightNodeSegmentInterface {
|
|
91
|
+
end: number;
|
|
92
|
+
start: number;
|
|
93
|
+
color: string;
|
|
94
|
+
reset: string;
|
|
95
|
+
}
|
|
13
96
|
/**
|
|
14
97
|
* An enum containing ANSI escape sequences for various colors
|
|
15
98
|
*
|
|
@@ -24,7 +107,7 @@ import * as ts from 'typescript';
|
|
|
24
107
|
*
|
|
25
108
|
* @since 1.0.0
|
|
26
109
|
*/
|
|
27
|
-
export
|
|
110
|
+
export const enum Colors {
|
|
28
111
|
reset = "\u001B[0m",
|
|
29
112
|
gray = "\u001B[38;5;243m",
|
|
30
113
|
darkGray = "\u001B[38;5;238m",
|
|
@@ -56,7 +139,7 @@ export declare const enum Colors {
|
|
|
56
139
|
*
|
|
57
140
|
* @since 1.0.0
|
|
58
141
|
*/
|
|
59
|
-
export
|
|
142
|
+
export class CodeHighlighter {
|
|
60
143
|
private sourceFile;
|
|
61
144
|
private code;
|
|
62
145
|
private schema;
|
|
@@ -337,4 +420,4 @@ export declare class CodeHighlighter {
|
|
|
337
420
|
*
|
|
338
421
|
* @since 1.0.0
|
|
339
422
|
*/
|
|
340
|
-
export
|
|
423
|
+
export function highlightCode(code: string, schema?: Partial<HighlightSchemeInterface>): string;
|