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