prettier-plugin-embed 0.0.4 → 0.0.5
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/embedded/index.d.ts +1 -1
- package/dist/embedded/noop/option.d.ts +2 -6
- package/dist/embedded/php/option.d.ts +8 -8
- package/dist/embedded/register.d.ts +2 -2
- package/dist/embedded/sql/option.d.ts +8 -8
- package/dist/embedded/types.d.ts +11 -3
- package/dist/embedded/utils.d.ts +1 -0
- package/dist/embedded/xml/option.d.ts +8 -8
- package/dist/index.js +185 -191
- package/dist/options.d.ts +7 -2
- package/package.json +1 -5
package/dist/embedded/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./register.js";
|
|
2
|
-
export type { EmbeddedName, EmbeddedParsers, EmbeddedEmbedders, EmbeddedOptions, } from "./types.js";
|
|
2
|
+
export type { EmbeddedName, EmbeddedParsers, EmbeddedEmbedders, EmbeddedOptions, PrettierPluginEmbedOptions, } from "./types.js";
|
|
@@ -5,11 +5,7 @@ declare module "../types.js" {
|
|
|
5
5
|
interface EmbeddedOptions {
|
|
6
6
|
[name]: typeof option;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
[name]?: string[];
|
|
11
|
-
}
|
|
12
|
-
declare module "prettier" {
|
|
13
|
-
interface Options extends PrettierPluginEmbedOptions {
|
|
8
|
+
interface PrettierPluginEmbedOptions {
|
|
9
|
+
[name]?: string[];
|
|
14
10
|
}
|
|
15
11
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { SupportOption } from "prettier";
|
|
2
2
|
import { name } from "./name.js";
|
|
3
3
|
export declare const option: SupportOption;
|
|
4
|
-
declare module "../types.js" {
|
|
5
|
-
interface EmbeddedOptions {
|
|
6
|
-
[name]: typeof option;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
4
|
export interface PrettierPluginDepsOptions {
|
|
10
5
|
phpVersion?: "5.0" | "5.1" | "5.2" | "5.3" | "5.4" | "5.5" | "5.6" | "7.0" | "7.1" | "7.2" | "7.3" | "7.4" | "8.0" | "8.1" | "8.2";
|
|
11
6
|
trailingCommaPHP?: boolean;
|
|
12
7
|
braceStyle?: "psr-2" | "per-cs" | "1tbs";
|
|
13
8
|
}
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
declare module "../types.js" {
|
|
10
|
+
interface EmbeddedOptions {
|
|
11
|
+
[name]: typeof option;
|
|
12
|
+
}
|
|
13
|
+
interface PrettierPluginEmbedOptions {
|
|
14
|
+
[name]?: string[];
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
declare module "prettier" {
|
|
18
|
-
interface Options extends PrettierPluginDepsOptions
|
|
18
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -4,6 +4,6 @@ export declare const embeddedParsers: EmbeddedParsers;
|
|
|
4
4
|
export declare const embeddedEmbedders: EmbeddedEmbedders;
|
|
5
5
|
export declare const embeddedOptions: EmbeddedOptions;
|
|
6
6
|
import * as __glob__0_0 from "./noop/index.js";
|
|
7
|
-
import * as __glob__0_1 from "./
|
|
8
|
-
import * as __glob__0_2 from "./
|
|
7
|
+
import * as __glob__0_1 from "./php/index.js";
|
|
8
|
+
import * as __glob__0_2 from "./sql/index.js";
|
|
9
9
|
import * as __glob__0_3 from "./xml/index.js";
|
|
@@ -2,20 +2,20 @@ import type { SupportOption } from "prettier";
|
|
|
2
2
|
import type { SqlBaseOptions as PrettierPluginDepsOptions } from "prettier-plugin-sql";
|
|
3
3
|
import { name } from "./name.js";
|
|
4
4
|
export declare const option: SupportOption;
|
|
5
|
-
declare module "../types.js" {
|
|
6
|
-
interface EmbeddedOptions {
|
|
7
|
-
[name]: typeof option;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
5
|
export declare const SQL_FORMATTER_LANGUAGES: readonly ["sql", "bigquery", "hive", "mariadb", "mysql", "postgresql", "db2", "plsql", "n1ql", "redshift", "singlestoredb", "spark", "sqlite", "transactsql", "tsql", "trino"];
|
|
11
6
|
export declare const NODE_SQL_PARSER_DATABASES: readonly ["bigquery", "db2", "hive", "mariadb", "mysql", "postgresql", "transactsql", "flinksql"];
|
|
12
7
|
export type SqlFormatterLanguage = (typeof SQL_FORMATTER_LANGUAGES)[number];
|
|
13
8
|
export type NodeSqlParserDataBase = (typeof NODE_SQL_PARSER_DATABASES)[number];
|
|
14
9
|
export { PrettierPluginDepsOptions };
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
declare module "../types.js" {
|
|
11
|
+
interface EmbeddedOptions {
|
|
12
|
+
[name]: typeof option;
|
|
13
|
+
}
|
|
14
|
+
interface PrettierPluginEmbedOptions {
|
|
15
|
+
[name]?: SqlFormatterLanguage[] | NodeSqlParserDataBase[] | string[];
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
18
|
declare module "prettier" {
|
|
19
|
-
interface Options extends PrettierPluginDepsOptions
|
|
19
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
20
20
|
}
|
|
21
21
|
}
|
package/dist/embedded/types.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import type { Parser, SupportOption, Options } from "prettier";
|
|
2
2
|
import type { Embedder } from "../types.js";
|
|
3
|
+
type EmbeddedNameConvention = `embedded${string}`;
|
|
3
4
|
export interface EmbeddedParsers {
|
|
4
|
-
[name:
|
|
5
|
+
[name: EmbeddedNameConvention]: Parser | undefined;
|
|
5
6
|
}
|
|
6
7
|
export interface EmbeddedEmbedders {
|
|
7
|
-
[name:
|
|
8
|
+
[name: EmbeddedNameConvention]: Embedder<Options> | undefined;
|
|
8
9
|
}
|
|
9
10
|
export interface EmbeddedOptions {
|
|
10
|
-
[name:
|
|
11
|
+
[name: EmbeddedNameConvention]: SupportOption | undefined;
|
|
11
12
|
}
|
|
12
13
|
export interface EmbeddedNamesHolder {
|
|
13
14
|
}
|
|
14
15
|
export type EmbeddedName = keyof EmbeddedNamesHolder;
|
|
16
|
+
export interface PrettierPluginEmbedOptions {
|
|
17
|
+
}
|
|
18
|
+
declare module "prettier" {
|
|
19
|
+
interface Options extends PrettierPluginEmbedOptions {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {};
|
package/dist/embedded/utils.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare function printTemplateExpression(path: AstPath<Expression & {
|
|
|
8
8
|
export declare function printTemplateExpressions(path: AstPath<TemplateLiteral>, print: InternalPrintFun): builders.Doc[][];
|
|
9
9
|
export declare function throwIfPluginIsNotFound(pluginName: string, options: Options, lang: string): void;
|
|
10
10
|
export declare function insertEmbeddedLanguageName(names: string[], name: string, headName: string): void;
|
|
11
|
+
export declare function uuidV4(): string;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { SupportOption } from "prettier";
|
|
2
2
|
import { name } from "./name.js";
|
|
3
3
|
export declare const option: SupportOption;
|
|
4
|
-
declare module "../types.js" {
|
|
5
|
-
interface EmbeddedOptions {
|
|
6
|
-
[name]: typeof option;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
4
|
export interface PrettierPluginDepsOptions {
|
|
10
5
|
xmlSelfClosingSpace?: boolean;
|
|
11
6
|
xmlWhitespaceSensitivity?: "strict" | "preserve" | "ignore";
|
|
12
7
|
xmlSortAttributesByKey?: boolean;
|
|
13
8
|
xmlQuoteAttributes?: "preserve" | "single" | "double";
|
|
14
9
|
}
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
declare module "../types.js" {
|
|
11
|
+
interface EmbeddedOptions {
|
|
12
|
+
[name]: typeof option;
|
|
13
|
+
}
|
|
14
|
+
interface PrettierPluginEmbedOptions {
|
|
15
|
+
[name]?: string[];
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
18
|
declare module "prettier" {
|
|
19
|
-
interface Options extends PrettierPluginDepsOptions
|
|
19
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
20
20
|
}
|
|
21
21
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,71 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { builders as
|
|
6
|
-
import { parse as
|
|
7
|
-
import { printers as
|
|
8
|
-
const P = "embeddedNoop",
|
|
1
|
+
import Q from "prettier/parser-babel";
|
|
2
|
+
import U from "prettier/parser-espree";
|
|
3
|
+
import X from "prettier/parser-flow";
|
|
4
|
+
import H from "prettier/parser-typescript";
|
|
5
|
+
import { builders as q, utils as T } from "prettier/doc";
|
|
6
|
+
import { parse as V } from "@xml-tools/parser";
|
|
7
|
+
import { printers as J } from "prettier/plugins/estree.mjs";
|
|
8
|
+
const P = "embeddedNoop", K = {
|
|
9
9
|
category: "Global",
|
|
10
10
|
type: "string",
|
|
11
11
|
array: !0,
|
|
12
12
|
default: [{ value: [] }],
|
|
13
13
|
description: "Specify embedded languages that will not be formatted."
|
|
14
|
-
},
|
|
14
|
+
}, Y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
15
15
|
__proto__: null,
|
|
16
16
|
name: P,
|
|
17
|
-
option:
|
|
18
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
19
|
-
|
|
20
|
-
const re = new Uint8Array(16);
|
|
21
|
-
function oe() {
|
|
22
|
-
if (!S && (S = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !S))
|
|
23
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
24
|
-
return S(re);
|
|
25
|
-
}
|
|
26
|
-
const c = [];
|
|
27
|
-
for (let e = 0; e < 256; ++e)
|
|
28
|
-
c.push((e + 256).toString(16).slice(1));
|
|
29
|
-
function se(e, t = 0) {
|
|
30
|
-
return c[e[t + 0]] + c[e[t + 1]] + c[e[t + 2]] + c[e[t + 3]] + "-" + c[e[t + 4]] + c[e[t + 5]] + "-" + c[e[t + 6]] + c[e[t + 7]] + "-" + c[e[t + 8]] + c[e[t + 9]] + "-" + c[e[t + 10]] + c[e[t + 11]] + c[e[t + 12]] + c[e[t + 13]] + c[e[t + 14]] + c[e[t + 15]];
|
|
31
|
-
}
|
|
32
|
-
const ie = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), L = {
|
|
33
|
-
randomUUID: ie
|
|
34
|
-
};
|
|
35
|
-
function k(e, t, n) {
|
|
36
|
-
if (L.randomUUID && !t && !e)
|
|
37
|
-
return L.randomUUID();
|
|
38
|
-
e = e || {};
|
|
39
|
-
const o = e.random || (e.rng || oe)();
|
|
40
|
-
if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, t) {
|
|
41
|
-
n = n || 0;
|
|
42
|
-
for (let r = 0; r < 16; ++r)
|
|
43
|
-
t[n + r] = o[r];
|
|
44
|
-
return t;
|
|
45
|
-
}
|
|
46
|
-
return se(o);
|
|
47
|
-
}
|
|
48
|
-
const { group: le, indent: ce, softline: I, lineSuffixBoundary: ae } = E;
|
|
49
|
-
function ue(e, t) {
|
|
17
|
+
option: K
|
|
18
|
+
}, Symbol.toStringTag, { value: "Module" })), Z = "embeddedPhp", { group: ee, indent: te, softline: j, lineSuffixBoundary: ne } = q;
|
|
19
|
+
function re(e, t) {
|
|
50
20
|
var r;
|
|
51
21
|
const { node: n } = e;
|
|
52
22
|
let o = t();
|
|
53
|
-
return (r = n == null ? void 0 : n.comments) != null && r.length && (o =
|
|
23
|
+
return (r = n == null ? void 0 : n.comments) != null && r.length && (o = ee([te([j, o]), j])), ["${", o, ne, "}"];
|
|
54
24
|
}
|
|
55
|
-
function
|
|
25
|
+
function D(e, t) {
|
|
56
26
|
return e.map(
|
|
57
|
-
(n) =>
|
|
27
|
+
(n) => re(n, t),
|
|
58
28
|
"expressions"
|
|
59
29
|
);
|
|
60
30
|
}
|
|
61
|
-
function
|
|
31
|
+
function N(e, t, n) {
|
|
62
32
|
var o;
|
|
63
|
-
if (!(((o = t.plugins) == null ? void 0 : o.
|
|
33
|
+
if (!(((o = t.plugins) == null ? void 0 : o.some(
|
|
34
|
+
(r) => {
|
|
35
|
+
var s;
|
|
36
|
+
return ((s = r.name) == null ? void 0 : s.includes(e)) ?? !1;
|
|
37
|
+
}
|
|
38
|
+
)) ?? !1))
|
|
64
39
|
throw new Error(
|
|
65
40
|
`Cannot format embedded language "${n}" because plugin "${e}" is not loaded.`
|
|
66
41
|
);
|
|
67
42
|
}
|
|
68
|
-
function
|
|
43
|
+
function oe(e, t, n) {
|
|
69
44
|
if (t === n) {
|
|
70
45
|
e.unshift(t);
|
|
71
46
|
return;
|
|
@@ -81,66 +56,85 @@ function de(e, t, n) {
|
|
|
81
56
|
}
|
|
82
57
|
e.splice(o, 0, t);
|
|
83
58
|
}
|
|
84
|
-
|
|
59
|
+
function k() {
|
|
60
|
+
function e(n) {
|
|
61
|
+
return t(Math.random() * (1 << (n << 2)) ^ Date.now()).slice(-n);
|
|
62
|
+
}
|
|
63
|
+
function t(n) {
|
|
64
|
+
return (n | 0).toString(16);
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
e(4) + e(4),
|
|
68
|
+
e(4),
|
|
69
|
+
"4" + e(3),
|
|
70
|
+
// UUID version 4
|
|
71
|
+
t(8 | Math.random() * 4) + e(3),
|
|
72
|
+
// {8|9|A|B}xxx
|
|
73
|
+
// s(4) + s(4) + s(4),
|
|
74
|
+
Date.now().toString(16).slice(-10) + e(2)
|
|
75
|
+
// Use timestamp to avoid collisions
|
|
76
|
+
].join("-");
|
|
77
|
+
}
|
|
78
|
+
const { label: se, hardline: ie, line: le, group: E, indent: ae } = q, { mapDoc: ce } = T, ue = async (e, t, n, o, r) => {
|
|
85
79
|
try {
|
|
86
|
-
|
|
87
|
-
const s = "$p" + k().replaceAll("-", ""), { node: a } = n,
|
|
88
|
-
(i, l, { length:
|
|
80
|
+
N("@prettier/plugin-php", o, r);
|
|
81
|
+
const s = "$p" + k().replaceAll("-", ""), { node: a } = n, g = a.quasis.map(
|
|
82
|
+
(i, l, { length: p }) => l === p - 1 ? i.value.cooked : i.value.cooked + `${s}${l}`
|
|
89
83
|
).join("");
|
|
90
|
-
let
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
const
|
|
84
|
+
let u = "", b = 0;
|
|
85
|
+
const f = /^\s+/.exec(g);
|
|
86
|
+
f && (b = f.index + f[0].length, u = " ");
|
|
87
|
+
const $ = /\s$/.test(g) ? " " : "", _ = D(n, t), v = await e(g.slice(b), {
|
|
94
88
|
parser: "php"
|
|
95
89
|
});
|
|
96
90
|
let h = !1;
|
|
97
|
-
const
|
|
91
|
+
const y = ce(v, (i) => {
|
|
98
92
|
if (typeof i != "string")
|
|
99
93
|
return Array.isArray(i) || (i.type === "group" && i.break || i.type === "line" && (i.hard || i.literal)) && (h = !0), i;
|
|
100
|
-
const l = [],
|
|
101
|
-
for (let
|
|
102
|
-
let
|
|
103
|
-
if (
|
|
104
|
-
if (!
|
|
94
|
+
const l = [], p = i.split(new RegExp("\\" + s + "(\\d+)", "g"));
|
|
95
|
+
for (let c = 0; c < p.length; c++) {
|
|
96
|
+
let m = p[c];
|
|
97
|
+
if (c % 2 == 0) {
|
|
98
|
+
if (!m)
|
|
105
99
|
continue;
|
|
106
|
-
|
|
100
|
+
m = m.replaceAll(/([\\`]|\${)/g, "\\$1"), l.push(m);
|
|
107
101
|
} else {
|
|
108
|
-
const
|
|
109
|
-
l.push(_[
|
|
102
|
+
const x = Number(m);
|
|
103
|
+
l.push(_[x]);
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
106
|
return l;
|
|
113
|
-
}),
|
|
114
|
-
return
|
|
107
|
+
}), d = h ? ie : u && $ ? le : null;
|
|
108
|
+
return d ? E([
|
|
115
109
|
"`",
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
ae([d, E(y)]),
|
|
111
|
+
d,
|
|
118
112
|
"`"
|
|
119
|
-
]) :
|
|
113
|
+
]) : se(
|
|
120
114
|
{ hug: !1 },
|
|
121
|
-
|
|
115
|
+
E([
|
|
122
116
|
"`",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
117
|
+
u,
|
|
118
|
+
E([y]),
|
|
119
|
+
$,
|
|
126
120
|
"`"
|
|
127
121
|
])
|
|
128
122
|
);
|
|
129
123
|
} catch (s) {
|
|
130
124
|
throw console.error(s), s;
|
|
131
125
|
}
|
|
132
|
-
},
|
|
126
|
+
}, de = {
|
|
133
127
|
category: "Global",
|
|
134
128
|
type: "string",
|
|
135
129
|
array: !0,
|
|
136
130
|
default: [{ value: ["php"] }],
|
|
137
131
|
description: "Specify embedded PHP languages. This requires @prettier/plugin-php"
|
|
138
|
-
},
|
|
132
|
+
}, pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
139
133
|
__proto__: null,
|
|
140
|
-
embedder:
|
|
141
|
-
name:
|
|
142
|
-
option:
|
|
143
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
134
|
+
embedder: ue,
|
|
135
|
+
name: Z,
|
|
136
|
+
option: de
|
|
137
|
+
}, Symbol.toStringTag, { value: "Module" })), fe = "embeddedSql", me = {
|
|
144
138
|
category: "Global",
|
|
145
139
|
type: "string",
|
|
146
140
|
array: !0,
|
|
@@ -172,79 +166,79 @@ const { label: pe, hardline: me, line: ge, group: w, indent: fe } = E, { mapDoc:
|
|
|
172
166
|
"postgresql",
|
|
173
167
|
"transactsql",
|
|
174
168
|
"flinksql"
|
|
175
|
-
], { label:
|
|
169
|
+
], { label: ge, hardline: A, group: S, line: be, indent: he } = q, { mapDoc: ye } = T, $e = async (e, t, n, o, r, s) => {
|
|
176
170
|
try {
|
|
177
|
-
|
|
178
|
-
const a = "p" + k().replaceAll("-", ""), { node:
|
|
179
|
-
(i, l, { length:
|
|
180
|
-
).join(""),
|
|
171
|
+
N("prettier-plugin-sql", o, r);
|
|
172
|
+
const a = "p" + k().replaceAll("-", ""), { node: g } = n, u = g.quasis.map(
|
|
173
|
+
(i, l, { length: p }) => l === p - 1 ? i.value.cooked : i.value.cooked + `${a}${l}`
|
|
174
|
+
).join(""), b = /^\s/.test(u) ? " " : "", f = /\s$/.test(u) ? " " : "", $ = D(n, t), _ = xe(o, r, s);
|
|
181
175
|
if (typeof _ > "u")
|
|
182
176
|
throw new SyntaxError(`Unrecognized language: ${r}`);
|
|
183
|
-
const
|
|
177
|
+
const v = await e(u, {
|
|
184
178
|
parser: "sql",
|
|
185
179
|
..._
|
|
186
180
|
});
|
|
187
181
|
let h = !1;
|
|
188
|
-
const
|
|
182
|
+
const y = ye(v, (i) => {
|
|
189
183
|
if (typeof i != "string")
|
|
190
184
|
return i;
|
|
191
|
-
const l = [],
|
|
192
|
-
for (let
|
|
193
|
-
let
|
|
194
|
-
if (
|
|
195
|
-
if (!
|
|
185
|
+
const l = [], p = i.split(new RegExp(a + "(\\d+)", "g"));
|
|
186
|
+
for (let c = 0; c < p.length; c++) {
|
|
187
|
+
let m = p[c];
|
|
188
|
+
if (c % 2 == 0) {
|
|
189
|
+
if (!m)
|
|
196
190
|
continue;
|
|
197
|
-
|
|
198
|
-
(
|
|
199
|
-
` ? (h = !0, l.push(
|
|
191
|
+
m = m.replaceAll(/([\\`]|\${)/g, "\\$1"), m.split(/(\n)/).forEach(
|
|
192
|
+
(x) => x === `
|
|
193
|
+
` ? (h = !0, l.push(A)) : l.push(x)
|
|
200
194
|
);
|
|
201
195
|
} else {
|
|
202
|
-
const
|
|
203
|
-
l.push(x
|
|
196
|
+
const x = Number(m);
|
|
197
|
+
l.push($[x]);
|
|
204
198
|
}
|
|
205
199
|
}
|
|
206
200
|
return l;
|
|
207
|
-
}),
|
|
208
|
-
return
|
|
201
|
+
}), d = h ? A : b && f ? be : null;
|
|
202
|
+
return d ? S([
|
|
209
203
|
"`",
|
|
210
|
-
|
|
211
|
-
|
|
204
|
+
he([d, S(y)]),
|
|
205
|
+
d,
|
|
212
206
|
"`"
|
|
213
|
-
]) :
|
|
207
|
+
]) : ge(
|
|
214
208
|
{ hug: !1 },
|
|
215
|
-
|
|
209
|
+
S([
|
|
216
210
|
"`",
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
211
|
+
b,
|
|
212
|
+
S(y),
|
|
213
|
+
f,
|
|
220
214
|
"`"
|
|
221
215
|
])
|
|
222
216
|
);
|
|
223
217
|
} catch (a) {
|
|
224
218
|
throw console.error(a), a;
|
|
225
219
|
}
|
|
226
|
-
},
|
|
220
|
+
}, _e = {
|
|
227
221
|
"sql-formatter": (e) => C.includes(e),
|
|
228
222
|
"node-sql-parser": (e) => G.includes(e)
|
|
229
223
|
};
|
|
230
|
-
function
|
|
224
|
+
function L(e, t) {
|
|
231
225
|
for (const n of t)
|
|
232
|
-
if (
|
|
226
|
+
if (_e[n](e))
|
|
233
227
|
return {
|
|
234
228
|
formatter: n,
|
|
235
229
|
language: e
|
|
236
230
|
};
|
|
237
231
|
}
|
|
238
232
|
function B(e, t, n) {
|
|
239
|
-
let o =
|
|
233
|
+
let o = L(e, n);
|
|
240
234
|
if (o)
|
|
241
235
|
return o;
|
|
242
236
|
const r = t.indexOf(e);
|
|
243
237
|
for (let s = r - 1; s >= 0; --s)
|
|
244
|
-
if (o =
|
|
238
|
+
if (o = L(t[s], n), o)
|
|
245
239
|
return o;
|
|
246
240
|
}
|
|
247
|
-
function
|
|
241
|
+
function xe(e, t, n) {
|
|
248
242
|
return e.formatter === "sql-formatter" ? B(t, n, [
|
|
249
243
|
"sql-formatter",
|
|
250
244
|
"node-sql-parser"
|
|
@@ -253,23 +247,23 @@ function Te(e, t, n) {
|
|
|
253
247
|
"sql-formatter"
|
|
254
248
|
]);
|
|
255
249
|
}
|
|
256
|
-
const
|
|
250
|
+
const ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
257
251
|
__proto__: null,
|
|
258
252
|
NODE_SQL_PARSER_DATABASES: G,
|
|
259
253
|
SQL_FORMATTER_LANGUAGES: C,
|
|
260
|
-
embedder:
|
|
261
|
-
name:
|
|
262
|
-
option:
|
|
263
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
254
|
+
embedder: $e,
|
|
255
|
+
name: fe,
|
|
256
|
+
option: me
|
|
257
|
+
}, Symbol.toStringTag, { value: "Module" })), I = "embeddedXml";
|
|
264
258
|
function F(e, t) {
|
|
265
259
|
const n = new SyntaxError(
|
|
266
260
|
e + " (" + t.loc.start.line + ":" + t.loc.start.column + ")"
|
|
267
261
|
);
|
|
268
262
|
return Object.assign(n, t);
|
|
269
263
|
}
|
|
270
|
-
const
|
|
264
|
+
const qe = {
|
|
271
265
|
parse(e) {
|
|
272
|
-
const { lexErrors: t, parseErrors: n, cst: o } =
|
|
266
|
+
const { lexErrors: t, parseErrors: n, cst: o } = V(e);
|
|
273
267
|
if (t.length > 0) {
|
|
274
268
|
const r = t[0];
|
|
275
269
|
throw F(r.message, {
|
|
@@ -306,83 +300,83 @@ const Ne = {
|
|
|
306
300
|
locEnd(e) {
|
|
307
301
|
return e.location.endOffset ?? NaN;
|
|
308
302
|
}
|
|
309
|
-
}, { label:
|
|
303
|
+
}, { label: Ee, hardline: Se, line: we, group: w, indent: Oe } = q, { mapDoc: Te } = T, De = async (e, t, n, o, r) => {
|
|
310
304
|
try {
|
|
311
|
-
|
|
312
|
-
const s = k(), { node: a } = n,
|
|
313
|
-
(
|
|
305
|
+
N("@prettier/plugin-xml", o, r);
|
|
306
|
+
const s = k(), { node: a } = n, g = a.quasis.map(
|
|
307
|
+
(d, i, { length: l }) => i === l - 1 ? d.value.cooked : d.value.cooked + `${s}-${i}`
|
|
314
308
|
).join("");
|
|
315
|
-
let
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
parser:
|
|
320
|
-
}), h =
|
|
321
|
-
if (typeof
|
|
322
|
-
return
|
|
323
|
-
const i = [], l =
|
|
324
|
-
for (let
|
|
325
|
-
let
|
|
326
|
-
if (
|
|
327
|
-
if (!
|
|
309
|
+
let u = "", b = 0;
|
|
310
|
+
const f = /^\s+/.exec(g);
|
|
311
|
+
f && (b = f.index + f[0].length, u = " ");
|
|
312
|
+
const $ = /\s$/.test(g) ? " " : "", _ = D(n, t), v = await e(g.slice(b), {
|
|
313
|
+
parser: I
|
|
314
|
+
}), h = Te(v, (d) => {
|
|
315
|
+
if (typeof d != "string")
|
|
316
|
+
return d;
|
|
317
|
+
const i = [], l = d.split(new RegExp(s + "-(\\d+)", "g"));
|
|
318
|
+
for (let p = 0; p < l.length; p++) {
|
|
319
|
+
let c = l[p];
|
|
320
|
+
if (p % 2 == 0) {
|
|
321
|
+
if (!c)
|
|
328
322
|
continue;
|
|
329
|
-
|
|
323
|
+
c = c.replaceAll(/([\\`]|\${)/g, "\\$1"), i.push(c);
|
|
330
324
|
} else {
|
|
331
|
-
const
|
|
332
|
-
i.push(_[
|
|
325
|
+
const m = Number(c);
|
|
326
|
+
i.push(_[m]);
|
|
333
327
|
}
|
|
334
328
|
}
|
|
335
329
|
return i;
|
|
336
|
-
}),
|
|
337
|
-
return
|
|
330
|
+
}), y = o.xmlWhitespaceSensitivity === "ignore" ? Se : u && $ ? we : null;
|
|
331
|
+
return y ? w([
|
|
338
332
|
"`",
|
|
339
|
-
|
|
340
|
-
|
|
333
|
+
Oe([y, w(h)]),
|
|
334
|
+
y,
|
|
341
335
|
"`"
|
|
342
|
-
]) :
|
|
336
|
+
]) : Ee(
|
|
343
337
|
{ hug: !1 },
|
|
344
|
-
|
|
338
|
+
w([
|
|
345
339
|
"`",
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
340
|
+
u,
|
|
341
|
+
w(h),
|
|
342
|
+
$,
|
|
349
343
|
"`"
|
|
350
344
|
])
|
|
351
345
|
);
|
|
352
346
|
} catch (s) {
|
|
353
347
|
throw console.error(s), s;
|
|
354
348
|
}
|
|
355
|
-
},
|
|
349
|
+
}, Ne = {
|
|
356
350
|
category: "Global",
|
|
357
351
|
type: "string",
|
|
358
352
|
array: !0,
|
|
359
353
|
default: [{ value: ["xml", "svg"] }],
|
|
360
354
|
description: "Specify embedded XML languages. This requires @prettier/plugin-xml"
|
|
361
|
-
},
|
|
355
|
+
}, ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
362
356
|
__proto__: null,
|
|
363
|
-
embedder:
|
|
364
|
-
name:
|
|
365
|
-
option:
|
|
366
|
-
parser:
|
|
367
|
-
}, Symbol.toStringTag, { value: "Module" })), M = [],
|
|
368
|
-
"./noop/index.ts":
|
|
369
|
-
"./php/index.ts":
|
|
370
|
-
"./sql/index.ts":
|
|
371
|
-
"./xml/index.ts":
|
|
357
|
+
embedder: De,
|
|
358
|
+
name: I,
|
|
359
|
+
option: Ne,
|
|
360
|
+
parser: qe
|
|
361
|
+
}, Symbol.toStringTag, { value: "Module" })), M = [], W = {}, R = {}, z = {}, je = /* @__PURE__ */ Object.assign({
|
|
362
|
+
"./noop/index.ts": Y,
|
|
363
|
+
"./php/index.ts": pe,
|
|
364
|
+
"./sql/index.ts": ve,
|
|
365
|
+
"./xml/index.ts": ke
|
|
372
366
|
});
|
|
373
|
-
Object.values(
|
|
374
|
-
|
|
367
|
+
Object.values(je).forEach(({ name: e, parser: t, embedder: n, option: o }) => {
|
|
368
|
+
oe(M, e, P), t && (W[e] = t), n && (R[e] = n), z[e] = o;
|
|
375
369
|
});
|
|
376
|
-
const
|
|
370
|
+
const Re = {
|
|
377
371
|
// parsers from internal
|
|
378
372
|
// TODO: find out which parsers are required and which are optional
|
|
379
|
-
...
|
|
373
|
+
...Q.parsers,
|
|
374
|
+
...U.parsers,
|
|
380
375
|
...X.parsers,
|
|
381
|
-
...
|
|
382
|
-
...K.parsers,
|
|
376
|
+
...H.parsers,
|
|
383
377
|
// parsers from this plugin
|
|
384
|
-
...
|
|
385
|
-
}, { estree:
|
|
378
|
+
...W
|
|
379
|
+
}, { estree: O } = J, Ae = function(e, t) {
|
|
386
380
|
var o;
|
|
387
381
|
const { node: n } = e;
|
|
388
382
|
if (n.type !== "TemplateLiteral" || n.quasis.some(({ value: { cooked: r } }) => r === null))
|
|
@@ -391,28 +385,28 @@ const Je = {
|
|
|
391
385
|
const s = t[r];
|
|
392
386
|
if (!s)
|
|
393
387
|
continue;
|
|
394
|
-
const a =
|
|
388
|
+
const a = Le(
|
|
395
389
|
e,
|
|
396
390
|
s,
|
|
397
391
|
t.noEmbeddedDetectionByComment ?? []
|
|
398
|
-
) ??
|
|
392
|
+
) ?? Be(e, s, t.noEmbeddedDetectionByTag ?? []);
|
|
399
393
|
if (a === void 0)
|
|
400
394
|
continue;
|
|
401
|
-
const
|
|
402
|
-
if (!
|
|
395
|
+
const g = R[r];
|
|
396
|
+
if (!g)
|
|
403
397
|
return null;
|
|
404
|
-
const
|
|
405
|
-
return
|
|
406
|
-
const
|
|
407
|
-
return
|
|
408
|
-
{ embed: !0, ...
|
|
409
|
-
|
|
398
|
+
const u = e.node;
|
|
399
|
+
return u.quasis.length === 1 && u.quasis[0].value.raw.trim() === "" ? "``" : async (...b) => {
|
|
400
|
+
const f = await g(...b, a, s);
|
|
401
|
+
return q.label(
|
|
402
|
+
{ embed: !0, ...f.label },
|
|
403
|
+
f
|
|
410
404
|
);
|
|
411
405
|
};
|
|
412
406
|
}
|
|
413
|
-
return ((o =
|
|
407
|
+
return ((o = O.embed) == null ? void 0 : o.call(O, e, t)) ?? null;
|
|
414
408
|
};
|
|
415
|
-
function
|
|
409
|
+
function Le({ node: e, parent: t }, n, o) {
|
|
416
410
|
if (n.length === 0 || e.type !== "TemplateLiteral")
|
|
417
411
|
return;
|
|
418
412
|
const r = e.comments ?? (t == null ? void 0 : t.comments);
|
|
@@ -425,20 +419,20 @@ function Ce({ node: e, parent: t }, n, o) {
|
|
|
425
419
|
return a;
|
|
426
420
|
}
|
|
427
421
|
}
|
|
428
|
-
function
|
|
422
|
+
function Be({ node: e, parent: t }, n, o) {
|
|
429
423
|
if (n.length !== 0 && !(e.type !== "TemplateLiteral" || (t == null ? void 0 : t.type) !== "TaggedTemplateExpression" || t.tag.type !== "Identifier")) {
|
|
430
424
|
for (const r of n)
|
|
431
425
|
if (t.tag.name === r && !o.includes(r))
|
|
432
426
|
return r;
|
|
433
427
|
}
|
|
434
428
|
}
|
|
435
|
-
const
|
|
429
|
+
const ze = {
|
|
436
430
|
estree: {
|
|
437
|
-
...
|
|
438
|
-
embed:
|
|
431
|
+
...O,
|
|
432
|
+
embed: Ae
|
|
439
433
|
}
|
|
440
|
-
},
|
|
441
|
-
...
|
|
434
|
+
}, Qe = {
|
|
435
|
+
...z,
|
|
442
436
|
noEmbeddedDetectionByComment: {
|
|
443
437
|
category: "Global",
|
|
444
438
|
type: "string",
|
|
@@ -455,11 +449,11 @@ const Ke = {
|
|
|
455
449
|
}
|
|
456
450
|
};
|
|
457
451
|
export {
|
|
458
|
-
|
|
452
|
+
R as embeddedEmbedders,
|
|
459
453
|
M as embeddedNames,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
454
|
+
z as embeddedOptions,
|
|
455
|
+
W as embeddedParsers,
|
|
456
|
+
Qe as options,
|
|
457
|
+
Re as parsers,
|
|
458
|
+
ze as printers
|
|
465
459
|
};
|
package/dist/options.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { SupportOptions } from "prettier";
|
|
2
|
+
import { PrettierPluginEmbedOptions } from "./embedded/index.js";
|
|
2
3
|
export declare const options: SupportOptions;
|
|
3
|
-
declare module "
|
|
4
|
-
interface
|
|
4
|
+
declare module "./embedded/types.js" {
|
|
5
|
+
interface PrettierPluginEmbedOptions {
|
|
5
6
|
noEmbeddedDetectionByComment?: string[];
|
|
6
7
|
noEmbeddedDetectionByTag?: string[];
|
|
7
8
|
}
|
|
8
9
|
}
|
|
10
|
+
declare module "prettier" {
|
|
11
|
+
interface Options extends PrettierPluginEmbedOptions {
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "prettier-plugin-embed",
|
|
3
3
|
"description": "A prettier plugin to format embedded languages in js/ts files.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"./dist"
|
|
@@ -55,9 +55,6 @@
|
|
|
55
55
|
"ncu": "npx npm-check-updates -u",
|
|
56
56
|
"postncu": "npm i"
|
|
57
57
|
},
|
|
58
|
-
"dependencies": {
|
|
59
|
-
"uuid": "^9.0.1"
|
|
60
|
-
},
|
|
61
58
|
"devDependencies": {
|
|
62
59
|
"@commitlint/cli": "^17.7.2",
|
|
63
60
|
"@commitlint/config-conventional": "^17.7.0",
|
|
@@ -65,7 +62,6 @@
|
|
|
65
62
|
"@prettier/plugin-xml": "^3.2.1",
|
|
66
63
|
"@semantic-release/git": "^10.0.1",
|
|
67
64
|
"@types/estree": "^1.0.2",
|
|
68
|
-
"@types/uuid": "^9.0.4",
|
|
69
65
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
70
66
|
"@typescript-eslint/parser": "^6.7.4",
|
|
71
67
|
"@vitest/browser": "^0.34.6",
|