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