prettier-plugin-sql-cst 0.16.0 → 0.17.0

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 CHANGED
@@ -125,16 +125,100 @@ The plugin provides the following parsers:
125
125
  ## Configuration
126
126
 
127
127
  The standard Prettier options [printWidth][], [tabWidth][], [useTabs][] apply.
128
- There are also some SQL-specific options:
129
-
130
- | API Option | Default | Description |
131
- | ----------------------------- | :-----: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132
- | `sqlKeywordCase` | `upper` | Convert SQL keywords to `upper` or `lower` case, or `preserve` existing. Note that for now `preserve` is somewhat incompatible with `sqlCanonicalSyntax: true` (e.g. the added `AS` keywords will always be in uppercase). In most dialects this also applies to data types, but not in PostgreSQL where data type names are treated as identifiers. |
133
- | `sqlLiteralCase` | `upper` | Convert SQL literals TRUE, FALSE and NULL to `upper` or `lower` case, or `preserve` existing. Also applies to `on` & `off` literals in PostgreSQL SET statements. |
134
- | `sqlParamTypes` | `[]` | Array of bound parameter types: `?`, `?nr`, `$nr`, `:name`, `@name`, `$name`. |
135
- | `sqlCanonicalSyntax` | `true` | When enabled, performs some opinionated changes of keywords and operators, like enforcing the use of `AS` in aliases and replacing `<>` comparisons with `!=`. See [STYLE_GUIDE][] for more details. (Since 0.11.0) |
136
- | `sqlFinalSemicolon` | `true` | When enabled, enforces a semicolon at the end of last statement. When disabled leaves it up to the author whether to add a final semicolon or not. (Since 0.13.0) |
137
- | `sqlAcceptUnsupportedGrammar` | `false` | Normally when the plugin encounters SQL syntax it doesn't support it will throw an error and won't format anything at all. With this option enabled, it will skip over SQL statements it doesn't recognize, leaving them as-is. |
128
+ There are also several SQL-specific options:
129
+
130
+ - **`sqlKeywordCase`**: `"upper" | "lower" | "preserve"` (default `"upper"`)
131
+
132
+ Enforce case of keywords.
133
+
134
+ This effects all keywords except literals (see `sqlLiteralCase`) and data types (see `sqlTypeCase`).
135
+
136
+ For now `preserve` is somewhat incompatible with `sqlCanonicalSyntax: true` (e.g. the added `AS` keywords will always be in uppercase).
137
+
138
+ - **`sqlLiteralCase`**: `"upper" | "lower" | "preserve"` (default `"upper"`)
139
+
140
+ Enforce case of literals TRUE, FALSE and NULL.
141
+
142
+ Also applies to ON & OFF literals in PostgreSQL SET statements.
143
+
144
+ _Since 0.14.0_
145
+
146
+ - **`sqlTypeCase`**: `"upper" | "lower" | "preserve"` (default `"upper"`)
147
+
148
+ Enforce case of type names.
149
+
150
+ In PostgreSQL this will only effect a limited set of builtin data types, the rest will be formatted as identifiers.
151
+ It will effect casing of all the keywords in types like `TIMESTAMP WITH TIME ZONE` and `INTERVAL DAY TO SECOND`,
152
+ but it won't effect the casing of `SETOF` and `TABLE` keywords in `SETOF type` and `TABLE (x int, y int)`.
153
+ For PostgreSQL the recommended setting of this option is `lower`.
154
+
155
+ In BigQuery this also effects the names parametric types,
156
+ for example `array<struct<x int64>>` will get formatted as `ARRAY<STRUCT<x INT64>>`.
157
+
158
+ _Since 0.17.0_
159
+
160
+ - **`sqlIdentifierCase`**: `"upper" | "lower" | "preserve"` (default `"preserve"`)
161
+
162
+ Enforce case of unquoted identifier names.
163
+
164
+ This effects all identifiers except function names (see `sqlFunctionCase`).
165
+
166
+ Beware that in BigQuery unquoted identifiers are case-sensitive, so use of this option with BigQuery is not recommended.
167
+
168
+ **Experimental:** This option is still new and not thoroughly tested. You have been warned.
169
+
170
+ _Since 0.17.0_
171
+
172
+ - **`sqlFunctionCase`**: `"upper" | "lower" | "preserve"` (default `"preserve"`)
173
+
174
+ Enforce case of unquoted function names.
175
+
176
+ This option also applies to schema-qualified function names,
177
+ for example `my_schema.foo()` will get formatted as `my_schema.FOO()`
178
+ when `sqlFunctionCase: "upper"` is configured.
179
+
180
+ **Experimental:** This option is still new and not thoroughly tested. You have been warned.
181
+
182
+ _Since 0.17.0_
183
+
184
+ - **`sqlParamTypes`**: `("?", "?nr", "$nr", ":name", "$name", "@name" "@``@name``")[]` (default `[]`)
185
+
186
+ Array of bound parameter types to support.
187
+
188
+ By default the parser will reject the following SQL:
189
+
190
+ ```sql
191
+ SELECT id, name FROM products WHERE price > ? AND category = ?
192
+ ```
193
+
194
+ Configuring `sqlParamTypes: ["?"]` will make the parser recognize the `?` placeholders.
195
+
196
+ _Since 0.7.0_
197
+
198
+ - **`sqlCanonicalSyntax`**: `boolean` (default `true`)
199
+
200
+ When enabled, performs some opinionated changes of keywords and operators,
201
+ like enforcing the use of `AS` in aliases and replacing `<>` comparisons with `!=`.
202
+ See [STYLE_GUIDE][] for more details.
203
+
204
+ _Since 0.11.0_
205
+
206
+ - **`sqlFinalSemicolon`**: `boolean` (default `true`)
207
+
208
+ When enabled, enforces a semicolon at the end of last statement.
209
+ When disabled leaves it up to the author whether to add a final semicolon or not.
210
+
211
+ _Since 0.13.0_
212
+
213
+ - **`sqlAcceptUnsupportedGrammar`**: `boolean` (default `false`)
214
+
215
+ Normally when the plugin encounters SQL syntax it doesn't support
216
+ it will throw an error and won't format anything at all.
217
+ With this option enabled, it will skip over SQL statements it doesn't recognize, leaving them as-is.
218
+
219
+ **Deprecated:** This doesn't really work as advertised and will likely be removed.
220
+
221
+ _Since 0.12.0_
138
222
 
139
223
  ## Usage inside VSCode
140
224
 
