prettier-plugin-sql-cst 0.18.0 → 0.19.1

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.
Files changed (76) hide show
  1. package/dist/CstToDocMap.d.ts +2 -2
  2. package/dist/CstToDocMap.js +1 -2
  3. package/dist/PrintFn.js +1 -2
  4. package/dist/embed.js +5 -13
  5. package/dist/embedJs.js +28 -84
  6. package/dist/embedJson.js +29 -85
  7. package/dist/embedSql.js +26 -76
  8. package/dist/index.js +28 -34
  9. package/dist/node_utils.d.ts +1 -0
  10. package/dist/node_utils.js +44 -54
  11. package/dist/options.js +1 -4
  12. package/dist/printComment.js +2 -6
  13. package/dist/printSql.js +29 -39
  14. package/dist/print_utils.js +19 -38
  15. package/dist/syntax/alias.js +2 -5
  16. package/dist/syntax/alter_action.js +115 -208
  17. package/dist/syntax/alter_table.js +18 -27
  18. package/dist/syntax/analyze.js +3 -8
  19. package/dist/syntax/base.js +6 -9
  20. package/dist/syntax/cast.js +3 -6
  21. package/dist/syntax/comment.js +53 -122
  22. package/dist/syntax/constraint.d.ts +1 -1
  23. package/dist/syntax/constraint.js +54 -90
  24. package/dist/syntax/create_table.js +49 -87
  25. package/dist/syntax/data_type.js +25 -44
  26. package/dist/syntax/dcl.js +78 -136
  27. package/dist/syntax/delete.js +4 -9
  28. package/dist/syntax/dialects/bigquery.js +70 -116
  29. package/dist/syntax/dialects/mysql.js +2 -5
  30. package/dist/syntax/dialects/postgresql.js +8 -13
  31. package/dist/syntax/dialects/sqlite.js +8 -17
  32. package/dist/syntax/do.js +3 -6
  33. package/dist/syntax/domain.js +10 -19
  34. package/dist/syntax/drop_table.js +10 -15
  35. package/dist/syntax/explain.js +6 -11
  36. package/dist/syntax/expr.js +124 -173
  37. package/dist/syntax/extension.js +12 -21
  38. package/dist/syntax/frame.js +11 -16
  39. package/dist/syntax/function.js +53 -63
  40. package/dist/syntax/index.js +54 -81
  41. package/dist/syntax/insert.js +32 -49
  42. package/dist/syntax/merge.js +25 -30
  43. package/dist/syntax/other_clauses.js +5 -14
  44. package/dist/syntax/parameter.js +13 -26
  45. package/dist/syntax/policy.js +26 -41
  46. package/dist/syntax/prepared_statements.js +23 -43
  47. package/dist/syntax/proc_clause.js +10 -15
  48. package/dist/syntax/procedural_language.js +80 -111
  49. package/dist/syntax/procedure.js +36 -40
  50. package/dist/syntax/program.js +15 -22
  51. package/dist/syntax/publication.js +26 -47
  52. package/dist/syntax/rename_table.js +7 -12
  53. package/dist/syntax/role.js +30 -55
  54. package/dist/syntax/schema.js +17 -35
  55. package/dist/syntax/select.js +157 -226
  56. package/dist/syntax/sequence.js +35 -52
  57. package/dist/syntax/subscription.js +9 -24
  58. package/dist/syntax/transaction.js +18 -33
  59. package/dist/syntax/transformMap.js +99 -63
  60. package/dist/syntax/trigger.js +48 -72
  61. package/dist/syntax/truncate.js +9 -14
  62. package/dist/syntax/type.js +11 -22
  63. package/dist/syntax/unsupported_grammar.js +3 -6
  64. package/dist/syntax/update.js +7 -14
  65. package/dist/syntax/view.js +32 -43
  66. package/dist/transform/addFinalSemicolon.js +5 -9
  67. package/dist/transform/aliasAs.js +4 -8
  68. package/dist/transform/canonicKeywords.js +16 -20
  69. package/dist/transform/canonicOperators.js +8 -12
  70. package/dist/transform/comments.js +10 -31
  71. package/dist/transform/stripTrailingCommas.js +7 -11
  72. package/dist/transform/transformCst.js +13 -17
  73. package/dist/transform/transformUtils.js +2 -6
  74. package/dist/utils.js +9 -30
  75. package/dist/visitAllNodes.js +8 -13
  76. package/package.json +9 -8
