prettier-plugin-sql-cst 0.8.3 → 0.9.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 CHANGED
@@ -3,8 +3,6 @@
3
3
  A [Prettier][] plugin for SQL that uses [sql-parser-cst][] and the
4
4
  actual [Prettier formatting algorithm][wadler-prettier].
5
5
 
6
- **Note:** This plugin only works with Prettier 2.x. It doesn't yet support the latest Prettier 3.x.
7
-
8
6
  **[Try it live!][live]**
9
7
 
10
8
  Like Prettier for JavaScript,
package/dist/embedJs.js CHANGED
@@ -10,31 +10,77 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  Object.defineProperty(exports, "__esModule", { value: true });
14
50
  exports.embedJs = void 0;
15
51
  var node_utils_1 = require("./node_utils");
16
52
  var print_utils_1 = require("./print_utils");
17
- var embedJs = function (path, print, textToDoc, options) {
18
- var node = path.getValue();
53
+ var embedJs = function (path, options) {
54
+ var node = path.getValue(); // TODO: Don't use deprecated method
19
55
  var parent = path.getParentNode(0);
20
56
  var grandParent = path.getParentNode(1);
21
57
  if ((0, node_utils_1.isStringLiteral)(node) &&
22
58
  (0, node_utils_1.isAsClause)(parent) &&
23
59
  (0, node_utils_1.isCreateFunctionStmt)(grandParent) &&
24
60
  grandParent.clauses.some(isJavaScriptLanguageClause)) {
25
- var quotes = detectQuotes(node.value);
26
- if (!quotes) {
27
- // Give up for now. Don't format JavaScript inside the string.
28
- // Perhaps tackle this corner-case in the future.
29
- return null;
30
- }
31
- var js = textToDoc(node.value, __assign(__assign({}, options), { parser: "babel" }));
32
- return [
33
- quotes[0],
34
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(js)]),
35
- print_utils_1.hardline,
36
- quotes[1],
37
- ];
61
+ return function (textToDoc) { return __awaiter(void 0, void 0, void 0, function () {
62
+ var quotes, js;
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0:
66
+ quotes = detectQuotes(node.value);
67
+ if (!quotes) {
68
+ // Give up for now. Don't format JavaScript inside the string.
69
+ // Perhaps tackle this corner-case in the future.
70
+ return [2 /*return*/, undefined];
71
+ }
72
+ return [4 /*yield*/, textToDoc(node.value, __assign(__assign({}, options), { parser: "babel" }))];
73
+ case 1:
74
+ js = _a.sent();
75
+ return [2 /*return*/, [
76
+ quotes[0],
77
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(js)]),
78
+ print_utils_1.hardline,
79
+ quotes[1],
80
+ ]];
81
+ }
82
+ });
83
+ }); };
38
84
  }
39
85
  return null;
40
86
  };
package/dist/embedJson.js CHANGED
@@ -10,29 +10,75 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  Object.defineProperty(exports, "__esModule", { value: true });
14
50
  exports.embedJson = void 0;
15
51
  var node_utils_1 = require("./node_utils");
16
52
  var print_utils_1 = require("./print_utils");
17
- var embedJson = function (path, print, textToDoc, options) {
18
- var node = path.getValue();
53
+ var embedJson = function (path, options) {
54
+ var node = path.getValue(); // TODO: Don't use deprecated method
19
55
  var parent = path.getParentNode();
20
56
  if ((0, node_utils_1.isStringLiteral)(node) && (0, node_utils_1.isJsonLiteral)(parent)) {
21
- if (containsTripleQuote(node.value) ||
22
- containsBackslash(node.value) ||
23
- isRawString(node)) {
24
- // Give up for now. Don't format JSON inside the string.
25
- // Tackle these corner-case in the future.
26
- return null;
27
- }
28
- var json = textToDoc(node.value, __assign(__assign({}, options), { parser: "json" }));
29
- var inlineQuote = containsSingleQuote(node.value) ? "'''" : "'";
30
- return [
31
- (0, print_utils_1.ifBreak)("'''", inlineQuote),
32
- (0, print_utils_1.indent)([print_utils_1.softline, (0, print_utils_1.stripTrailingHardline)(json)]),
33
- print_utils_1.softline,
34
- (0, print_utils_1.ifBreak)("'''", inlineQuote),
35
- ];
57
+ return function (textToDoc) { return __awaiter(void 0, void 0, void 0, function () {
58
+ var json, inlineQuote;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ if (containsTripleQuote(node.value) ||
63
+ containsBackslash(node.value) ||
64
+ isRawString(node)) {
65
+ // Give up for now. Don't format JSON inside the string.
66
+ // Tackle these corner-case in the future.
67
+ return [2 /*return*/, undefined];
68
+ }
69
+ return [4 /*yield*/, textToDoc(node.value, __assign(__assign({}, options), { parser: "json" }))];
70
+ case 1:
71
+ json = _a.sent();
72
+ inlineQuote = containsSingleQuote(node.value) ? "'''" : "'";
73
+ return [2 /*return*/, [
74
+ (0, print_utils_1.ifBreak)("'''", inlineQuote),
75
+ (0, print_utils_1.indent)([print_utils_1.softline, (0, print_utils_1.stripTrailingHardline)(json)]),
76
+ print_utils_1.softline,
77
+ (0, print_utils_1.ifBreak)("'''", inlineQuote),
78
+ ]];
79
+ }
80
+ });
81
+ }); };
36
82
  }