@@ -12,9 +12,24 @@ export declare const isStringLiteral: (node: any) => node is import("sql-parser-
12
12
  export declare const isArraySubscript: (node: any) => node is import("sql-parser-cst").ArraySubscript;
13
13
  export declare const isAsClause: (node: any) => node is import("sql-parser-cst").AsClause<Node>;
14
14
  export declare const isParenExpr: (node: any) => node is import("sql-parser-cst").ParenExpr<Node>;
15
+ export declare const isMemberExpr: (node: any) => node is import("sql-parser-cst").MemberExpr;
15
16
  export declare const isSelectStmt: (node: any) => node is import("sql-parser-cst").SelectStmt;
16
17
  export declare const isCompoundSelectStmt: (node: any) => node is import("sql-parser-cst").CompoundSelectStmt;
17
18
  export declare const isListExpr: (node: any) => node is import("sql-parser-cst").ListExpr<Node>;
18
19
  export declare const isCreateFunctionStmt: (node: any) => node is import("sql-parser-cst").CreateFunctionStmt;
20
+ export declare const isAlterFunctionStmt: (node: any) => node is import("sql-parser-cst").AlterFunctionStmt;
21
+ export declare const isDropFunctionStmt: (node: any) => node is import("sql-parser-cst").DropFunctionStmt;
22
+ export declare const isCreateProcedureStmt: (node: any) => node is import("sql-parser-cst").CreateProcedureStmt;
23
+ export declare const isAlterProcedureStmt: (node: any) => node is import("sql-parser-cst").AlterProcedureStmt;
24
+ export declare const isDropProcedureStmt: (node: any) => node is import("sql-parser-cst").DropProcedureStmt;
25
+ export declare const isAlterActionRename: (node: any) => node is import("sql-parser-cst").AlterActionRename;
19
26
  export declare const isLanguageClause: (node: any) => node is import("sql-parser-cst").LanguageClause;
20
27
  export declare const isDynamicallyLoadedFunction: (node: any) => node is import("sql-parser-cst").DynamicallyLoadedFunction;
28
+ export declare const isBigqueryQuotedMemberExpr: (node: any) => node is import("sql-parser-cst").BigQueryQuotedMemberExpr;
29
+ export declare const isCreateTriggerStmt: (node: any) => node is import("sql-parser-cst").CreateTriggerStmt;
30
+ export declare const isExecuteClause: (node: any) => node is import("sql-parser-cst").ExecuteClause;
31
+ export declare const isDataTypeName: (node: any) => node is import("sql-parser-cst").DataTypeName;
32
+ export declare const isIntervalDataType: (node: any) => node is import("sql-parser-cst").IntervalDataType;
33
+ export declare const isTimeDataType: (node: any) => node is import("sql-parser-cst").TimeDataType;
34
+ export declare const isParametricDataType: (node: any) => node is import("sql-parser-cst").ParametricDataType;
35
+ export declare const isDataType: (node: any) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDynamicallyLoadedFunction = exports.isLanguageClause = exports.isCreateFunctionStmt = exports.isListExpr = exports.isCompoundSelectStmt = exports.isSelectStmt = exports.isParenExpr = exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = exports.isJsonbLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncArgs = exports.isFuncCall = exports.isValuesClause = exports.isProgram = void 0;
3
+ exports.isDataType = exports.isParametricDataType = exports.isTimeDataType = exports.isIntervalDataType = exports.isDataTypeName = exports.isExecuteClause = exports.isCreateTriggerStmt = exports.isBigqueryQuotedMemberExpr = exports.isDynamicallyLoadedFunction = exports.isLanguageClause = exports.isAlterActionRename = exports.isDropProcedureStmt = exports.isAlterProcedureStmt = exports.isCreateProcedureStmt = exports.isDropFunctionStmt = exports.isAlterFunctionStmt = exports.isCreateFunctionStmt = exports.isListExpr = exports.isCompoundSelectStmt = exports.isSelectStmt = exports.isMemberExpr = exports.isParenExpr = exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = exports.isJsonbLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncArgs = exports.isFuncCall = exports.isValuesClause = exports.isProgram = void 0;
4
4
  var utils_1 = require("./utils");
5
5
  var is = function (type) {
6
6
  return function (node) {
@@ -20,9 +20,30 @@ exports.isStringLiteral = is("string_literal");
20
20
  exports.isArraySubscript = is("array_subscript");
21
21
  exports.isAsClause = is("as_clause");
22
22
  exports.isParenExpr = is("paren_expr");
23
+ exports.isMemberExpr = is("member_expr");
23
24
  exports.isSelectStmt = is("select_stmt");
24
25
  exports.isCompoundSelectStmt = is("compound_select_stmt");
25
26
  exports.isListExpr = is("list_expr");
26
27
  exports.isCreateFunctionStmt = is("create_function_stmt");
28
+ exports.isAlterFunctionStmt = is("alter_function_stmt");
29
+ exports.isDropFunctionStmt = is("drop_function_stmt");
30
+ exports.isCreateProcedureStmt = is("create_procedure_stmt");
31
+ exports.isAlterProcedureStmt = is("alter_procedure_stmt");
32
+ exports.isDropProcedureStmt = is("drop_procedure_stmt");
33
+ exports.isAlterActionRename = is("alter_action_rename");
27
34
  exports.isLanguageClause = is("language_clause");
28
35
  exports.isDynamicallyLoadedFunction = is("dynamically_loaded_function");
36
+ exports.isBigqueryQuotedMemberExpr = is("bigquery_quoted_member_expr");
37
+ exports.isCreateTriggerStmt = is("create_trigger_stmt");
38
+ exports.isExecuteClause = is("execute_clause");
39
+ exports.isDataTypeName = is("data_type_name");
40
+ exports.isIntervalDataType = is("interval_data_type");
41
+ exports.isTimeDataType = is("time_data_type");
42
+ exports.isParametricDataType = is("parametric_data_type");
43
+ var isDataType = function (node) {
44
+ return (0, exports.isDataTypeName)(node) ||
45
+ (0, exports.isIntervalDataType)(node) ||
46
+ (0, exports.isTimeDataType)(node) ||
47
+ (0, exports.isParametricDataType)(node);
48
+ };
49
+ exports.isDataType = isDataType;
package/dist/options.d.ts CHANGED
@@ -3,6 +3,9 @@ import { Node, ParserOptions as CstParserOptions } from "sql-parser-cst";
3
3
  export interface SqlPluginOptions {
4
4
  sqlKeywordCase: "preserve" | "upper" | "lower";
5
5
  sqlLiteralCase: "preserve" | "upper" | "lower";
6
+ sqlTypeCase: "preserve" | "upper" | "lower";
7
+ sqlIdentifierCase: "preserve" | "upper" | "lower";
8
+ sqlFunctionCase: "preserve" | "upper" | "lower";
6
9
  sqlParamTypes: NonNullable<CstParserOptions["paramTypes"]>;
7
10
  sqlCanonicalSyntax: boolean;
8
11
  sqlFinalSemicolon: boolean;
package/dist/options.js CHANGED
@@ -38,16 +38,85 @@ exports.options = {
38
38
  },
39
39
  {
40
40
  value: "upper",
41
- description: "forces all keywords to uppercase",
41
+ description: "forces all literals to uppercase",
42
42
  since: "0.14.0",
43
43
  },
44
44
  {
45
45
  value: "lower",
46
- description: "forces all keywords to lowercase",
46
+ description: "forces all literals to lowercase",
47
47
  since: "0.14.0",
48
48
  },
49
49
  ],
50
50
  },
51
+ sqlTypeCase: {
52
+ type: "choice",
53
+ category: "SQL",
54
+ default: "upper",
55
+ description: "Enforces upper/lower case for SQL types",
56
+ choices: [
57
+ {
58
+ value: "preserve",
59
+ description: "preserves the existing case",
60
+ since: "0.17.0",
61
+ },
62
+ {
63
+ value: "upper",
64
+ description: "forces all type names to uppercase",
65
+ since: "0.17.0",
66
+ },
67
+ {
68
+ value: "lower",
69
+ description: "forces all type names to lowercase",
70
+ since: "0.17.0",
71
+ },
72
+ ],
73
+ },
74
+ sqlIdentifierCase: {
75
+ type: "choice",
76
+ category: "SQL",
77
+ default: "preserve",
78
+ description: "Enforces upper/lower case for unquoted SQL identifiers",
79
+ choices: [
80
+ {
81
+ value: "preserve",
82
+ description: "preserves the existing case",
83
+ since: "0.17.0",
84
+ },
85
+ {
86
+ value: "upper",
87
+ description: "forces all unquoted identifier names to uppercase",
88
+ since: "0.17.0",
89
+ },
90
+ {
91
+ value: "lower",
92
+ description: "forces all unquoted identifier names to lowercase",
93
+ since: "0.17.0",
94
+ },
95
+ ],
96
+ },
97
+ sqlFunctionCase: {
98
+ type: "choice",
99
+ category: "SQL",
100
+ default: "preserve",
101
+ description: "Enforces upper/lower case for SQL function names",
102
+ choices: [
103
+ {
104
+ value: "preserve",
105
+ description: "preserves the existing case",
106
+ since: "0.17.0",
107
+ },
108
+ {
109
+ value: "upper",
110
+ description: "forces all unquoted function names to uppercase",
111
+ since: "0.17.0",
112
+ },
113
+ {
114
+ value: "lower",
115
+ description: "forces all unquoted function names to lowercase",
116
+ since: "0.17.0",
117
+ },
118
+ ],
119
+ },
51
120
  sqlParamTypes: {
52
121
  type: "string",
53
122
  array: true,
@@ -55,7 +124,7 @@ exports.options = {
55
124
  default: [{ value: [] }],
56
125
  description: "Syntax for bound parameters",
57
126
  // Since 0.7.0
58
- // Possible values in array: "?" | "?nr" | "$nr" | ":name" | "$name" | "@name"
127
+ // Possible values in array: "?" | "?nr" | "$nr" | ":name" | "$name" | "@name" | "@`name`"
59
128
  },
60
129
  sqlCanonicalSyntax: {
61
130
  type: "boolean",
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.analyzeMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
4
5
  exports.analyzeMap = {
5
- analyze_stmt: function (print) { return print.spaced(["analyzeKw", "tableKw", "tables"]); },
6
+ analyze_stmt: function (print) {
7
+ return (0, print_utils_1.group)(print.spaced(["analyzeKw", "tableKw", "tables"]));
8
+ },
6
9
  };
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.baseMap = void 0;
4
+ var node_utils_1 = require("../node_utils");
4
5
  exports.baseMap = {
5
6
  /** cst-ignore: name */
6
7
  keyword: function (print, node, path, options) {
7
- var _a;
8
- // Treat PostgreSQL "WITH TIME ZONE" as part of data type, not keyword,
9
- // so skip keyword case conversion for it
10
- if (((_a = path.parent) === null || _a === void 0 ? void 0 : _a.type) === "with_time_zone_data_type") {
11
- return path.node.text;
12
- }
13
- switch (options.sqlKeywordCase) {
8
+ var keywordCase = (0, node_utils_1.isDataType)(path.parent)
9
+ ? options.sqlTypeCase
10
+ : options.sqlKeywordCase;
11
+ switch (keywordCase) {
14
12
  case "preserve":
15
13
  return path.node.text;
16
14
  case "upper":
@@ -19,7 +19,7 @@ exports.createTableMap = {
19
19
  for (var _i = 2; _i < arguments.length; _i++) {
20
20
  rest[_i - 2] = arguments[_i];
21
21
  }
22
- return [
22
+ return (0, print_utils_1.group)([
23
23
  print.spaced([
24
24
  "createKw",
25
25
  "orReplaceKw",
@@ -33,7 +33,7 @@ exports.createTableMap = {
33
33
  ]),
34
34
  printClauses.apply(void 0, __spreadArray([print, node], rest, false)),
35
35
  node.options ? [print_utils_1.line, (0, print_utils_1.group)(print("options"))] : [],
36
- ];
36
+ ]);
37
37
  },
38
38
  relation_kind: function (print) { return print.spaced("kindKw"); },
39
39
  column_definition: function (print) {
@@ -1,20 +1,39 @@
1
1
  "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.dataTypeMap = void 0;
4
13
  var utils_1 = require("../utils");
5
14
  var print_utils_1 = require("../print_utils");
15
+ var node_utils_1 = require("../node_utils");
6
16
  exports.dataTypeMap = {
17
+ data_type_name: function (print) { return print.spaced("name"); },
7
18
  // print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
8
- named_data_type: function (print, node) {
9
- return (isMultiWordTypeName(node) ? print.spaced : print)(["name", "params"]);
19
+ modified_data_type: function (print, node) {
20
+ return (isMultiWordTypeName(node.dataType) ? print.spaced : print)([
21
+ "dataType",
22
+ "modifiers",
23
+ ]);
10
24
  },
11
- data_type_identifier: function (print) { return print.spaced("name"); },
12
25
  setof_data_type: function (print) { return print.spaced(["setofKw", "dataType"]); },
13
26
  array_data_type: function (print) { return print(["dataType", "bounds"]); },
14
27
  array_bounds: function (print) { return ["[", print("bounds"), "]"]; },
15
- with_time_zone_data_type: function (print) {
16
- return print.spaced(["dataType", "withTimeZoneKw"]);
28
+ time_data_type: function (print, node) {
29
+ return (0, print_utils_1.group)((0, print_utils_1.join)(" ", __spreadArray([
30
+ print(["timeKw", "precision"])
31
+ ], (node.timeZoneKw ? [print.spaced("timeZoneKw")] : []), true)));
32
+ },
33
+ interval_data_type: function (print) {
34
+ return print.spaced(["intervalKw", "fieldsKw", "precision"]);
17
35
  },
36
+ parametric_data_type: function (print) { return print(["typeKw", "params"]); },
18
37
  generic_type_params: function (print) {
19
38
  return (0, print_utils_1.group)(["<", (0, print_utils_1.indent)([print_utils_1.softline, print("params")]), print_utils_1.softline, ">"]);
20
39
  },
@@ -25,6 +44,5 @@ exports.dataTypeMap = {
25
44
  table_data_type: function (print) { return print.spaced(["tableKw", "columns"]); },
26
45
  };
27
46
  function isMultiWordTypeName(node) {
28
- return ((0, utils_1.isArray)(node.name) ||
29
- (node.name.type === "data_type_identifier" && (0, utils_1.isArray)(node.name.name)));
47
+ return (0, node_utils_1.isDataTypeName)(node) && (0, utils_1.isArray)(node.name) && node.name.length > 1;
30
48
  }
@@ -18,7 +18,7 @@ exports.bigqueryMap = {
18
18
  },
19
19
  // ROW ACCESS POLICY
20
20
  create_row_access_policy_stmt: function (print) {
21
- return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
21
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
22
22
  print.spaced([
23
23
  "createKw",
24
24
  "orReplaceKw",
@@ -28,7 +28,7 @@ exports.bigqueryMap = {
28
28
  "onKw",
29
29
  "table",
30
30
  ])
31
- ], print("clauses"), true));
31
+ ], print("clauses"), true)));
32
32
  },
33
33
  row_access_policy_grant_clause: function (print) {
34
34
  return print.spaced(["grantToKw", "grantees"]);
@@ -37,7 +37,7 @@ exports.bigqueryMap = {
37
37
  return print.spaced(["filterUsingKw", "expr"]);
38
38
  },
39
39
  drop_row_access_policy_stmt: function (print) {
40
- return print.spaced([
40
+ return (0, print_utils_1.group)(print.spaced([
41
41
  "dropKw",
42
42
  "allKw",
43
43
  "rowAccessPolicyKw",
@@ -45,80 +45,86 @@ exports.bigqueryMap = {
45
45
  "name",
46
46
  "onKw",
47
47
  "table",
48
- ]);
48
+ ]));
49
49
  },
50
50
  // CAPACITY
51
- create_capacity_stmt: function (print) { return [
52
- print.spaced(["createKw", "capacityKw", "name"]),
53
- print_utils_1.hardline,
54
- print("options"),
55
- ]; },
51
+ create_capacity_stmt: function (print) {
52
+ return (0, print_utils_1.group)([
53
+ print.spaced(["createKw", "capacityKw", "name"]),
54
+ print_utils_1.hardline,
55
+ print("options"),
56
+ ]);
57
+ },
56
58
  drop_capacity_stmt: function (print) {
57
- return print.spaced(["dropKw", "capacityKw", "ifExistsKw", "name"]);
59
+ return (0, print_utils_1.group)(print.spaced(["dropKw", "capacityKw", "ifExistsKw", "name"]));
58
60
  },
59
61
  // RESERVATION
60
- create_reservation_stmt: function (print) { return [
61
- print.spaced(["createKw", "reservationKw", "name"]),
62
- print_utils_1.hardline,
63
- print("options"),
64
- ]; },
62
+ create_reservation_stmt: function (print) {
63
+ return (0, print_utils_1.group)([
64
+ print.spaced(["createKw", "reservationKw", "name"]),
65
+ print_utils_1.hardline,
66
+ print("options"),
67
+ ]);
68
+ },
65
69
  drop_reservation_stmt: function (print) {
66
- return print.spaced(["dropKw", "reservationKw", "ifExistsKw", "name"]);
70
+ return (0, print_utils_1.group)(print.spaced(["dropKw", "reservationKw", "ifExistsKw", "name"]));
67
71
  },
68
72
  // ASSIGNMENT
69
- create_assignment_stmt: function (print) { return [
70
- print.spaced(["createKw", "assignmentKw", "name"]),
71
- print_utils_1.hardline,
72
- print("options"),
73
- ]; },
73
+ create_assignment_stmt: function (print) {
74
+ return (0, print_utils_1.group)([
75
+ print.spaced(["createKw", "assignmentKw", "name"]),
76
+ print_utils_1.hardline,
77
+ print("options"),
78
+ ]);
79
+ },
74
80
  drop_assignment_stmt: function (print) {
75
- return print.spaced(["dropKw", "assignmentKw", "ifExistsKw", "name"]);
81
+ return (0, print_utils_1.group)(print.spaced(["dropKw", "assignmentKw", "ifExistsKw", "name"]));
76
82
  },
77
83
  // ALTER ORGANIZATION
78
84
  alter_organization_stmt: function (print) {
79
- return (0, print_utils_1.join)(print_utils_1.hardline, [print.spaced("alterOrganizationKw"), print("actions")]);
85
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [print.spaced("alterOrganizationKw"), print("actions")]));
80
86
  },
81
87
  // ALTER PROJECT
82
88
  alter_project_stmt: function (print) {
83
- return (0, print_utils_1.join)(print_utils_1.hardline, [
89
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
84
90
  print.spaced(["alterProjectKw", "name"]),
85
91
  print("actions"),
86
- ]);
92
+ ]));
87
93
  },
88
94
  alter_bi_capacity_stmt: function (print) {
89
- return (0, print_utils_1.join)(print_utils_1.hardline, [
95
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
90
96
  print.spaced(["alterBiCapacityKw", "name"]),
91
97
  print("actions"),
92
- ]);
98
+ ]));
93
99
  },
94
100
  alter_capacity_stmt: function (print) {
95
- return (0, print_utils_1.join)(print_utils_1.hardline, [
101
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
96
102
  print.spaced(["alterCapacityKw", "name"]),
97
103
  print("actions"),
98
- ]);
104
+ ]));
99
105
  },
