prettier-plugin-sql-cst 0.12.2 → 0.12.3
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/dist/print_utils.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
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
|
var _a;
|
|
3
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
13
|
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;
|
|
@@ -21,9 +30,39 @@ var containsNewline = function (node, opts) {
|
|
|
21
30
|
};
|
|
22
31
|
exports.containsNewline = containsNewline;
|
|
23
32
|
var hasEmptyLineBetweenNodes = function (node1, node2, opts) {
|
|
33
|
+
var _a, _b;
|
|
24
34
|
if (!node1.range || !node2.range) {
|
|
25
35
|
throw new Error("emptyLineBetweenNodes() expects Nodes with range info");
|
|
26
36
|
}
|
|
27
|
-
|
|
37
|
+
var start = node1.range[1];
|
|
38
|
+
var end = node2.range[0];
|
|
39
|
+
var indexes = emptyLineIndexes(opts.originalText.slice(start, end)).map(function (i) { return start + i; });
|
|
40
|
+
// when no empty lines between nodes, we can return early
|
|
41
|
+
if (indexes.length === 0) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// otherwise we need to check whether the empty line happens to be
|
|
45
|
+
// inside a comment or between comments
|
|
46
|
+
var comments = __spreadArray(__spreadArray([], ((_a = node1.trailing) !== null && _a !== void 0 ? _a : []), true), ((_b = node2.leading) !== null && _b !== void 0 ? _b : []), true);
|
|
47
|
+
return (indexes.filter(function (index) { return !isIndexInsideOrBetweenComments(index, comments); })
|
|
48
|
+
.length > 0);
|
|
28
49
|
};
|
|
29
50
|
exports.hasEmptyLineBetweenNodes = hasEmptyLineBetweenNodes;
|
|
51
|
+
function emptyLineIndexes(text) {
|
|
52
|
+
var indexes = [];
|
|
53
|
+
var re = /\n[ \t]*\r?\n/g;
|
|
54
|
+
var match;
|
|
55
|
+
while ((match = re.exec(text))) {
|
|
56
|
+
indexes.push(match.index);
|
|
57
|
+
}
|
|
58
|
+
return indexes;
|
|
59
|
+
}
|
|
60
|
+
function isIndexInsideOrBetweenComments(index, comments) {
|
|
61
|
+
if (comments.length === 0) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
// Assume all nodes have range info
|
|
65
|
+
var start = comments[0].range[0];
|
|
66
|
+
var end = comments[comments.length - 1].range[1];
|
|
67
|
+
return start <= index && index <= end;
|
|
68
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.policyMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.policyMap = {
|
|
6
|
+
create_policy_stmt: function (print, node) {
|
|
7
|
+
return (0, print_utils_1.group)([
|
|
8
|
+
print.spaced(["createPolicyKw", "name", "onKw", "table"]),
|
|
9
|
+
node.clauses.length > 0 ? print.dynamicLine() : [],
|
|
10
|
+
(0, print_utils_1.join)(print.dynamicLine(), print("clauses")),
|
|
11
|
+
]);
|
|
12
|
+
},
|
|
13
|
+
policy_permissive_clause: function (print) {
|
|
14
|
+
return (0, print_utils_1.group)(print.spaced(["asKw", "permissiveKw"]));
|
|
15
|
+
},
|
|
16
|
+
policy_restrictive_clause: function (print) {
|
|
17
|
+
return (0, print_utils_1.group)(print.spaced(["asKw", "restrictiveKw"]));
|
|
18
|
+
},
|
|
19
|
+
policy_command_clause: function (print) { return (0, print_utils_1.group)(print.spaced(["forKw", "commandKw"])); },
|
|
20
|
+
policy_roles_clause: function (print) { return (0, print_utils_1.group)(print.spaced(["toKw", "roles"])); },
|
|
21
|
+
policy_using_clause: function (print) { return (0, print_utils_1.group)(print.spaced(["usingKw", "expr"])); },
|
|
22
|
+
policy_check_clause: function (print) {
|
|
23
|
+
return (0, print_utils_1.group)(print.spaced(["withKw", "checkKw", "expr"]));
|
|
24
|
+
},
|
|
25
|
+
alter_policy_stmt: function (print) {
|
|
26
|
+
return (0, print_utils_1.group)([
|
|
27
|
+
print.spaced(["alterPolicyKw", "name", "onKw", "table"]),
|
|
28
|
+
print.dynamicLine(),
|
|
29
|
+
(0, print_utils_1.join)(print.dynamicLine(), print("actions")),
|
|
30
|
+
]);
|
|
31
|
+
},
|
|
32
|
+
drop_policy_stmt: function (print) {
|
|
33
|
+
return (0, print_utils_1.group)(print.spaced([
|
|
34
|
+
"dropPolicyKw",
|
|
35
|
+
"ifExistsKw",
|
|
36
|
+
"name",
|
|
37
|
+
"onKw",
|
|
38
|
+
"table",
|
|
39
|
+
"behaviorKw",
|
|
40
|
+
]));
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -34,6 +34,7 @@ var merge_1 = require("./merge");
|
|
|
34
34
|
var other_clauses_1 = require("./other_clauses");
|
|
35
35
|
var rename_table_1 = require("./rename_table");
|
|
36
36
|
var role_1 = require("./role");
|
|
37
|
+
var policy_1 = require("./policy");
|
|
37
38
|
var prepared_statements_1 = require("./prepared_statements");
|
|
38
39
|
var procedural_language_1 = require("./procedural_language");
|
|
39
40
|
var procedure_1 = require("./procedure");
|
|
@@ -53,4 +54,4 @@ var bigquery_1 = require("./dialects/bigquery");
|
|
|
53
54
|
var mysql_1 = require("./dialects/mysql");
|
|
54
55
|
var sqlite_1 = require("./dialects/sqlite");
|
|
55
56
|
var postgresql_1 = require("./dialects/postgresql");
|
|
56
|
-
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(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_action_1.alterActionMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), dcl_1.dclMap), delete_1.deleteMap), domain_1.domainMap), 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), other_clauses_1.otherClausesMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), rename_table_1.renameTableMap), role_1.roleMap), schema_1.schemaMap), select_1.selectMap), sequence_1.sequenceMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), type_1.typeMap), unsupported_grammar_1.unsupportedGrammarMap), update_1.updateMap), view_1.viewMap), bigquery_1.bigqueryMap), mysql_1.mysqlMap), postgresql_1.postgresqlMap), sqlite_1.sqliteMap);
|
|
57
|
+
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(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_action_1.alterActionMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), dcl_1.dclMap), delete_1.deleteMap), domain_1.domainMap), 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), other_clauses_1.otherClausesMap), policy_1.policyMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), rename_table_1.renameTableMap), role_1.roleMap), schema_1.schemaMap), select_1.selectMap), sequence_1.sequenceMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), type_1.typeMap), unsupported_grammar_1.unsupportedGrammarMap), update_1.updateMap), view_1.viewMap), bigquery_1.bigqueryMap), mysql_1.mysqlMap), postgresql_1.postgresqlMap), sqlite_1.sqliteMap);
|
|
@@ -3,7 +3,9 @@ import { Program, Whitespace } from "sql-parser-cst";
|
|
|
3
3
|
* Gathers comments from .leading and .trailing fields of all nodes
|
|
4
4
|
* into a single .comments field in root Program node.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Previously this also deleted all .leading and .trailing fields,
|
|
7
|
+
* but we need this info to check whether the empty lines between nodes
|
|
8
|
+
* are perhaps inside comments (see hasEmptyLineBetweenNodes()).
|
|
7
9
|
*/
|
|
8
10
|
export declare const moveCommentsToRoot: (cst: Program) => Program & {
|
|
9
11
|
comments: Whitespace[];
|
|
@@ -26,7 +26,9 @@ var visitAllNodes_1 = require("../visitAllNodes");
|
|
|
26
26
|
* Gathers comments from .leading and .trailing fields of all nodes
|
|
27
27
|
* into a single .comments field in root Program node.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
29
|
+
* Previously this also deleted all .leading and .trailing fields,
|
|
30
|
+
* but we need this info to check whether the empty lines between nodes
|
|
31
|
+
* are perhaps inside comments (see hasEmptyLineBetweenNodes()).
|
|
30
32
|
*/
|
|
31
33
|
var moveCommentsToRoot = function (cst) {
|
|
32
34
|
return __assign(__assign({}, cst), { comments: extractComments(cst) });
|
|
@@ -36,8 +38,6 @@ var extractComments = function (cst) {
|
|
|
36
38
|
var comments = [];
|
|
37
39
|
(0, visitAllNodes_1.visitAllNodes)(cst, function (node) {
|
|
38
40
|
comments.push.apply(comments, __spreadArray(__spreadArray([], (node.leading || []), false), (node.trailing || []), false));
|
|
39
|
-
delete node.leading;
|
|
40
|
-
delete node.trailing;
|
|
41
41
|
});
|
|
42
42
|
return comments;
|
|
43
43
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
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.
|
|
40
|
+
"sql-parser-cst": "^0.33.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/jest": "^29.2.5",
|