37
83
  return null;
38
84
  };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Node } from "sql-parser-cst";
2
2
  import { Parser, Printer, SupportLanguage } from "prettier";
3
3
  export { options } from "./options";
4
+ export type { SqlPluginOptions } from "./options";
4
5
  export declare const languages: SupportLanguage[];
5
6
  export declare const parsers: Record<string, Parser<Node>>;
6
7
  export declare const printers: Record<string, Printer>;
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ exports.languages = [
22
22
  },
23
23
  ];
24
24
  var createParser = function (dialect) { return ({
25
- parse: function (text, parsers, options) {
25
+ parse: function (text, options) {
26
26
  return (0, transformCst_1.transformCst)((0, sql_parser_cst_1.parse)(text, {
27
27
  dialect: dialect,
28
28
  includeRange: true,
package/dist/options.js CHANGED
@@ -5,25 +5,33 @@ exports.options = {
5
5
  sqlKeywordCase: {
6
6
  type: "choice",
7
7
  category: "SQL",
8
- since: "0.1.0",
9
8
  default: "upper",
10
9
  description: "Enforces upper/lower case for SQL keywords",
11
10
  choices: [
12
11
  {
13
12
  value: "preserve",
14
13
  description: "preserves the existing case",
14
+ since: "0.1.0",
15
+ },
16
+ {
17
+ value: "upper",
18
+ description: "forces all keywords to uppercase",
19
+ since: "0.1.0",
20
+ },
21
+ {
22
+ value: "lower",
23
+ description: "forces all keywords to lowercase",
24
+ since: "0.1.0",
15
25
  },
16
- { value: "upper", description: "forces all keywords to uppercase" },
17
- { value: "lower", description: "forces all keywords to lowercase" },
18
26
  ],
19
27
  },
20
28
  sqlParamTypes: {
21
29
  type: "string",
22
30
  array: true,
23
31
  category: "SQL",
24
- since: "0.7.0",
25
32
  default: [{ value: [] }],
26
33
  description: "Syntax for bound parameters",
34
+ // Since 0.7.0
27
35
  // Possible values in array: "?" | "?nr" | ":name" | "$name" | "@name"
28
36
  },
29
37
  };
@@ -1,6 +1,6 @@
1
1
  import { Doc, doc } from "prettier";
2
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;
3
+ export declare const line: doc.builders.Line, hardline: doc.builders.Hardline, 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
4
  export declare const stripTrailingHardline: typeof doc.utils.stripTrailingHardline;
5
5
  /** Improved join() that also accepts a non-array docs parameter */
6
6
  export declare const join: (sep: Doc, docs: Doc) => Doc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-sql-cst",
3
- "version": "0.8.3",
3
+ "version": "0.9.1",
4
4
  "description": "Prettier plugin for SQL",
5
5
  "author": "Rene Saarsoo <nene@triin.net>",
6
6
  "license": "GPL-3.0-or-later",
@@ -21,7 +21,8 @@
21
21
  "prepublishOnly": "yarn test && yarn build",
22
22
  "clean": "rm -rf dist",
23
23
  "build": "yarn clean && tsc",
24
- "test": "jest"
24
+ "test": "yarn node --experimental-vm-modules $(yarn bin jest)",
25
+ "pretty": "prettier -w src/"
25
26
  },
26
27
  "keywords": [
27
28
  "prettier",
@@ -29,14 +30,14 @@
29
30
  "plugin"
30
31
  ],
31
32
  "dependencies": {
32
- "prettier": "^2.8.2",
33
+ "prettier": "^3.0.3",
33
34
  "sql-parser-cst": "^0.17.1"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/jest": "^29.2.5",
37
38
  "dedent-js": "^1.0.1",
38
- "jest": "^29.3.1",
39
- "ts-jest": "^29.0.3",
39
+ "jest": "^29.7.0",
40
+ "ts-jest": "^29.1.1",
40
41
  "typescript": "^4.9.4"
41
42
  }
42
43
  }