100
106
  alter_reservation_stmt: function (print) {
101
- return (0, print_utils_1.join)(print_utils_1.hardline, [
107
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
102
108
  print.spaced(["alterReservationKw", "name"]),
103
109
  print("actions"),
104
- ]);
110
+ ]));
105
111
  },
106
112
  // ASSERT
107
- assert_stmt: function (print) { return print.spaced(["assertKw", "expr", "as"]); },
113
+ assert_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["assertKw", "expr", "as"])); },
108
114
  // EXPORT
109
115
  export_data_stmt: function (print) {
110
- return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([
116
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([
111
117
  print.spaced("exportDataKw")
112
118
  ], print.spaced(["withConnection"]), true), [
113
119
  print.spaced("options"),
114
120
  print.spaced("as"),
115
- ], false));
121
+ ], false)));
116
122
  },
117
123
  // LOAD
118
124
  load_data_stmt: function (print) {
119
- return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
125
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
120
126
  print.spaced(["loadDataKw", "intoKw", "table", "columns"])
121
- ], print("clauses"), true));
127
+ ], print("clauses"), true)));
122
128
  },
123
129
  from_files_options: function (print) { return print.spaced(["fromFilesKw", "options"]); },
124
130
  };
@@ -4,15 +4,15 @@ exports.sqliteMap = void 0;
4
4
  var print_utils_1 = require("../../print_utils");
