pgsql-deparser 17.18.1 → 17.18.2

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/deparser.js CHANGED
@@ -658,10 +658,15 @@ class Deparser {
658
658
  return context.format([leftExpr, operator, rightExpr]);
659
659
  }
660
660
  else if (rexpr) {
661
- return context.format([
662
- this.deparseOperatorName(name, context),
663
- this.visit(rexpr, context)
664
- ]);
661
+ // Unary operator (e.g., unary minus: - expr)
662
+ const operator = this.deparseOperatorName(name, context);
663
+ let rightExpr = this.visit(rexpr, context);
664
+ // Wrap in parentheses if rexpr is a binary A_Expr to preserve semantics
665
+ // e.g., -(a - b) must stay -(a - b), not become -a - b
666
+ if (rexpr && 'A_Expr' in rexpr && rexpr.A_Expr?.kind === 'AEXPR_OP' && rexpr.A_Expr?.lexpr) {
667
+ rightExpr = context.parens(rightExpr);
668
+ }
669
+ return context.format([operator, rightExpr]);
665
670
  }
666
671
  break;
667
672
  case 'AEXPR_OP_ANY':
package/esm/deparser.js CHANGED
@@ -655,10 +655,15 @@ export class Deparser {
655
655
  return context.format([leftExpr, operator, rightExpr]);
656
656
  }
657
657
  else if (rexpr) {
658
- return context.format([
659
- this.deparseOperatorName(name, context),
660
- this.visit(rexpr, context)
661
- ]);
658
+ // Unary operator (e.g., unary minus: - expr)
659
+ const operator = this.deparseOperatorName(name, context);
660
+ let rightExpr = this.visit(rexpr, context);
661
+ // Wrap in parentheses if rexpr is a binary A_Expr to preserve semantics
662
+ // e.g., -(a - b) must stay -(a - b), not become -a - b
663
+ if (rexpr && 'A_Expr' in rexpr && rexpr.A_Expr?.kind === 'AEXPR_OP' && rexpr.A_Expr?.lexpr) {
664
+ rightExpr = context.parens(rightExpr);
665
+ }
666
+ return context.format([operator, rightExpr]);
662
667
  }
663
668
  break;
664
669
  case 'AEXPR_OP_ANY':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "17.18.1",
3
+ "version": "17.18.2",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PostgreSQL AST Deparser",
6
6
  "main": "index.js",
@@ -60,5 +60,5 @@
60
60
  "@pgsql/quotes": "17.1.0",
61
61
  "@pgsql/types": "^17.6.2"
62
62
  },
63
- "gitHead": "58ddefe11a5d002db6645fa7bc2f284123d48470"
63
+ "gitHead": "cdd732b4694b84522895d2d1dd8d5db9944875d5"
64
64
  }