prettier-plugin-embed 0.0.3 → 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 +3 -7
- package/dist/embedded/php/option.d.ts +9 -9
- package/dist/embedded/register.d.ts +6 -2
- package/dist/embedded/sql/option.d.ts +9 -9
- package/dist/embedded/types.d.ts +14 -6
- package/dist/embedded/utils.d.ts +4 -3
- package/dist/embedded/xml/option.d.ts +9 -9
- package/dist/index.js +203 -211
- package/dist/options.d.ts +8 -3
- package/dist/types.d.ts +1 -1
- package/package.json +5 -6
package/dist/embedded/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./register.js";
|
|
2
|
-
export type {
|
|
2
|
+
export type { EmbeddedName, EmbeddedParsers, EmbeddedEmbedders, EmbeddedOptions, PrettierPluginEmbedOptions, } from "./types.js";
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { SupportOption } from "prettier";
|
|
1
|
+
import type { SupportOption } from "prettier";
|
|
2
2
|
import { name } from "./name.js";
|
|
3
3
|
export declare const option: SupportOption;
|
|
4
4
|
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
|
-
import { SupportOption } from "prettier";
|
|
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
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type { EmbeddedEmbedders,
|
|
2
|
-
export declare const embeddedNames:
|
|
1
|
+
import type { EmbeddedEmbedders, EmbeddedName, EmbeddedParsers, EmbeddedOptions } from "./types.js";
|
|
2
|
+
export declare const embeddedNames: EmbeddedName[];
|
|
3
3
|
export declare const embeddedParsers: EmbeddedParsers;
|
|
4
4
|
export declare const embeddedEmbedders: EmbeddedEmbedders;
|
|
5
5
|
export declare const embeddedOptions: EmbeddedOptions;
|
|
6
|
+
import * as __glob__0_0 from "./noop/index.js";
|
|
7
|
+
import * as __glob__0_1 from "./php/index.js";
|
|
8
|
+
import * as __glob__0_2 from "./sql/index.js";
|
|
9
|
+
import * as __glob__0_3 from "./xml/index.js";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { SupportOption } from "prettier";
|
|
1
|
+
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
|
-
import { Parser, SupportOption, Options } from "prettier";
|
|
2
|
-
import { Embedder } from "../types.js";
|
|
1
|
+
import type { Parser, SupportOption, Options } from "prettier";
|
|
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
|
-
export type
|
|
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
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Expression, Comment, TemplateLiteral } from "estree";
|
|
2
|
-
import { AstPath, Options } from "prettier";
|
|
1
|
+
import type { Expression, Comment, TemplateLiteral } from "estree";
|
|
2
|
+
import type { AstPath, Options } from "prettier";
|
|
3
3
|
import { builders } from "prettier/doc";
|
|
4
|
-
import { InternalPrintFun } from "../types.js";
|
|
4
|
+
import type { InternalPrintFun } from "../types.js";
|
|
5
5
|
export declare function printTemplateExpression(path: AstPath<Expression & {
|
|
6
6
|
comments?: Comment[];
|
|
7
7
|
}>, print: InternalPrintFun): builders.Doc[];
|
|
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
|
-
import { SupportOption } from "prettier";
|
|
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
|
|
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
|
-
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), I = {
|
|
33
|
-
randomUUID: ie
|
|
34
|
-
};
|
|
35
|
-
function k(e, t, n) {
|
|
36
|
-
if (I.randomUUID && !t && !e)
|
|
37
|
-
return I.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: U, lineSuffixBoundary: ae } = E;
|
|
49
|
-
function ue(e, t) {
|
|
16
|
+
name: P,
|
|
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,72 +56,91 @@ 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,
|
|
147
141
|
default: [{ value: ["sql"] }],
|
|
148
142
|
description: "Specify embedded SQL languages. This requires prettier-plugin-sql"
|
|
149
|
-
},
|
|
143
|
+
}, C = [
|
|
150
144
|
"sql",
|
|
151
145
|
"bigquery",
|
|
152
146
|
"hive",
|
|
@@ -163,7 +157,7 @@ const { label: pe, hardline: me, line: ge, group: w, indent: fe } = E, { mapDoc:
|
|
|
163
157
|
"transactsql",
|
|
164
158
|
"tsql",
|
|
165
159
|
"trino"
|
|
166
|
-
],
|
|
160
|
+
], G = [
|
|
167
161
|
"bigquery",
|
|
168
162
|
"db2",
|
|
169
163
|
"hive",
|
|
@@ -172,107 +166,107 @@ 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
|
-
},
|
|
227
|
-
"sql-formatter": (e) =>
|
|
228
|
-
"node-sql-parser": (e) =>
|
|
220
|
+
}, _e = {
|
|
221
|
+
"sql-formatter": (e) => C.includes(e),
|
|
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
|
-
function
|
|
239
|
-
let o =
|
|
232
|
+
function B(e, t, n) {
|
|
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
|
|
248
|
-
return e.formatter === "sql-formatter" ?
|
|
241
|
+
function xe(e, t, n) {
|
|
242
|
+
return e.formatter === "sql-formatter" ? B(t, n, [
|
|
249
243
|
"sql-formatter",
|
|
250
244
|
"node-sql-parser"
|
|
251
|
-
]) :
|
|
245
|
+
]) : B(t, n, [
|
|
252
246
|
"node-sql-parser",
|
|
253
247
|
"sql-formatter"
|
|
254
248
|
]);
|
|
255
249
|
}
|
|
256
|
-
const
|
|
250
|
+
const ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
257
251
|
__proto__: null,
|
|
258
|
-
NODE_SQL_PARSER_DATABASES:
|
|
259
|
-
SQL_FORMATTER_LANGUAGES:
|
|
260
|
-
embedder:
|
|
261
|
-
name:
|
|
262
|
-
option:
|
|
263
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
264
|
-
function
|
|
252
|
+
NODE_SQL_PARSER_DATABASES: G,
|
|
253
|
+
SQL_FORMATTER_LANGUAGES: C,
|
|
254
|
+
embedder: $e,
|
|
255
|
+
name: fe,
|
|
256
|
+
option: me
|
|
257
|
+
}, Symbol.toStringTag, { value: "Module" })), I = "embeddedXml";
|
|
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
|
-
throw
|
|
269
|
+
throw F(r.message, {
|
|
276
270
|
loc: {
|
|
277
271
|
start: { line: r.line, column: r.column },
|
|
278
272
|
end: {
|
|
@@ -284,7 +278,7 @@ const Ne = {
|
|
|
284
278
|
}
|
|
285
279
|
if (n.length > 0) {
|
|
286
280
|
const r = n[0];
|
|
287
|
-
throw
|
|
281
|
+
throw F(r.message, {
|
|
288
282
|
loc: {
|
|
289
283
|
start: {
|
|
290
284
|
line: r.token.startLine ?? NaN,
|
|
@@ -306,115 +300,113 @@ 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" })),
|
|
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
|
-
}
|
|
386
|
-
console.log(L);
|
|
387
|
-
const { estree: D } = Z, Pe = function(e, t) {
|
|
378
|
+
...W
|
|
379
|
+
}, { estree: O } = J, Ae = function(e, t) {
|
|
388
380
|
var o;
|
|
389
381
|
const { node: n } = e;
|
|
390
382
|
if (n.type !== "TemplateLiteral" || n.quasis.some(({ value: { cooked: r } }) => r === null))
|
|
391
383
|
return null;
|
|
392
|
-
for (const r of
|
|
384
|
+
for (const r of M) {
|
|
393
385
|
const s = t[r];
|
|
394
386
|
if (!s)
|
|
395
387
|
continue;
|
|
396
|
-
const a =
|
|
388
|
+
const a = Le(
|
|
397
389
|
e,
|
|
398
390
|
s,
|
|
399
|
-
t.
|
|
400
|
-
) ??
|
|
391
|
+
t.noEmbeddedDetectionByComment ?? []
|
|
392
|
+
) ?? Be(e, s, t.noEmbeddedDetectionByTag ?? []);
|
|
401
393
|
if (a === void 0)
|
|
402
394
|
continue;
|
|
403
|
-
const
|
|
404
|
-
if (!
|
|
395
|
+
const g = R[r];
|
|
396
|
+
if (!g)
|
|
405
397
|
return null;
|
|
406
|
-
const
|
|
407
|
-
return
|
|
408
|
-
const
|
|
409
|
-
return
|
|
410
|
-
{ embed: !0, ...
|
|
411
|
-
|
|
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
|
|
412
404
|
);
|
|
413
405
|
};
|
|
414
406
|
}
|
|
415
|
-
return ((o =
|
|
407
|
+
return ((o = O.embed) == null ? void 0 : o.call(O, e, t)) ?? null;
|
|
416
408
|
};
|
|
417
|
-
function
|
|
409
|
+
function Le({ node: e, parent: t }, n, o) {
|
|
418
410
|
if (n.length === 0 || e.type !== "TemplateLiteral")
|
|
419
411
|
return;
|
|
420
412
|
const r = e.comments ?? (t == null ? void 0 : t.comments);
|
|
@@ -427,28 +419,28 @@ function Ce({ node: e, parent: t }, n, o) {
|
|
|
427
419
|
return a;
|
|
428
420
|
}
|
|
429
421
|
}
|
|
430
|
-
function
|
|
422
|
+
function Be({ node: e, parent: t }, n, o) {
|
|
431
423
|
if (n.length !== 0 && !(e.type !== "TemplateLiteral" || (t == null ? void 0 : t.type) !== "TaggedTemplateExpression" || t.tag.type !== "Identifier")) {
|
|
432
424
|
for (const r of n)
|
|
433
425
|
if (t.tag.name === r && !o.includes(r))
|
|
434
426
|
return r;
|
|
435
427
|
}
|
|
436
428
|
}
|
|
437
|
-
const
|
|
429
|
+
const ze = {
|
|
438
430
|
estree: {
|
|
439
|
-
...
|
|
440
|
-
embed:
|
|
431
|
+
...O,
|
|
432
|
+
embed: Ae
|
|
441
433
|
}
|
|
442
|
-
},
|
|
443
|
-
...
|
|
444
|
-
|
|
434
|
+
}, Qe = {
|
|
435
|
+
...z,
|
|
436
|
+
noEmbeddedDetectionByComment: {
|
|
445
437
|
category: "Global",
|
|
446
438
|
type: "string",
|
|
447
439
|
array: !0,
|
|
448
440
|
default: [{ value: [] }],
|
|
449
441
|
description: 'This option turns off "/* lang */`...`" comment-based language detection for the specified languages.'
|
|
450
442
|
},
|
|
451
|
-
|
|
443
|
+
noEmbeddedDetectionByTag: {
|
|
452
444
|
category: "Global",
|
|
453
445
|
type: "string",
|
|
454
446
|
array: !0,
|
|
@@ -457,11 +449,11 @@ const Ke = {
|
|
|
457
449
|
}
|
|
458
450
|
};
|
|
459
451
|
export {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
452
|
+
R as embeddedEmbedders,
|
|
453
|
+
M as embeddedNames,
|
|
454
|
+
z as embeddedOptions,
|
|
455
|
+
W as embeddedParsers,
|
|
456
|
+
Qe as options,
|
|
457
|
+
Re as parsers,
|
|
458
|
+
ze as printers
|
|
467
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;
|
|
4
|
+
declare module "./embedded/types.js" {
|
|
5
|
+
interface PrettierPluginEmbedOptions {
|
|
6
|
+
noEmbeddedDetectionByComment?: string[];
|
|
7
|
+
noEmbeddedDetectionByTag?: string[];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
declare module "prettier" {
|
|
4
|
-
interface Options {
|
|
5
|
-
disableEmbeddedDetectionByComment?: string[];
|
|
6
|
-
disableEmbeddedDetectionByTag?: string[];
|
|
11
|
+
interface Options extends PrettierPluginEmbedOptions {
|
|
7
12
|
}
|
|
8
13
|
}
|
package/dist/types.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.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"./dist"
|
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
"format": "prettier . --write",
|
|
47
47
|
"prebuild": "npm run lint && npm run type-check && npm run format",
|
|
48
48
|
"build": "vite build",
|
|
49
|
-
"
|
|
49
|
+
"add-glob-import-types": "tsx ./scripts/add-glob-import-types.ts",
|
|
50
|
+
"postbuild": "tsc --project ./tsconfig.production.json && npm run add-glob-import-types",
|
|
50
51
|
"test": "vitest",
|
|
51
52
|
"test:ui": "vitest --ui",
|
|
52
53
|
"preview": "vite preview",
|
|
@@ -54,9 +55,6 @@
|
|
|
54
55
|
"ncu": "npx npm-check-updates -u",
|
|
55
56
|
"postncu": "npm i"
|
|
56
57
|
},
|
|
57
|
-
"dependencies": {
|
|
58
|
-
"uuid": "^9.0.1"
|
|
59
|
-
},
|
|
60
58
|
"devDependencies": {
|
|
61
59
|
"@commitlint/cli": "^17.7.2",
|
|
62
60
|
"@commitlint/config-conventional": "^17.7.0",
|
|
@@ -64,7 +62,6 @@
|
|
|
64
62
|
"@prettier/plugin-xml": "^3.2.1",
|
|
65
63
|
"@semantic-release/git": "^10.0.1",
|
|
66
64
|
"@types/estree": "^1.0.2",
|
|
67
|
-
"@types/uuid": "^9.0.4",
|
|
68
65
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
69
66
|
"@typescript-eslint/parser": "^6.7.4",
|
|
70
67
|
"@vitest/browser": "^0.34.6",
|
|
@@ -72,10 +69,12 @@
|
|
|
72
69
|
"@vitest/ui": "^0.34.6",
|
|
73
70
|
"code-tag": "^1.1.0",
|
|
74
71
|
"eslint": "^8.50.0",
|
|
72
|
+
"fast-glob": "^3.3.1",
|
|
75
73
|
"npm-check-updates": "^16.14.5",
|
|
76
74
|
"playwright": "^1.38.1",
|
|
77
75
|
"prettier-plugin-sql": "^0.15.1",
|
|
78
76
|
"semantic-release": "^22.0.5",
|
|
77
|
+
"tsx": "^3.13.0",
|
|
79
78
|
"typescript": "^5.2.2",
|
|
80
79
|
"vite": "^4.4.11",
|
|
81
80
|
"vitest": "^0.34.6"
|