File tree Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 22 "name" : " prettier-plugin-sql-cst" ,
33 "version" : " 0.11.6" ,
44 "description" : " Prettier plugin for SQL" ,
5- "author" : " Rene Saarsoo <nene@triin.net>" ,
5+ "contributors" : [
6+ " Bowen Parnell <bparnell@4tel.com.au>" ,
7+ " Rene Saarsoo <nene@triin.net>"
8+ ],
69 "license" : " GPL-3.0-or-later" ,
710 "main" : " dist/index.js" ,
811 "types" : " dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ export const isStringLiteral = is("string_literal");
2020export const isArraySubscript = is ( "array_subscript" ) ;
2121export const isAsClause = is ( "as_clause" ) ;
2222export const isParenExpr = is ( "paren_expr" ) ;
23+ export const isSelectStmt = is ( "select_stmt" ) ;
24+ export const isCompoundSelectStmt = is ( "compound_select_stmt" ) ;
2325export const isListExpr = is ( "list_expr" ) ;
2426export const isCreateFunctionStmt = is ( "create_function_stmt" ) ;
2527export const isLanguageClause = is ( "language_clause" ) ;
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ import {
1919 isFuncArgs ,
2020 isListExpr ,
2121 isProgram ,
22+ isSelectStmt ,
23+ isCompoundSelectStmt ,
2224} from "../node_utils" ;
2325import { isString , last } from "../utils" ;
2426
@@ -48,7 +50,9 @@ export const exprMap: CstToDocMap<AllExprNodes> = {
4850 // Discard unnecessary parenthesis around function arguments
4951 if (
5052 isListExpr ( path . getParentNode ( 0 ) ) &&
51- isFuncArgs ( path . getParentNode ( 1 ) )
53+ isFuncArgs ( path . getParentNode ( 1 ) ) &&
54+ ! isSelectStmt ( node . expr ) &&
55+ ! isCompoundSelectStmt ( node . expr )
5256 ) {
5357 return print ( "expr" ) ;
5458 }
Original file line number Diff line number Diff line change @@ -110,6 +110,27 @@ describe("expr", () => {
110110 ` ) ;
111111 } ) ;
112112
113+ it ( `preserves parenthesis around SELECT inside function arguments` , async ( ) => {
114+ await test ( dedent `
115+ SELECT coalesce((SELECT foo FROM bar), 'default') FROM tbl
116+ ` ) ;
117+ } ) ;
118+
119+ it ( `preserves parenthesis around compound-SELECT inside function arguments` , async ( ) => {
120+ await test ( dedent `
121+ SELECT
122+ coalesce(
123+ '',
124+ (
125+ SELECT x FROM xs
126+ UNION
127+ SELECT y FROM ys
128+ )
129+ )
130+ FROM tbl
131+ ` ) ;
132+ } ) ;
133+
113134 describe ( "case" , ( ) => {
114135 it ( `formats CASE expression always on multiple lines` , async ( ) => {
115136 await test ( dedent `
You can’t perform that action at this time.
0 commit comments