prettier-plugin-embed 0.0.4 → 0.0.6
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 +204 -201
- package/dist/options.d.ts +7 -2
- package/dist/parsers.d.ts +1 -0
- 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,47 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
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 V from "prettier/parser-meriyah";
|
|
6
|
+
import { builders as q, utils as T } from "prettier/doc";
|
|
7
|
+
import { parse as J } from "@xml-tools/parser";
|
|
8
|
+
import { printers as K } from "prettier/plugins/estree.mjs";
|
|
9
|
+
const M = "embeddedNoop", Y = {
|
|
9
10
|
category: "Global",
|
|
10
11
|
type: "string",
|
|
11
12
|
array: !0,
|
|
12
13
|
default: [{ value: [] }],
|
|
13
14
|
description: "Specify embedded languages that will not be formatted."
|
|
14
|
-
},
|
|
15
|
+
}, Z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
15
16
|
__proto__: null,
|
|
16
|
-
name:
|
|
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
|
+
name: M,
|
|
18
|
+
option: Y
|
|
19
|
+
}, Symbol.toStringTag, { value: "Module" })), ee = "embeddedPhp", { group: te, indent: ne, softline: j, lineSuffixBoundary: re } = q;
|
|
20
|
+
function oe(e, t) {
|
|
50
21
|
var r;
|
|
51
22
|
const { node: n } = e;
|
|
52
23
|
let o = t();
|
|
53
|
-
return (r = n == null ? void 0 : n.comments) != null && r.length && (o =
|
|
24
|
+
return (r = n == null ? void 0 : n.comments) != null && r.length && (o = te([ne([j, o]), j])), ["${", o, re, "}"];
|
|
54
25
|
}
|
|
55
|
-
function
|
|
26
|
+
function k(e, t) {
|
|
56
27
|
return e.map(
|
|
57
|
-
(n) =>
|
|
28
|
+
(n) => oe(n, t),
|
|
58
29
|
"expressions"
|
|
59
30
|
);
|
|
60
31
|
}
|
|
61
|
-
function
|
|
32
|
+
function D(e, t, n) {
|
|
62
33
|
var o;
|
|
63
|
-
if (!(((o = t.plugins) == null ? void 0 : o.
|
|
34
|
+
if (!(((o = t.plugins) == null ? void 0 : o.some(
|
|
35
|
+
(r) => {
|
|
36
|
+
var s;
|
|
37
|
+
return ((s = r.name) == null ? void 0 : s.includes(e)) ?? !1;
|
|
38
|
+
}
|
|
39
|
+
)) ?? !1))
|
|
64
40
|
throw new Error(
|
|
65
41
|
`Cannot format embedded language "${n}" because plugin "${e}" is not loaded.`
|
|
66
42
|
);
|
|
67
43
|
}
|
|
68
|
-
function
|
|
44
|
+
function se(e, t, n) {
|
|
69
45
|
if (t === n) {
|
|
70
46
|
e.unshift(t);
|
|
71
47
|
return;
|
|
@@ -81,72 +57,91 @@ function de(e, t, n) {
|
|
|
81
57
|
}
|
|
82
58
|
e.splice(o, 0, t);
|
|
83
59
|
}
|
|
84
|
-
|
|
60
|
+
function N() {
|
|
61
|
+
function e(n) {
|
|
62
|
+
return t(Math.random() * (1 << (n << 2)) ^ Date.now()).slice(-n);
|
|
63
|
+
}
|
|
64
|
+
function t(n) {
|
|
65
|
+
return (n | 0).toString(16);
|
|
66
|
+
}
|
|
67
|
+
return [
|
|
68
|
+
e(4) + e(4),
|
|
69
|
+
e(4),
|
|
70
|
+
"4" + e(3),
|
|
71
|
+
// UUID version 4
|
|
72
|
+
t(8 | Math.random() * 4) + e(3),
|
|
73
|
+
// {8|9|A|B}xxx
|
|
74
|
+
// s(4) + s(4) + s(4),
|
|
75
|
+
Date.now().toString(16).slice(-10) + e(2)
|
|
76
|
+
// Use timestamp to avoid collisions
|
|
77
|
+
].join("-");
|
|
78
|
+
}
|
|
79
|
+
const { label: ie, hardline: le, line: ae, group: E, indent: ce } = q, { mapDoc: ue } = T, de = async (e, t, n, o, r) => {
|
|
85
80
|
try {
|
|
86
|
-
|
|
87
|
-
const s = "$p" +
|
|
88
|
-
(i, l, { length:
|
|
81
|
+
D("@prettier/plugin-php", o, r);
|
|
82
|
+
const s = "$p" + N().replaceAll("-", ""), { node: a } = n, g = a.quasis.map(
|
|
83
|
+
(i, l, { length: p }) => l === p - 1 ? i.value.cooked : i.value.cooked + `${s}${l}`
|
|
89
84
|
).join("");
|
|
90
|
-
let
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
const
|
|
85
|
+
let u = "", b = 0;
|
|
86
|
+
const f = /^\s+/.exec(g);
|
|
87
|
+
f && (b = f.index + f[0].length, u = " ");
|
|
88
|
+
const $ = /\s$/.test(g) ? " " : "", _ = k(n, t), v = await e(g.slice(b), {
|
|
94
89
|
parser: "php"
|
|
95
90
|
});
|
|
96
91
|
let h = !1;
|
|
97
|
-
const
|
|
92
|
+
const y = ue(v, (i) => {
|
|
98
93
|
if (typeof i != "string")
|
|
99
94
|
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 (!
|
|
95
|
+
const l = [], p = i.split(new RegExp("\\" + s + "(\\d+)", "g"));
|
|
96
|
+
for (let c = 0; c < p.length; c++) {
|
|
97
|
+
let m = p[c];
|
|
98
|
+
if (c % 2 == 0) {
|
|
99
|
+
if (!m)
|
|
105
100
|
continue;
|
|
106
|
-
|
|
101
|
+
m = m.replaceAll(/([\\`]|\${)/g, "\\$1"), l.push(m);
|
|
107
102
|
} else {
|
|
108
|
-
const
|
|
109
|
-
l.push(_[
|
|
103
|
+
const x = Number(m);
|
|
104
|
+
l.push(_[x]);
|
|
110
105
|
}
|
|
111
106
|
}
|
|
112
107
|
return l;
|
|
113
|
-
}),
|
|
114
|
-
return
|
|
108
|
+
}), d = h ? le : u && $ ? ae : null;
|
|
109
|
+
return d ? E([
|
|
115
110
|
"`",
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
ce([d, E(y)]),
|
|
112
|
+
d,
|
|
118
113
|
"`"
|
|
119
|
-
]) :
|
|
114
|
+
]) : ie(
|
|
120
115
|
{ hug: !1 },
|
|
121
|
-
|
|
116
|
+
E([
|
|
122
117
|
"`",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
u,
|
|
119
|
+
E([y]),
|
|
120
|
+
$,
|
|
126
121
|
"`"
|
|
127
122
|
])
|
|
128
123
|
);
|
|
129
124
|
} catch (s) {
|
|
130
125
|
throw console.error(s), s;
|
|
131
126
|
}
|
|
132
|
-
},
|
|
127
|
+
}, pe = {
|
|
133
128
|
category: "Global",
|
|
134
129
|
type: "string",
|
|
135
130
|
array: !0,
|
|
136
131
|
default: [{ value: ["php"] }],
|
|
137
132
|
description: "Specify embedded PHP languages. This requires @prettier/plugin-php"
|
|
138
|
-
},
|
|
133
|
+
}, fe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
139
134
|
__proto__: null,
|
|
140
|
-
embedder:
|
|
141
|
-
name:
|
|
142
|
-
option:
|
|
143
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
135
|
+
embedder: de,
|
|
136
|
+
name: ee,
|
|
137
|
+
option: pe
|
|
138
|
+
}, Symbol.toStringTag, { value: "Module" })), me = "embeddedSql", ge = {
|
|
144
139
|
category: "Global",
|
|
145
140
|
type: "string",
|
|
146
141
|
array: !0,
|
|
147
142
|
default: [{ value: ["sql"] }],
|
|
148
143
|
description: "Specify embedded SQL languages. This requires prettier-plugin-sql"
|
|
149
|
-
},
|
|
144
|
+
}, P = [
|
|
150
145
|
"sql",
|
|
151
146
|
"bigquery",
|
|
152
147
|
"hive",
|
|
@@ -163,7 +158,7 @@ const { label: pe, hardline: me, line: ge, group: w, indent: fe } = E, { mapDoc:
|
|
|
163
158
|
"transactsql",
|
|
164
159
|
"tsql",
|
|
165
160
|
"trino"
|
|
166
|
-
],
|
|
161
|
+
], C = [
|
|
167
162
|
"bigquery",
|
|
168
163
|
"db2",
|
|
169
164
|
"hive",
|
|
@@ -172,79 +167,79 @@ const { label: pe, hardline: me, line: ge, group: w, indent: fe } = E, { mapDoc:
|
|
|
172
167
|
"postgresql",
|
|
173
168
|
"transactsql",
|
|
174
169
|
"flinksql"
|
|
175
|
-
], { label:
|
|
170
|
+
], { label: be, hardline: L, group: S, line: he, indent: ye } = q, { mapDoc: $e } = T, _e = async (e, t, n, o, r, s) => {
|
|
176
171
|
try {
|
|
177
|
-
|
|
178
|
-
const a = "p" +
|
|
179
|
-
(i, l, { length:
|
|
180
|
-
).join(""),
|
|
172
|
+
D("prettier-plugin-sql", o, r);
|
|
173
|
+
const a = "p" + N().replaceAll("-", ""), { node: g } = n, u = g.quasis.map(
|
|
174
|
+
(i, l, { length: p }) => l === p - 1 ? i.value.cooked : i.value.cooked + `${a}${l}`
|
|
175
|
+
).join(""), b = /^\s/.test(u) ? " " : "", f = /\s$/.test(u) ? " " : "", $ = k(n, t), _ = ve(o, r, s);
|
|
181
176
|
if (typeof _ > "u")
|
|
182
177
|
throw new SyntaxError(`Unrecognized language: ${r}`);
|
|
183
|
-
const
|
|
178
|
+
const v = await e(u, {
|
|
184
179
|
parser: "sql",
|
|
185
180
|
..._
|
|
186
181
|
});
|
|
187
182
|
let h = !1;
|
|
188
|
-
const
|
|
183
|
+
const y = $e(v, (i) => {
|
|
189
184
|
if (typeof i != "string")
|
|
190
185
|
return i;
|
|
191
|
-
const l = [],
|
|
192
|
-
for (let
|
|
193
|
-
let
|
|
194
|
-
if (
|
|
195
|
-
if (!
|
|
186
|
+
const l = [], p = i.split(new RegExp(a + "(\\d+)", "g"));
|
|
187
|
+
for (let c = 0; c < p.length; c++) {
|
|
188
|
+
let m = p[c];
|
|
189
|
+
if (c % 2 == 0) {
|
|
190
|
+
if (!m)
|
|
196
191
|
continue;
|
|
197
|
-
|
|
198
|
-
(
|
|
199
|
-
` ? (h = !0, l.push(
|
|
192
|
+
m = m.replaceAll(/([\\`]|\${)/g, "\\$1"), m.split(/(\n)/).forEach(
|
|
193
|
+
(x) => x === `
|
|
194
|
+
` ? (h = !0, l.push(L)) : l.push(x)
|
|
200
195
|
);
|
|
201
196
|
} else {
|
|
202
|
-
const
|
|
203
|
-
l.push(x
|
|
197
|
+
const x = Number(m);
|
|
198
|
+
l.push($[x]);
|
|
204
199
|
}
|
|
205
200
|
}
|
|
206
201
|
return l;
|
|
207
|
-
}),
|
|
208
|
-
return
|
|
202
|
+
}), d = h ? L : b && f ? he : null;
|
|
203
|
+
return d ? S([
|
|
209
204
|
"`",
|
|
210
|
-
|
|
211
|
-
|
|
205
|
+
ye([d, S(y)]),
|
|
206
|
+
d,
|
|
212
207
|
"`"
|
|
213
|
-
]) :
|
|
208
|
+
]) : be(
|
|
214
209
|
{ hug: !1 },
|
|
215
|
-
|
|
210
|
+
S([
|
|
216
211
|
"`",
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
212
|
+
b,
|
|
213
|
+
S(y),
|
|
214
|
+
f,
|
|
220
215
|
"`"
|
|
221
216
|
])
|
|
222
217
|
);
|
|
223
218
|
} catch (a) {
|
|
224
219
|
throw console.error(a), a;
|
|
225
220
|
}
|
|
226
|
-
},
|
|
227
|
-
"sql-formatter": (e) =>
|
|
228
|
-
"node-sql-parser": (e) =>
|
|
221
|
+
}, xe = {
|
|
222
|
+
"sql-formatter": (e) => P.includes(e),
|
|
223
|
+
"node-sql-parser": (e) => C.includes(e)
|
|
229
224
|
};
|
|
230
|
-
function
|
|
225
|
+
function A(e, t) {
|
|
231
226
|
for (const n of t)
|
|
232
|
-
if (
|
|
227
|
+
if (xe[n](e))
|
|
233
228
|
return {
|
|
234
229
|
formatter: n,
|
|
235
230
|
language: e
|
|
236
231
|
};
|
|
237
232
|
}
|
|
238
233
|
function B(e, t, n) {
|
|
239
|
-
let o =
|
|
234
|
+
let o = A(e, n);
|
|
240
235
|
if (o)
|
|
241
236
|
return o;
|
|
242
237
|
const r = t.indexOf(e);
|
|
243
238
|
for (let s = r - 1; s >= 0; --s)
|
|
244
|
-
if (o =
|
|
239
|
+
if (o = A(t[s], n), o)
|
|
245
240
|
return o;
|
|
246
241
|
}
|
|
247
|
-
function
|
|
242
|
+
function ve(e, t, n) {
|
|
248
243
|
return e.formatter === "sql-formatter" ? B(t, n, [
|
|
249
244
|
"sql-formatter",
|
|
250
245
|
"node-sql-parser"
|
|
@@ -253,23 +248,23 @@ function Te(e, t, n) {
|
|
|
253
248
|
"sql-formatter"
|
|
254
249
|
]);
|
|
255
250
|
}
|
|
256
|
-
const
|
|
251
|
+
const qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
257
252
|
__proto__: null,
|
|
258
|
-
NODE_SQL_PARSER_DATABASES:
|
|
259
|
-
SQL_FORMATTER_LANGUAGES:
|
|
260
|
-
embedder:
|
|
261
|
-
name:
|
|
262
|
-
option:
|
|
263
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
253
|
+
NODE_SQL_PARSER_DATABASES: C,
|
|
254
|
+
SQL_FORMATTER_LANGUAGES: P,
|
|
255
|
+
embedder: _e,
|
|
256
|
+
name: me,
|
|
257
|
+
option: ge
|
|
258
|
+
}, Symbol.toStringTag, { value: "Module" })), G = "embeddedXml";
|
|
264
259
|
function F(e, t) {
|
|
265
260
|
const n = new SyntaxError(
|
|
266
261
|
e + " (" + t.loc.start.line + ":" + t.loc.start.column + ")"
|
|
267
262
|
);
|
|
268
263
|
return Object.assign(n, t);
|
|
269
264
|
}
|
|
270
|
-
const
|
|
265
|
+
const Ee = {
|
|
271
266
|
parse(e) {
|
|
272
|
-
const { lexErrors: t, parseErrors: n, cst: o } =
|
|
267
|
+
const { lexErrors: t, parseErrors: n, cst: o } = J(e);
|
|
273
268
|
if (t.length > 0) {
|
|
274
269
|
const r = t[0];
|
|
275
270
|
throw F(r.message, {
|
|
@@ -306,139 +301,147 @@ const Ne = {
|
|
|
306
301
|
locEnd(e) {
|
|
307
302
|
return e.location.endOffset ?? NaN;
|
|
308
303
|
}
|
|
309
|
-
}, { label:
|
|
304
|
+
}, { label: Se, hardline: we, line: Oe, group: w, indent: Te } = q, { mapDoc: ke } = T, De = async (e, t, n, o, r) => {
|
|
310
305
|
try {
|
|
311
|
-
|
|
312
|
-
const s =
|
|
313
|
-
(
|
|
306
|
+
D("@prettier/plugin-xml", o, r);
|
|
307
|
+
const s = N(), { node: a } = n, g = a.quasis.map(
|
|
308
|
+
(d, i, { length: l }) => i === l - 1 ? d.value.cooked : d.value.cooked + `${s}-${i}`
|
|
314
309
|
).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 (!
|
|
310
|
+
let u = "", b = 0;
|
|
311
|
+
const f = /^\s+/.exec(g);
|
|
312
|
+
f && (b = f.index + f[0].length, u = " ");
|
|
313
|
+
const $ = /\s$/.test(g) ? " " : "", _ = k(n, t), v = await e(g.slice(b), {
|
|
314
|
+
parser: G
|
|
315
|
+
}), h = ke(v, (d) => {
|
|
316
|
+
if (typeof d != "string")
|
|
317
|
+
return d;
|
|
318
|
+
const i = [], l = d.split(new RegExp(s + "-(\\d+)", "g"));
|
|
319
|
+
for (let p = 0; p < l.length; p++) {
|
|
320
|
+
let c = l[p];
|
|
321
|
+
if (p % 2 == 0) {
|
|
322
|
+
if (!c)
|
|
328
323
|
continue;
|
|
329
|
-
|
|
324
|
+
c = c.replaceAll(/([\\`]|\${)/g, "\\$1"), i.push(c);
|
|
330
325
|
} else {
|
|
331
|
-
const
|
|
332
|
-
i.push(_[
|
|
326
|
+
const m = Number(c);
|
|
327
|
+
i.push(_[m]);
|
|
333
328
|
}
|
|
334
329
|
}
|
|
335
330
|
return i;
|
|
336
|
-
}),
|
|
337
|
-
return
|
|
331
|
+
}), y = o.xmlWhitespaceSensitivity === "ignore" ? we : u && $ ? Oe : null;
|
|
332
|
+
return y ? w([
|
|
338
333
|
"`",
|
|
339
|
-
|
|
340
|
-
|
|
334
|
+
Te([y, w(h)]),
|
|
335
|
+
y,
|
|
341
336
|
"`"
|
|
342
|
-
]) :
|
|
337
|
+
]) : Se(
|
|
343
338
|
{ hug: !1 },
|
|
344
|
-
|
|
339
|
+
w([
|
|
345
340
|
"`",
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
341
|
+
u,
|
|
342
|
+
w(h),
|
|
343
|
+
$,
|
|
349
344
|
"`"
|
|
350
345
|
])
|
|
351
346
|
);
|
|
352
347
|
} catch (s) {
|
|
353
348
|
throw console.error(s), s;
|
|
354
349
|
}
|
|
355
|
-
},
|
|
350
|
+
}, Ne = {
|
|
356
351
|
category: "Global",
|
|
357
352
|
type: "string",
|
|
358
353
|
array: !0,
|
|
359
354
|
default: [{ value: ["xml", "svg"] }],
|
|
360
355
|
description: "Specify embedded XML languages. This requires @prettier/plugin-xml"
|
|
361
|
-
},
|
|
356
|
+
}, je = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
362
357
|
__proto__: null,
|
|
363
|
-
embedder:
|
|
364
|
-
name:
|
|
365
|
-
option:
|
|
366
|
-
parser:
|
|
367
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
368
|
-
"./noop/index.ts":
|
|
369
|
-
"./php/index.ts":
|
|
370
|
-
"./sql/index.ts":
|
|
371
|
-
"./xml/index.ts":
|
|
358
|
+
embedder: De,
|
|
359
|
+
name: G,
|
|
360
|
+
option: Ne,
|
|
361
|
+
parser: Ee
|
|
362
|
+
}, Symbol.toStringTag, { value: "Module" })), I = [], W = {}, R = {}, z = {}, Le = /* @__PURE__ */ Object.assign({
|
|
363
|
+
"./noop/index.ts": Z,
|
|
364
|
+
"./php/index.ts": fe,
|
|
365
|
+
"./sql/index.ts": qe,
|
|
366
|
+
"./xml/index.ts": je
|
|
372
367
|
});
|
|
373
|
-
Object.values(
|
|
374
|
-
|
|
368
|
+
Object.values(Le).forEach(({ name: e, parser: t, embedder: n, option: o }) => {
|
|
369
|
+
se(I, e, M), t && (W[e] = t), n && (R[e] = n), z[e] = o;
|
|
375
370
|
});
|
|
376
|
-
const
|
|
371
|
+
const Qe = {
|
|
377
372
|
// parsers from internal
|
|
378
373
|
// TODO: find out which parsers are required and which are optional
|
|
379
|
-
...
|
|
374
|
+
...Q.parsers,
|
|
375
|
+
...U.parsers,
|
|
380
376
|
...X.parsers,
|
|
381
|
-
...
|
|
382
|
-
...
|
|
377
|
+
...H.parsers,
|
|
378
|
+
...V.parsers,
|
|
383
379
|
// parsers from this plugin
|
|
384
|
-
...
|
|
385
|
-
}, { estree:
|
|
380
|
+
...W
|
|
381
|
+
}, { estree: O } = K, Ae = function(e, t) {
|
|
386
382
|
var o;
|
|
387
383
|
const { node: n } = e;
|
|
388
384
|
if (n.type !== "TemplateLiteral" || n.quasis.some(({ value: { cooked: r } }) => r === null))
|
|
389
385
|
return null;
|
|
390
|
-
for (const r of
|
|
386
|
+
for (const r of I) {
|
|
391
387
|
const s = t[r];
|
|
392
388
|
if (!s)
|
|
393
389
|
continue;
|
|
394
|
-
const a =
|
|
390
|
+
const a = Be(
|
|
395
391
|
e,
|
|
396
392
|
s,
|
|
397
393
|
t.noEmbeddedDetectionByComment ?? []
|
|
398
|
-
) ??
|
|
394
|
+
) ?? Fe(e, s, t.noEmbeddedDetectionByTag ?? []);
|
|
399
395
|
if (a === void 0)
|
|
400
396
|
continue;
|
|
401
|
-
const
|
|
402
|
-
if (!
|
|
397
|
+
const g = R[r];
|
|
398
|
+
if (!g)
|
|
403
399
|
return null;
|
|
404
|
-
const
|
|
405
|
-
return
|
|
406
|
-
const
|
|
407
|
-
return
|
|
408
|
-
{ embed: !0, ...
|
|
409
|
-
|
|
400
|
+
const u = e.node;
|
|
401
|
+
return u.quasis.length === 1 && u.quasis[0].value.raw.trim() === "" ? "``" : async (...b) => {
|
|
402
|
+
const f = await g(...b, a, s);
|
|
403
|
+
return q.label(
|
|
404
|
+
{ embed: !0, ...f.label },
|
|
405
|
+
f
|
|
410
406
|
);
|
|
411
407
|
};
|
|
412
408
|
}
|
|
413
|
-
return ((o =
|
|
409
|
+
return ((o = O.embed) == null ? void 0 : o.call(O, e, t)) ?? null;
|
|
414
410
|
};
|
|
415
|
-
function
|
|
411
|
+
function Be({ node: e, parent: t }, n, o) {
|
|
416
412
|
if (n.length === 0 || e.type !== "TemplateLiteral")
|
|
417
413
|
return;
|
|
418
414
|
const r = e.comments ?? (t == null ? void 0 : t.comments);
|
|
419
415
|
if (!r)
|
|
420
416
|
return;
|
|
421
417
|
const s = r[r.length - 1];
|
|
422
|
-
if (!(
|
|
418
|
+
if (!(![
|
|
419
|
+
"MultiLine",
|
|
420
|
+
// meriyah
|
|
421
|
+
"Block",
|
|
422
|
+
// typescript, acorn, espree, flow
|
|
423
|
+
"CommentBlock"
|
|
424
|
+
// babel, babel-flow, babel-ts
|
|
425
|
+
].includes(s.type) || !s.leading)) {
|
|
423
426
|
for (const a of n)
|
|
424
427
|
if (` ${a} ` === s.value && !o.includes(a))
|
|
425
428
|
return a;
|
|
426
429
|
}
|
|
427
430
|
}
|
|
428
|
-
function
|
|
431
|
+
function Fe({ node: e, parent: t }, n, o) {
|
|
429
432
|
if (n.length !== 0 && !(e.type !== "TemplateLiteral" || (t == null ? void 0 : t.type) !== "TaggedTemplateExpression" || t.tag.type !== "Identifier")) {
|
|
430
433
|
for (const r of n)
|
|
431
434
|
if (t.tag.name === r && !o.includes(r))
|
|
432
435
|
return r;
|
|
433
436
|
}
|
|
434
437
|
}
|
|
435
|
-
const
|
|
438
|
+
const Ue = {
|
|
436
439
|
estree: {
|
|
437
|
-
...
|
|
438
|
-
embed:
|
|
440
|
+
...O,
|
|
441
|
+
embed: Ae
|
|
439
442
|
}
|
|
440
|
-
},
|
|
441
|
-
...
|
|
443
|
+
}, Xe = {
|
|
444
|
+
...z,
|
|
442
445
|
noEmbeddedDetectionByComment: {
|
|
443
446
|
category: "Global",
|
|
444
447
|
type: "string",
|
|
@@ -455,11 +458,11 @@ const Ke = {
|
|
|
455
458
|
}
|
|
456
459
|
};
|
|
457
460
|
export {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
461
|
+
R as embeddedEmbedders,
|
|
462
|
+
I as embeddedNames,
|
|
463
|
+
z as embeddedOptions,
|
|
464
|
+
W as embeddedParsers,
|
|
465
|
+
Xe as options,
|
|
466
|
+
Qe as parsers,
|
|
467
|
+
Ue as printers
|
|
465
468
|
};
|
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/dist/parsers.d.ts
CHANGED
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.6",
|
|
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",
|