prettier-plugin-sql-cst 0.7.0 → 0.8.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.
- package/README.md +4 -2
- package/dist/CstToDocMap.d.ts +11 -0
- package/dist/PrintFn.d.ts +14 -0
- package/dist/embed.d.ts +3 -0
- package/dist/embedJs.d.ts +3 -0
- package/dist/embedJson.d.ts +3 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -3
- package/dist/node_utils.d.ts +16 -0
- package/dist/node_utils.js +2 -1
- package/dist/options.d.ts +8 -0
- package/dist/printComment.d.ts +3 -0
- package/dist/printComment.js +16 -0
- package/dist/printSql.d.ts +5 -0
- package/dist/print_utils.d.ts +13 -0
- package/dist/print_utils.js +8 -1
- package/dist/syntax/alias.d.ts +3 -0
- package/dist/syntax/alter_table.d.ts +3 -0
- package/dist/syntax/analyze.d.ts +3 -0
- package/dist/syntax/base.d.ts +3 -0
- package/dist/syntax/bigquery.d.ts +3 -0
- package/dist/syntax/bigquery.js +31 -1
- package/dist/syntax/constraint.d.ts +3 -0
- package/dist/syntax/create_table.d.ts +3 -0
- package/dist/syntax/data_type.d.ts +3 -0
- package/dist/syntax/dcl.d.ts +3 -0
- package/dist/syntax/dcl.js +20 -0
- package/dist/syntax/delete.d.ts +3 -0
- package/dist/syntax/drop_table.d.ts +3 -0
- package/dist/syntax/explain.d.ts +3 -0
- package/dist/syntax/expr.d.ts +3 -0
- package/dist/syntax/expr.js +16 -2
- package/dist/syntax/frame.d.ts +3 -0
- package/dist/syntax/function.d.ts +3 -0
- package/dist/syntax/index.d.ts +3 -0
- package/dist/syntax/insert.d.ts +3 -0
- package/dist/syntax/merge.d.ts +3 -0
- package/dist/syntax/prepared_statements.d.ts +3 -0
- package/dist/syntax/prepared_statements.js +25 -0
- package/dist/syntax/proc_clause.d.ts +3 -0
- package/dist/syntax/procedural_language.d.ts +3 -0
- package/dist/syntax/procedural_language.js +108 -1
- package/dist/syntax/procedure.d.ts +3 -0
- package/dist/syntax/program.d.ts +3 -0
- package/dist/syntax/program.js +10 -4
- package/dist/syntax/schema.d.ts +3 -0
- package/dist/syntax/select.d.ts +3 -0
- package/dist/syntax/sqlite.d.ts +3 -0
- package/dist/syntax/transaction.d.ts +3 -0
- package/dist/syntax/transformMap.d.ts +3 -0
- package/dist/syntax/transformMap.js +3 -1
- package/dist/syntax/trigger.d.ts +3 -0
- package/dist/syntax/truncate.d.ts +3 -0
- package/dist/syntax/update.d.ts +3 -0
- package/dist/syntax/view.d.ts +3 -0
- package/dist/transform/addFinalSemicolon.d.ts +2 -0
- package/dist/transform/aliasAs.d.ts +2 -0
- package/dist/transform/comments.d.ts +10 -0
- package/dist/transform/stripTrailingCommas.d.ts +2 -0
- package/dist/transform/transformCst.d.ts +2 -0
- package/dist/utils.d.ts +9 -0
- package/dist/visitAllNodes.d.ts +2 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -103,7 +103,10 @@ There are also some SQL-specific options:
|
|
|
103
103
|
Currently this plugin supports two SQL dialects:
|
|
104
104
|
|
|
105
105
|
- **SQLite** - full support.
|
|
106
|
-
- **BigQuery** -
|
|
106
|
+
- **BigQuery** - full support.
|
|
107
|
+
|
|
108
|
+
The specifics of the [SQL formatting style][STYLE_GUIDE] are still very much subject to change.
|
|
109
|
+
Though the general principles should be mostly in place by now.
|
|
107
110
|
|
|
108
111
|
[prettier]: https://prettier.io/
|
|
109
112
|
[printWidth]: https://prettier.io/docs/en/options.html#print-width
|
|
@@ -112,4 +115,3 @@ Currently this plugin supports two SQL dialects:
|
|
|
112
115
|
[sql-parser-cst]: https://github.com/nene/sql-parser-cst
|
|
113
116
|
[wadler-prettier]: http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
|
|
114
117
|
[STYLE_GUIDE]: ./STYLE_GUIDE.md
|
|
115
|
-
[#2]: https://github.com/nene/prettier-plugin-sql-cst/issues/2
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node } from "sql-parser-cst";
|
|
2
|
+
import { AstPath, Doc } from "prettier";
|
|
3
|
+
import { PrintFn } from "./PrintFn";
|
|
4
|
+
import { AllPrettierOptions } from "./options";
|
|
5
|
+
export type NodeByType<TType, TNode> = Extract<TNode, {
|
|
6
|
+
type: TType;
|
|
7
|
+
}>;
|
|
8
|
+
export type ToDocFn<TNode> = (print: PrintFn<TNode>, node: TNode, path: AstPath<TNode>, options: AllPrettierOptions<TNode>) => Doc;
|
|
9
|
+
export type CstToDocMap<TNode extends Node> = {
|
|
10
|
+
[TType in TNode["type"]]: ToDocFn<NodeByType<TType, TNode>>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AstPath, Doc } from "prettier";
|
|
2
|
+
import { Node } from "sql-parser-cst";
|
|
3
|
+
export type OldPrintFn = (path: AstPath<Node> | string) => Doc;
|
|
4
|
+
export type PrintFn<T, K = PrintableKey<T>> = {
|
|
5
|
+
(path: AstPath<Node>): Doc;
|
|
6
|
+
(path: K extends keyof T ? (T[K] extends any[] ? K : never) : never): Doc[];
|
|
7
|
+
(path: K): Doc;
|
|
8
|
+
(path: K[]): Doc[];
|
|
9
|
+
spaced(path: K): Doc[];
|
|
10
|
+
spaced(path: K[]): Doc[];
|
|
11
|
+
};
|
|
12
|
+
export type PrintableKey<T> = Exclude<keyof T, ReservedKey>;
|
|
13
|
+
type ReservedKey = "type" | "range" | "leading" | "trailing";
|
|
14
|
+
export {};
|
package/dist/embed.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Node } from "sql-parser-cst";
|
|
2
|
+
import { Parser, Printer, SupportLanguage } from "prettier";
|
|
3
|
+
export { options } from "./options";
|
|
4
|
+
export declare const languages: SupportLanguage[];
|
|
5
|
+
export declare const parsers: Record<string, Parser<Node>>;
|
|
6
|
+
export declare const printers: Record<string, Printer>;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.printers = exports.parsers = exports.languages = exports.options = void 0;
|
|
4
4
|
var sql_parser_cst_1 = require("sql-parser-cst");
|
|
5
5
|
var printSql_1 = require("./printSql");
|
|
6
|
+
var printComment_1 = require("./printComment");
|
|
6
7
|
var embed_1 = require("./embed");
|
|
7
8
|
var utils_1 = require("./utils");
|
|
8
9
|
var transformCst_1 = require("./transform/transformCst");
|
|
@@ -42,9 +43,7 @@ exports.printers = {
|
|
|
42
43
|
"sql-cst": {
|
|
43
44
|
print: printSql_1.printSql,
|
|
44
45
|
embed: embed_1.embed,
|
|
45
|
-
printComment:
|
|
46
|
-
return path.getValue().text;
|
|
47
|
-
},
|
|
46
|
+
printComment: printComment_1.printComment,
|
|
48
47
|
canAttachComment: utils_1.isNode,
|
|
49
48
|
isBlockComment: function (node) { return node.type === "block_comment"; },
|
|
50
49
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Node } from "sql-parser-cst";
|
|
2
|
+
export declare const isProgram: (node: any) => node is import("sql-parser-cst").Program;
|
|
3
|
+
export declare const isValuesClause: (node: any) => node is import("sql-parser-cst").ValuesClause;
|
|
4
|
+
export declare const isFuncCall: (node: any) => node is import("sql-parser-cst").FuncCall;
|
|
5
|
+
export declare const isFuncArgs: (node: any) => node is import("sql-parser-cst").FuncArgs;
|
|
6
|
+
export declare const isCreateTableStmt: (node: any) => node is import("sql-parser-cst").CreateTableStmt;
|
|
7
|
+
export declare const isKeyword: (node: any) => node is import("sql-parser-cst").Keyword<string>;
|
|
8
|
+
export declare const isEmpty: (node: any) => node is import("sql-parser-cst").Empty;
|
|
9
|
+
export declare const isJsonLiteral: (node: any) => node is import("sql-parser-cst").JsonLiteral;
|
|
10
|
+
export declare const isStringLiteral: (node: any) => node is import("sql-parser-cst").StringLiteral;
|
|
11
|
+
export declare const isArraySubscript: (node: any) => node is import("sql-parser-cst").ArraySubscript;
|
|
12
|
+
export declare const isAsClause: (node: any) => node is import("sql-parser-cst").AsClause<Node>;
|
|
13
|
+
export declare const isParenExpr: (node: any) => node is import("sql-parser-cst").ParenExpr<Node>;
|
|
14
|
+
export declare const isListExpr: (node: any) => node is import("sql-parser-cst").ListExpr<Node>;
|
|
15
|
+
export declare const isCreateFunctionStmt: (node: any) => node is import("sql-parser-cst").CreateFunctionStmt;
|
|
16
|
+
export declare const isLanguageClause: (node: any) => node is import("sql-parser-cst").LanguageClause;
|
package/dist/node_utils.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLanguageClause = exports.isCreateFunctionStmt = exports.isListExpr = exports.isParenExpr = exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncArgs = exports.isFuncCall = exports.isValuesClause = void 0;
|
|
3
|
+
exports.isLanguageClause = exports.isCreateFunctionStmt = exports.isListExpr = exports.isParenExpr = exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = 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) {
|
|
7
7
|
return (0, utils_1.isObject)(node) && node.type === type;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
+
exports.isProgram = is("program");
|
|
10
11
|
exports.isValuesClause = is("values_clause");
|
|
11
12
|
exports.isFuncCall = is("func_call");
|
|
12
13
|
exports.isFuncArgs = is("func_args");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParserOptions, SupportOptions } from "prettier";
|
|
2
|
+
import { Node, ParserOptions as CstParserOptions } from "sql-parser-cst";
|
|
3
|
+
export interface SqlPluginOptions {
|
|
4
|
+
sqlKeywordCase: "preserve" | "upper" | "lower";
|
|
5
|
+
sqlParamTypes: NonNullable<CstParserOptions["paramTypes"]>;
|
|
6
|
+
}
|
|
7
|
+
export type AllPrettierOptions<T = Node> = ParserOptions<T> & SqlPluginOptions;
|
|
8
|
+
export declare const options: SupportOptions;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printComment = void 0;
|
|
4
|
+
var printComment = function (path) {
|
|
5
|
+
var node = path.getValue();
|
|
6
|
+
if (node.type === "line_comment") {
|
|
7
|
+
if (/^--[^ \t]/.test(node.text)) {
|
|
8
|
+
return node.text.replace(/^--/, "-- ");
|
|
9
|
+
}
|
|
10
|
+
if (/^#[^ \t!]/.test(node.text)) {
|
|
11
|
+
return node.text.replace(/^#/, "# ");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return node.text;
|
|
15
|
+
};
|
|
16
|
+
exports.printComment = printComment;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Node } from "sql-parser-cst";
|
|
2
|
+
import { AstPath, Doc } from "prettier";
|
|
3
|
+
import { OldPrintFn } from "./PrintFn";
|
|
4
|
+
import { AllPrettierOptions } from "./options";
|
|
5
|
+
export declare function printSql(path: AstPath<Node>, options: AllPrettierOptions, oldPrint: OldPrintFn): Doc;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Doc, doc } from "prettier";
|
|
2
|
+
import { Node } from "sql-parser-cst";
|
|
3
|
+
export declare const line: doc.builders.Line, hardline: doc.builders.Concat, softline: doc.builders.Softline, indent: typeof doc.builders.indent, group: typeof doc.builders.group, lineSuffix: typeof doc.builders.lineSuffix, ifBreak: typeof doc.builders.ifBreak, breakParent: doc.builders.BreakParent;
|
|
4
|
+
export declare const stripTrailingHardline: typeof doc.utils.stripTrailingHardline;
|
|
5
|
+
/** Improved join() that also accepts a non-array docs parameter */
|
|
6
|
+
export declare const join: (sep: Doc, docs: Doc) => Doc;
|
|
7
|
+
/** True when the Node contains a newline in original source code */
|
|
8
|
+
export declare const containsNewline: (node: Node, opts: {
|
|
9
|
+
originalText: string;
|
|
10
|
+
}) => boolean;
|
|
11
|
+
export declare const hasEmptyLineBetweenNodes: (node1: Node, node2: Node, opts: {
|
|
12
|
+
originalText: string;
|
|
13
|
+
}) => boolean;
|
package/dist/print_utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.containsNewline = exports.join = exports.stripTrailingHardline = exports.breakParent = exports.ifBreak = exports.lineSuffix = exports.group = exports.indent = exports.softline = exports.hardline = exports.line = void 0;
|
|
4
|
+
exports.hasEmptyLineBetweenNodes = exports.containsNewline = exports.join = exports.stripTrailingHardline = exports.breakParent = exports.ifBreak = exports.lineSuffix = exports.group = exports.indent = exports.softline = exports.hardline = exports.line = void 0;
|
|
5
5
|
var prettier_1 = require("prettier");
|
|
6
6
|
var utils_1 = require("./utils");
|
|
7
7
|
exports.line = (_a = prettier_1.doc.builders, _a.line), exports.hardline = _a.hardline, exports.softline = _a.softline, exports.indent = _a.indent, exports.group = _a.group, exports.lineSuffix = _a.lineSuffix, exports.ifBreak = _a.ifBreak, exports.breakParent = _a.breakParent;
|
|
@@ -20,3 +20,10 @@ var containsNewline = function (node, opts) {
|
|
|
20
20
|
return prettier_1.util.hasNewlineInRange(opts.originalText, node.range[0], node.range[1]);
|
|
21
21
|
};
|
|
22
22
|
exports.containsNewline = containsNewline;
|
|
23
|
+
var hasEmptyLineBetweenNodes = function (node1, node2, opts) {
|
|
24
|
+
if (!node1.range || !node2.range) {
|
|
25
|
+
throw new Error("emptyLineBetweenNodes() expects Nodes with range info");
|
|
26
|
+
}
|
|
27
|
+
return /\n[ \t]*\r?\n/.test(opts.originalText.slice(node1.range[1], node2.range[0]));
|
|
28
|
+
};
|
|
29
|
+
exports.hasEmptyLineBetweenNodes = hasEmptyLineBetweenNodes;
|
package/dist/syntax/bigquery.js
CHANGED
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.bigqueryMap = void 0;
|
|
13
13
|
var print_utils_1 = require("../print_utils");
|
|
14
14
|
exports.bigqueryMap = {
|
|
15
|
-
bigquery_options: function (print) { return print(["optionsKw", "options"]); },
|
|
15
|
+
bigquery_options: function (print) { return print.spaced(["optionsKw", "options"]); },
|
|
16
16
|
bigquery_option_default_collate: function (print) {
|
|
17
17
|
return print.spaced(["defaultCollateKw", "collation"]);
|
|
18
18
|
},
|
|
@@ -91,4 +91,34 @@ exports.bigqueryMap = {
|
|
|
91
91
|
print("actions"),
|
|
92
92
|
]);
|
|
93
93
|
},
|
|
94
|
+
alter_capacity_stmt: function (print) {
|
|
95
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
96
|
+
print.spaced(["alterCapacityKw", "name"]),
|
|
97
|
+
print("actions"),
|
|
98
|
+
]);
|
|
99
|
+
},
|
|
100
|
+
alter_reservation_stmt: function (print) {
|
|
101
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
102
|
+
print.spaced(["alterReservationKw", "name"]),
|
|
103
|
+
print("actions"),
|
|
104
|
+
]);
|
|
105
|
+
},
|
|
106
|
+
// ASSERT
|
|
107
|
+
assert_stmt: function (print) { return print.spaced(["assertKw", "expr", "as"]); },
|
|
108
|
+
// EXPORT
|
|
109
|
+
export_data_stmt: function (print) {
|
|
110
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([
|
|
111
|
+
print.spaced("exportDataKw")
|
|
112
|
+
], print.spaced(["withConnection"]), true), [
|
|
113
|
+
print.spaced("options"),
|
|
114
|
+
print.spaced("as"),
|
|
115
|
+
], false));
|
|
116
|
+
},
|
|
117
|
+
// LOAD
|
|
118
|
+
load_data_stmt: function (print) {
|
|
119
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
120
|
+
print.spaced(["loadDataKw", "intoKw", "table", "columns"])
|
|
121
|
+
], print("clauses"), true));
|
|
122
|
+
},
|
|
123
|
+
from_files_options: function (print) { return print.spaced(["fromFilesKw", "options"]); },
|
|
94
124
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dclMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.dclMap = {
|
|
6
|
+
grant_stmt: function (print) {
|
|
7
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
8
|
+
(0, print_utils_1.group)([print("grantKw"), (0, print_utils_1.indent)([print_utils_1.line, print("roles")])]),
|
|
9
|
+
(0, print_utils_1.group)(print.spaced(["onKw", "resourceType", "resourceName"])),
|
|
10
|
+
(0, print_utils_1.group)([print("toKw"), (0, print_utils_1.indent)([print_utils_1.line, print("users")])]),
|
|
11
|
+
]);
|
|
12
|
+
},
|
|
13
|
+
revoke_stmt: function (print) {
|
|
14
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
15
|
+
(0, print_utils_1.group)([print("revokeKw"), (0, print_utils_1.indent)([print_utils_1.line, print("roles")])]),
|
|
16
|
+
(0, print_utils_1.group)(print.spaced(["onKw", "resourceType", "resourceName"])),
|
|
17
|
+
(0, print_utils_1.group)([print("fromKw"), (0, print_utils_1.indent)([print_utils_1.line, print("users")])]),
|
|
18
|
+
]);
|
|
19
|
+
},
|
|
20
|
+
};
|
package/dist/syntax/expr.js
CHANGED
|
@@ -65,10 +65,24 @@ exports.exprMap = {
|
|
|
65
65
|
print_utils_1.hardline,
|
|
66
66
|
print("endKw"),
|
|
67
67
|
]; },
|
|
68
|
-
case_when: function (print) {
|
|
68
|
+
case_when: function (print, node) {
|
|
69
|
+
if ((0, node_utils_1.isProgram)(node.result)) {
|
|
70
|
+
return [
|
|
71
|
+
print.spaced(["whenKw", "condition", "thenKw"]),
|
|
72
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("result"))]),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
69
75
|
return print.spaced(["whenKw", "condition", "thenKw", "result"]);
|
|
70
76
|
},
|
|
71
|
-
case_else: function (print
|
|
77
|
+
case_else: function (print, node) {
|
|
78
|
+
if ((0, node_utils_1.isProgram)(node.result)) {
|
|
79
|
+
return [
|
|
80
|
+
print("elseKw"),
|
|
81
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("result"))]),
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
return print.spaced(["elseKw", "result"]);
|
|
85
|
+
},
|
|
72
86
|
member_expr: function (print, node) {
|
|
73
87
|
return (0, node_utils_1.isArraySubscript)(node.property)
|
|
74
88
|
? print(["object", "property"])
|
|
@@ -0,0 +1,25 @@
|
|
|
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.preparedStatementsMap = void 0;
|
|
13
|
+
var print_utils_1 = require("../print_utils");
|
|
14
|
+
exports.preparedStatementsMap = {
|
|
15
|
+
execute_stmt: function (print) {
|
|
16
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
17
|
+
(0, print_utils_1.group)([
|
|
18
|
+
print.spaced(["executeKw", "immediateKw"]),
|
|
19
|
+
(0, print_utils_1.indent)([print_utils_1.line, print("expr")]),
|
|
20
|
+
])
|
|
21
|
+
], print(["into", "using"]).map(function (clause) { return (0, print_utils_1.group)(clause); }), true));
|
|
22
|
+
},
|
|
23
|
+
execute_into_clause: function (print) { return print.spaced(["intoKw", "variables"]); },
|
|
24
|
+
execute_using_clause: function (print) { return print.spaced(["usingKw", "values"]); },
|
|
25
|
+
};
|
|
@@ -1,12 +1,119 @@
|
|
|
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.proceduralLanguageMap = void 0;
|
|
4
13
|
var print_utils_1 = require("../print_utils");
|
|
5
14
|
exports.proceduralLanguageMap = {
|
|
6
|
-
|
|
15
|
+
// BEGIN .. END
|
|
16
|
+
block_stmt: function (print, node) { return [
|
|
7
17
|
print("beginKw"),
|
|
8
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")] : [],
|
|
9
20
|
print_utils_1.hardline,
|
|
10
21
|
print("endKw"),
|
|
11
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
|
+
]; },
|
|
27
|
+
error_category: function (print) { return print("errorKw"); },
|
|
28
|
+
// DECLARE
|
|
29
|
+
declare_stmt: function (print) {
|
|
30
|
+
return (0, print_utils_1.join)(" ", __spreadArray([
|
|
31
|
+
print("declareKw"),
|
|
32
|
+
(0, print_utils_1.group)(print("names"))
|
|
33
|
+
], print.spaced(["dataType", "default"]), true));
|
|
34
|
+
},
|
|
35
|
+
declare_default: function (print) { return print.spaced(["defaultKw", "expr"]); },
|
|
36
|
+
// SET
|
|
37
|
+
set_stmt: function (print) { return print.spaced(["setKw", "assignments"]); },
|
|
38
|
+
// IF
|
|
39
|
+
if_stmt: function (print) {
|
|
40
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([], print("clauses"), true), [print.spaced("endIfKw")], false));
|
|
41
|
+
},
|
|
42
|
+
if_clause: function (print) { return [
|
|
43
|
+
(0, print_utils_1.group)([
|
|
44
|
+
print("ifKw"),
|
|
45
|
+
(0, print_utils_1.indent)([print_utils_1.line, print("condition")]),
|
|
46
|
+
print_utils_1.line,
|
|
47
|
+
print("thenKw"),
|
|
48
|
+
]),
|
|
49
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("consequent"))]),
|
|
50
|
+
]; },
|
|
51
|
+
elseif_clause: function (print) { return [
|
|
52
|
+
(0, print_utils_1.group)([
|
|
53
|
+
print("elseifKw"),
|
|
54
|
+
(0, print_utils_1.indent)([print_utils_1.line, print("condition")]),
|
|
55
|
+
print_utils_1.line,
|
|
56
|
+
print("thenKw"),
|
|
57
|
+
]),
|
|
58
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("consequent"))]),
|
|
59
|
+
]; },
|
|
60
|
+
else_clause: function (print) { return [
|
|
61
|
+
print("elseKw"),
|
|
62
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("consequent"))]),
|
|
63
|
+
]; },
|
|
64
|
+
// 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
|
+
]; },
|
|
71
|
+
// 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
|
+
// 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
|
+
]; },
|
|
85
|
+
// 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
|
+
]; },
|
|
92
|
+
// 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
|
+
]; },
|
|
99
|
+
// 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
|
+
]; },
|
|
108
|
+
// CALL
|
|
109
|
+
call_stmt: function (print) { return print.spaced(["callKw", "func"]); },
|
|
110
|
+
// RETURN
|
|
111
|
+
return_stmt: function (print) { return print("returnKw"); },
|
|
112
|
+
// RAISE
|
|
113
|
+
raise_stmt: function (print) { return print.spaced(["raiseKw", "message"]); },
|
|
114
|
+
raise_message: function (print) { return [
|
|
115
|
+
print.spaced("usingMessageKw"),
|
|
116
|
+
" = ",
|
|
117
|
+
print("string"),
|
|
118
|
+
]; },
|
|
12
119
|
};
|
package/dist/syntax/program.js
CHANGED
|
@@ -3,19 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.programMap = void 0;
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
5
|
exports.programMap = {
|
|
6
|
-
program: function (print, node) {
|
|
6
|
+
program: function (print, node, path, options) {
|
|
7
7
|
return print("statements").map(function (doc, i) {
|
|
8
|
-
return printStatement(doc, i, node.statements);
|
|
8
|
+
return printStatement(doc, i, node.statements, options);
|
|
9
9
|
});
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
|
-
var printStatement = function (doc, i, statements) {
|
|
12
|
+
var printStatement = function (doc, i, statements, options) {
|
|
13
|
+
var prevNode = statements[i - 1];
|
|
13
14
|
var node = statements[i];
|
|
14
15
|
if (i === 0) {
|
|
15
16
|
return doc;
|
|
16
17
|
}
|
|
17
18
|
else if (node.type !== "empty") {
|
|
18
|
-
|
|
19
|
+
if ((0, print_utils_1.hasEmptyLineBetweenNodes)(prevNode, node, options)) {
|
|
20
|
+
return [";", print_utils_1.hardline, print_utils_1.hardline, doc];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return [";", print_utils_1.hardline, doc];
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
else {
|
|
21
27
|
return [";", print_utils_1.hardline, doc];
|
|
@@ -20,6 +20,7 @@ var bigquery_1 = require("./bigquery");
|
|
|
20
20
|
var constraint_1 = require("./constraint");
|
|
21
21
|
var create_table_1 = require("./create_table");
|
|
22
22
|
var data_type_1 = require("./data_type");
|
|
23
|
+
var dcl_1 = require("./dcl");
|
|
23
24
|
var delete_1 = require("./delete");
|
|
24
25
|
var drop_table_1 = require("./drop_table");
|
|
25
26
|
var explain_1 = require("./explain");
|
|
@@ -29,6 +30,7 @@ var function_1 = require("./function");
|
|
|
29
30
|
var index_1 = require("./index");
|
|
30
31
|
var insert_1 = require("./insert");
|
|
31
32
|
var merge_1 = require("./merge");
|
|
33
|
+
var prepared_statements_1 = require("./prepared_statements");
|
|
32
34
|
var procedural_language_1 = require("./procedural_language");
|
|
33
35
|
var procedure_1 = require("./procedure");
|
|
34
36
|
var proc_clause_1 = require("./proc_clause");
|
|
@@ -41,4 +43,4 @@ var trigger_1 = require("./trigger");
|
|
|
41
43
|
var truncate_1 = require("./truncate");
|
|
42
44
|
var update_1 = require("./update");
|
|
43
45
|
var view_1 = require("./view");
|
|
44
|
-
exports.transformMap = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), bigquery_1.bigqueryMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), delete_1.deleteMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), function_1.functionMap), index_1.indexMap), insert_1.insertMap), merge_1.mergeMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), schema_1.schemaMap), select_1.selectMap), sqlite_1.sqliteMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
|
|
46
|
+
exports.transformMap = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), bigquery_1.bigqueryMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), dcl_1.dclMap), delete_1.deleteMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), function_1.functionMap), index_1.indexMap), insert_1.insertMap), merge_1.mergeMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), schema_1.schemaMap), select_1.selectMap), sqlite_1.sqliteMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Program, Whitespace } from "sql-parser-cst";
|
|
2
|
+
/**
|
|
3
|
+
* Gathers comments from .leading and .trailing fields of all nodes
|
|
4
|
+
* into a single .comments field in root Program node.
|
|
5
|
+
*
|
|
6
|
+
* Deletes the .leading and .trailing fields of all nodes.
|
|
7
|
+
*/
|
|
8
|
+
export declare const moveCommentsToRoot: (cst: Program) => Program & {
|
|
9
|
+
comments: Whitespace[];
|
|
10
|
+
};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Node } from "sql-parser-cst";
|
|
2
|
+
export declare const isDefined: <T>(value: T | undefined) => value is T;
|
|
3
|
+
export declare const isString: (value: any) => value is string;
|
|
4
|
+
export declare const isObject: (x: any) => x is Record<string, any>;
|
|
5
|
+
export declare const isArray: (x: any) => x is any[];
|
|
6
|
+
export declare const isEmptyArray: (x: any) => x is [];
|
|
7
|
+
export declare const isNode: (value: any) => value is Node;
|
|
8
|
+
export declare const arrayWrap: <T>(x: T | T[]) => T[];
|
|
9
|
+
export declare const last: <T>(arr: T[]) => T;
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Prettier plugin for SQL",
|
|
5
5
|
"author": "Rene Saarsoo <nene@triin.net>",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "https://github.com/nene/prettier-plugin-sql-cst"
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
],
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"prettier": "^2.8.2",
|
|
32
|
-
"sql-parser-cst": "^0.14.
|
|
33
|
+
"sql-parser-cst": "^0.14.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/jest": "^29.2.5",
|