Skip to content

Commit 6cc2f4e

Browse files
committed
feat: improve indentation for boolean expressions and SELECT clauses
- Replace hardcoded ' AND ' and ' OR ' spacing with context.indent() in BoolExpr - Add proper indentLevel context spawning for GROUP BY and ORDER BY clauses - Boolean expressions now use context-aware indentation for better logical grouping - SELECT clause elements properly track indent levels through context spawning - Consistent indentation management across nested statements and expressions Co-Authored-By: Dan Lynch <[email protected]>
1 parent 22d5915 commit 6cc2f4e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/deparser/src/deparser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ 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 }));
475+
const groupStr = this.visit(e as Node, context.spawn('SelectStmt', { group: true, indentLevel: context.indentLevel + 1 }));
476476
if (this.containsMultilineStringLiteral(groupStr)) {
477477
return groupStr;
478478
}
@@ -519,7 +519,7 @@ 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 }));
522+
const sortStr = this.visit(e as Node, context.spawn('SelectStmt', { sort: true, indentLevel: context.indentLevel + 1 }));
523523
if (this.containsMultilineStringLiteral(sortStr)) {
524524
return sortStr;
525525
}
@@ -1282,15 +1282,15 @@ export class Deparser implements DeparserVisitor {
12821282
switch (boolop) {
12831283
case 'AND_EXPR':
12841284
if (context.isPretty() && args.length > 1) {
1285-
const andArgs = args.map(arg => this.visit(arg, boolContext)).join(context.newline() + ' AND ');
1285+
const andArgs = args.map(arg => this.visit(arg, boolContext)).join(context.newline() + context.indent('AND '));
12861286
return formatStr.replace('%s', () => andArgs);
12871287
} else {
12881288
const andArgs = args.map(arg => this.visit(arg, boolContext)).join(' AND ');
12891289
return formatStr.replace('%s', () => andArgs);
12901290
}
12911291
case 'OR_EXPR':
12921292
if (context.isPretty() && args.length > 1) {
1293-
const orArgs = args.map(arg => this.visit(arg, boolContext)).join(context.newline() + ' OR ');
1293+
const orArgs = args.map(arg => this.visit(arg, boolContext)).join(context.newline() + context.indent('OR '));
12941294
return formatStr.replace('%s', () => orArgs);
12951295
} else {
12961296
const orArgs = args.map(arg => this.visit(arg, boolContext)).join(' OR ');

0 commit comments

Comments
 (0)