5
5
  exports.sqliteMap = {
6
6
  attach_database_stmt: function (print) {
7
- return print.spaced(["attachKw", "databaseKw", "file", "asKw", "schema"]);
7
+ return (0, print_utils_1.group)(print.spaced(["attachKw", "databaseKw", "file", "asKw", "schema"]));
8
8
  },
9
9
  detach_database_stmt: function (print) {
10
- return print.spaced(["detachKw", "databaseKw", "schema"]);
10
+ return (0, print_utils_1.group)(print.spaced(["detachKw", "databaseKw", "schema"]));
11
11
  },
12
12
  vacuum_stmt: function (print) {
13
- return print.spaced(["vacuumKw", "schema", "intoKw", "file"]);
13
+ return (0, print_utils_1.group)(print.spaced(["vacuumKw", "schema", "intoKw", "file"]));
14
14
  },
15
- pragma_stmt: function (print) { return print.spaced(["pragmaKw", "pragma"]); },
15
+ pragma_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["pragmaKw", "pragma"])); },
16
16
  pragma_assignment: function (print) { return (0, print_utils_1.join)(" = ", print(["name", "value"])); },
17
17
  pragma_func_call: function (print) { return print(["name", "args"]); },
18
18
  };
package/dist/syntax/do.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.doMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
4
5
  exports.doMap = {
5
- do_stmt: function (print) { return print.spaced(["doKw", "language", "body"]); },
6
+ do_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["doKw", "language", "body"])); },
6
7
  };
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dropTableMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
4
5
  exports.dropTableMap = {
5
6
  drop_table_stmt: function (print) {
6
- return print.spaced([
7
+ return (0, print_utils_1.group)(print.spaced([
7
8
  "dropKw",
8
9
  "kind",
9
10
  "tableKw",
10
11
  "ifExistsKw",
11
12
  "tables",
12
13
  "behaviorKw",
13
- ]);
14
+ ]));
14
15
  },
15
16
  };