@@ -1,58 +1,46 @@
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
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.printLiteral = exports.exprMap = void 0;
13
- var print_utils_1 = require("../print_utils");
14
- var node_utils_1 = require("../node_utils");
15
- var utils_1 = require("../utils");
16
- exports.exprMap = {
17
- list_expr: function (print, node, path) {
18
- var parent = path.getParentNode();
19
- var children = print("items").map(function (it) { return (0, print_utils_1.group)(it); });
20
- var lineType = (0, node_utils_1.isValuesClause)(parent) ? print_utils_1.hardline : print_utils_1.line;
1
+ import { join, line, softline, hardline, indent, group, stripTrailingHardline, } from "../print_utils";
2
+ import { isCreateTableStmt, isKeyword, isValuesClause, isEmpty, isArraySubscript, isParenExpr, isFuncArgs, isListExpr, isProgram, isSelectStmt, isCompoundSelectStmt, isBigqueryQuotedMemberExpr, isFuncCall, isMemberExpr, isCreateFunctionStmt, isAlterFunctionStmt, isAlterActionRename, isCreateProcedureStmt, isAlterProcedureStmt, isCreateTriggerStmt, isExecuteClause, isFunctionSignature, } from "../node_utils";
3
+ import { isString, last } from "../utils";
4
+ export const exprMap = {
5
+ list_expr: (print, node, path) => {
6
+ const parent = path.getParentNode();
7
+ const children = print("items").map((it) => group(it));
8
+ const lineType = isValuesClause(parent) ? hardline : line;
21
9
  // When last item is type:empty, we're dealing with a trailing comma.
22
10
  // Don't add a space (or newline) after it.
23
11
  // We still want to print it though, as it might have comments attached.
24
- if ((0, node_utils_1.isEmpty)((0, utils_1.last)(node.items))) {
12
+ if (isEmpty(last(node.items))) {
25
13
  return [
26
- (0, print_utils_1.join)([",", lineType], children.slice(0, -1)),
14
+ join([",", lineType], children.slice(0, -1)),
27
15
  ",",
28
- (0, utils_1.last)(children),
16
+ last(children),
29
17
  ];
30
18
  }
31
19
  else {
32
- return (0, print_utils_1.join)([",", lineType], children);
20
+ return join([",", lineType], children);
33
21
  }
34
22
  },
35
- paren_expr: function (print, node, path) {
23
+ paren_expr: (print, node, path) => {
36
24
  // discard unnecessary nested ((parentheses))
37
- if ((0, node_utils_1.isParenExpr)(node.expr)) {
25
+ if (isParenExpr(node.expr)) {
38
26
  return print("expr");
39
27
  }
40
28
  // Discard unnecessary parenthesis around function arguments
41
- if ((0, node_utils_1.isListExpr)(path.getParentNode(0)) &&
42
- (0, node_utils_1.isFuncArgs)(path.getParentNode(1)) &&
43
- !(0, node_utils_1.isSelectStmt)(node.expr) &&
44
- !(0, node_utils_1.isCompoundSelectStmt)(node.expr)) {
29
+ if (isListExpr(path.getParentNode(0)) &&
30
+ isFuncArgs(path.getParentNode(1)) &&
31
+ !isSelectStmt(node.expr) &&
32
+ !isCompoundSelectStmt(node.expr)) {
45
33
  return print("expr");
46
34
  }
47
- var parent = path.getParentNode();
48
- var lineStyle = (0, node_utils_1.isCreateTableStmt)(parent) && print.dynamicLine() === print_utils_1.hardline
49
- ? print_utils_1.hardline
50
- : print_utils_1.softline;
51
- return (0, print_utils_1.group)(["(", (0, print_utils_1.indent)([lineStyle, print("expr")]), lineStyle, ")"]);
52
- },
53
- binary_expr: function (print, node) {
54
- if ((0, node_utils_1.isKeyword)(node.operator) && isBooleanOp(node.operator)) {
55
- return (0, print_utils_1.join)(print_utils_1.line, [print("left"), print.spaced(["operator", "right"])]);
35
+ const parent = path.getParentNode();
36
+ const lineStyle = isCreateTableStmt(parent) && print.dynamicLine() === hardline
37
+ ? hardline
38
+ : softline;
39
+ return group(["(", indent([lineStyle, print("expr")]), lineStyle, ")"]);
40
+ },
41
+ binary_expr: (print, node) => {
42
+ if (isKeyword(node.operator) && isBooleanOp(node.operator)) {
43
+ return join(line, [print("left"), print.spaced(["operator", "right"])]);
56
44
  }
57
45
  if (node.operator === "") {
58
46
  // String concatenation with whitespace (MySQL / MariaDB)
@@ -60,129 +48,109 @@ exports.exprMap = {
60
48
  }
61
49
  return print.spaced(["left", "operator", "right"]);
62
50
  },
63
- prefix_op_expr: function (print, node) {
64
- return ((0, utils_1.isString)(node.operator) ? print : print.spaced)(["operator", "expr"]);
65
- },
66
- postfix_op_expr: function (print) { return print.spaced(["expr", "operator"]); },
67
- between_expr: function (print) {
68
- return print.spaced(["left", "betweenKw", "begin", "andKw", "end"]);
69
- },
70
- case_expr: function (print) { return [
51
+ prefix_op_expr: (print, node) => (isString(node.operator) ? print : print.spaced)(["operator", "expr"]),
52
+ postfix_op_expr: (print) => print.spaced(["expr", "operator"]),
53
+ between_expr: (print) => print.spaced(["left", "betweenKw", "begin", "andKw", "end"]),
54
+ case_expr: (print) => [
71
55
  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,
56
+ indent([hardline, join(hardline, print("clauses"))]),
57
+ hardline,
74
58
  print("endKw"),
75
- ]; },
76
- case_when: function (print, node) {
77
- if ((0, node_utils_1.isProgram)(node.result)) {
59
+ ],
60
+ case_when: (print, node) => {
61
+ if (isProgram(node.result)) {
78
62
  return [
79
63
  print.spaced(["whenKw", "condition", "thenKw"]),
80
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("result"))]),
64
+ indent([hardline, stripTrailingHardline(print("result"))]),
81
65
  ];
82
66
  }
83
67
  return print.spaced(["whenKw", "condition", "thenKw", "result"]);
84
68
  },
85
- case_else: function (print, node) {
86
- if ((0, node_utils_1.isProgram)(node.result)) {
69
+ case_else: (print, node) => {
70
+ if (isProgram(node.result)) {
87
71
  return [
88
72
  print("elseKw"),
89
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("result"))]),
73
+ indent([hardline, stripTrailingHardline(print("result"))]),
90
74
  ];
91
75
  }
92
76
  return print.spaced(["elseKw", "result"]);
93
77
  },
94
- member_expr: function (print, node) {
95
- return (0, node_utils_1.isArraySubscript)(node.property)
96
- ? print(["object", "property"])
97
- : [print("object"), ".", print("property")];
98
- },
99
- bigquery_quoted_member_expr: function (print) { return ["`", print("expr"), "`"]; },
100
- array_subscript: function (print) {
101
- return (0, print_utils_1.group)(["[", (0, print_utils_1.indent)([print_utils_1.softline, print("expr")]), print_utils_1.softline, "]"]);
102
- },
103
- array_subscript_specifier: function (print) { return print(["specifierKw", "args"]); },
104
- array_slice_specifier: function (print) { return [print("from"), ":", print("to")]; },
105
- func_call: function (print) {
106
- var fnCall = print(["name", "args"]);
107
- var extras = print(["filter", "over"]);
78
+ member_expr: (print, node) => isArraySubscript(node.property)
79
+ ? print(["object", "property"])
80
+ : [print("object"), ".", print("property")],
81
+ bigquery_quoted_member_expr: (print) => ["`", print("expr"), "`"],
82
+ array_subscript: (print) => group(["[", indent([softline, print("expr")]), softline, "]"]),
83
+ array_subscript_specifier: (print) => print(["specifierKw", "args"]),
84
+ array_slice_specifier: (print) => [print("from"), ":", print("to")],
85
+ func_call: (print) => {
86
+ const fnCall = print(["name", "args"]);
87
+ const extras = print(["filter", "over"]);
108
88
  if (extras.length > 1) {
109
- return (0, print_utils_1.group)([fnCall, (0, print_utils_1.indent)([print_utils_1.line, (0, print_utils_1.join)(print_utils_1.line, extras)])]);
89
+ return group([fnCall, indent([line, join(line, extras)])]);
110
90
  }
111
91
  else {
112
- return (0, print_utils_1.group)((0, print_utils_1.join)(" ", __spreadArray([fnCall], extras, true)));
92
+ return group(join(" ", [fnCall, ...extras]));
113
93
  }
114
94
  },
115
- func_args: function (print, node) {
116
- return (0, print_utils_1.join)(print_utils_1.line, __spreadArray(__spreadArray(__spreadArray([], print(["distinctKw", "args"]), true), (node.nullHandlingKw ? print.spaced("nullHandlingKw") : []), true), print(["orderBy", "limit", "having"]), true));
117
- },
118
- filter_arg: function (print) { return print.spaced(["filterKw", "where"]); },
119
- over_arg: function (print) { return print.spaced(["overKw", "window"]); },
120
- having_arg: function (print) { return print.spaced(["havingKw", "minMaxKw", "expr"]); },
121
- named_arg: function (print) {
122
- return (0, print_utils_1.group)([
123
- print("name"),
124
- " ",
125
- print("operator"),
126
- (0, print_utils_1.indent)([print_utils_1.line, print("value")]),
127
- ]);
128
- },
129
- cast_expr: function (print) { return print(["castKw", "args"]); },
130
- cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType", "format"]); },
131
- cast_format: function (print) { return print.spaced(["formatKw", "string", "timezone"]); },
132
- cast_format_timezone: function (print) { return print.spaced(["atTimeZoneKw", "timezone"]); },
133
- cast_operator_expr: function (print) { return [
95
+ func_args: (print, node) => join(line, [
96
+ ...print(["distinctKw", "args"]),
97
+ ...(node.nullHandlingKw ? print.spaced("nullHandlingKw") : []),
98
+ ...print(["orderBy", "limit", "having"]),
99
+ ]),
100
+ filter_arg: (print) => print.spaced(["filterKw", "where"]),
101
+ over_arg: (print) => print.spaced(["overKw", "window"]),
102
+ having_arg: (print) => print.spaced(["havingKw", "minMaxKw", "expr"]),
103
+ named_arg: (print) => group([
104
+ print("name"),
105
+ " ",
106
+ print("operator"),
107
+ indent([line, print("value")]),
108
+ ]),
109
+ cast_expr: (print) => print(["castKw", "args"]),
110
+ cast_arg: (print) => print.spaced(["expr", "asKw", "dataType", "format"]),
111
+ cast_format: (print) => print.spaced(["formatKw", "string", "timezone"]),
112
+ cast_format_timezone: (print) => print.spaced(["atTimeZoneKw", "timezone"]),
113
+ cast_operator_expr: (print) => [
134
114
  print("left"),
135
115
  print("operator"),
136
116
  print("right"),
137
- ]; },
138
- string_with_charset: function (print) { return ["_", print(["charset", "string"])]; },
139
- raise_expr: function (print) { return print(["raiseKw", "args"]); },
140
- raise_expr_type: function (print) { return print("typeKw"); },
141
- extract_expr: function (print) { return print(["extractKw", "args"]); },
142
- extract_from: function (print) { return print.spaced(["unit", "fromKw", "expr"]); },
143
- week_expr: function (print) { return print(["weekKw", "args"]); },
144
- interval_literal: function (print) {
145
- return print.spaced(["intervalKw", "precision", "value", "unit"]);
146
- },
147
- array_literal_expr: function (print) { return print(["arrayKw", "expr"]); },
148
- array_expr: function (print) {
149
- return (0, print_utils_1.group)(["[", (0, print_utils_1.indent)([print_utils_1.softline, print("expr")]), print_utils_1.softline, "]"]);
150
- },
151
- struct_expr: function (print) {
152
- return (0, print_utils_1.group)(["(", (0, print_utils_1.indent)([print_utils_1.softline, print("expr")]), print_utils_1.softline, ")"]);
153
- },
154
- typed_expr: function (print) { return print(["dataType", "expr"]); },
155
- row_constructor: function (print) { return print(["rowKw", "row"]); },
156
- array_constructor: function (print) { return print(["arrayKw", "expr"]); },
157
- quantifier_expr: function (print) { return print.spaced(["quantifierKw", "expr"]); },
158
- full_text_match_expr: function (print) {
159
- return print.spaced(["matchKw", "columns", "againstKw", "args"]);
160
- },
161
- full_text_match_args: function (print) { return print.spaced(["expr", "modifier"]); },
117
+ ],
118
+ string_with_charset: (print) => ["_", print(["charset", "string"])],
119
+ raise_expr: (print) => print(["raiseKw", "args"]),
120
+ raise_expr_type: (print) => print("typeKw"),
121
+ extract_expr: (print) => print(["extractKw", "args"]),
122
+ extract_from: (print) => print.spaced(["unit", "fromKw", "expr"]),
123
+ week_expr: (print) => print(["weekKw", "args"]),
124
+ interval_literal: (print) => print.spaced(["intervalKw", "precision", "value", "unit"]),
125
+ array_literal_expr: (print) => print(["arrayKw", "expr"]),
126
+ array_expr: (print) => group(["[", indent([softline, print("expr")]), softline, "]"]),
127
+ struct_expr: (print) => group(["(", indent([softline, print("expr")]), softline, ")"]),
128
+ typed_expr: (print) => print(["dataType", "expr"]),
129
+ row_constructor: (print) => print(["rowKw", "row"]),
130
+ array_constructor: (print) => print(["arrayKw", "expr"]),
131
+ quantifier_expr: (print) => print.spaced(["quantifierKw", "expr"]),
132
+ full_text_match_expr: (print) => print.spaced(["matchKw", "columns", "againstKw", "args"]),
133
+ full_text_match_args: (print) => print.spaced(["expr", "modifier"]),
162
134
  /** cst-ignore: value */
163
- number_literal: function (print) { return print("text"); },
135
+ number_literal: (print) => print("text"),
164
136
  /** cst-ignore: value */
165
- boolean_literal: function (print, node, path, options) {
166
- return (0, exports.printLiteral)(node.valueKw, options);
167
- },
137
+ boolean_literal: (print, node, path, options) => printLiteral(node.valueKw, options),
168
138
  /** cst-ignore: value */
169
- string_literal: function (print) { return print("text"); },
139
+ string_literal: (print) => print("text"),
170
140
  /** cst-ignore: value */
171
- blob_literal: function (print) { return print("text"); },
141
+ blob_literal: (print) => print("text"),
172
142
  /** cst-ignore: value */
173
- null_literal: function (print, node, path, options) {
174
- return (0, exports.printLiteral)(node.nullKw, options);
175
- },
176
- numeric_literal: function (print) { return print.spaced(["numericKw", "string"]); },
177
- bignumeric_literal: function (print) { return print.spaced(["bignumericKw", "string"]); },
178
- date_literal: function (print) { return print.spaced(["dateKw", "string"]); },
179
- time_literal: function (print) { return print.spaced(["timeKw", "string"]); },
180
- datetime_literal: function (print) { return print.spaced(["datetimeKw", "string"]); },
181
- timestamp_literal: function (print) { return print.spaced(["timestampKw", "string"]); },
182
- json_literal: function (print) { return print.spaced(["jsonKw", "string"]); },
183
- jsonb_literal: function (print) { return print.spaced(["jsonbKw", "string"]); },
143
+ null_literal: (print, node, path, options) => printLiteral(node.nullKw, options),
144
+ numeric_literal: (print) => print.spaced(["numericKw", "string"]),
145
+ bignumeric_literal: (print) => print.spaced(["bignumericKw", "string"]),
146
+ date_literal: (print) => print.spaced(["dateKw", "string"]),
147
+ time_literal: (print) => print.spaced(["timeKw", "string"]),
148
+ datetime_literal: (print) => print.spaced(["datetimeKw", "string"]),
149
+ timestamp_literal: (print) => print.spaced(["timestampKw", "string"]),
150
+ json_literal: (print) => print.spaced(["jsonKw", "string"]),
151
+ jsonb_literal: (print) => print.spaced(["jsonbKw", "string"]),
184
152
  /** cst-ignore: name */
185
- identifier: function (print, node, path, options) {
153
+ identifier: (print, node, path, options) => {
186
154
  if (isQuotedIdentifier(node) || isInsideBigqueryQuotedMemberExpr(path)) {
187
155
  return print("text");
188
156
  }
@@ -196,14 +164,10 @@ exports.exprMap = {
196
164
  }
197
165
  },
198
166
  /** cst-ignore: name */
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
- },
167
+ variable: (print, node, path, options) => isQuotedVariable(node) ? print("text") : printIdentifier(node, options),
168
+ parameter: (print, node, path, options) => isQuotedParameter(node) ? print("text") : printIdentifier(node, options),
205
169
  };
206
- var printLiteral = function (node, options) {
170
+ export const printLiteral = (node, options) => {
207
171
  switch (options.sqlLiteralCase) {
208
172
  case "preserve":
209
173
  return node.text;
@@ -213,8 +177,7 @@ var printLiteral = function (node, options) {
213
177
  return node.text.toLowerCase();
214
178
  }
215
179
  };
216
- exports.printLiteral = printLiteral;
217
- var printIdentifier = function (node, options) {
180
+ const printIdentifier = (node, options) => {
218
181
  switch (options.sqlIdentifierCase) {
219
182
  case "preserve":
220
183
  return node.text;
@@ -224,7 +187,7 @@ var printIdentifier = function (node, options) {
224
187
  return node.text.toLowerCase();
225
188
  }
226
189
  };
227
- var printFunctionName = function (node, options) {
190
+ const printFunctionName = (node, options) => {
228
191
  switch (options.sqlFunctionCase) {
229
192
  case "preserve":
230
193
  return node.text;
@@ -234,40 +197,28 @@ var printFunctionName = function (node, options) {
234
197
  return node.text.toLowerCase();
235
198
  }
236
199
  };
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;
200
+ const isQuotedIdentifier = (node) => node.name !== node.text;
201
+ const isQuotedVariable = (node) => !(node.text === "@" + node.name || node.text === "@@" + node.name);
202
+ const isQuotedParameter = (node) => /`$/.test(node.text);
203
+ const isInsideBigqueryQuotedMemberExpr = (path) => path.ancestors.some(isBigqueryQuotedMemberExpr);
204
+ const isFunctionName = (node, path) => {
205
+ const parent = path.parent;
249
206
  if (isFunctionContext(parent, path.grandparent)) {
250
207
  return true;
251
208
  }
252
- if ((0, node_utils_1.isMemberExpr)(parent) && parent.property === node) {
253
- var _a = path.ancestors, _ = _a[0], gp = _a[1], ggp = _a[2];
209
+ if (isMemberExpr(parent) && parent.property === node) {
210
+ const [_, gp, ggp] = path.ancestors;
254
211
  return isFunctionContext(gp, ggp);
255
212
  }
256
213
  return false;
257
214
  };
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
- };
270
- var isBooleanOp = function (_a) {
271
- var name = _a.name;
272
- return name === "AND" || name === "OR";
215
+ const isFunctionContext = (node, parent) => {
216
+ return (isFuncCall(node) ||
217
+ isFunctionSignature(node) ||
218
+ isCreateFunctionStmt(node) ||
219
+ isCreateProcedureStmt(node) ||
220
+ (isAlterActionRename(node) &&
221
+ (isAlterFunctionStmt(parent) || isAlterProcedureStmt(parent))) ||
222
+ (isExecuteClause(node) && isCreateTriggerStmt(parent)));
273
223
  };
224
+ const isBooleanOp = ({ name }) => name === "AND" || name === "OR";
@@ -1,22 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extensionMap = void 0;
4
- var print_utils_1 = require("../print_utils");
5
- exports.extensionMap = {
6
- create_extension_stmt: function (print, node) {
7
- return (0, print_utils_1.group)([
8
- print.spaced(["createExtensionKw", "ifNotExistsKw", "name"]),
9
- node.clauses.length > 0
10
- ? (0, print_utils_1.indent)([print_utils_1.line, print.spaced(["withKw", "clauses"])])
11
- : [],
12
- ]);
13
- },
14
- extension_cascade_clause: function (print) { return (0, print_utils_1.group)(print.spaced(["cascadeKw"])); },
15
- extension_schema_clause: function (print) { return (0, print_utils_1.group)(print.spaced(["schemaKw", "name"])); },
16
- extension_version_clause: function (print) {
17
- return (0, print_utils_1.group)(print.spaced(["versionKw", "name"]));
18
- },
19
- drop_extension_stmt: function (print) {
20
- return (0, print_utils_1.group)(print.spaced(["dropExtensionKw", "ifExistsKw", "names", "behaviorKw"]));
21
- },
1
+ import { group, indent, line } from "../print_utils";
2
+ export const extensionMap = {
3
+ create_extension_stmt: (print, node) => group([
4
+ print.spaced(["createExtensionKw", "ifNotExistsKw", "name"]),
5
+ node.clauses.length > 0
6
+ ? indent([line, print.spaced(["withKw", "clauses"])])
7
+ : [],
8
+ ]),
9
+ extension_cascade_clause: (print) => group(print.spaced(["cascadeKw"])),
10
+ extension_schema_clause: (print) => group(print.spaced(["schemaKw", "name"])),
11
+ extension_version_clause: (print) => group(print.spaced(["versionKw", "name"])),
12
+ drop_extension_stmt: (print) => group(print.spaced(["dropExtensionKw", "ifExistsKw", "names", "behaviorKw"])),
22
13
  };
@@ -1,18 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.frameMap = void 0;
4
- var print_utils_1 = require("../print_utils");
5
- exports.frameMap = {
6
- frame_clause: function (print, node) { return [
1
+ import { hardline } from "../print_utils";
2
+ export const frameMap = {
3
+ frame_clause: (print, node) => [
7
4
  print.spaced(["unitKw", "extent"]),
8
- node.exclusion ? [print_utils_1.hardline, print("exclusion")] : [],
9
- ]; },
10
- frame_bound_current_row: function (print) { return print.spaced("currentRowKw"); },
11
- frame_bound_preceding: function (print) { return print.spaced(["expr", "precedingKw"]); },
12
- frame_bound_following: function (print) { return print.spaced(["expr", "followingKw"]); },
13
- frame_unbounded: function (print) { return print.spaced("unboundedKw"); },
14
- frame_between: function (print) {
15
- return print.spaced(["betweenKw", "begin", "andKw", "end"]);
16
- },
17
- frame_exclusion: function (print) { return print.spaced(["excludeKw", "kindKw"]); },
5
+ node.exclusion ? [hardline, print("exclusion")] : [],
6
+ ],
7
+ frame_bound_current_row: (print) => print.spaced("currentRowKw"),
8
+ frame_bound_preceding: (print) => print.spaced(["expr", "precedingKw"]),
9
+ frame_bound_following: (print) => print.spaced(["expr", "followingKw"]),
10
+ frame_unbounded: (print) => print.spaced("unboundedKw"),
11
+ frame_between: (print) => print.spaced(["betweenKw", "begin", "andKw", "end"]),
12
+ frame_exclusion: (print) => print.spaced(["excludeKw", "kindKw"]),
18
13
  };
@@ -1,65 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasOnlyAsClause = exports.functionMap = void 0;
4
- var print_utils_1 = require("../print_utils");
5
- var node_utils_1 = require("../node_utils");
6
- exports.functionMap = {
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
- },
27
- function_signature: function (print) { return print(["name", "params"]); },
28
- function_param: function (print) {
29
- return print.spaced(["mode", "name", "dataType", "default"]);
30
- },
31
- function_param_default: function (print) { return print.spaced(["operator", "expr"]); },
32
- return_clause: function (print) { return print.spaced(["returnKw", "expr"]); },
33
- function_behavior_clause: function (print) { return print.spaced(["behaviorKw"]); },
34
- function_security_clause: function (print) {
35
- return print.spaced(["externalKw", "securityKw"]);
36
- },
37
- function_cost_clause: function (print) { return print.spaced(["costKw", "cost"]); },
38
- function_rows_clause: function (print) { return print.spaced(["rowsKw", "rows"]); },
39
- function_support_clause: function (print) { return print.spaced(["supportKw", "name"]); },
40
- function_window_clause: function (print) { return print.spaced("windowKw"); },
41
- function_transform_clause: function (print) { return print.spaced(["transformKw", "types"]); },
42
- transform_type: function (print) { return print.spaced(["forTypeKw", "dataType"]); },
43
- dynamically_loaded_function: function (print) {
44
- return (0, print_utils_1.join)(", ", print(["objectFile", "symbol"]));
45
- },
46
- drop_function_stmt: function (print) {
47
- return (0, print_utils_1.group)([
48
- print.spaced(["dropKw", "tableKw", "functionKw", "ifExistsKw", "name"]),
49
- print.spaced(["params", "behaviorKw"]),
50
- ]);
51
- },
1
+ import { group, hardline, join } from "../print_utils";
2
+ import { isAsClause } from "../node_utils";
3
+ export const functionMap = {
4
+ create_function_stmt: (print, node) => group([
5
+ print.spaced([
6
+ "createKw",
7
+ "orReplaceKw",
8
+ "temporaryKw",
9
+ "tableKw",
10
+ "functionKw",
11
+ "ifNotExistsKw",
12
+ "name",
13
+ ]),
14
+ print("params"),
15
+ hasOnlyAsClause(node)
16
+ ? [" ", group(print("clauses"))]
17
+ : [
18
+ hardline,
19
+ join(hardline, print("clauses").map((cls) => group(cls))),
20
+ ],
21
+ ]),
22
+ function_signature: (print) => print(["name", "params"]),
23
+ function_param: (print) => print.spaced(["mode", "name", "dataType", "default"]),
24
+ function_param_default: (print) => print.spaced(["operator", "expr"]),
25
+ return_clause: (print) => print.spaced(["returnKw", "expr"]),
26
+ function_behavior_clause: (print) => print.spaced(["behaviorKw"]),
27
+ function_security_clause: (print) => print.spaced(["externalKw", "securityKw"]),
28
+ function_cost_clause: (print) => print.spaced(["costKw", "cost"]),
29
+ function_rows_clause: (print) => print.spaced(["rowsKw", "rows"]),
30
+ function_support_clause: (print) => print.spaced(["supportKw", "name"]),
31
+ function_window_clause: (print) => print.spaced("windowKw"),
32
+ function_transform_clause: (print) => print.spaced(["transformKw", "types"]),
33
+ transform_type: (print) => print.spaced(["forTypeKw", "dataType"]),
34
+ dynamically_loaded_function: (print) => join(", ", print(["objectFile", "symbol"])),
35
+ drop_function_stmt: (print) => group([
36
+ print.spaced([
37
+ "dropKw",
38
+ "tableKw",
39
+ "functionKw",
40
+ "ifExistsKw",
41
+ "signatures",
42
+ "behaviorKw",
43
+ ]),
44
+ ]),
52
45
  // almost exact copy of alter_procedure_stmt
53
- alter_function_stmt: function (print, node) {
54
- return (0, print_utils_1.group)([
55
- print.spaced(["alterKw", "functionKw"]),
56
- " ",
57
- print(["name", "params"]),
58
- print.dynamicLine(),
59
- (0, print_utils_1.join)(print.dynamicLine(), print("actions")),
60
- node.behaviorKw ? [print.dynamicLine(), print("behaviorKw")] : [],
61
- ]);
62
- },
46
+ alter_function_stmt: (print, node) => group([
47
+ print.spaced(["alterKw", "functionKw"]),
48
+ " ",
49
+ print(["signature"]),
50
+ print.dynamicLine(),
51
+ join(print.dynamicLine(), print("actions")),
52
+ node.behaviorKw ? [print.dynamicLine(), print("behaviorKw")] : [],
53
+ ]),
63
54
  };
64
- var hasOnlyAsClause = function (node) { return node.clauses.length === 1 && (0, node_utils_1.isAsClause)(node.clauses[0]); };
65
- exports.hasOnlyAsClause = hasOnlyAsClause;
55
+ export const hasOnlyAsClause = (node) => node.clauses.length === 1 && isAsClause(node.clauses[0]);