@remotex-labs/xmap 2.0.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -27
- package/dist/cjs/formatter.component.js +5 -0
- package/dist/cjs/formatter.component.js.map +8 -0
- package/dist/cjs/highlighter.component.js +2 -0
- package/dist/cjs/highlighter.component.js.map +8 -0
- package/dist/cjs/index.js +3 -7
- package/dist/cjs/index.js.map +5 -5
- package/dist/cjs/parser.component.js +3 -0
- package/dist/cjs/parser.component.js.map +8 -0
- package/dist/components/base64.component.d.ts +58 -14
- package/dist/components/formatter.component.d.ts +37 -35
- package/dist/components/highlighter.component.d.ts +228 -74
- package/dist/components/interfaces/{formatter.interface.d.ts → formatter-component.interface.d.ts} +27 -9
- package/dist/components/interfaces/highlighter-component.interface.d.ts +94 -0
- package/dist/components/interfaces/parse-component.interface.d.ts +52 -0
- package/dist/components/parser.component.d.ts +216 -5
- package/dist/esm/formatter.component.js +5 -0
- package/dist/esm/formatter.component.js.map +8 -0
- package/dist/esm/highlighter.component.js +2 -0
- package/dist/esm/highlighter.component.js.map +8 -0
- package/dist/esm/index.js +3 -7
- package/dist/esm/index.js.map +5 -5
- package/dist/esm/parser.component.js +3 -0
- package/dist/esm/parser.component.js.map +8 -0
- package/dist/index.d.ts +3 -9
- package/dist/providers/interfaces/mapping-provider.interface.d.ts +141 -0
- package/dist/providers/mapping.provider.d.ts +258 -174
- package/dist/services/interfaces/source-service.interface.d.ts +139 -0
- package/dist/services/source.service.d.ts +96 -97
- package/package.json +37 -11
- package/dist/components/interfaces/highlighter.interface.d.ts +0 -48
- package/dist/components/interfaces/parse.interface.d.ts +0 -31
- package/dist/providers/interfaces/mapping.interface.d.ts +0 -52
- package/dist/services/interfaces/source.interface.d.ts +0 -53
|
@@ -1,26 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Export interfaces
|
|
3
|
+
*/
|
|
4
|
+
export type { HighlightSchemeInterface, HighlightNodeSegmentInterface } from "./interfaces/highlighter-component.interface";
|
|
1
5
|
/**
|
|
2
6
|
* Import will remove at compile time
|
|
3
7
|
*/
|
|
4
|
-
import type { HighlightSchemeInterface } from "./interfaces/highlighter.interface";
|
|
8
|
+
import type { HighlightSchemeInterface } from "./interfaces/highlighter-component.interface";
|
|
5
9
|
/**
|
|
6
10
|
* Imports
|
|
7
11
|
*/
|
|
8
12
|
import * as ts from 'typescript';
|
|
9
13
|
/**
|
|
10
|
-
* An enum containing ANSI escape sequences for various colors
|
|
14
|
+
* An enum containing ANSI escape sequences for various colors
|
|
11
15
|
*
|
|
16
|
+
* @remarks
|
|
12
17
|
* This enum is primarily intended for terminal output and won't work directly in JavaScript for web development.
|
|
13
|
-
* It defines color codes for various colors and a reset code to return to
|
|
14
|
-
* the default text color.
|
|
18
|
+
* It defines color codes for various colors and a reset code to return to the default text color.
|
|
15
19
|
*
|
|
16
20
|
* @example
|
|
17
|
-
* ```
|
|
18
|
-
* console.log(`${Colors.red}This
|
|
21
|
+
* ```ts
|
|
22
|
+
* console.log(`${Colors.red}This text will be red in the terminal.${Colors.reset}`);
|
|
19
23
|
* ```
|
|
20
24
|
*
|
|
21
|
-
*
|
|
22
|
-
* Consider alternative methods
|
|
23
|
-
* for color highlighting in web development contexts, such as CSS classes.
|
|
25
|
+
* @since 1.0.0
|
|
24
26
|
*/
|
|
25
27
|
export declare const enum Colors {
|
|
26
28
|
reset = "\u001B[0m",
|
|
@@ -38,149 +40,301 @@ export declare const enum Colors {
|
|
|
38
40
|
brightPink = "\u001B[38;5;197m"
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
41
|
-
* Class responsible for applying semantic highlighting to a source code string based on a given color scheme
|
|
43
|
+
* Class responsible for applying semantic highlighting to a source code string based on a given color scheme
|
|
42
44
|
*
|
|
43
|
-
* @
|
|
45
|
+
* @remarks
|
|
46
|
+
* Processes TypeScript AST nodes and applies color formatting to different code elements
|
|
47
|
+
* according to the provided color scheme.
|
|
44
48
|
*
|
|
45
|
-
* @
|
|
46
|
-
*
|
|
47
|
-
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const sourceFile = ts.createSourceFile('example.ts', code, ts.ScriptTarget.Latest);
|
|
52
|
+
* const highlighter = new CodeHighlighter(sourceFile, code, customScheme);
|
|
53
|
+
* highlighter.parseNode(sourceFile);
|
|
54
|
+
* const highlightedCode = highlighter.highlight();
|
|
55
|
+
* ```
|
|
48
56
|
*
|
|
49
|
-
*
|
|
57
|
+
* @since 1.0.0
|
|
50
58
|
*/
|
|
51
59
|
export declare class CodeHighlighter {
|
|
52
60
|
private sourceFile;
|
|
53
61
|
private code;
|
|
54
62
|
private schema;
|
|
55
63
|
/**
|
|
56
|
-
* A Map of segments where the key is a combination of start and end positions
|
|
57
|
-
*
|
|
64
|
+
* A Map of segments where the key is a combination of start and end positions.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
58
67
|
* This structure ensures unique segments and allows for fast lookups and updates.
|
|
59
68
|
*
|
|
60
|
-
* @
|
|
61
|
-
*
|
|
62
|
-
* ['0-10', { start: 1, end: 11, color: '\x1b[31m', reset: '\x1b[0m' }],
|
|
63
|
-
* ['11-20', { start: 12, end: 20, color: '\x1b[32m', reset: '\x1b[0m' }]
|
|
64
|
-
* ]);
|
|
69
|
+
* @see HighlightNodeSegmentInterface
|
|
70
|
+
* @since 1.0.0
|
|
65
71
|
*/
|
|
66
72
|
private segments;
|
|
67
73
|
/**
|
|
68
74
|
* Creates an instance of the CodeHighlighter class.
|
|
69
75
|
*
|
|
70
|
-
* @param sourceFile - The TypeScript AST node representing the source file
|
|
71
|
-
* @param code - The source code string to be highlighted
|
|
72
|
-
* @param schema - The color scheme used for highlighting different elements in the code
|
|
76
|
+
* @param sourceFile - The TypeScript AST node representing the source file
|
|
77
|
+
* @param code - The source code string to be highlighted
|
|
78
|
+
* @param schema - The color scheme used for highlighting different elements in the code
|
|
79
|
+
*
|
|
80
|
+
* @since 1.0.0
|
|
73
81
|
*/
|
|
74
82
|
constructor(sourceFile: ts.Node, code: string, schema: HighlightSchemeInterface);
|
|
75
83
|
/**
|
|
76
84
|
* Parses a TypeScript AST node and processes its comments to identify segments that need highlighting.
|
|
77
85
|
*
|
|
78
|
-
* @param node - The TypeScript AST node to be parsed
|
|
86
|
+
* @param node - The TypeScript AST node to be parsed
|
|
87
|
+
*
|
|
88
|
+
* @since 1.0.0
|
|
79
89
|
*/
|
|
80
90
|
parseNode(node: ts.Node): void;
|
|
81
91
|
/**
|
|
82
92
|
* Generates a string with highlighted code segments based on the provided color scheme.
|
|
83
93
|
*
|
|
94
|
+
* @returns The highlighted code as a string, with ANSI color codes applied to the segments
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
84
97
|
* This method processes the stored segments, applies the appropriate colors to each segment,
|
|
85
98
|
* and returns the resulting highlighted code as a single string.
|
|
86
99
|
*
|
|
87
|
-
* @
|
|
100
|
+
* @since 1.0.0
|
|
88
101
|
*/
|
|
89
102
|
highlight(): string;
|
|
90
103
|
/**
|
|
91
|
-
* Extracts a
|
|
104
|
+
* Extracts a text segment from the source code using position indices.
|
|
105
|
+
*
|
|
106
|
+
* @param start - The starting index position in the source text
|
|
107
|
+
* @param end - The ending index position in the source text (optional)
|
|
108
|
+
* @returns The substring of source text between the start and end positions
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* This utility method provides access to specific portions of the source code
|
|
112
|
+
* based on character positions. When the end parameter is omitted, the extraction
|
|
113
|
+
* will continue to the end of the source text.
|
|
114
|
+
*
|
|
115
|
+
* This method is typically used during the highlighting process to access the
|
|
116
|
+
* actual text content that corresponds to syntax nodes or other text ranges
|
|
117
|
+
* before applying formatting.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* // Extract a variable name
|
|
122
|
+
* const variableName = this.getSegmentSource(10, 15);
|
|
92
123
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
124
|
+
* // Extract from a position to the end of source
|
|
125
|
+
* const remaining = this.getSegmentSource(100);
|
|
126
|
+
* ```
|
|
96
127
|
*
|
|
97
|
-
* @
|
|
98
|
-
* @
|
|
99
|
-
*
|
|
128
|
+
* @see addSegment
|
|
129
|
+
* @see highlight
|
|
130
|
+
*
|
|
131
|
+
* @since 1.0.0
|
|
100
132
|
*/
|
|
101
133
|
private getSegmentSource;
|
|
102
134
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
135
|
+
* Registers a text segment for syntax highlighting with specified style information.
|
|
136
|
+
*
|
|
137
|
+
* @param start - The starting position of the segment in the source text
|
|
138
|
+
* @param end - The ending position of the segment in the source text
|
|
139
|
+
* @param color - The color code to apply to this segment
|
|
140
|
+
* @param reset - The color reset code to apply after the segment (defaults to the standard reset code)
|
|
141
|
+
*
|
|
142
|
+
* @remarks
|
|
143
|
+
* This method creates a unique key for each segment based on its position and stores the segment information in a map.
|
|
144
|
+
* Each segment contains its position information, styling code,
|
|
145
|
+
* and reset code which will later be used during the highlighting process.
|
|
146
|
+
*
|
|
147
|
+
* If multiple segments are added with the same positions, the later additions will
|
|
148
|
+
* overwrite earlier ones due to the map's key-based storage.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* // Highlight a variable name in red
|
|
153
|
+
* this.addSegment(10, 15, Colors.red);
|
|
154
|
+
*
|
|
155
|
+
* // Highlight a keyword with custom color and reset
|
|
156
|
+
* this.addSegment(20, 26, Colors.blue, Colors.customReset);
|
|
157
|
+
* ```
|
|
105
158
|
*
|
|
106
|
-
* @
|
|
107
|
-
* @
|
|
108
|
-
*
|
|
109
|
-
* @
|
|
159
|
+
* @see Colors
|
|
160
|
+
* @see processNode
|
|
161
|
+
*
|
|
162
|
+
* @since 1.0.0
|
|
110
163
|
*/
|
|
111
164
|
private addSegment;
|
|
112
165
|
/**
|
|
113
|
-
* Processes comments
|
|
114
|
-
*
|
|
166
|
+
* Processes and highlights comments associated with a TypeScript AST node.
|
|
167
|
+
*
|
|
168
|
+
* @param node - The TypeScript AST node whose comments are to be processed
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* This method identifies both leading and trailing comments associated with the given node
|
|
172
|
+
* and adds them to the highlighting segments.
|
|
173
|
+
* The comments are extracted from the full source text using TypeScript's utility functions
|
|
174
|
+
* and are highlighted using the color specified
|
|
175
|
+
* in the schema's commentColor property.
|
|
176
|
+
*
|
|
177
|
+
* Leading comments appear before the node, while trailing comments appear after it.
|
|
178
|
+
* Both types are processed with the same highlighting style.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* // For a node that might have comments like:
|
|
183
|
+
* // This is a leading comment
|
|
184
|
+
* const x = 5; // This is a trailing comment
|
|
115
185
|
*
|
|
116
|
-
*
|
|
186
|
+
* this.processComments(someNode);
|
|
187
|
+
* // Both comments will be added to segments with the comment color
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @see addSegment
|
|
191
|
+
* @see ts.getLeadingCommentRanges
|
|
192
|
+
* @see ts.getTrailingCommentRanges
|
|
193
|
+
*
|
|
194
|
+
* @since 1.0.0
|
|
117
195
|
*/
|
|
118
196
|
private processComments;
|
|
119
197
|
/**
|
|
120
|
-
* Processes
|
|
198
|
+
* Processes TypeScript keywords and primitive type references in an AST node for syntax highlighting.
|
|
199
|
+
*
|
|
200
|
+
* @param node - The TypeScript AST node to be processed for keywords
|
|
201
|
+
*
|
|
202
|
+
* @remarks
|
|
203
|
+
* This method handles two categories of tokens that require special highlighting:
|
|
121
204
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* The method considers the current node, its first token, and its last token to determine if they should be highlighted
|
|
125
|
-
* as keywords.
|
|
205
|
+
* 1. Primitive type references: Highlights references to built-in types like `null`,
|
|
206
|
+
* `void`, `string`, `number`, `boolean`, and `undefined` using the type color.
|
|
126
207
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
208
|
+
* 2. TypeScript keywords: Identifies any node whose kind falls within the TypeScript
|
|
209
|
+
* keyword range (between FirstKeyword and LastKeyword) and highlights it using
|
|
210
|
+
* the keyword color.
|
|
211
|
+
*
|
|
212
|
+
* Each identified token is added to the segments collection with appropriate position
|
|
213
|
+
* and color information.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* // Inside syntax highlighting process
|
|
218
|
+
* this.processKeywords(someNode);
|
|
219
|
+
* // If the node represents a keyword like 'const' or a primitive type like 'string',
|
|
220
|
+
* // it will be added to the segments with the appropriate color
|
|
221
|
+
* ```
|
|
130
222
|
*
|
|
131
|
-
* @
|
|
223
|
+
* @see addSegment
|
|
224
|
+
* @see ts.SyntaxKind
|
|
225
|
+
*
|
|
226
|
+
* @since 1.0.0
|
|
132
227
|
*/
|
|
133
228
|
private processKeywords;
|
|
134
229
|
/**
|
|
135
|
-
* Processes
|
|
136
|
-
*
|
|
230
|
+
* Processes identifier nodes and applies appropriate syntax highlighting based on their context.
|
|
231
|
+
*
|
|
232
|
+
* @param node - The TypeScript AST node representing the identifier to be processed
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* This method determines the appropriate color for an identifier by examining its parent node's kind.
|
|
236
|
+
* Different colors are applied based on the identifier's role in the code:
|
|
237
|
+
* - Enum members use enumColor
|
|
238
|
+
* - Interface names use interfaceColor
|
|
239
|
+
* - Class names use classColor
|
|
240
|
+
* - Function and method names use functionColor
|
|
241
|
+
* - Parameters use parameterColor
|
|
242
|
+
* - Variables and properties use variableColor
|
|
243
|
+
* - Types use typeColor
|
|
244
|
+
* - And more specialized cases for other syntax kinds
|
|
245
|
+
*
|
|
246
|
+
* Special handling is applied to property access expressions to differentiate between
|
|
247
|
+
* the object being accessed and the property being accessed.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* // Inside the CodeHighlighter class
|
|
252
|
+
* const identifierNode = getIdentifierNode(); // Get some identifier node
|
|
253
|
+
* this.processIdentifier(identifierNode);
|
|
254
|
+
* // The identifier is now added to segments with appropriate color based on its context
|
|
255
|
+
* ```
|
|
137
256
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* Supported parent kinds include various declarations, expressions, and signatures.
|
|
257
|
+
* @see addSegment
|
|
258
|
+
* @see HighlightSchemeInterface
|
|
141
259
|
*
|
|
142
|
-
* @
|
|
260
|
+
* @since 1.0.0
|
|
143
261
|
*/
|
|
144
262
|
private processIdentifier;
|
|
145
263
|
/**
|
|
146
|
-
* Processes a TypeScript template expression and adds segments for
|
|
264
|
+
* Processes a TypeScript template expression and adds highlighting segments for its literal parts.
|
|
147
265
|
*
|
|
148
|
-
*
|
|
149
|
-
* It also processes each template span within the expression, adding
|
|
150
|
-
* segments for each span's literal part.
|
|
266
|
+
* @param templateExpression - The TypeScript template expression to be processed
|
|
151
267
|
*
|
|
152
|
-
* @
|
|
268
|
+
* @remarks
|
|
269
|
+
* This method adds color segments for both the template head and each template span's literal part.
|
|
270
|
+
* All template string components are highlighted using the color defined in the schema's stringColor.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* // Given a template expression like: `Hello ${name}`
|
|
275
|
+
* this.processTemplateExpression(templateNode);
|
|
276
|
+
* // Both "Hello " and the closing part after the expression will be highlighted
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @see addSegment
|
|
280
|
+
*
|
|
281
|
+
* @since 1.0.0
|
|
153
282
|
*/
|
|
154
283
|
private processTemplateExpression;
|
|
155
284
|
/**
|
|
156
|
-
* Processes a TypeScript AST node and adds segments
|
|
285
|
+
* Processes a TypeScript AST node and adds highlighting segments based on the node's kind.
|
|
157
286
|
*
|
|
158
|
-
*
|
|
159
|
-
* It handles various node kinds including string literals, regular expressions, template expressions, and identifiers.
|
|
160
|
-
* Specific methods are invoked for more complex node kinds, such as template expressions and identifiers.
|
|
287
|
+
* @param node - The TypeScript AST node to be processed
|
|
161
288
|
*
|
|
162
|
-
* @
|
|
289
|
+
* @remarks
|
|
290
|
+
* This method identifies the node's kind and applies the appropriate color for highlighting.
|
|
291
|
+
* It handles various syntax kinds including literals (string, numeric, regular expressions),
|
|
292
|
+
* template expressions, identifiers, and type references.
|
|
293
|
+
* For complex node types like template expressions and identifiers, it delegates to specialized processing methods.
|
|
294
|
+
*
|
|
295
|
+
* @throws Error - When casting to TypeParameterDeclaration fails for non-compatible node kinds
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* // Inside the CodeHighlighter class
|
|
300
|
+
* const node = sourceFile.getChildAt(0);
|
|
301
|
+
* this.processNode(node);
|
|
302
|
+
* // Node is now added to the segments map with appropriate colors
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @see processTemplateExpression
|
|
306
|
+
* @see processIdentifier
|
|
307
|
+
*
|
|
308
|
+
* @since 1.0.0
|
|
163
309
|
*/
|
|
164
310
|
private processNode;
|
|
165
311
|
}
|
|
166
312
|
/**
|
|
167
313
|
* Applies semantic highlighting to the provided code string using the specified color scheme.
|
|
168
314
|
*
|
|
169
|
-
* @param code - The source code to be highlighted
|
|
170
|
-
* @param schema - An optional partial schema defining the color styles for various code elements
|
|
171
|
-
*
|
|
315
|
+
* @param code - The source code to be highlighted
|
|
316
|
+
* @param schema - An optional partial schema defining the color styles for various code elements
|
|
317
|
+
*
|
|
318
|
+
* @returns A string with the code elements wrapped in the appropriate color styles
|
|
172
319
|
*
|
|
173
|
-
* @
|
|
320
|
+
* @remarks
|
|
321
|
+
* If no schema is provided, the default schema will be used. The function creates a TypeScript
|
|
322
|
+
* source file from the provided code and walks through its AST to apply syntax highlighting.
|
|
174
323
|
*
|
|
175
324
|
* @example
|
|
325
|
+
* ```ts
|
|
176
326
|
* const code = 'const x: number = 42;';
|
|
177
327
|
* const schema = {
|
|
178
328
|
* keywordColor: '\x1b[34m', // Blue
|
|
179
|
-
* stringColor: '\x1b[32m', // Green
|
|
180
329
|
* numberColor: '\x1b[31m', // Red
|
|
181
|
-
* reset: '\x1b[0m' // Reset
|
|
182
330
|
* };
|
|
183
331
|
* const highlightedCode = highlightCode(code, schema);
|
|
184
332
|
* console.log(highlightedCode);
|
|
333
|
+
* ```
|
|
334
|
+
*
|
|
335
|
+
* @see CodeHighlighter
|
|
336
|
+
* @see HighlightSchemeInterface
|
|
337
|
+
*
|
|
338
|
+
* @since 1.0.0
|
|
185
339
|
*/
|
|
186
340
|
export declare function highlightCode(code: string, schema?: Partial<HighlightSchemeInterface>): string;
|
package/dist/components/interfaces/{formatter.interface.d.ts → formatter-component.interface.d.ts}
RENAMED
|
@@ -1,42 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A callback function
|
|
2
|
+
* A callback function for formatting code lines
|
|
3
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
|
|
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
|
|
8
10
|
*/
|
|
9
11
|
export type FormatCodeCallbackType = (lineString: string, padding: number, line: number) => string;
|
|
10
12
|
/**
|
|
11
|
-
* Configuration options for formatting code
|
|
13
|
+
* Configuration options for formatting code
|
|
14
|
+
*
|
|
15
|
+
* @since 1.0.0
|
|
12
16
|
*/
|
|
13
17
|
export interface FormatCodeInterface {
|
|
14
18
|
/**
|
|
15
|
-
* The amount of padding to be applied to each line
|
|
19
|
+
* The amount of padding to be applied to each line
|
|
20
|
+
* @since 1.0.0
|
|
16
21
|
*/
|
|
17
22
|
padding?: number;
|
|
18
23
|
/**
|
|
19
|
-
* The starting line number for formatting
|
|
24
|
+
* The starting line number for formatting
|
|
25
|
+
* @since 1.0.0
|
|
20
26
|
*/
|
|
21
27
|
startLine?: number;
|
|
22
28
|
/**
|
|
23
29
|
* An optional action object specifying a line where a callback function should be triggered.
|
|
30
|
+
* @since 1.0.0
|
|
24
31
|
*/
|
|
25
32
|
action?: {
|
|
26
33
|
/**
|
|
27
34
|
* The line number at which the callback function should be triggered.
|
|
35
|
+
* @since 1.0.0
|
|
28
36
|
*/
|
|
29
37
|
triggerLine: number;
|
|
30
38
|
/**
|
|
31
39
|
* The callback function to be executed when the trigger line is encountered.
|
|
40
|
+
* @since 1.0.0
|
|
32
41
|
*/
|
|
33
42
|
callback: FormatCodeCallbackType;
|
|
34
43
|
};
|
|
35
44
|
}
|
|
36
45
|
/**
|
|
37
|
-
*
|
|
46
|
+
* Configuration for ANSI color styling of error pointers
|
|
47
|
+
* @since 1.0.0
|
|
38
48
|
*/
|
|
39
49
|
export interface AnsiOptionInterface {
|
|
50
|
+
/**
|
|
51
|
+
* ANSI color code to apply to the error pointer
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
*/
|
|
40
54
|
color: string;
|
|
55
|
+
/**
|
|
56
|
+
* ANSI reset code to restore default styling after the error pointer
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
*/
|
|
41
59
|
reset: string;
|
|
42
60
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the color scheme for syntax highlighting different code elements.
|
|
3
|
+
*
|
|
4
|
+
* @interface HighlightSchemeInterface
|
|
5
|
+
*
|
|
6
|
+
* @property enumColor - Color code for enum declarations and references
|
|
7
|
+
* @property typeColor - Color code for type annotations and primitive types
|
|
8
|
+
* @property classColor - Color code for class declarations and references
|
|
9
|
+
* @property stringColor - Color code for string literals and template strings
|
|
10
|
+
* @property keywordColor - Color code for language keywords
|
|
11
|
+
* @property commentColor - Color code for comments (single-line and multi-line)
|
|
12
|
+
* @property functionColor - Color code for function declarations and calls
|
|
13
|
+
* @property variableColor - Color code for variable declarations and references
|
|
14
|
+
* @property interfaceColor - Color code for interface declarations and references
|
|
15
|
+
* @property parameterColor - Color code for function and method parameters
|
|
16
|
+
* @property getAccessorColor - Color code for getter accessor methods
|
|
17
|
+
* @property numericLiteralColor - Color code for numeric literals
|
|
18
|
+
* @property methodSignatureColor - Color code for method signatures in interfaces
|
|
19
|
+
* @property regularExpressionColor - Color code for regular expression literals
|
|
20
|
+
* @property propertyAssignmentColor - Color code for property assignments in object literals
|
|
21
|
+
* @property propertyAccessExpressionColor - Color code for property access expressions
|
|
22
|
+
* @property expressionWithTypeArgumentsColor - Color code for type arguments in expressions
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const darkTheme: HighlightSchemeInterface = {
|
|
27
|
+
* enumColor: Colors.cyan,
|
|
28
|
+
* typeColor: Colors.blue,
|
|
29
|
+
* classColor: Colors.yellow,
|
|
30
|
+
* // ...other color definitions
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
export interface HighlightSchemeInterface {
|
|
37
|
+
enumColor: string;
|
|
38
|
+
typeColor: string;
|
|
39
|
+
classColor: string;
|
|
40
|
+
stringColor: string;
|
|
41
|
+
keywordColor: string;
|
|
42
|
+
commentColor: string;
|
|
43
|
+
functionColor: string;
|
|
44
|
+
variableColor: string;
|
|
45
|
+
interfaceColor: string;
|
|
46
|
+
parameterColor: string;
|
|
47
|
+
getAccessorColor: string;
|
|
48
|
+
numericLiteralColor: string;
|
|
49
|
+
methodSignatureColor: string;
|
|
50
|
+
regularExpressionColor: string;
|
|
51
|
+
propertyAssignmentColor: string;
|
|
52
|
+
propertyAccessExpressionColor: string;
|
|
53
|
+
expressionWithTypeArgumentsColor: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents a segment of source code to be highlighted with specific styling.
|
|
57
|
+
*
|
|
58
|
+
* @interface HighlightNodeSegmentInterface
|
|
59
|
+
*
|
|
60
|
+
* @property start - The starting character position of the segment in the source text
|
|
61
|
+
* @property end - The ending character position of the segment in the source text
|
|
62
|
+
* @property color - The color or style code to apply to this segment
|
|
63
|
+
* @property reset - The reset code that returns formatting to normal after this segment
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Segments are the fundamental units of the highlighting system.
|
|
67
|
+
* Each segment represents a portion of text that should receive specific styling.
|
|
68
|
+
* When the source code is processed for display,
|
|
69
|
+
* these segments are used to insert the appropriate color/style codes at the correct positions.
|
|
70
|
+
*
|
|
71
|
+
* The highlighter maintains a collection of these segments and applies them
|
|
72
|
+
* in position order to create the complete highlighted output.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const keywordSegment: HighlightNodeSegmentInterface = {
|
|
77
|
+
* start: 0,
|
|
78
|
+
* end: 6,
|
|
79
|
+
* color: '\x1b[34m', // Blue for the keyword "import"
|
|
80
|
+
* reset: '\x1b[0m' // Reset to default
|
|
81
|
+
* };
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @see HighlightSchemeInterface
|
|
85
|
+
* @see addSegment
|
|
86
|
+
*
|
|
87
|
+
* @since 1.0.0
|
|
88
|
+
*/
|
|
89
|
+
export interface HighlightNodeSegmentInterface {
|
|
90
|
+
end: number;
|
|
91
|
+
start: number;
|
|
92
|
+
color: string;
|
|
93
|
+
reset: string;
|
|
94
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface representing a stack frame in a stack trace.
|
|
3
|
+
*
|
|
4
|
+
* This structure provides detailed information about the location
|
|
5
|
+
* of a specific frame in the stack trace, primarily used in error debugging and stack analysis.
|
|
6
|
+
* It optionally includes information about the line, column, file, function name, and other details
|
|
7
|
+
* about the origin of the code.
|
|
8
|
+
*
|
|
9
|
+
* Properties:
|
|
10
|
+
* - source: The source code relevant to the stack frame.
|
|
11
|
+
* - line: An optional line number in the code associated with this frame.
|
|
12
|
+
* - column: An optional column number in the line associated with this frame.
|
|
13
|
+
* - fileName: The name of the file associated with the frame, if available.
|
|
14
|
+
* - functionName: The name of the function where the stack frame is located, if available.
|
|
15
|
+
* - eval: Indicates if the stack frame originates from an evaluated script.
|
|
16
|
+
* - async: Indicates if the stack frame is part of an asynchronous operation.
|
|
17
|
+
* - native: Indicates if the stack frame is part of native code execution.
|
|
18
|
+
* - constructor: Indicates if the frame is related to an object constructor invocation.
|
|
19
|
+
* - evalOrigin: Optional information about the origin of the code if it resulted from an eval execution,
|
|
20
|
+
* including line number, column number, file name, and function name.
|
|
21
|
+
*
|
|
22
|
+
* @since 3.0.0
|
|
23
|
+
*/
|
|
24
|
+
export interface StackFrame {
|
|
25
|
+
source: string;
|
|
26
|
+
line?: number;
|
|
27
|
+
column?: number;
|
|
28
|
+
fileName?: string;
|
|
29
|
+
functionName?: string;
|
|
30
|
+
eval: boolean;
|
|
31
|
+
async: boolean;
|
|
32
|
+
native: boolean;
|
|
33
|
+
constructor: boolean;
|
|
34
|
+
evalOrigin?: {
|
|
35
|
+
line?: number;
|
|
36
|
+
column?: number;
|
|
37
|
+
fileName?: string;
|
|
38
|
+
functionName?: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Represents a fully parsed error stack trace with structured information
|
|
43
|
+
*
|
|
44
|
+
* @see StackFrame
|
|
45
|
+
* @since 2.1.0
|
|
46
|
+
*/
|
|
47
|
+
export interface ParsedStackTrace {
|
|
48
|
+
name: string;
|
|
49
|
+
message: string;
|
|
50
|
+
stack: StackFrame[];
|
|
51
|
+
rawStack: string;
|
|
52
|
+
}
|