@@ -1,5 +1,5 @@
1
1
  import { AllExprNodes, Keyword } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- import { AllPrettierOptions } from "src/options";
3
+ import { AllPrettierOptions } from "../options";
4
4
  export declare const exprMap: CstToDocMap<AllExprNodes>;
5
5
  export declare const printLiteral: <T>(node: Keyword, options: AllPrettierOptions<T>) => string;
@@ -182,10 +182,26 @@ exports.exprMap = {
182
182
  json_literal: function (print) { return print.spaced(["jsonKw", "string"]); },
183
183
  jsonb_literal: function (print) { return print.spaced(["jsonbKw", "string"]); },
184
184
  /** cst-ignore: name */
185
- identifier: function (print) { return print("text"); },
185
+ identifier: function (print, node, path, options) {
186
+ if (isQuotedIdentifier(node) || isInsideBigqueryQuotedMemberExpr(path)) {
187
+ return print("text");
188
+ }
189
+ else {
190
+ if (isFunctionName(node, path)) {
191
+ return printFunctionName(node, options);
192
+ }
193
+ else {
194
+ return printIdentifier(node, options);
195
+ }
196
+ }
197
+ },
186
198
  /** cst-ignore: name */
187
- variable: function (print) { return print("text"); },
188
- parameter: function (print) { return print("text"); },
199
+ variable: function (print, node, path, options) {
200
+ return isQuotedVariable(node) ? print("text") : printIdentifier(node, options);
201
+ },
202
+ parameter: function (print, node, path, options) {
203
+ return isQuotedParameter(node) ? print("text") : printIdentifier(node, options);
204
+ },
189
205
  };
