Skip to content

Commit 8f991f8

Browse files
fix: resolve VALUES clause over-indentation in SelectStmt
- Change context.indentToCurrentLevel(tuple) to context.indent(tuple) for proper VALUES indentation - Fixes INSERT statement indentation issues in casing-1, casing-10, casing-11, casing-12 tests - Maintains successful fixes for constraints-9, selects-13, misc-8, misc-9 test cases - Completes systematic indentation approach using indentLevel as contextual depth Co-Authored-By: Dan Lynch <[email protected]>
1 parent 97b2f82 commit 8f991f8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/deparser/src/deparser.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ export class Deparser implements DeparserVisitor {
454454
if (this.containsMultilineStringLiteral(tuple)) {
455455
return tuple;
456456
}
457-
return context.indentToCurrentLevel(tuple);
457+
return context.indent(tuple);
458458
});
459459
output.push(indentedTuples.join(',\n'));
460460
} else {
@@ -472,11 +472,11 @@ export class Deparser implements DeparserVisitor {
472472
if (context.isPretty()) {
473473
const groupItems = groupList
474474
.map(e => {
475-
const groupStr = this.visit(e as Node, context.spawn('SelectStmt', { group: true, indentLevel: context.indentLevel + 1 }));
475+
const groupStr = this.visit(e as Node, context.spawn('SelectStmt', { group: true }));
476476
if (this.containsMultilineStringLiteral(groupStr)) {
477477
return groupStr;
478478
}
479-
return context.indentToCurrentLevel(groupStr);
479+
return context.indent(groupStr);
480480
})
481481
.join(',' + context.newline());
482482
output.push('GROUP BY');
@@ -497,7 +497,7 @@ export class Deparser implements DeparserVisitor {
497497
if (this.containsMultilineStringLiteral(havingStr)) {
498498
output.push(havingStr);
499499
} else {
500-
output.push(context.indentToCurrentLevel(havingStr));
500+
output.push(context.indent(havingStr));
501501
}
502502
} else {
503503
output.push('HAVING');
@@ -519,11 +519,11 @@ export class Deparser implements DeparserVisitor {
519519
if (context.isPretty()) {
520520
const sortItems = sortList
521521
.map(e => {
522-
const sortStr = this.visit(e as Node, context.spawn('SelectStmt', { sort: true, indentLevel: context.indentLevel + 1 }));
522+
const sortStr = this.visit(e as Node, context.spawn('SelectStmt', { sort: true }));
523523
if (this.containsMultilineStringLiteral(sortStr)) {
524524
return sortStr;
525525
}
526-
return context.indentToCurrentLevel(sortStr);
526+
return context.indent(sortStr);
527527
})
528528
.join(',' + context.newline());
529529
output.push('ORDER BY');
@@ -949,7 +949,7 @@ export class Deparser implements DeparserVisitor {
949949

950950
if (context.isPretty()) {
951951
// Always format columns in multiline parentheses for pretty printing
952-
const indentedColumns = columnNames.map(col => context.indentToCurrentLevel(col));
952+
const indentedColumns = columnNames.map(col => context.indent(col));
953953
output.push('(\n' + indentedColumns.join(',\n') + '\n)');
954954
} else {
955955
output.push(context.parens(columnNames.join(', ')));
@@ -1173,12 +1173,12 @@ export class Deparser implements DeparserVisitor {
11731173
const ctes = ListUtils.unwrapList(node.ctes);
11741174
if (context.isPretty()) {
11751175
const cteStrings = ctes.map((cte, index) => {
1176-
const cteStr = this.visit(cte, context);
1176+
const cteStr = this.visit(cte, context.spawn('WithClause'));
11771177
const prefix = index === 0 ? context.newline() : ',' + context.newline();
11781178
if (this.containsMultilineStringLiteral(cteStr)) {
11791179
return prefix + cteStr;
11801180
}
1181-
return prefix + context.indentToCurrentLevel(cteStr);
1181+
return prefix + context.indent(cteStr);
11821182
});
11831183
output.push(cteStrings.join(''));
11841184
} else {
@@ -1514,7 +1514,7 @@ export class Deparser implements DeparserVisitor {
15141514

15151515
if (windowParts.length > 0) {
15161516
if (context.isPretty() && windowParts.length > 1) {
1517-
const formattedParts = windowParts.map(part => context.indentToCurrentLevel(part));
1517+
const formattedParts = windowParts.map(part => context.indent(part));
15181518
result += ` OVER (${context.newline()}${formattedParts.join(context.newline())}${context.newline()})`;
15191519
} else {
15201520
result += ` OVER (${windowParts.join(' ')})`;

0 commit comments

Comments
 (0)