rawsql-ts 0.11.41-beta → 0.11.43-beta
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 +6 -6
- package/dist/esm/index.min.js +18 -9
- package/dist/esm/index.min.js.map +2 -2
- package/dist/esm/src/parsers/KeywordParser.js +4 -2
- package/dist/esm/src/parsers/KeywordParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlPrintTokenParser.d.ts +11 -18
- package/dist/esm/src/parsers/SqlPrintTokenParser.js +126 -218
- package/dist/esm/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlTokenizer.js +26 -13
- package/dist/esm/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/esm/src/transformers/LinePrinter.d.ts +1 -0
- package/dist/esm/src/transformers/LinePrinter.js +22 -1
- package/dist/esm/src/transformers/LinePrinter.js.map +1 -1
- package/dist/esm/src/transformers/SqlFormatter.d.ts +6 -4
- package/dist/esm/src/transformers/SqlFormatter.js +2 -2
- package/dist/esm/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/esm/src/transformers/SqlPrinter.d.ts +40 -2
- package/dist/esm/src/transformers/SqlPrinter.js +489 -27
- package/dist/esm/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/src/utils/stringUtils.d.ts +1 -1
- package/dist/esm/src/utils/stringUtils.js +8 -2
- package/dist/esm/src/utils/stringUtils.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +18 -9
- package/dist/index.min.js.map +2 -2
- package/dist/src/parsers/KeywordParser.js +4 -2
- package/dist/src/parsers/KeywordParser.js.map +1 -1
- package/dist/src/parsers/SqlPrintTokenParser.d.ts +11 -18
- package/dist/src/parsers/SqlPrintTokenParser.js +126 -218
- package/dist/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/src/parsers/SqlTokenizer.js +26 -13
- package/dist/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/src/transformers/LinePrinter.d.ts +1 -0
- package/dist/src/transformers/LinePrinter.js +22 -1
- package/dist/src/transformers/LinePrinter.js.map +1 -1
- package/dist/src/transformers/SqlFormatter.d.ts +6 -4
- package/dist/src/transformers/SqlFormatter.js +2 -2
- package/dist/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/src/transformers/SqlPrinter.d.ts +40 -2
- package/dist/src/transformers/SqlPrinter.js +489 -27
- package/dist/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/src/utils/stringUtils.d.ts +1 -1
- package/dist/src/utils/stringUtils.js +8 -2
- package/dist/src/utils/stringUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -43,7 +43,7 @@ class KeywordParser {
|
|
|
43
43
|
let lexeme = result.identifier;
|
|
44
44
|
const commentResult = stringUtils_1.StringUtils.readWhiteSpaceAndComment(input, result.newPosition);
|
|
45
45
|
position = commentResult.position;
|
|
46
|
-
const collectedComments = [...commentResult.lines]; // Cache comments during multi-word parsing
|
|
46
|
+
const collectedComments = commentResult.lines ? [...commentResult.lines] : []; // Cache comments during multi-word parsing
|
|
47
47
|
// end of input
|
|
48
48
|
if (this.isEndOfInput(input, position)) {
|
|
49
49
|
if (matchResult === KeywordMatchResult.PartialOrFinal) {
|
|
@@ -74,7 +74,9 @@ class KeywordParser {
|
|
|
74
74
|
lexeme += ' ' + result.identifier;
|
|
75
75
|
const nextCommentResult = stringUtils_1.StringUtils.readWhiteSpaceAndComment(input, result.newPosition);
|
|
76
76
|
position = nextCommentResult.position;
|
|
77
|
-
|
|
77
|
+
if (nextCommentResult.lines && nextCommentResult.lines.length > 0) {
|
|
78
|
+
collectedComments.push(...nextCommentResult.lines); // Collect comments between multi-word tokens
|
|
79
|
+
}
|
|
78
80
|
if (matchResult === KeywordMatchResult.Final) {
|
|
79
81
|
break;
|
|
80
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeywordPar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AAM,CAAC;gBACJ,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QAED,OAAO;YACH,OAAO,EAAE,MAAM;YACf,WAAW,EAAE,QAAQ;YACrB,QAAQ,EAAE,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS;SACzE,CAAC;IACN,CAAC;CACJ;AArGD,sCAqGC"}
|
|
@@ -39,7 +39,6 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
|
|
|
39
39
|
parameterDecorator: ParameterDecorator;
|
|
40
40
|
identifierDecorator: IdentifierDecorator;
|
|
41
41
|
index: number;
|
|
42
|
-
private commentStyle;
|
|
43
42
|
constructor(options?: {
|
|
44
43
|
preset?: FormatterConfig;
|
|
45
44
|
identifierEscape?: {
|
|
@@ -51,7 +50,6 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
|
|
|
51
50
|
end: string;
|
|
52
51
|
};
|
|
53
52
|
parameterStyle?: 'anonymous' | 'indexed' | 'named';
|
|
54
|
-
commentStyle?: 'block' | 'smart';
|
|
55
53
|
});
|
|
56
54
|
/**
|
|
57
55
|
* Pretty-prints a BinarySelectQuery (e.g., UNION, INTERSECT, EXCEPT).
|
|
@@ -111,10 +109,6 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
|
|
|
111
109
|
* This structure supports both oneliner and multiline formatting modes.
|
|
112
110
|
*/
|
|
113
111
|
private createCommentBlocks;
|
|
114
|
-
/**
|
|
115
|
-
* Creates smart comment blocks by merging consecutive block comments into multi-line format
|
|
116
|
-
*/
|
|
117
|
-
private createSmartCommentBlocks;
|
|
118
112
|
/**
|
|
119
113
|
* Determines if a comment should be merged with consecutive comments
|
|
120
114
|
*/
|
|
@@ -123,12 +117,6 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
|
|
|
123
117
|
* Creates a multi-line block comment structure from consecutive comments
|
|
124
118
|
* Returns a CommentBlock containing multiple comment lines for proper LinePrinter integration
|
|
125
119
|
*/
|
|
126
|
-
private createMultiLineCommentBlock;
|
|
127
|
-
/**
|
|
128
|
-
* Creates a multi-line comment block specifically for headerComments
|
|
129
|
-
* headerComments come as pre-split lines, so we handle them differently
|
|
130
|
-
*/
|
|
131
|
-
private createHeaderMultiLineCommentBlock;
|
|
132
120
|
/**
|
|
133
121
|
* Creates a single CommentBlock with the standard structure:
|
|
134
122
|
* Comment -> CommentNewline -> Space
|
|
@@ -143,12 +131,6 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
|
|
|
143
131
|
* and converting others to block format for safety
|
|
144
132
|
*/
|
|
145
133
|
private formatComment;
|
|
146
|
-
/**
|
|
147
|
-
* Formats comments using smart style rules:
|
|
148
|
-
* - Only multi-line block comment merging is supported
|
|
149
|
-
* - Single-line comments remain as block comments (no dash conversion)
|
|
150
|
-
*/
|
|
151
|
-
private formatCommentSmart;
|
|
152
134
|
/**
|
|
153
135
|
* Inserts comment blocks into a token and handles spacing logic.
|
|
154
136
|
* Adds separator spaces for clause-level containers and manages duplicate space removal.
|
|
@@ -180,6 +162,17 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
|
|
|
180
162
|
* Prevents SQL injection by removing dangerous comment sequences.
|
|
181
163
|
*/
|
|
182
164
|
private formatBlockComment;
|
|
165
|
+
private shouldMergeHeaderComments;
|
|
166
|
+
private createHeaderMultiLineCommentBlock;
|
|
167
|
+
/**
|
|
168
|
+
* Formats text as a single-line comment while sanitizing unsafe sequences.
|
|
169
|
+
*/
|
|
170
|
+
private formatLineComment;
|
|
171
|
+
/**
|
|
172
|
+
* Sanitizes content intended for a single-line comment.
|
|
173
|
+
*/
|
|
174
|
+
private sanitizeLineCommentContent;
|
|
175
|
+
private escapeCommentDelimiters;
|
|
183
176
|
private visitValueList;
|
|
184
177
|
private visitColumnReference;
|
|
185
178
|
private visitFunctionCall;
|
|
@@ -142,10 +142,9 @@ class SqlPrintTokenParser {
|
|
|
142
142
|
return this._selfHandlingComponentTypes;
|
|
143
143
|
}
|
|
144
144
|
constructor(options) {
|
|
145
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
145
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
146
146
|
this.handlers = new Map();
|
|
147
147
|
this.index = 1;
|
|
148
|
-
this.commentStyle = 'block';
|
|
149
148
|
if (options === null || options === void 0 ? void 0 : options.preset) {
|
|
150
149
|
const preset = options.preset;
|
|
151
150
|
options = { ...preset, ...options };
|
|
@@ -159,7 +158,6 @@ class SqlPrintTokenParser {
|
|
|
159
158
|
start: (_e = (_d = options === null || options === void 0 ? void 0 : options.identifierEscape) === null || _d === void 0 ? void 0 : _d.start) !== null && _e !== void 0 ? _e : '"',
|
|
160
159
|
end: (_g = (_f = options === null || options === void 0 ? void 0 : options.identifierEscape) === null || _f === void 0 ? void 0 : _f.end) !== null && _g !== void 0 ? _g : '"'
|
|
161
160
|
});
|
|
162
|
-
this.commentStyle = (_h = options === null || options === void 0 ? void 0 : options.commentStyle) !== null && _h !== void 0 ? _h : 'block';
|
|
163
161
|
this.handlers.set(ValueComponent_1.ValueList.kind, (expr) => this.visitValueList(expr));
|
|
164
162
|
this.handlers.set(ValueComponent_1.ColumnReference.kind, (expr) => this.visitColumnReference(expr));
|
|
165
163
|
this.handlers.set(ValueComponent_1.QualifiedName.kind, (expr) => this.visitQualifiedName(expr));
|
|
@@ -250,9 +248,7 @@ class SqlPrintTokenParser {
|
|
|
250
248
|
arg.positionedComments = null;
|
|
251
249
|
}
|
|
252
250
|
else if (arg.headerComments && arg.headerComments.length > 0) {
|
|
253
|
-
|
|
254
|
-
// For smart comment style, treat headerComments as a single multi-line block
|
|
255
|
-
if (this.commentStyle === 'smart' && arg.headerComments.length > 1) {
|
|
251
|
+
if (this.shouldMergeHeaderComments(arg.headerComments)) {
|
|
256
252
|
const mergedHeaderComment = this.createHeaderMultiLineCommentBlock(arg.headerComments);
|
|
257
253
|
token.innerTokens.push(mergedHeaderComment);
|
|
258
254
|
}
|
|
@@ -441,14 +437,9 @@ class SqlPrintTokenParser {
|
|
|
441
437
|
const beforeComments = component.getPositionedComments('before');
|
|
442
438
|
if (beforeComments.length > 0) {
|
|
443
439
|
const commentBlocks = this.createCommentBlocks(beforeComments);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
for (const commentBlock of commentBlocks) {
|
|
447
|
-
beforeTokens.push(commentBlock);
|
|
448
|
-
beforeTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.space, ' '));
|
|
440
|
+
for (let i = commentBlocks.length - 1; i >= 0; i--) {
|
|
441
|
+
token.innerTokens.unshift(commentBlocks[i]);
|
|
449
442
|
}
|
|
450
|
-
// Insert before the existing content
|
|
451
|
-
token.innerTokens.unshift(...beforeTokens);
|
|
452
443
|
}
|
|
453
444
|
// Handle 'after' comments - add inline after the main content
|
|
454
445
|
const afterComments = component.getPositionedComments('after');
|
|
@@ -456,7 +447,7 @@ class SqlPrintTokenParser {
|
|
|
456
447
|
const commentBlocks = this.createCommentBlocks(afterComments);
|
|
457
448
|
// Append after comments with spaces for inline formatting
|
|
458
449
|
for (const commentBlock of commentBlocks) {
|
|
459
|
-
token.innerTokens.push(
|
|
450
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
460
451
|
token.innerTokens.push(commentBlock);
|
|
461
452
|
}
|
|
462
453
|
}
|
|
@@ -485,16 +476,8 @@ class SqlPrintTokenParser {
|
|
|
485
476
|
if (!(comments === null || comments === void 0 ? void 0 : comments.length)) {
|
|
486
477
|
return;
|
|
487
478
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
const inlineComments = this.createInlineCommentSequence(comments);
|
|
491
|
-
this.insertCommentBlocksWithSpacing(token, inlineComments);
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
// Create CommentBlock containers for single comment
|
|
495
|
-
const commentBlocks = this.createCommentBlocks(comments);
|
|
496
|
-
this.insertCommentBlocksWithSpacing(token, commentBlocks);
|
|
497
|
-
}
|
|
479
|
+
const commentBlocks = this.createCommentBlocks(comments);
|
|
480
|
+
this.insertCommentBlocksWithSpacing(token, commentBlocks);
|
|
498
481
|
}
|
|
499
482
|
/**
|
|
500
483
|
* Creates inline comment sequence for multiple comments without newlines
|
|
@@ -505,7 +488,7 @@ class SqlPrintTokenParser {
|
|
|
505
488
|
const comment = comments[i];
|
|
506
489
|
if (comment.trim()) {
|
|
507
490
|
// Add comment token directly
|
|
508
|
-
const commentToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, this.
|
|
491
|
+
const commentToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, this.formatComment(comment));
|
|
509
492
|
commentTokens.push(commentToken);
|
|
510
493
|
// Add space between comments (except after last comment)
|
|
511
494
|
if (i < comments.length - 1) {
|
|
@@ -522,10 +505,7 @@ class SqlPrintTokenParser {
|
|
|
522
505
|
* This structure supports both oneliner and multiline formatting modes.
|
|
523
506
|
*/
|
|
524
507
|
createCommentBlocks(comments) {
|
|
525
|
-
|
|
526
|
-
return this.createSmartCommentBlocks(comments);
|
|
527
|
-
}
|
|
528
|
-
// Block style (default) - each comment gets its own block
|
|
508
|
+
// Create individual comment blocks for each comment entry
|
|
529
509
|
const commentBlocks = [];
|
|
530
510
|
for (const comment of comments) {
|
|
531
511
|
// Accept comments that have content after trim OR are separator lines OR are empty (for structure preservation)
|
|
@@ -537,46 +517,6 @@ class SqlPrintTokenParser {
|
|
|
537
517
|
}
|
|
538
518
|
return commentBlocks;
|
|
539
519
|
}
|
|
540
|
-
/**
|
|
541
|
-
* Creates smart comment blocks by merging consecutive block comments into multi-line format
|
|
542
|
-
*/
|
|
543
|
-
createSmartCommentBlocks(comments) {
|
|
544
|
-
const commentBlocks = [];
|
|
545
|
-
const blockComments = [];
|
|
546
|
-
const flushBlockComments = () => {
|
|
547
|
-
if (blockComments.length > 0) {
|
|
548
|
-
if (blockComments.length === 1) {
|
|
549
|
-
// Single comment - keep as-is
|
|
550
|
-
commentBlocks.push(this.createSingleCommentBlock(blockComments[0]));
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
// Multiple consecutive comments - create multi-line block
|
|
554
|
-
commentBlocks.push(this.createMultiLineCommentBlock(blockComments));
|
|
555
|
-
}
|
|
556
|
-
blockComments.length = 0;
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
for (const comment of comments) {
|
|
560
|
-
const trimmed = comment.trim();
|
|
561
|
-
const isSeparatorLine = /^[-=_+*#]+$/.test(trimmed);
|
|
562
|
-
if (!trimmed && !isSeparatorLine && comment !== '') {
|
|
563
|
-
continue;
|
|
564
|
-
}
|
|
565
|
-
// Check if this is a block comment that should be merged
|
|
566
|
-
if (this.shouldMergeComment(trimmed)) {
|
|
567
|
-
blockComments.push(comment);
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
// Flush any accumulated block comments first
|
|
571
|
-
flushBlockComments();
|
|
572
|
-
// Add this comment as-is
|
|
573
|
-
commentBlocks.push(this.createSingleCommentBlock(comment));
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
// Flush any remaining block comments
|
|
577
|
-
flushBlockComments();
|
|
578
|
-
return commentBlocks;
|
|
579
|
-
}
|
|
580
520
|
/**
|
|
581
521
|
* Determines if a comment should be merged with consecutive comments
|
|
582
522
|
*/
|
|
@@ -587,8 +527,14 @@ class SqlPrintTokenParser {
|
|
|
587
527
|
return false;
|
|
588
528
|
}
|
|
589
529
|
// Don't merge if it's already a proper multi-line block comment
|
|
590
|
-
if (trimmed.startsWith('/*') && trimmed.endsWith('*/')
|
|
591
|
-
|
|
530
|
+
if (trimmed.startsWith('/*') && trimmed.endsWith('*/')) {
|
|
531
|
+
const inner = trimmed.slice(2, -2).trim();
|
|
532
|
+
if (!inner) {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
if (trimmed.includes('\n')) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
592
538
|
}
|
|
593
539
|
// Merge all other content including separator lines, plain text, and single-line block comments
|
|
594
540
|
// Separator lines within comment blocks should be merged together
|
|
@@ -598,98 +544,6 @@ class SqlPrintTokenParser {
|
|
|
598
544
|
* Creates a multi-line block comment structure from consecutive comments
|
|
599
545
|
* Returns a CommentBlock containing multiple comment lines for proper LinePrinter integration
|
|
600
546
|
*/
|
|
601
|
-
createMultiLineCommentBlock(comments) {
|
|
602
|
-
const lines = [];
|
|
603
|
-
for (const comment of comments) {
|
|
604
|
-
const trimmed = comment.trim();
|
|
605
|
-
// Remove existing /* */ markers if present and extract content
|
|
606
|
-
if (trimmed.startsWith('/*') && trimmed.endsWith('*/')) {
|
|
607
|
-
const content = trimmed.slice(2, -2);
|
|
608
|
-
if (content.trim()) {
|
|
609
|
-
// Sanitize the content (only remove /* and */)
|
|
610
|
-
const sanitized = content
|
|
611
|
-
.replace(/\*\//g, '*') // Remove */ sequences
|
|
612
|
-
.replace(/\/\*/g, '*'); // Remove /* sequences
|
|
613
|
-
// Split multi-line content and add each line
|
|
614
|
-
const contentLines = sanitized.split('\n').map(line => line.trim()).filter(line => line);
|
|
615
|
-
lines.push(...contentLines);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
else if (trimmed) {
|
|
619
|
-
// Sanitize plain text content
|
|
620
|
-
const sanitized = trimmed
|
|
621
|
-
.replace(/\*\//g, '*') // Remove */ sequences
|
|
622
|
-
.replace(/\/\*/g, '*'); // Remove /* sequences
|
|
623
|
-
// Split plain text content by lines
|
|
624
|
-
const contentLines = sanitized.split('\n').map(line => line.trim()).filter(line => line);
|
|
625
|
-
lines.push(...contentLines);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
// Create multi-line comment block structure
|
|
629
|
-
const commentBlock = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock);
|
|
630
|
-
if (lines.length === 0) {
|
|
631
|
-
// Empty comment
|
|
632
|
-
const commentToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '/* */');
|
|
633
|
-
commentBlock.innerTokens.push(commentToken);
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
636
|
-
// Opening /*
|
|
637
|
-
const openToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '/*');
|
|
638
|
-
commentBlock.innerTokens.push(openToken);
|
|
639
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
640
|
-
// Content lines (each as separate comment token)
|
|
641
|
-
for (const line of lines) {
|
|
642
|
-
const lineToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, ` ${line}`);
|
|
643
|
-
commentBlock.innerTokens.push(lineToken);
|
|
644
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
645
|
-
}
|
|
646
|
-
// Closing */
|
|
647
|
-
const closeToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '*/');
|
|
648
|
-
commentBlock.innerTokens.push(closeToken);
|
|
649
|
-
}
|
|
650
|
-
// Add final newline and space for standard structure
|
|
651
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
652
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.space, ' '));
|
|
653
|
-
return commentBlock;
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Creates a multi-line comment block specifically for headerComments
|
|
657
|
-
* headerComments come as pre-split lines, so we handle them differently
|
|
658
|
-
*/
|
|
659
|
-
createHeaderMultiLineCommentBlock(headerComments) {
|
|
660
|
-
// Keep all lines including empty ones to preserve structure
|
|
661
|
-
const lines = headerComments;
|
|
662
|
-
// Create multi-line comment block structure
|
|
663
|
-
const commentBlock = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock);
|
|
664
|
-
if (lines.length === 0) {
|
|
665
|
-
// Empty comment
|
|
666
|
-
const commentToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '/* */');
|
|
667
|
-
commentBlock.innerTokens.push(commentToken);
|
|
668
|
-
}
|
|
669
|
-
else {
|
|
670
|
-
// Opening /*
|
|
671
|
-
const openToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '/*');
|
|
672
|
-
commentBlock.innerTokens.push(openToken);
|
|
673
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
674
|
-
// Content lines (each as separate comment token)
|
|
675
|
-
for (const line of lines) {
|
|
676
|
-
// Sanitize the line content
|
|
677
|
-
const sanitized = line
|
|
678
|
-
.replace(/\*\//g, '*') // Remove */ sequences
|
|
679
|
-
.replace(/\/\*/g, '*'); // Remove /* sequences
|
|
680
|
-
const lineToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, ` ${sanitized}`);
|
|
681
|
-
commentBlock.innerTokens.push(lineToken);
|
|
682
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
683
|
-
}
|
|
684
|
-
// Closing */
|
|
685
|
-
const closeToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '*/');
|
|
686
|
-
commentBlock.innerTokens.push(closeToken);
|
|
687
|
-
}
|
|
688
|
-
// Add final newline and space for standard structure
|
|
689
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
690
|
-
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.space, ' '));
|
|
691
|
-
return commentBlock;
|
|
692
|
-
}
|
|
693
547
|
/**
|
|
694
548
|
* Creates a single CommentBlock with the standard structure:
|
|
695
549
|
* Comment -> CommentNewline -> Space
|
|
@@ -717,42 +571,28 @@ class SqlPrintTokenParser {
|
|
|
717
571
|
*/
|
|
718
572
|
formatComment(comment) {
|
|
719
573
|
const trimmed = comment.trim();
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
574
|
+
if (!trimmed) {
|
|
575
|
+
return '/* */';
|
|
576
|
+
}
|
|
577
|
+
const isSeparatorLine = /^[-=_+*#]+$/.test(trimmed);
|
|
578
|
+
if (isSeparatorLine) {
|
|
579
|
+
return this.formatBlockComment(trimmed);
|
|
723
580
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
// But exclude separator lines (lines with only dashes, equals, etc.)
|
|
727
|
-
if (trimmed.startsWith('--') && !/^--[-=_+*#]*$/.test(trimmed)) {
|
|
728
|
-
return trimmed;
|
|
581
|
+
if (trimmed.startsWith('--')) {
|
|
582
|
+
return this.formatLineComment(trimmed.slice(2));
|
|
729
583
|
}
|
|
730
|
-
// If it's already a block comment, preserve it (but sanitize)
|
|
731
584
|
if (trimmed.startsWith('/*') && trimmed.endsWith('*/')) {
|
|
732
|
-
// Pass the entire comment including /* and */ for proper sanitization
|
|
733
585
|
return this.formatBlockComment(trimmed);
|
|
734
586
|
}
|
|
735
|
-
// For plain text comments, convert to block format
|
|
736
587
|
return this.formatBlockComment(trimmed);
|
|
737
588
|
}
|
|
738
|
-
/**
|
|
739
|
-
* Formats comments using smart style rules:
|
|
740
|
-
* - Only multi-line block comment merging is supported
|
|
741
|
-
* - Single-line comments remain as block comments (no dash conversion)
|
|
742
|
-
*/
|
|
743
|
-
formatCommentSmart(comment) {
|
|
744
|
-
// Smart style only affects multi-line comment merging at createSmartCommentBlocks level
|
|
745
|
-
// Individual comment formatting remains the same as block style
|
|
746
|
-
return this.formatBlockComment(comment);
|
|
747
|
-
}
|
|
748
589
|
/**
|
|
749
590
|
* Inserts comment blocks into a token and handles spacing logic.
|
|
750
591
|
* Adds separator spaces for clause-level containers and manages duplicate space removal.
|
|
751
592
|
*/
|
|
752
593
|
insertCommentBlocksWithSpacing(token, commentBlocks) {
|
|
753
|
-
// For SelectItem, append
|
|
594
|
+
// For SelectItem, append comment blocks after ensuring spacing
|
|
754
595
|
if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.SelectItem) {
|
|
755
|
-
// Add space before comment if not already present
|
|
756
596
|
if (token.innerTokens.length > 0) {
|
|
757
597
|
const lastToken = token.innerTokens[token.innerTokens.length - 1];
|
|
758
598
|
if (lastToken.type !== SqlPrintToken_1.SqlPrintTokenType.space) {
|
|
@@ -772,7 +612,6 @@ class SqlPrintTokenParser {
|
|
|
772
612
|
}
|
|
773
613
|
// Special handling for IdentifierString to add space before comment
|
|
774
614
|
if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.IdentifierString) {
|
|
775
|
-
// Add space before comment if not already present
|
|
776
615
|
if (token.innerTokens.length > 0) {
|
|
777
616
|
const lastToken = token.innerTokens[token.innerTokens.length - 1];
|
|
778
617
|
if (lastToken.type !== SqlPrintToken_1.SqlPrintTokenType.space) {
|
|
@@ -875,27 +714,94 @@ class SqlPrintTokenParser {
|
|
|
875
714
|
* Prevents SQL injection by removing dangerous comment sequences.
|
|
876
715
|
*/
|
|
877
716
|
formatBlockComment(comment) {
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
return
|
|
717
|
+
const hasDelimiters = comment.startsWith('/*') && comment.endsWith('*/');
|
|
718
|
+
const rawContent = hasDelimiters ? comment.slice(2, -2) : comment;
|
|
719
|
+
const escapedContent = this.escapeCommentDelimiters(rawContent);
|
|
720
|
+
const normalized = escapedContent.replace(/\r?\n/g, '\n');
|
|
721
|
+
const lines = normalized
|
|
722
|
+
.split('\n')
|
|
723
|
+
.map(line => line.replace(/\s+/g, ' ').trim())
|
|
724
|
+
.filter(line => line.length > 0);
|
|
725
|
+
if (lines.length === 0) {
|
|
726
|
+
return '/* */';
|
|
727
|
+
}
|
|
728
|
+
const isSeparatorLine = lines.length === 1 && /^[-=_+*#]+$/.test(lines[0]);
|
|
729
|
+
if (!hasDelimiters) {
|
|
730
|
+
// Flatten free-form comments to a single block to avoid leaking multi-line structures.
|
|
731
|
+
if (isSeparatorLine) {
|
|
732
|
+
return `/* ${lines[0]} */`;
|
|
733
|
+
}
|
|
734
|
+
const flattened = lines.join(' ');
|
|
735
|
+
return `/* ${flattened} */`;
|
|
736
|
+
}
|
|
737
|
+
if (isSeparatorLine || lines.length === 1) {
|
|
738
|
+
return `/* ${lines[0]} */`;
|
|
739
|
+
}
|
|
740
|
+
const body = lines.map(line => ` ${line}`).join('\n');
|
|
741
|
+
return `/*\n${body}\n*/`;
|
|
742
|
+
}
|
|
743
|
+
shouldMergeHeaderComments(comments) {
|
|
744
|
+
if (comments.length <= 1) {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
return comments.some(comment => {
|
|
748
|
+
const trimmed = comment.trim();
|
|
749
|
+
return /^[-=_+*#]{3,}$/.test(trimmed) || trimmed.startsWith('- ') || trimmed.startsWith('* ');
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
createHeaderMultiLineCommentBlock(headerComments) {
|
|
753
|
+
const commentBlock = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock);
|
|
754
|
+
if (headerComments.length === 0) {
|
|
755
|
+
const commentToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '/* */');
|
|
756
|
+
commentBlock.innerTokens.push(commentToken);
|
|
888
757
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
.
|
|
892
|
-
.
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
758
|
+
else {
|
|
759
|
+
const openToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '/*');
|
|
760
|
+
commentBlock.innerTokens.push(openToken);
|
|
761
|
+
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
762
|
+
for (const line of headerComments) {
|
|
763
|
+
const sanitized = this.escapeCommentDelimiters(line);
|
|
764
|
+
const lineToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, ` ${sanitized}`);
|
|
765
|
+
commentBlock.innerTokens.push(lineToken);
|
|
766
|
+
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
767
|
+
}
|
|
768
|
+
const closeToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '*/');
|
|
769
|
+
commentBlock.innerTokens.push(closeToken);
|
|
897
770
|
}
|
|
898
|
-
|
|
771
|
+
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
772
|
+
commentBlock.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.space, ' '));
|
|
773
|
+
return commentBlock;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Formats text as a single-line comment while sanitizing unsafe sequences.
|
|
777
|
+
*/
|
|
778
|
+
formatLineComment(content) {
|
|
779
|
+
// Normalize content to a single line and remove dangerous sequences
|
|
780
|
+
const sanitized = this.sanitizeLineCommentContent(content);
|
|
781
|
+
if (!sanitized) {
|
|
782
|
+
return '--';
|
|
783
|
+
}
|
|
784
|
+
return `-- ${sanitized}`;
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Sanitizes content intended for a single-line comment.
|
|
788
|
+
*/
|
|
789
|
+
sanitizeLineCommentContent(content) {
|
|
790
|
+
// Replace comment delimiters to avoid nested comment injection
|
|
791
|
+
let sanitized = this.escapeCommentDelimiters(content)
|
|
792
|
+
.replace(/\r?\n/g, ' ')
|
|
793
|
+
.replace(/\u2028|\u2029/g, ' ')
|
|
794
|
+
.replace(/\s+/g, ' ')
|
|
795
|
+
.trim();
|
|
796
|
+
if (sanitized.startsWith('--')) {
|
|
797
|
+
sanitized = sanitized.slice(2).trimStart();
|
|
798
|
+
}
|
|
799
|
+
return sanitized;
|
|
800
|
+
}
|
|
801
|
+
escapeCommentDelimiters(content) {
|
|
802
|
+
return content
|
|
803
|
+
.replace(/\/\*/g, '\\/\\*')
|
|
804
|
+
.replace(/\*\//g, '*\\/');
|
|
899
805
|
}
|
|
900
806
|
visitValueList(arg) {
|
|
901
807
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ValueList);
|
|
@@ -1358,19 +1264,16 @@ class SqlPrintTokenParser {
|
|
|
1358
1264
|
const originalValuePositionedComments = arg.value.positionedComments;
|
|
1359
1265
|
// Clear positioned comments from the value to avoid duplication since SelectItem handles them
|
|
1360
1266
|
arg.value.positionedComments = null;
|
|
1361
|
-
// Add
|
|
1267
|
+
// Add positioned comments in recorded order
|
|
1362
1268
|
const beforeComments = arg.getPositionedComments('before');
|
|
1269
|
+
const afterComments = arg.getPositionedComments('after');
|
|
1270
|
+
const isParenExpression = arg.value.constructor.name === 'ParenExpression';
|
|
1363
1271
|
if (beforeComments.length > 0) {
|
|
1364
1272
|
const commentTokens = this.createInlineCommentSequence(beforeComments);
|
|
1365
1273
|
token.innerTokens.push(...commentTokens);
|
|
1366
1274
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1367
1275
|
}
|
|
1368
|
-
// Add the value (column name)
|
|
1369
1276
|
token.innerTokens.push(this.visit(arg.value));
|
|
1370
|
-
// Add 'after' positioned comments for the value
|
|
1371
|
-
// Skip after comments if the value is ParenExpression (already handled in ParenExpression processing)
|
|
1372
|
-
const afterComments = arg.getPositionedComments('after');
|
|
1373
|
-
const isParenExpression = arg.value.constructor.name === 'ParenExpression';
|
|
1374
1277
|
if (afterComments.length > 0 && !isParenExpression) {
|
|
1375
1278
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1376
1279
|
const commentTokens = this.createInlineCommentSequence(afterComments);
|
|
@@ -1806,9 +1709,7 @@ class SqlPrintTokenParser {
|
|
|
1806
1709
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.SimpleSelectQuery);
|
|
1807
1710
|
// Handle positioned comments for SimpleSelectQuery (unified spec)
|
|
1808
1711
|
if (arg.headerComments && arg.headerComments.length > 0) {
|
|
1809
|
-
|
|
1810
|
-
// For smart comment style, treat headerComments as a single multi-line block
|
|
1811
|
-
if (this.commentStyle === 'smart' && arg.headerComments.length > 1) {
|
|
1712
|
+
if (this.shouldMergeHeaderComments(arg.headerComments)) {
|
|
1812
1713
|
const mergedHeaderComment = this.createHeaderMultiLineCommentBlock(arg.headerComments);
|
|
1813
1714
|
token.innerTokens.push(mergedHeaderComment);
|
|
1814
1715
|
}
|
|
@@ -1894,11 +1795,18 @@ class SqlPrintTokenParser {
|
|
|
1894
1795
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'values', SqlPrintToken_1.SqlPrintTokenContainerType.ValuesQuery);
|
|
1895
1796
|
// Add headerComments before VALUES keyword
|
|
1896
1797
|
if (arg.headerComments && arg.headerComments.length > 0) {
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
token.innerTokens.push(
|
|
1798
|
+
if (this.shouldMergeHeaderComments(arg.headerComments)) {
|
|
1799
|
+
const mergedHeaderComment = this.createHeaderMultiLineCommentBlock(arg.headerComments);
|
|
1800
|
+
token.innerTokens.push(mergedHeaderComment);
|
|
1900
1801
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1901
1802
|
}
|
|
1803
|
+
else {
|
|
1804
|
+
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments);
|
|
1805
|
+
for (const commentBlock of headerCommentBlocks) {
|
|
1806
|
+
token.innerTokens.push(commentBlock);
|
|
1807
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1902
1810
|
}
|
|
1903
1811
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1904
1812
|
const values = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.Values);
|