190
206
  var printLiteral = function (node, options) {
191
207
  switch (options.sqlLiteralCase) {
@@ -198,6 +214,59 @@ var printLiteral = function (node, options) {
198
214
  }
199
215
  };
200
216
  exports.printLiteral = printLiteral;
217
+ var printIdentifier = function (node, options) {
218
+ switch (options.sqlIdentifierCase) {
219
+ case "preserve":
220
+ return node.text;
221
+ case "upper":
222
+ return node.text.toUpperCase();
223
+ case "lower":
224
+ return node.text.toLowerCase();
225
+ }
226
+ };
227
+ var printFunctionName = function (node, options) {
228
+ switch (options.sqlFunctionCase) {
229
+ case "preserve":
230
+ return node.text;
231
+ case "upper":
232
+ return node.text.toUpperCase();
233
+ case "lower":
234
+ return node.text.toLowerCase();
235
+ }
236
+ };
237
+ var isQuotedIdentifier = function (node) {
238
+ return node.name !== node.text;
239
+ };
240
+ var isQuotedVariable = function (node) {
241
+ return !(node.text === "@" + node.name || node.text === "@@" + node.name);
242
+ };
243
+ var isQuotedParameter = function (node) { return /`$/.test(node.text); };
244
+ var isInsideBigqueryQuotedMemberExpr = function (path) {
245
+ return path.ancestors.some(node_utils_1.isBigqueryQuotedMemberExpr);
246
+ };
247
+ var isFunctionName = function (node, path) {
248
+ var parent = path.parent;
249
+ if (isFunctionContext(parent, path.grandparent)) {
250
+ return true;
251
+ }
252
+ if ((0, node_utils_1.isMemberExpr)(parent) && parent.property === node) {
253
+ var _a = path.ancestors, _ = _a[0], gp = _a[1], ggp = _a[2];
254
+ return isFunctionContext(gp, ggp);
255
+ }
256
+ return false;
257
+ };
258
+ var isFunctionContext = function (node, parent) {
259
+ return ((0, node_utils_1.isFuncCall)(node) ||
260
+ (0, node_utils_1.isCreateFunctionStmt)(node) ||
261
+ (0, node_utils_1.isCreateProcedureStmt)(node) ||
262
+ (0, node_utils_1.isAlterFunctionStmt)(node) ||
263
+ (0, node_utils_1.isAlterProcedureStmt)(node) ||
264
+ ((0, node_utils_1.isAlterActionRename)(node) &&
265
+ ((0, node_utils_1.isAlterFunctionStmt)(parent) || (0, node_utils_1.isAlterProcedureStmt)(parent))) ||
266
+ (0, node_utils_1.isDropFunctionStmt)(node) ||
267
+ (0, node_utils_1.isDropProcedureStmt)(node) ||
268
+ ((0, node_utils_1.isExecuteClause)(node) && (0, node_utils_1.isCreateTriggerStmt)(parent)));
269
+ };
201
270
  var isBooleanOp = function (_a) {
202
271
  var name = _a.name;
203
272
  return name === "AND" || name === "OR";
@@ -1,3 +1,4 @@
1
- import { AllFunctionNodes } from "sql-parser-cst";
1
+ import { AllFunctionNodes, CreateFunctionStmt, CreateProcedureStmt } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
3
  export declare const functionMap: CstToDocMap<AllFunctionNodes>;
4
+ export declare const hasOnlyAsClause: (node: CreateFunctionStmt | CreateProcedureStmt) => boolean;
@@ -1,27 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.functionMap = void 0;
3
+ exports.hasOnlyAsClause = exports.functionMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  var node_utils_1 = require("../node_utils");
6
6
  exports.functionMap = {
7
- create_function_stmt: function (print, node) { return [
8
- print.spaced([
9
- "createKw",
10
- "orReplaceKw",
11
- "temporaryKw",
12
- "tableKw",
13
- "functionKw",
14
- "ifNotExistsKw",
15
- "name",
16
- ]),
17
- print("params"),
18
- hasOnlyAsClause(node)
19
- ? [" ", (0, print_utils_1.group)(print("clauses"))]
20
- : [
21
- print_utils_1.hardline,
22
- (0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (cls) { return (0, print_utils_1.group)(cls); })),
23
- ],
24
- ]; },
7
+ create_function_stmt: function (print, node) {
8
+ return (0, print_utils_1.group)([
9
+ print.spaced([
10
+ "createKw",
11
+ "orReplaceKw",
12
+ "temporaryKw",
13
+ "tableKw",
14
+ "functionKw",
15
+ "ifNotExistsKw",
16
+ "name",
17
+ ]),
18
+ print("params"),
19
+ (0, exports.hasOnlyAsClause)(node)
20
+ ? [" ", (0, print_utils_1.group)(print("clauses"))]
21
+ : [
22
+ print_utils_1.hardline,
23
+ (0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (cls) { return (0, print_utils_1.group)(cls); })),
24
+ ],
25
+ ]);
26
+ },
25
27
  function_signature: function (print) { return print(["name", "params"]); },
26
28
  function_param: function (print) {
27
29
  return print.spaced(["mode", "name", "dataType", "default"]);
@@ -59,6 +61,5 @@ exports.functionMap = {
59
61
  ]);
60
62
  },
61
63
  };
62
- var hasOnlyAsClause = function (node) {
63
- return node.clauses.length === 1 && (0, node_utils_1.isAsClause)(node.clauses[0]);
64
- };
64
+ var hasOnlyAsClause = function (node) { return node.clauses.length === 1 && (0, node_utils_1.isAsClause)(node.clauses[0]); };
65
+ exports.hasOnlyAsClause = hasOnlyAsClause;
@@ -71,13 +71,13 @@ exports.indexMap = {
71
71
  ]);
72
72
  },
73
73
  reindex_stmt: function (print) {
74
- return print.spaced([
74
+ return (0, print_utils_1.group)(print.spaced([
75
75
  "reindexKw",
76
76
  "options",
77
77
  "targetKw",
78
78
  "concurrentlyKw",
79
79
  "name",
80
- ]);
80
+ ]));
81
81
  },
82
82
  reindex_option_concurrently: function (print) {
83
83
  return print.spaced(["concurrentlyKw", "value"]);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.mergeMap = {
6
- merge_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.line, print("clauses")); },
6
+ merge_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, print("clauses"))); },
7
7
  merge_clause: function (print) {
8
8
  return (0, print_utils_1.join)(print_utils_1.line, [
9
9
  print.spaced(["mergeKw", "intoKw", "target"]),
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parameterMap = void 0;
4
4
  var expr_1 = require("./expr");
5
+ var print_utils_1 = require("../print_utils");
5
6
  exports.parameterMap = {
6
7
  // SET
7
8
  set_parameter_stmt: function (print) {
8
- return print.spaced(["setKw", "modifierKw", "name", "operator", "value"]);
9
+ return (0, print_utils_1.group)(print.spaced(["setKw", "modifierKw", "name", "operator", "value"]));
9
10
  },
10
11
  set_time_zone_parameter_stmt: function (print) {
11
- return print.spaced(["setKw", "modifierKw", "timeZoneKw", "value"]);
12
+ return (0, print_utils_1.group)(print.spaced(["setKw", "modifierKw", "timeZoneKw", "value"]));
12
13
  },
13
14
  set_parameter_clause: function (print) {
14
15
  return print.spaced(["setKw", "name", "operator", "value"]);
@@ -18,11 +19,11 @@ exports.parameterMap = {
18
19
  return print.spaced(["setKw", "name", "fromCurrentKw"]);
19
20
  },
20
21
  // RESET
21
- reset_parameter_stmt: function (print) { return print.spaced(["resetKw", "name"]); },
22
+ reset_parameter_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["resetKw", "name"])); },
22
23
  reset_parameter_clause: function (print) { return print.spaced(["resetKw", "name"]); },
23
24
  all_parameters: function (print) { return print("allKw"); },
24
25
  // SHOW
25
- show_parameter_stmt: function (print) { return print.spaced(["showKw", "name"]); },
26
+ show_parameter_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["showKw", "name"])); },
26
27
  /** cst-ignore: value */
27
28
  boolean_on_off_literal: function (print, node, path, options) {
28
29
  return (0, expr_1.printLiteral)(node.valueKw, options);
@@ -23,12 +23,12 @@ exports.preparedStatementsMap = {
23
23
  }
24
24
  },
25
25
  execute_immediate_stmt: function (print) {
26
- return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
26
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
27
27
  (0, print_utils_1.group)([
28
28
  print.spaced(["executeKw", "immediateKw"]),
29
29
  (0, print_utils_1.indent)([print_utils_1.line, print("expr")]),
30
30
  ])
31
- ], print(["into", "using"]).map(function (clause) { return (0, print_utils_1.group)(clause); }), true));
31
+ ], print(["into", "using"]).map(function (clause) { return (0, print_utils_1.group)(clause); }), true)));
32
32
  },
33
33
  execute_into_clause: function (print) { return print.spaced(["intoKw", "variables"]); },
34
34
  execute_using_clause: function (print) {
@@ -46,6 +46,6 @@ exports.preparedStatementsMap = {
46
46
  return (0, print_utils_1.group)([print("fromKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
47
47
  },
48
48
  // DEALLOCATE
49
- deallocate_stmt: function (print) { return print.spaced(["deallocateKw", "name"]); },
49
+ deallocate_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["deallocateKw", "name"])); },
50
50
  deallocate_all: function (print) { return print("allKw"); },
51
51
  };
@@ -13,31 +13,35 @@ exports.proceduralLanguageMap = void 0;
13
13
  var print_utils_1 = require("../print_utils");
14
14
  exports.proceduralLanguageMap = {
15
15
  // BEGIN .. END
16
- block_stmt: function (print, node) { return [
17
- print.spaced(["beginKw", "atomicKw"]),
18
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("program"))]),
19
- node.exception ? [print_utils_1.hardline, print("exception")] : [],
20
- print_utils_1.hardline,
21
- print("endKw"),
22
- ]; },
23
- exception_clause: function (print) { return [
24
- print.spaced(["exceptionKw", "whenKw", "condition", "thenKw"]),
25
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("program"))]),
26
- ]; },
16
+ block_stmt: function (print, node) {
17
+ return (0, print_utils_1.group)([
18
+ print.spaced(["beginKw", "atomicKw"]),
19
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("program"))]),
20
+ node.exception ? [print_utils_1.hardline, print("exception")] : [],
21
+ print_utils_1.hardline,
22
+ print("endKw"),
23
+ ]);
24
+ },
25
+ exception_clause: function (print) {
26
+ return (0, print_utils_1.group)([
27
+ print.spaced(["exceptionKw", "whenKw", "condition", "thenKw"]),
28
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("program"))]),
29
+ ]);
30
+ },
27
31
  error_category: function (print) { return print("errorKw"); },
28
32
  // DECLARE
29
33
  declare_stmt: function (print) {
30
- return (0, print_utils_1.join)(" ", __spreadArray([
34
+ return (0, print_utils_1.group)((0, print_utils_1.join)(" ", __spreadArray([
31
35
  print("declareKw"),
32
36
  (0, print_utils_1.group)(print("names"))
33
- ], print.spaced(["dataType", "default"]), true));
37
+ ], print.spaced(["dataType", "default"]), true)));
34
38
  },
35
39
  declare_default: function (print) { return print.spaced(["defaultKw", "expr"]); },
36
40
  // SET
37
- set_stmt: function (print) { return print.spaced(["setKw", "assignments"]); },
41
+ set_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["setKw", "assignments"])); },
38
42
  // IF
39
43
  if_stmt: function (print) {
40
- return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([], print("clauses"), true), [print.spaced("endIfKw")], false));
44
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([], print("clauses"), true), [print.spaced("endIfKw")], false)));
41
45
  },
42
46
  if_clause: function (print) { return [
43
47
  (0, print_utils_1.group)([
@@ -62,55 +66,67 @@ exports.proceduralLanguageMap = {
62
66
  (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("consequent"))]),
63
67
  ]; },
64
68
  // CASE
65
- case_stmt: function (print) { return [
66
- print.spaced(["caseKw", "expr"]),
67
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.join)(print_utils_1.hardline, print("clauses"))]),
68
- print_utils_1.hardline,
69
- print.spaced("endCaseKw"),
70
- ]; },
69
+ case_stmt: function (print) {
70
+ return (0, print_utils_1.group)([
71
+ print.spaced(["caseKw", "expr"]),
72
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.join)(print_utils_1.hardline, print("clauses"))]),
73
+ print_utils_1.hardline,
74
+ print.spaced("endCaseKw"),
75
+ ]);
76
+ },
71
77
  // LOOP
72
- loop_stmt: function (print) { return [
73
- print("loopKw"),
74
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
75
- print_utils_1.hardline,
76
- print.spaced("endLoopKw"),
77
- ]; },
78
+ loop_stmt: function (print) {
79
+ return (0, print_utils_1.group)([
80
+ print("loopKw"),
81
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
82
+ print_utils_1.hardline,
83
+ print.spaced("endLoopKw"),
84
+ ]);
85
+ },
78
86
  // REPEAT
79
- repeat_stmt: function (print) { return [
80
- print("repeatKw"),
81
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
82
- print_utils_1.hardline,
83
- print.spaced(["untilKw", "condition", "endRepeatKw"]),
84
- ]; },
87
+ repeat_stmt: function (print) {
88
+ return (0, print_utils_1.group)([
89
+ print("repeatKw"),
90
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
91
+ print_utils_1.hardline,
92
+ print.spaced(["untilKw", "condition", "endRepeatKw"]),
93
+ ]);
94
+ },
85
95
  // WHILE
86
- while_stmt: function (print) { return [
87
- print.spaced(["whileKw", "condition", "doKw"]),
88
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
89
- print_utils_1.hardline,
90
- print.spaced("endWhileKw"),
91
- ]; },
96
+ while_stmt: function (print) {
97
+ return (0, print_utils_1.group)([
98
+ print.spaced(["whileKw", "condition", "doKw"]),
99
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
100
+ print_utils_1.hardline,
101
+ print.spaced("endWhileKw"),
102
+ ]);
103
+ },
92
104
  // FOR .. IN
93
- for_stmt: function (print) { return [
94
- print.spaced(["forKw", "left", "inKw", "right", "doKw"]),
95
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
96
- print_utils_1.hardline,
97
- print.spaced("endForKw"),
98
- ]; },
105
+ for_stmt: function (print) {
106
+ return (0, print_utils_1.group)([
107
+ print.spaced(["forKw", "left", "inKw", "right", "doKw"]),
108
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("body"))]),
109
+ print_utils_1.hardline,
110
+ print.spaced("endForKw"),
111
+ ]);
112
+ },
99
113
  // BREAK/CONTINUE
100
- break_stmt: function (print) { return print.spaced(["breakKw", "label"]); },
101
- continue_stmt: function (print) { return print.spaced(["continueKw", "label"]); },
102
- labeled_stmt: function (print, node) { return [
103
- print("beginLabel"),
104
- ": ",
105
- print("statement"),
106
- node.endLabel ? [" ", print(["endLabel"])] : [],
107
- ]; },
114
+ break_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["breakKw", "label"])); },
115
+ continue_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["continueKw", "label"])); },
116
+ labeled_stmt: function (print, node) {
117
+ return (0, print_utils_1.group)([
118
+ print("beginLabel"),
119
+ ": ",
120
+ print("statement"),
121
+ node.endLabel ? [" ", print(["endLabel"])] : [],
122
+ ]);
123
+ },
108
124
  // CALL
109
- call_stmt: function (print) { return print.spaced(["callKw", "func"]); },
125
+ call_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["callKw", "func"])); },
110
126
  // RETURN
111
- return_stmt: function (print) { return print.spaced(["returnKw", "expr"]); },
127
+ return_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["returnKw", "expr"])); },
112
128
  // RAISE
113
- raise_stmt: function (print) { return print.spaced(["raiseKw", "message"]); },
129
+ raise_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["raiseKw", "message"])); },
114
130
  raise_message: function (print) { return [
115
131
  print.spaced("usingMessageKw"),
116
132
  " = ",
@@ -2,19 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.procedureMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
+ var function_1 = require("./function");
5
6
  exports.procedureMap = {
6
- create_procedure_stmt: function (print, node) { return [
7
- print.spaced([
8
- "createKw",
9
- "orReplaceKw",
10
- "procedureKw",
11
- "ifNotExistsKw",
12
- "name",
13
- ]),
14
- print("params"),
15
- print_utils_1.hardline,
16
- (0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (clause) { return (0, print_utils_1.group)(clause); })),
17
- ]; },
7
+ create_procedure_stmt: function (print, node) {
8
+ return (0, print_utils_1.group)([
9
+ print.spaced([
10
+ "createKw",
11
+ "orReplaceKw",
12
+ "procedureKw",
13
+ "ifNotExistsKw",
14
+ "name",
15
+ ]),
16
+ print("params"),
17
+ (0, function_1.hasOnlyAsClause)(node)
18
+ ? [" ", (0, print_utils_1.group)(print("clauses"))]
19
+ : [
20
+ print_utils_1.hardline,
21
+ (0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (clause) { return (0, print_utils_1.group)(clause); })),
22
+ ],
23
+ ]);
24
+ },
18
25
  drop_procedure_stmt: function (print) {
19
26
  return (0, print_utils_1.group)([
20
27
  print.spaced(["dropKw", "procedureKw", "ifExistsKw", "name"]),
@@ -26,7 +26,7 @@ exports.schemaMap = {
26
26
  return print.spaced(["authorizationKw", "role"]);
27
27
  },
28
28
  drop_schema_stmt: function (print) {
29
- return print.spaced(["dropSchemaKw", "ifExistsKw", "schemas", "behaviorKw"]);
29
+ return (0, print_utils_1.group)(print.spaced(["dropSchemaKw", "ifExistsKw", "schemas", "behaviorKw"]));
30
30
  },
31
31
  alter_schema_stmt: function (print) {
32
32
  return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), __spreadArray([
@@ -5,7 +5,7 @@ var utils_1 = require("../utils");
5
5
  var print_utils_1 = require("../print_utils");
6
6
  exports.selectMap = {
7
7
  compound_select_stmt: function (print) {
8
- return (0, print_utils_1.join)(print_utils_1.hardline, [print("left"), print.spaced("operator"), print("right")]);
8
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [print("left"), print.spaced("operator"), print("right")]));
9
9
  },
10
10
  select_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
11
11
  // WITH clause
@@ -10,17 +10,17 @@ exports.transactionMap = {
10
10
  ]);
11
11
  },
12
12
  commit_transaction_stmt: function (print) {
13
- return print.spaced(["commitKw", "transactionKw", "chain"]);
13
+ return (0, print_utils_1.group)(print.spaced(["commitKw", "transactionKw", "chain"]));
14
14
  },
15
15
  rollback_transaction_stmt: function (print) {
16
- return print.spaced(["rollbackKw", "transactionKw", "savepoint", "chain"]);
16
+ return (0, print_utils_1.group)(print.spaced(["rollbackKw", "transactionKw", "savepoint", "chain"]));
17
17
  },
18
18
  rollback_to_savepoint: function (print) {
19
19
  return print.spaced(["toKw", "savepointKw", "savepoint"]);
20
20
  },
21
- savepoint_stmt: function (print) { return print.spaced(["savepointKw", "savepoint"]); },
21
+ savepoint_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["savepointKw", "savepoint"])); },
22
22
  release_savepoint_stmt: function (print) {
23
- return print.spaced(["releaseKw", "savepointKw", "savepoint"]);
23
+ return (0, print_utils_1.group)(print.spaced(["releaseKw", "savepointKw", "savepoint"]));
24
24
  },
25
25
  transaction_chain_clause: function (print) { return print.spaced("andChainKw"); },
26
26
  transaction_no_chain_clause: function (print) { return print.spaced("andNoChainKw"); },
@@ -13,7 +13,7 @@ exports.triggerMap = void 0;
13
13
  var print_utils_1 = require("../print_utils");
14
14
  exports.triggerMap = {
15
15
  create_trigger_stmt: function (print, node) {
16
- return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([
16
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([
17
17
  print.spaced([
18
18
  "createKw",
19
19
  "orReplaceKw",
@@ -30,7 +30,7 @@ exports.triggerMap = {
30
30
  ])
31
31
  ], print("clauses"), true), [
32
32
  print("body"),
33
- ], false));
33
+ ], false)));
34
34
  },
35
35
  trigger_event: function (print, node) {
36
36
  return (0, print_utils_1.group)([
@@ -65,12 +65,12 @@ exports.triggerMap = {
65
65
  ]));
66
66
  },
67
67
  drop_trigger_stmt: function (print) {
68
- return print.spaced([
68
+ return (0, print_utils_1.group)(print.spaced([
69
69
  "dropTriggerKw",
70
70
  "ifExistsKw",
71
71
  "trigger",
72
72
  "target",
73
73
  "behaviorKw",
74
- ]);
74
+ ]));
75
75
  },
76
76
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unsupportedGrammarMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
4
5
  exports.unsupportedGrammarMap = {
5
- unsupported_grammar_stmt: function (print) { return print("text"); },
6
+ unsupported_grammar_stmt: function (print) { return (0, print_utils_1.group)(print("text")); },
6
7
  };
@@ -6,7 +6,7 @@ exports.viewMap = {
6
6
  create_view_stmt: function (print, node) {
7
7
  var hasOnlyAsClause = node.clauses.length === 1;
8
8
  var hasManyClauses = node.clauses.length > 1;
9
- return [
9
+ return (0, print_utils_1.group)([
10
10
  print.spaced([
11
11
  "createKw",
12
12
  "orReplaceKw",
@@ -18,7 +18,7 @@ exports.viewMap = {
18
18
  ]),
19
19
  hasOnlyAsClause ? [" ", print("clauses")] : [],
20
20
  hasManyClauses ? [print_utils_1.hardline, (0, print_utils_1.join)(print_utils_1.hardline, print("clauses"))] : [],
21
- ];
21
+ ]);
22
22
  },
23
23
  with_check_option_clause: function (print) {
24
24
  return print.spaced(["withKw", "levelKw", "checkOptionKw"]);
@@ -34,18 +34,20 @@ exports.viewMap = {
34
34
  "behaviorKw",
35
35
  ]));
36
36
  },
37
- alter_view_stmt: function (print) { return [
38
- print.spaced([
39
- "alterKw",
40
- "kind",
41
- "viewKw",
42
- "ifExistsKw",
43
- "name",
44
- "columns",
45
- ]),
46
- print_utils_1.hardline,
47
- print("actions"),
48
- ]; },
37
+ alter_view_stmt: function (print) {
38
+ return (0, print_utils_1.group)([
39
+ print.spaced([
40
+ "alterKw",
41
+ "kind",
42
+ "viewKw",
43
+ "ifExistsKw",
44
+ "name",
45
+ "columns",
46
+ ]),
47
+ print_utils_1.hardline,
48
+ print("actions"),
49
+ ]);
50
+ },
49
51
  refresh_materialized_view_stmt: function (print, node) {
50
52
  return (0, print_utils_1.group)([
51
53
  print.spaced(["refreshMaterializedViewKw", "concurrentlyKw", "name"]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-sql-cst",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Prettier plugin for SQL",
5
5
  "contributors": [
6
6
  "Barna Magyarkuti <bmagyarkuti@gmail.com>",
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "prettier": "^3.0.3",
40
- "sql-parser-cst": "^0.36.1"
40
+ "sql-parser-cst": "^0.37.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/jest": "^29.2.5",