@herb-tools/printer 0.6.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 +123 -0
- package/bin/herb-print +3 -0
- package/dist/cli.js +190 -0
- package/dist/cli.js.map +1 -0
- package/dist/herb-print.js +17200 -0
- package/dist/herb-print.js.map +1 -0
- package/dist/identity-printer.js +13 -0
- package/dist/identity-printer.js.map +1 -0
- package/dist/index.cjs +436 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +431 -0
- package/dist/index.js.map +1 -0
- package/dist/print-context.js +92 -0
- package/dist/print-context.js.map +1 -0
- package/dist/printer.js +325 -0
- package/dist/printer.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/cli.d.ts +6 -0
- package/dist/types/herb-print.d.ts +2 -0
- package/dist/types/identity-printer.d.ts +12 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/print-context.d.ts +54 -0
- package/dist/types/printer.d.ts +75 -0
- package/package.json +50 -0
- package/src/cli.ts +226 -0
- package/src/herb-print.ts +6 -0
- package/src/identity-printer.ts +14 -0
- package/src/index.ts +4 -0
- package/src/print-context.ts +104 -0
- package/src/printer.ts +438 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { Visitor, isToken, isParseResult } from '@herb-tools/core';
|
|
2
|
+
|
|
3
|
+
class PrintContext {
|
|
4
|
+
output = "";
|
|
5
|
+
indentLevel = 0;
|
|
6
|
+
currentColumn = 0;
|
|
7
|
+
preserveStack = [];
|
|
8
|
+
/**
|
|
9
|
+
* Write text to the output
|
|
10
|
+
*/
|
|
11
|
+
write(text) {
|
|
12
|
+
this.output += text;
|
|
13
|
+
this.currentColumn += text.length;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Write text and update column tracking for newlines
|
|
17
|
+
*/
|
|
18
|
+
writeWithColumnTracking(text) {
|
|
19
|
+
this.output += text;
|
|
20
|
+
const lines = text.split('\n');
|
|
21
|
+
if (lines.length > 1) {
|
|
22
|
+
this.currentColumn = lines[lines.length - 1].length;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.currentColumn += text.length;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Increase indentation level
|
|
30
|
+
*/
|
|
31
|
+
indent() {
|
|
32
|
+
this.indentLevel++;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decrease indentation level
|
|
36
|
+
*/
|
|
37
|
+
dedent() {
|
|
38
|
+
if (this.indentLevel > 0) {
|
|
39
|
+
this.indentLevel--;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Enter a tag that may preserve whitespace
|
|
44
|
+
*/
|
|
45
|
+
enterTag(tagName) {
|
|
46
|
+
this.preserveStack.push(tagName.toLowerCase());
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Exit the current tag
|
|
50
|
+
*/
|
|
51
|
+
exitTag() {
|
|
52
|
+
this.preserveStack.pop();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if we're at the start of a line
|
|
56
|
+
*/
|
|
57
|
+
isAtStartOfLine() {
|
|
58
|
+
return this.currentColumn === 0;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get current indentation level
|
|
62
|
+
*/
|
|
63
|
+
getCurrentIndentLevel() {
|
|
64
|
+
return this.indentLevel;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get current column position
|
|
68
|
+
*/
|
|
69
|
+
getCurrentColumn() {
|
|
70
|
+
return this.currentColumn;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the current tag stack (for debugging)
|
|
74
|
+
*/
|
|
75
|
+
getTagStack() {
|
|
76
|
+
return [...this.preserveStack];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the complete output string
|
|
80
|
+
*/
|
|
81
|
+
getOutput() {
|
|
82
|
+
return this.output;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Reset the context for reuse
|
|
86
|
+
*/
|
|
87
|
+
reset() {
|
|
88
|
+
this.output = "";
|
|
89
|
+
this.indentLevel = 0;
|
|
90
|
+
this.currentColumn = 0;
|
|
91
|
+
this.preserveStack = [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Default print options used when none are provided
|
|
97
|
+
*/
|
|
98
|
+
const DEFAULT_PRINT_OPTIONS = {
|
|
99
|
+
ignoreErrors: false
|
|
100
|
+
};
|
|
101
|
+
class Printer extends Visitor {
|
|
102
|
+
context = new PrintContext();
|
|
103
|
+
/**
|
|
104
|
+
* Static method to print a node without creating an instance
|
|
105
|
+
*
|
|
106
|
+
* @param input - The AST Node, Token, or ParseResult to print
|
|
107
|
+
* @param options - Print options to control behavior
|
|
108
|
+
* @returns The printed string representation of the input
|
|
109
|
+
* @throws {Error} When node has parse errors and ignoreErrors is false
|
|
110
|
+
*/
|
|
111
|
+
static print(input, options = DEFAULT_PRINT_OPTIONS) {
|
|
112
|
+
const printer = new this();
|
|
113
|
+
return printer.print(input, options);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Print a node, token, or parse result to a string
|
|
117
|
+
*
|
|
118
|
+
* @param input - The AST Node, Token, or ParseResult to print
|
|
119
|
+
* @param options - Print options to control behavior
|
|
120
|
+
* @returns The printed string representation of the input
|
|
121
|
+
* @throws {Error} When node has parse errors and ignoreErrors is false
|
|
122
|
+
*/
|
|
123
|
+
print(input, options = DEFAULT_PRINT_OPTIONS) {
|
|
124
|
+
if (isToken(input)) {
|
|
125
|
+
return input.value;
|
|
126
|
+
}
|
|
127
|
+
const node = isParseResult(input) ? input.value : input;
|
|
128
|
+
if (options.ignoreErrors === false && node.recursiveErrors().length > 0) {
|
|
129
|
+
throw new Error(`Cannot print the node (${node.type}) since it or any of its children has parse errors. Either pass in a valid Node or call \`print()\` using \`print(node, { ignoreErrors: true })\``);
|
|
130
|
+
}
|
|
131
|
+
this.context.reset();
|
|
132
|
+
this.visit(node);
|
|
133
|
+
return this.context.getOutput();
|
|
134
|
+
}
|
|
135
|
+
visitDocumentNode(node) {
|
|
136
|
+
this.visitChildNodes(node);
|
|
137
|
+
}
|
|
138
|
+
visitLiteralNode(node) {
|
|
139
|
+
this.context.write(node.content);
|
|
140
|
+
}
|
|
141
|
+
visitHTMLTextNode(node) {
|
|
142
|
+
this.write(node.content);
|
|
143
|
+
}
|
|
144
|
+
visitWhitespaceNode(node) {
|
|
145
|
+
if (node.value) {
|
|
146
|
+
this.write(node.value.value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
visitHTMLOpenTagNode(node) {
|
|
150
|
+
if (node.tag_opening) {
|
|
151
|
+
this.context.write(node.tag_opening.value);
|
|
152
|
+
}
|
|
153
|
+
if (node.tag_name) {
|
|
154
|
+
this.context.write(node.tag_name.value);
|
|
155
|
+
}
|
|
156
|
+
this.visitChildNodes(node);
|
|
157
|
+
if (node.tag_closing) {
|
|
158
|
+
this.context.write(node.tag_closing.value);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
visitHTMLCloseTagNode(node) {
|
|
162
|
+
if (node.tag_opening) {
|
|
163
|
+
this.context.write(node.tag_opening.value);
|
|
164
|
+
}
|
|
165
|
+
if (node.tag_name) {
|
|
166
|
+
this.context.write(node.tag_name.value);
|
|
167
|
+
}
|
|
168
|
+
if (node.tag_closing) {
|
|
169
|
+
this.context.write(node.tag_closing.value);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
visitHTMLElementNode(node) {
|
|
173
|
+
const tagName = node.tag_name?.value;
|
|
174
|
+
if (tagName) {
|
|
175
|
+
this.context.enterTag(tagName);
|
|
176
|
+
}
|
|
177
|
+
if (node.open_tag) {
|
|
178
|
+
this.visit(node.open_tag);
|
|
179
|
+
}
|
|
180
|
+
if (node.body) {
|
|
181
|
+
node.body.forEach(child => this.visit(child));
|
|
182
|
+
}
|
|
183
|
+
if (node.close_tag) {
|
|
184
|
+
this.visit(node.close_tag);
|
|
185
|
+
}
|
|
186
|
+
if (tagName) {
|
|
187
|
+
this.context.exitTag();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
visitHTMLAttributeNode(node) {
|
|
191
|
+
if (node.name) {
|
|
192
|
+
this.visit(node.name);
|
|
193
|
+
}
|
|
194
|
+
if (node.equals) {
|
|
195
|
+
this.context.write(node.equals.value);
|
|
196
|
+
}
|
|
197
|
+
if (node.equals && node.value) {
|
|
198
|
+
this.visit(node.value);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
visitHTMLAttributeNameNode(node) {
|
|
202
|
+
this.visitChildNodes(node);
|
|
203
|
+
}
|
|
204
|
+
visitHTMLAttributeValueNode(node) {
|
|
205
|
+
if (node.quoted && node.open_quote) {
|
|
206
|
+
this.context.write(node.open_quote.value);
|
|
207
|
+
}
|
|
208
|
+
this.visitChildNodes(node);
|
|
209
|
+
if (node.quoted && node.close_quote) {
|
|
210
|
+
this.context.write(node.close_quote.value);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
visitHTMLCommentNode(node) {
|
|
214
|
+
if (node.comment_start) {
|
|
215
|
+
this.context.write(node.comment_start.value);
|
|
216
|
+
}
|
|
217
|
+
this.visitChildNodes(node);
|
|
218
|
+
if (node.comment_end) {
|
|
219
|
+
this.context.write(node.comment_end.value);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
visitHTMLDoctypeNode(node) {
|
|
223
|
+
if (node.tag_opening) {
|
|
224
|
+
this.context.write(node.tag_opening.value);
|
|
225
|
+
}
|
|
226
|
+
this.visitChildNodes(node);
|
|
227
|
+
if (node.tag_closing) {
|
|
228
|
+
this.context.write(node.tag_closing.value);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
visitXMLDeclarationNode(node) {
|
|
232
|
+
if (node.tag_opening) {
|
|
233
|
+
this.context.write(node.tag_opening.value);
|
|
234
|
+
}
|
|
235
|
+
this.visitChildNodes(node);
|
|
236
|
+
if (node.tag_closing) {
|
|
237
|
+
this.context.write(node.tag_closing.value);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
visitCDATANode(node) {
|
|
241
|
+
if (node.tag_opening) {
|
|
242
|
+
this.context.write(node.tag_opening.value);
|
|
243
|
+
}
|
|
244
|
+
this.visitChildNodes(node);
|
|
245
|
+
if (node.tag_closing) {
|
|
246
|
+
this.context.write(node.tag_closing.value);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
visitERBContentNode(node) {
|
|
250
|
+
this.printERBNode(node);
|
|
251
|
+
}
|
|
252
|
+
visitERBIfNode(node) {
|
|
253
|
+
this.printERBNode(node);
|
|
254
|
+
if (node.statements) {
|
|
255
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
256
|
+
}
|
|
257
|
+
if (node.subsequent) {
|
|
258
|
+
this.visit(node.subsequent);
|
|
259
|
+
}
|
|
260
|
+
if (node.end_node) {
|
|
261
|
+
this.visit(node.end_node);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
visitERBElseNode(node) {
|
|
265
|
+
this.printERBNode(node);
|
|
266
|
+
if (node.statements) {
|
|
267
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
visitERBEndNode(node) {
|
|
271
|
+
this.printERBNode(node);
|
|
272
|
+
}
|
|
273
|
+
visitERBBlockNode(node) {
|
|
274
|
+
this.printERBNode(node);
|
|
275
|
+
if (node.body) {
|
|
276
|
+
node.body.forEach(child => this.visit(child));
|
|
277
|
+
}
|
|
278
|
+
if (node.end_node) {
|
|
279
|
+
this.visit(node.end_node);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
visitERBCaseNode(node) {
|
|
283
|
+
this.printERBNode(node);
|
|
284
|
+
if (node.children) {
|
|
285
|
+
node.children.forEach(child => this.visit(child));
|
|
286
|
+
}
|
|
287
|
+
if (node.conditions) {
|
|
288
|
+
node.conditions.forEach(condition => this.visit(condition));
|
|
289
|
+
}
|
|
290
|
+
if (node.else_clause) {
|
|
291
|
+
this.visit(node.else_clause);
|
|
292
|
+
}
|
|
293
|
+
if (node.end_node) {
|
|
294
|
+
this.visit(node.end_node);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
visitERBWhenNode(node) {
|
|
298
|
+
this.printERBNode(node);
|
|
299
|
+
if (node.statements) {
|
|
300
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
visitERBWhileNode(node) {
|
|
304
|
+
this.printERBNode(node);
|
|
305
|
+
if (node.statements) {
|
|
306
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
307
|
+
}
|
|
308
|
+
if (node.end_node) {
|
|
309
|
+
this.visit(node.end_node);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
visitERBUntilNode(node) {
|
|
313
|
+
this.printERBNode(node);
|
|
314
|
+
if (node.statements) {
|
|
315
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
316
|
+
}
|
|
317
|
+
if (node.end_node) {
|
|
318
|
+
this.visit(node.end_node);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
visitERBForNode(node) {
|
|
322
|
+
this.printERBNode(node);
|
|
323
|
+
if (node.statements) {
|
|
324
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
325
|
+
}
|
|
326
|
+
if (node.end_node) {
|
|
327
|
+
this.visit(node.end_node);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
visitERBBeginNode(node) {
|
|
331
|
+
this.printERBNode(node);
|
|
332
|
+
if (node.statements) {
|
|
333
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
334
|
+
}
|
|
335
|
+
if (node.rescue_clause) {
|
|
336
|
+
this.visit(node.rescue_clause);
|
|
337
|
+
}
|
|
338
|
+
if (node.else_clause) {
|
|
339
|
+
this.visit(node.else_clause);
|
|
340
|
+
}
|
|
341
|
+
if (node.ensure_clause) {
|
|
342
|
+
this.visit(node.ensure_clause);
|
|
343
|
+
}
|
|
344
|
+
if (node.end_node) {
|
|
345
|
+
this.visit(node.end_node);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
visitERBRescueNode(node) {
|
|
349
|
+
this.printERBNode(node);
|
|
350
|
+
if (node.statements) {
|
|
351
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
352
|
+
}
|
|
353
|
+
if (node.subsequent) {
|
|
354
|
+
this.visit(node.subsequent);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
visitERBEnsureNode(node) {
|
|
358
|
+
this.printERBNode(node);
|
|
359
|
+
if (node.statements) {
|
|
360
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
visitERBUnlessNode(node) {
|
|
364
|
+
this.printERBNode(node);
|
|
365
|
+
if (node.statements) {
|
|
366
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
367
|
+
}
|
|
368
|
+
if (node.else_clause) {
|
|
369
|
+
this.visit(node.else_clause);
|
|
370
|
+
}
|
|
371
|
+
if (node.end_node) {
|
|
372
|
+
this.visit(node.end_node);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
visitERBYieldNode(node) {
|
|
376
|
+
this.printERBNode(node);
|
|
377
|
+
}
|
|
378
|
+
visitERBInNode(node) {
|
|
379
|
+
this.printERBNode(node);
|
|
380
|
+
if (node.statements) {
|
|
381
|
+
node.statements.forEach(statement => this.visit(statement));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
visitERBCaseMatchNode(node) {
|
|
385
|
+
this.printERBNode(node);
|
|
386
|
+
if (node.children) {
|
|
387
|
+
node.children.forEach(child => this.visit(child));
|
|
388
|
+
}
|
|
389
|
+
if (node.conditions) {
|
|
390
|
+
node.conditions.forEach(condition => this.visit(condition));
|
|
391
|
+
}
|
|
392
|
+
if (node.else_clause) {
|
|
393
|
+
this.visit(node.else_clause);
|
|
394
|
+
}
|
|
395
|
+
if (node.end_node) {
|
|
396
|
+
this.visit(node.end_node);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Print ERB node tags and content
|
|
401
|
+
*/
|
|
402
|
+
printERBNode(node) {
|
|
403
|
+
if (node.tag_opening) {
|
|
404
|
+
this.context.write(node.tag_opening.value);
|
|
405
|
+
}
|
|
406
|
+
if (node.content) {
|
|
407
|
+
this.context.write(node.content.value);
|
|
408
|
+
}
|
|
409
|
+
if (node.tag_closing) {
|
|
410
|
+
this.context.write(node.tag_closing.value);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
write(content) {
|
|
414
|
+
this.context.write(content);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* IdentityPrinter - Provides lossless reconstruction of the original source
|
|
420
|
+
*
|
|
421
|
+
* This printer aims to reconstruct the original input as faithfully as possible,
|
|
422
|
+
* preserving all whitespace, formatting, and structure. It's useful for:
|
|
423
|
+
* - Testing parser accuracy (input should equal output)
|
|
424
|
+
* - Baseline printing before applying transformations
|
|
425
|
+
* - Verifying AST round-trip fidelity
|
|
426
|
+
*/
|
|
427
|
+
class IdentityPrinter extends Printer {
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export { DEFAULT_PRINT_OPTIONS, IdentityPrinter, PrintContext, Printer };
|
|
431
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/print-context.ts","../src/printer.ts","../src/identity-printer.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":";;MAAa,YAAY,CAAA;IACf,MAAM,GAAW,EAAE;IACnB,WAAW,GAAW,CAAC;IACvB,aAAa,GAAW,CAAC;IACzB,aAAa,GAAa,EAAE;AAEp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nD;AAEA,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;AACnB,YAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC7D;AAEA,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;AACpB,YAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC;QAC9B;AAEA,QAAA,IAAI,IAAI,CAAC,QAAQ,EAAE;AACjB,YAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B;IACF;AAEA;;AAEG;AACO,IAAA,YAAY,CAAC,IAAmB,EAAA;AACxC,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAC5C;AAEA,QAAA,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QACxC;AAEA,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAC5C;IACD;AAES,IAAA,KAAK,CAAC,OAAe,EAAA;AAC7B,QAAA,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAC7B;AACD;;ACnbD;;;;;;;;AAQG;AACG,MAAO,eAAgB,SAAQ,OAAO,CAAA;AAE3C;;;;"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export class PrintContext {
|
|
2
|
+
output = "";
|
|
3
|
+
indentLevel = 0;
|
|
4
|
+
currentColumn = 0;
|
|
5
|
+
preserveStack = [];
|
|
6
|
+
/**
|
|
7
|
+
* Write text to the output
|
|
8
|
+
*/
|
|
9
|
+
write(text) {
|
|
10
|
+
this.output += text;
|
|
11
|
+
this.currentColumn += text.length;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Write text and update column tracking for newlines
|
|
15
|
+
*/
|
|
16
|
+
writeWithColumnTracking(text) {
|
|
17
|
+
this.output += text;
|
|
18
|
+
const lines = text.split('\n');
|
|
19
|
+
if (lines.length > 1) {
|
|
20
|
+
this.currentColumn = lines[lines.length - 1].length;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.currentColumn += text.length;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Increase indentation level
|
|
28
|
+
*/
|
|
29
|
+
indent() {
|
|
30
|
+
this.indentLevel++;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decrease indentation level
|
|
34
|
+
*/
|
|
35
|
+
dedent() {
|
|
36
|
+
if (this.indentLevel > 0) {
|
|
37
|
+
this.indentLevel--;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Enter a tag that may preserve whitespace
|
|
42
|
+
*/
|
|
43
|
+
enterTag(tagName) {
|
|
44
|
+
this.preserveStack.push(tagName.toLowerCase());
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Exit the current tag
|
|
48
|
+
*/
|
|
49
|
+
exitTag() {
|
|
50
|
+
this.preserveStack.pop();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if we're at the start of a line
|
|
54
|
+
*/
|
|
55
|
+
isAtStartOfLine() {
|
|
56
|
+
return this.currentColumn === 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get current indentation level
|
|
60
|
+
*/
|
|
61
|
+
getCurrentIndentLevel() {
|
|
62
|
+
return this.indentLevel;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get current column position
|
|
66
|
+
*/
|
|
67
|
+
getCurrentColumn() {
|
|
68
|
+
return this.currentColumn;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the current tag stack (for debugging)
|
|
72
|
+
*/
|
|
73
|
+
getTagStack() {
|
|
74
|
+
return [...this.preserveStack];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the complete output string
|
|
78
|
+
*/
|
|
79
|
+
getOutput() {
|
|
80
|
+
return this.output;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Reset the context for reuse
|
|
84
|
+
*/
|
|
85
|
+
reset() {
|
|
86
|
+
this.output = "";
|
|
87
|
+
this.indentLevel = 0;
|
|
88
|
+
this.currentColumn = 0;
|
|
89
|
+
this.preserveStack = [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=print-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-context.js","sourceRoot":"","sources":["../src/print-context.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;IACf,MAAM,GAAW,EAAE,CAAA;IACnB,WAAW,GAAW,CAAC,CAAA;IACvB,aAAa,GAAW,CAAC,CAAA;IACzB,aAAa,GAAa,EAAE,CAAA;IAEpC;;OAEG;IACH,KAAK,CAAC,IAAY;QAChB,IAAI,CAAC,MAAM,IAAI,IAAI,CAAA;QACnB,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,uBAAuB,CAAC,IAAY;QAClC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAA;QAEnB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAE9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;QACrD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAA;QACnC,CAAC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