prettier-plugin-sql-cst 0.22.0 → 0.23.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 +4 -5
- package/dist/index.js +212 -93
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -29,10 +29,9 @@ SELECT
|
|
|
29
29
|
client.name AS client_name,
|
|
30
30
|
organization.name AS org_name,
|
|
31
31
|
count(orders.id) AS nr_of_orders
|
|
32
|
-
FROM
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
LEFT JOIN orders ON orders.client_id = client.id
|
|
32
|
+
FROM client
|
|
33
|
+
LEFT JOIN organization ON client.organization_id = organization.id
|
|
34
|
+
LEFT JOIN orders ON orders.client_id = client.id
|
|
36
35
|
WHERE
|
|
37
36
|
client.status = 'active'
|
|
38
37
|
AND client.id IN (28, 214, 457)
|
|
@@ -182,7 +181,7 @@ There are also several SQL-specific options:
|
|
|
182
181
|
|
|
183
182
|
_Since 0.17.0_
|
|
184
183
|
|
|
185
|
-
- **`sqlParamTypes`**:
|
|
184
|
+
- **`sqlParamTypes`**: ``("?", "?nr", "$nr", ":name", "$name", "@name", "@`name`")[]`` (default `[]`)
|
|
186
185
|
|
|
187
186
|
Array of bound parameter types to support.
|
|
188
187
|
|
package/dist/index.js
CHANGED
|
@@ -307,6 +307,7 @@ var isFuncArgs = is("func_args");
|
|
|
307
307
|
var isCreateTableStmt = is("create_table_stmt");
|
|
308
308
|
var isKeyword = is("keyword");
|
|
309
309
|
var isEmpty = is("empty");
|
|
310
|
+
var isIdentifier = is("identifier");
|
|
310
311
|
var isJsonLiteral = is("json_literal");
|
|
311
312
|
var isJsonbLiteral = is("jsonb_literal");
|
|
312
313
|
var isStringLiteral = is("string_literal");
|
|
@@ -317,18 +318,22 @@ var isMemberExpr = is("member_expr");
|
|
|
317
318
|
var isSelectStmt = is("select_stmt");
|
|
318
319
|
var isCompoundSelectStmt = is("compound_select_stmt");
|
|
319
320
|
var isListExpr = is("list_expr");
|
|
321
|
+
var isJoinExpr = is("join_expr");
|
|
320
322
|
var isCreateFunctionStmt = is("create_function_stmt");
|
|
321
323
|
var isAlterFunctionStmt = is("alter_function_stmt");
|
|
322
324
|
var isDropFunctionStmt = is("drop_function_stmt");
|
|
323
325
|
var isCreateProcedureStmt = is("create_procedure_stmt");
|
|
324
326
|
var isAlterProcedureStmt = is("alter_procedure_stmt");
|
|
325
327
|
var isDropProcedureStmt = is("drop_procedure_stmt");
|
|
328
|
+
var isDoStmt = is("do_stmt");
|
|
326
329
|
var isAlterActionRename = is("alter_action_rename");
|
|
327
330
|
var isLanguageClause = is("language_clause");
|
|
328
331
|
var isDynamicallyLoadedFunction = is("dynamically_loaded_function");
|
|
329
332
|
var isBigqueryQuotedMemberExpr = is("bigquery_quoted_member_expr");
|
|
330
333
|
var isCreateTriggerStmt = is("create_trigger_stmt");
|
|
331
334
|
var isExecuteClause = is("execute_clause");
|
|
335
|
+
var isExecuteImmediateStmt = is("execute_immediate_stmt");
|
|
336
|
+
var isExecuteExpr = is("execute_expr");
|
|
332
337
|
var isFunctionSignature = is("function_signature");
|
|
333
338
|
var isDataTypeName = is("data_type_name");
|
|
334
339
|
var isIntervalDataType = is("interval_data_type");
|
|
@@ -364,8 +369,11 @@ var castMap = {
|
|
|
364
369
|
// src/syntax/comment.ts
|
|
365
370
|
var commentMap = {
|
|
366
371
|
comment_stmt: (print) => group([
|
|
367
|
-
print.spaced(["commentKw", "onKw"
|
|
368
|
-
|
|
372
|
+
print.spaced(["commentKw", "onKw"]),
|
|
373
|
+
line,
|
|
374
|
+
print("target"),
|
|
375
|
+
line,
|
|
376
|
+
print.spaced(["isKw", "message"])
|
|
369
377
|
]),
|
|
370
378
|
comment_target_aggregate: (print) => group([print.spaced(["aggregateKw", "name"]), print(["params"])]),
|
|
371
379
|
comment_target_function: (print) => group([print.spaced(["functionKw", "name"]), print(["params"])]),
|
|
@@ -682,10 +690,16 @@ var exprMap = {
|
|
|
682
690
|
if (isParenExpr(node.expr)) {
|
|
683
691
|
return print("expr");
|
|
684
692
|
}
|
|
685
|
-
|
|
693
|
+
const parent = path.getParentNode(0);
|
|
694
|
+
const grandParent = path.getParentNode(1);
|
|
695
|
+
if (isListExpr(parent) && isFuncArgs(grandParent) && // TODO: We really should parse the DISTINCT (...) expression as a separate thing.
|
|
696
|
+
// For now this check here patches up the deficiency in the parser.
|
|
697
|
+
!grandParent.distinctKw && !isSelectStmt(node.expr) && !isCompoundSelectStmt(node.expr)) {
|
|
686
698
|
return print("expr");
|
|
687
699
|
}
|
|
688
|
-
|
|
700
|
+
if (isEmptyParenExpr(node)) {
|
|
701
|
+
return ["(", print("expr"), ")"];
|
|
702
|
+
}
|
|
689
703
|
const lineStyle = isCreateTableStmt(parent) && print.dynamicLine() === hardline ? hardline : softline;
|
|
690
704
|
return group(["(", indent([lineStyle, print("expr")]), lineStyle, ")"]);
|
|
691
705
|
},
|
|
@@ -696,7 +710,13 @@ var exprMap = {
|
|
|
696
710
|
if (node.operator === "") {
|
|
697
711
|
return print.spaced(["left", "right"]);
|
|
698
712
|
}
|
|
699
|
-
|
|
713
|
+
if (isString(node.operator) && isCompactOp(node.operator)) {
|
|
714
|
+
return print(["left", "operator", "right"]);
|
|
715
|
+
}
|
|
716
|
+
return group([
|
|
717
|
+
print("left"),
|
|
718
|
+
group([" ", print.spaced("operator"), indent([line, print("right")])])
|
|
719
|
+
]);
|
|
700
720
|
},
|
|
701
721
|
prefix_op_expr: (print, node) => (isString(node.operator) ? print : print.spaced)(["operator", "expr"]),
|
|
702
722
|
postfix_op_expr: (print) => print.spaced(["expr", "operator"]),
|
|
@@ -708,13 +728,18 @@ var exprMap = {
|
|
|
708
728
|
print("endKw")
|
|
709
729
|
],
|
|
710
730
|
case_when: (print, node) => {
|
|
731
|
+
const whenThen = group([
|
|
732
|
+
group([print("whenKw"), indent([line, print("condition")])]),
|
|
733
|
+
line,
|
|
734
|
+
print("thenKw")
|
|
735
|
+
]);
|
|
711
736
|
if (isProgram(node.result)) {
|
|
712
737
|
return [
|
|
713
|
-
|
|
738
|
+
whenThen,
|
|
714
739
|
indent([hardline, stripTrailingHardline(print("result"))])
|
|
715
740
|
];
|
|
716
741
|
}
|
|
717
|
-
return
|
|
742
|
+
return group([whenThen, indent([line, print("result")])]);
|
|
718
743
|
},
|
|
719
744
|
case_else: (print, node) => {
|
|
720
745
|
if (isProgram(node.result)) {
|
|
@@ -723,7 +748,7 @@ var exprMap = {
|
|
|
723
748
|
indent([hardline, stripTrailingHardline(print("result"))])
|
|
724
749
|
];
|
|
725
750
|
}
|
|
726
|
-
return print
|
|
751
|
+
return group([print("elseKw"), indent([line, print("result")])]);
|
|
727
752
|
},
|
|
728
753
|
member_expr: (print, node) => isArraySubscript(node.property) ? print(["object", "property"]) : [print("object"), ".", print("property")],
|
|
729
754
|
bigquery_quoted_member_expr: (print) => ["`", print("expr"), "`"],
|
|
@@ -861,6 +886,20 @@ var isFunctionContext = (node, parent) => {
|
|
|
861
886
|
return isFuncCall(node) || isFunctionSignature(node) || isCreateFunctionStmt(node) || isCreateProcedureStmt(node) || isAlterActionRename(node) && (isAlterFunctionStmt(parent) || isAlterProcedureStmt(parent)) || isExecuteClause(node) && isCreateTriggerStmt(parent);
|
|
862
887
|
};
|
|
863
888
|
var isBooleanOp = ({ name }) => name === "AND" || name === "OR";
|
|
889
|
+
var isCompactOp = (op) => op === "->" || op === "->>";
|
|
890
|
+
var hasComments = (node) => (node.leading?.length ?? 0) > 0 || (node.trailing?.length ?? 0) > 0;
|
|
891
|
+
var isEmptyParenExpr = (node) => {
|
|
892
|
+
if (hasComments(node) || hasComments(node.expr)) {
|
|
893
|
+
return false;
|
|
894
|
+
}
|
|
895
|
+
if (isFuncArgs(node.expr)) {
|
|
896
|
+
return node.expr.args.items.length === 0 && !node.expr.distinctKw && !node.expr.nullHandlingKw && !node.expr.orderBy && !node.expr.limit && !node.expr.having;
|
|
897
|
+
}
|
|
898
|
+
if (isListExpr(node.expr)) {
|
|
899
|
+
return node.expr.items.length === 0;
|
|
900
|
+
}
|
|
901
|
+
return false;
|
|
902
|
+
};
|
|
864
903
|
|
|
865
904
|
// src/syntax/extension.ts
|
|
866
905
|
var extensionMap = {
|
|
@@ -948,21 +987,27 @@ var hasOnlyAsClause = (node) => node.clauses.length === 1 && isAsClause(node.cla
|
|
|
948
987
|
|
|
949
988
|
// src/syntax/index.ts
|
|
950
989
|
var indexMap = {
|
|
951
|
-
create_index_stmt: (print) => group(
|
|
990
|
+
create_index_stmt: (print, node) => group(
|
|
952
991
|
join(print.dynamicLine(), [
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
992
|
+
group(
|
|
993
|
+
join(line, [
|
|
994
|
+
print.spaced([
|
|
995
|
+
"createKw",
|
|
996
|
+
"orReplaceKw",
|
|
997
|
+
"indexTypeKw",
|
|
998
|
+
"indexKw",
|
|
999
|
+
"concurrentlyKw",
|
|
1000
|
+
"ifNotExistsKw",
|
|
1001
|
+
"name"
|
|
1002
|
+
]),
|
|
1003
|
+
print.spaced([
|
|
1004
|
+
"onKw",
|
|
1005
|
+
"table",
|
|
1006
|
+
...node.using ? [] : ["columns"]
|
|
1007
|
+
]),
|
|
1008
|
+
...node.using ? [print.spaced(["using", "columns"])] : []
|
|
1009
|
+
])
|
|
1010
|
+
),
|
|
966
1011
|
...print("clauses")
|
|
967
1012
|
])
|
|
968
1013
|
),
|
|
@@ -1362,7 +1407,7 @@ var proceduralLanguageMap = {
|
|
|
1362
1407
|
// CALL
|
|
1363
1408
|
call_stmt: (print) => group(print.spaced(["callKw", "func"])),
|
|
1364
1409
|
// RETURN
|
|
1365
|
-
return_stmt: (print) => group(print
|
|
1410
|
+
return_stmt: (print, node) => node.expr ? group([print("returnKw"), indent([line, print("expr")])]) : print("returnKw"),
|
|
1366
1411
|
return_next_stmt: (print) => group(print.spaced(["returnNextKw", "expr"])),
|
|
1367
1412
|
return_query_stmt: (print, node) => {
|
|
1368
1413
|
if (node.expr.type === "execute_expr") {
|
|
@@ -1555,11 +1600,16 @@ var selectMap = {
|
|
|
1555
1600
|
print.spaced(["defaultKw", "defaultValue"])
|
|
1556
1601
|
]),
|
|
1557
1602
|
// SELECT clause
|
|
1558
|
-
select_clause: (print, node, path, opts) =>
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1603
|
+
select_clause: (print, node, path, opts) => {
|
|
1604
|
+
if (hasSingleColumn(node)) {
|
|
1605
|
+
return group(print.spaced(["selectKw", "modifiers", "columns"]));
|
|
1606
|
+
}
|
|
1607
|
+
return group([
|
|
1608
|
+
print.spaced(["selectKw", "modifiers"]),
|
|
1609
|
+
node.columns ? indent([line, print("columns")]) : [],
|
|
1610
|
+
containsNewline(node, opts) ? breakParent : []
|
|
1611
|
+
]);
|
|
1612
|
+
},
|
|
1563
1613
|
select_all: (print) => print.spaced(["allKw"]),
|
|
1564
1614
|
select_distinct: (print) => print.spaced(["distinctKw"]),
|
|
1565
1615
|
select_distinct_on: (print) => group([print.spaced(["distinctOnKw", "columns"])]),
|
|
@@ -1568,7 +1618,7 @@ var selectMap = {
|
|
|
1568
1618
|
except_columns: (print) => print.spaced(["expr", "exceptKw", "columns"]),
|
|
1569
1619
|
replace_columns: (print) => print.spaced(["expr", "replaceKw", "columns"]),
|
|
1570
1620
|
// FROM clause
|
|
1571
|
-
from_clause: (print) => group([print("fromKw"), indent([line, print("expr")])]),
|
|
1621
|
+
from_clause: (print, node) => hasCommaJoin(node.expr) ? group([print("fromKw"), indent([line, print("expr")])]) : print.spaced(["fromKw", "expr"]),
|
|
1572
1622
|
join_expr: (print, node) => {
|
|
1573
1623
|
if (node.operator === ",") {
|
|
1574
1624
|
return join([",", hardline], print(["left", "right"]));
|
|
@@ -1596,7 +1646,10 @@ var selectMap = {
|
|
|
1596
1646
|
not_indexed_table: (print) => print.spaced(["table", "notIndexedKw"]),
|
|
1597
1647
|
unnest_expr: (print) => print(["unnestKw", "expr"]),
|
|
1598
1648
|
unnest_with_offset_expr: (print) => print.spaced(["unnest", "withOffsetKw"]),
|
|
1599
|
-
pivot_expr: (print) => [
|
|
1649
|
+
pivot_expr: (print) => [
|
|
1650
|
+
print("left"),
|
|
1651
|
+
indent([hardline, print(["pivotKw", "args"])])
|
|
1652
|
+
],
|
|
1600
1653
|
pivot_for_in: (print) => group(
|
|
1601
1654
|
join(line, [
|
|
1602
1655
|
group(print("aggregations")),
|
|
@@ -1606,11 +1659,13 @@ var selectMap = {
|
|
|
1606
1659
|
),
|
|
1607
1660
|
unpivot_expr: (print, node) => [
|
|
1608
1661
|
print("left"),
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1662
|
+
indent([
|
|
1663
|
+
hardline,
|
|
1664
|
+
(node.nullHandlingKw ? print.spaced : print)([
|
|
1665
|
+
"unpivotKw",
|
|
1666
|
+
"nullHandlingKw",
|
|
1667
|
+
"args"
|
|
1668
|
+
])
|
|
1614
1669
|
])
|
|
1615
1670
|
],
|
|
1616
1671
|
unpivot_for_in: (print) => group(
|
|
@@ -1622,13 +1677,18 @@ var selectMap = {
|
|
|
1622
1677
|
),
|
|
1623
1678
|
tablesample_expr: (print) => group([
|
|
1624
1679
|
print("left"),
|
|
1625
|
-
|
|
1626
|
-
|
|
1680
|
+
indent([
|
|
1681
|
+
line,
|
|
1682
|
+
print.spaced(["tablesampleKw", "method", "args", "repeatable"])
|
|
1683
|
+
])
|
|
1627
1684
|
]),
|
|
1628
1685
|
tablesample_method: (print) => print.spaced(["methodKw"]),
|
|
1629
1686
|
tablesample_percent: (print) => print.spaced(["percent", "percentKw"]),
|
|
1630
1687
|
tablesample_repeatable: (print) => print.spaced(["repeatableKw", "seed"]),
|
|
1631
|
-
for_system_time_as_of_expr: (print) => group([
|
|
1688
|
+
for_system_time_as_of_expr: (print) => group([
|
|
1689
|
+
print("left"),
|
|
1690
|
+
indent([line, print.spaced(["forSystemTimeAsOfKw", "expr"])])
|
|
1691
|
+
]),
|
|
1632
1692
|
partitioned_table: (print) => print.spaced(["table", "partitionKw", "partitions"]),
|
|
1633
1693
|
dual_table: (print) => print("dualKw"),
|
|
1634
1694
|
lateral_derived_table: (print) => print.spaced(["lateralKw", "expr"]),
|
|
@@ -1749,6 +1809,13 @@ var printLimitValues = (print, node) => {
|
|
|
1749
1809
|
return print("count");
|
|
1750
1810
|
}
|
|
1751
1811
|
};
|
|
1812
|
+
var hasSingleColumn = (node) => {
|
|
1813
|
+
if (!node.columns) {
|
|
1814
|
+
return false;
|
|
1815
|
+
}
|
|
1816
|
+
return node.columns.items.filter((item) => !isEmpty(item)).length === 1;
|
|
1817
|
+
};
|
|
1818
|
+
var hasCommaJoin = (node) => isJoinExpr(node) && (node.operator === "," || hasCommaJoin(node.left));
|
|
1752
1819
|
|
|
1753
1820
|
// src/syntax/sequence.ts
|
|
1754
1821
|
var sequenceMap = {
|
|
@@ -2199,51 +2266,61 @@ function printNode(path, options2, print) {
|
|
|
2199
2266
|
var printComment = (path) => {
|
|
2200
2267
|
const node = path.node;
|
|
2201
2268
|
if (node.type === "line_comment") {
|
|
2202
|
-
if (/^--[^ \t]/.test(node.text)) {
|
|
2269
|
+
if (/^--[^ \t-]/.test(node.text)) {
|
|
2203
2270
|
return node.text.replace(/^--/, "-- ");
|
|
2204
2271
|
}
|
|
2205
|
-
if (/^#[^ \t
|
|
2272
|
+
if (/^#[^ \t!#]/.test(node.text)) {
|
|
2206
2273
|
return node.text.replace(/^#/, "# ");
|
|
2207
2274
|
}
|
|
2208
2275
|
}
|
|
2209
2276
|
return node.text;
|
|
2210
2277
|
};
|
|
2211
2278
|
|
|
2279
|
+
// src/languageClause.ts
|
|
2280
|
+
var isJavaScriptLanguageClause = (clause) => isLanguageClause(clause) && languageName(clause.name) === "js";
|
|
2281
|
+
var isSqlLanguageClause = (clause) => isLanguageClause(clause) && languageName(clause.name).toLowerCase() === "sql";
|
|
2282
|
+
var isPlpgsqlLanguageClause = (clause) => isLanguageClause(clause) && languageName(clause.name).toLowerCase() === "plpgsql";
|
|
2283
|
+
var languageName = (node) => isIdentifier(node) ? node.name : node.value;
|
|
2284
|
+
|
|
2285
|
+
// src/formatBigqueryString.ts
|
|
2286
|
+
var formatBigqueryString = (node, options2) => {
|
|
2287
|
+
return async (textToDoc) => {
|
|
2288
|
+
const quotes = detectQuotes(node.value);
|
|
2289
|
+
if (!quotes) {
|
|
2290
|
+
return void 0;
|
|
2291
|
+
}
|
|
2292
|
+
const code = await textToDoc(node.value, options2);
|
|
2293
|
+
return [
|
|
2294
|
+
quotes[0],
|
|
2295
|
+
indent([hardline, stripTrailingHardline(code)]),
|
|
2296
|
+
hardline,
|
|
2297
|
+
quotes[1]
|
|
2298
|
+
];
|
|
2299
|
+
};
|
|
2300
|
+
};
|
|
2301
|
+
var detectQuotes = (code) => {
|
|
2302
|
+
if (!/'''/.test(code)) {
|
|
2303
|
+
return ["r'''", "'''"];
|
|
2304
|
+
}
|
|
2305
|
+
if (!/"""/.test(code)) {
|
|
2306
|
+
return ['r"""', '"""'];
|
|
2307
|
+
}
|
|
2308
|
+
return void 0;
|
|
2309
|
+
};
|
|
2310
|
+
|
|
2212
2311
|
// src/embedJs.ts
|
|
2213
2312
|
var embedJs = (path, options2) => {
|
|
2214
2313
|
const node = path.node;
|
|
2215
2314
|
const parent = path.getParentNode(0);
|
|
2216
2315
|
const grandParent = path.getParentNode(1);
|
|
2217
2316
|
if (isStringLiteral(node) && isAsClause(parent) && isCreateFunctionStmt(grandParent) && grandParent.clauses.some(isJavaScriptLanguageClause)) {
|
|
2218
|
-
return
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
}
|
|
2223
|
-
const js = await textToDoc(node.value, {
|
|
2224
|
-
...options2,
|
|
2225
|
-
parser: "babel"
|
|
2226
|
-
});
|
|
2227
|
-
return [
|
|
2228
|
-
quotes[0],
|
|
2229
|
-
indent([hardline, stripTrailingHardline(js)]),
|
|
2230
|
-
hardline,
|
|
2231
|
-
quotes[1]
|
|
2232
|
-
];
|
|
2233
|
-
};
|
|
2317
|
+
return formatBigqueryString(node, {
|
|
2318
|
+
...options2,
|
|
2319
|
+
parser: "babel"
|
|
2320
|
+
});
|
|
2234
2321
|
}
|
|
2235
2322
|
return null;
|
|
2236
2323
|
};
|
|
2237
|
-
var isJavaScriptLanguageClause = (clause) => isLanguageClause(clause) && clause.name.name === "js";
|
|
2238
|
-
var detectQuotes = (js) => {
|
|
2239
|
-
if (!/'''/.test(js)) {
|
|
2240
|
-
return ["r'''", "'''"];
|
|
2241
|
-
}
|
|
2242
|
-
if (!/"""/.test(js)) {
|
|
2243
|
-
return ['r"""', '"""'];
|
|
2244
|
-
}
|
|
2245
|
-
return void 0;
|
|
2246
|
-
};
|
|
2247
2324
|
|
|
2248
2325
|
// src/embedJson.ts
|
|
2249
2326
|
var embedJson = (path, options2) => {
|
|
@@ -2280,40 +2357,82 @@ var embedSql = (path, options2) => {
|
|
|
2280
2357
|
const parent = path.getParentNode(0);
|
|
2281
2358
|
const grandParent = path.getParentNode(1);
|
|
2282
2359
|
const pluginOptions = options2;
|
|
2283
|
-
if (isStringLiteral(node)
|
|
2360
|
+
if (!isStringLiteral(node)) {
|
|
2361
|
+
return null;
|
|
2362
|
+
}
|
|
2363
|
+
if (isAsClause(parent) && isRoutine(grandParent)) {
|
|
2284
2364
|
if (grandParent.clauses.some(isSqlLanguageClause)) {
|
|
2285
|
-
return
|
|
2286
|
-
const quote = detectQuote(node);
|
|
2287
|
-
if (!quote) {
|
|
2288
|
-
return void 0;
|
|
2289
|
-
}
|
|
2290
|
-
const sql = await textToDoc(node.value, pluginOptions);
|
|
2291
|
-
return [
|
|
2292
|
-
quote,
|
|
2293
|
-
indent([hardline, stripTrailingHardline(sql)]),
|
|
2294
|
-
hardline,
|
|
2295
|
-
quote
|
|
2296
|
-
];
|
|
2297
|
-
};
|
|
2365
|
+
return sqlFormatter(node, pluginOptions);
|
|
2298
2366
|
}
|
|
2299
2367
|
if (grandParent.clauses.some(isPlpgsqlLanguageClause) && pluginOptions.sqlExperimentalPlpgsql) {
|
|
2300
|
-
return
|
|
2301
|
-
const quote = detectQuote(node);
|
|
2302
|
-
if (!quote) {
|
|
2303
|
-
return void 0;
|
|
2304
|
-
}
|
|
2305
|
-
const sql = await textToDoc(node.value, {
|
|
2306
|
-
...pluginOptions,
|
|
2307
|
-
parser: "plpgsql"
|
|
2308
|
-
});
|
|
2309
|
-
return [quote, [hardline, stripTrailingHardline(sql)], hardline, quote];
|
|
2310
|
-
};
|
|
2368
|
+
return plpgsqlFormatter(node, pluginOptions);
|
|
2311
2369
|
}
|
|
2312
2370
|
}
|
|
2371
|
+
if (isDoStmt(parent)) {
|
|
2372
|
+
if (!parent.language || isPlpgsqlLanguageClause(parent.language)) {
|
|
2373
|
+
return plpgsqlFormatter(node, pluginOptions);
|
|
2374
|
+
}
|
|
2375
|
+
if (isSqlLanguageClause(parent.language)) {
|
|
2376
|
+
return sqlFormatter(node, pluginOptions);
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
if (options2.parser === "plpgsql" && (isExecuteImmediateStmt(parent) || isExecuteExpr(parent)) && parent.expr === node && node.text.startsWith("$")) {
|
|
2380
|
+
return sqlFormatter(node, {
|
|
2381
|
+
...pluginOptions,
|
|
2382
|
+
parser: "postgresql",
|
|
2383
|
+
// Enable $1-style parameters supplied by EXECUTE ... USING.
|
|
2384
|
+
sqlParamTypes: [
|
|
2385
|
+
.../* @__PURE__ */ new Set([...pluginOptions.sqlParamTypes ?? [], "$nr"])
|
|
2386
|
+
],
|
|
2387
|
+
// Nested embedding can introduce dollar delimiters that close an outer string.
|
|
2388
|
+
embeddedLanguageFormatting: "off"
|
|
2389
|
+
});
|
|
2390
|
+
}
|
|
2391
|
+
if (options2.parser === "bigquery" && isExecuteImmediateStmt(parent) && parent.expr === node) {
|
|
2392
|
+
return formatBigqueryString(node, {
|
|
2393
|
+
...pluginOptions,
|
|
2394
|
+
// EXECUTE IMMEDIATE ... USING binds positional or named parameters.
|
|
2395
|
+
sqlParamTypes: [
|
|
2396
|
+
.../* @__PURE__ */ new Set([
|
|
2397
|
+
...pluginOptions.sqlParamTypes ?? [],
|
|
2398
|
+
"?",
|
|
2399
|
+
"@name"
|
|
2400
|
+
])
|
|
2401
|
+
],
|
|
2402
|
+
embeddedLanguageFormatting: "off"
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2313
2405
|
return null;
|
|
2314
2406
|
};
|
|
2315
|
-
var
|
|
2316
|
-
|
|
2407
|
+
var sqlFormatter = (node, pluginOptions) => {
|
|
2408
|
+
return async (textToDoc) => {
|
|
2409
|
+
const quote = detectQuote(node);
|
|
2410
|
+
if (!quote) {
|
|
2411
|
+
return void 0;
|
|
2412
|
+
}
|
|
2413
|
+
const sql = await textToDoc(node.value, pluginOptions);
|
|
2414
|
+
return [
|
|
2415
|
+
quote,
|
|
2416
|
+
indent([hardline, stripTrailingHardline(sql)]),
|
|
2417
|
+
hardline,
|
|
2418
|
+
quote
|
|
2419
|
+
];
|
|
2420
|
+
};
|
|
2421
|
+
};
|
|
2422
|
+
var plpgsqlFormatter = (node, pluginOptions) => {
|
|
2423
|
+
return async (textToDoc) => {
|
|
2424
|
+
const quote = detectQuote(node);
|
|
2425
|
+
if (!quote) {
|
|
2426
|
+
return void 0;
|
|
2427
|
+
}
|
|
2428
|
+
const sql = await textToDoc(node.value, {
|
|
2429
|
+
...pluginOptions,
|
|
2430
|
+
parser: "plpgsql"
|
|
2431
|
+
});
|
|
2432
|
+
return [quote, [hardline, stripTrailingHardline(sql)], hardline, quote];
|
|
2433
|
+
};
|
|
2434
|
+
};
|
|
2435
|
+
var isRoutine = (node) => isCreateFunctionStmt(node) || isCreateProcedureStmt(node);
|
|
2317
2436
|
var detectQuote = (node) => {
|
|
2318
2437
|
const match = node.text.match(/^('|\$[^$]*\$)/);
|
|
2319
2438
|
const quote = match?.[1];
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Prettier plugin for SQL",
|
|
5
5
|
"contributors": [
|
|
6
|
+
"Abraham Guo <abrahamjguo@gmail.com>",
|
|
6
7
|
"Barna Magyarkuti <bmagyarkuti@gmail.com>",
|
|
7
8
|
"Bowen Parnell <bparnell@4tel.com.au>",
|
|
8
9
|
"Joel Mukuthu <joelmukuthu@gmail.com>",
|
|
@@ -30,7 +31,8 @@
|
|
|
30
31
|
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
|
|
31
32
|
"pretty": "prettier -w src/ test/",
|
|
32
33
|
"ts:check": "tsc --noEmit",
|
|
33
|
-
"analyze-field-access": "tsx scripts/analyze-field-access.ts src/index.ts"
|
|
34
|
+
"analyze-field-access": "tsx scripts/analyze-field-access.ts src/index.ts",
|
|
35
|
+
"upgrade-parser": "sh scripts/upgrade-parser.sh"
|
|
34
36
|
},
|
|
35
37
|
"keywords": [
|
|
36
38
|
"prettier",
|
|
@@ -39,7 +41,7 @@
|
|
|
39
41
|
],
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"prettier": "^3.0.3",
|
|
42
|
-
"sql-parser-cst": "^0.42.
|
|
44
|
+
"sql-parser-cst": "^0.42.2"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@types/jest": "^30.0.0",
|