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.
@@ -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
- export interface PrettierPluginEmbedOptions {
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
- export interface PrettierPluginEmbedOptions {
15
- [name]?: string[];
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, PrettierPluginEmbedOptions {
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 "./sql/index.js";
8
- import * as __glob__0_2 from "./php/index.js";
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
- export interface PrettierPluginEmbedOptions {
16
- [name]?: SqlFormatterLanguage[] | NodeSqlParserDataBase[] | string[];
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, PrettierPluginEmbedOptions {
19
+ interface Options extends PrettierPluginDepsOptions {
20
20
  }
21
21
  }
@@ -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: string]: Parser | undefined;
5
+ [name: EmbeddedNameConvention]: Parser | undefined;
5
6
  }
6
7
  export interface EmbeddedEmbedders {
7
- [name: string]: Embedder<Options> | undefined;
8
+ [name: EmbeddedNameConvention]: Embedder<Options> | undefined;
8
9
  }
9
10
  export interface EmbeddedOptions {
10
- [name: string]: SupportOption | undefined;
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 {};
@@ -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
- export interface PrettierPluginEmbedOptions {
16
- [name]?: string[];
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, PrettierPluginEmbedOptions {
19
+ interface Options extends PrettierPluginDepsOptions {
20
20
  }
21
21
  }
package/dist/index.js CHANGED
@@ -1,71 +1,47 @@
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 P = "embeddedNoop", ee = {
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
- }, te = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
15
+ }, Z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
15
16
  __proto__: null,
16
- name: P,
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))
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 = le([ce([I, o]), I])), ["${", o, ae, "}"];
24
+ return (r = n == null ? void 0 : n.comments) != null && r.length && (o = te([ne([j, o]), j])), ["${", o, re, "}"];
54
25
  }
55
- function j(e, t) {
26
+ function k(e, t) {
56
27
  return e.map(
57
- (n) => ue(n, t),
28
+ (n) => oe(n, t),
58
29
  "expressions"
59
30
  );
60
31
  }
61
- function A(e, t, n) {
32
+ function D(e, t, n) {
62
33
  var o;
63
- if (!(((o = t.plugins) == null ? void 0 : o.map((r) => r.name)) ?? []).includes(e))
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 de(e, t, n) {
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
- const { label: pe, hardline: me, line: ge, group: w, indent: fe } = E, { mapDoc: be } = N, ye = async (e, t, n, o, r) => {
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
- 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}`
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 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), {
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 $ = be(q, (i) => {
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 = [], 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)
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
- f = f.replaceAll(/([\\`]|\${)/g, "\\$1"), l.push(f);
101
+ m = m.replaceAll(/([\\`]|\${)/g, "\\$1"), l.push(m);
107
102
  } else {
108
- const v = Number(f);
109
- l.push(_[v]);
103
+ const x = Number(m);
104
+ l.push(_[x]);
110
105
  }
111
106
  }
112
107
  return l;
113
- }), p = h ? me : d && x ? ge : null;
114
- return p ? w([
108
+ }), d = h ? le : u && $ ? ae : null;
109
+ return d ? E([
115
110
  "`",
116
- fe([p, w($)]),
117
- p,
111
+ ce([d, E(y)]),
112
+ d,
118
113
  "`"
119
- ]) : pe(
114
+ ]) : ie(
120
115
  { hug: !1 },
121
- w([
116
+ E([
122
117
  "`",
123
- d,
124
- w([$]),
125
- x,
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
- }, he = {
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
- }, $e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
133
+ }, fe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
139
134
  __proto__: null,
140
- embedder: ye,
141
- name: ne,
142
- option: he
143
- }, Symbol.toStringTag, { value: "Module" })), xe = "embeddedSql", _e = {
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
- }, C = [
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
- ], G = [
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: ve, hardline: U, group: O, line: qe, indent: Ee } = E, { mapDoc: Se } = N, we = async (e, t, n, o, r, s) => {
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
- 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);
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 q = await e(d, {
178
+ const v = await e(u, {
184
179
  parser: "sql",
185
180
  ..._
186
181
  });
187
182
  let h = !1;
188
- const $ = Se(q, (i) => {
183
+ const y = $e(v, (i) => {
189
184
  if (typeof i != "string")
190
185
  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)
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
- f = f.replaceAll(/([\\`]|\${)/g, "\\$1"), f.split(/(\n)/).forEach(
198
- (v) => v === `
199
- ` ? (h = !0, l.push(U)) : l.push(v)
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 v = Number(f);
203
- l.push(x[v]);
197
+ const x = Number(m);
198
+ l.push($[x]);
204
199
  }
205
200
  }
206
201
  return l;
207
- }), p = h ? U : y && g ? qe : null;
208
- return p ? O([
202
+ }), d = h ? L : b && f ? he : null;
203
+ return d ? S([
209
204
  "`",
210
- Ee([p, O($)]),
211
- p,
205
+ ye([d, S(y)]),
206
+ d,
212
207
  "`"
213
- ]) : ve(
208
+ ]) : be(
214
209
  { hug: !1 },
215
- O([
210
+ S([
216
211
  "`",
217
- y,
218
- O($),
219
- g,
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
- }, Oe = {
227
- "sql-formatter": (e) => C.includes(e),
228
- "node-sql-parser": (e) => G.includes(e)
221
+ }, xe = {
222
+ "sql-formatter": (e) => P.includes(e),
223
+ "node-sql-parser": (e) => C.includes(e)
229
224
  };
230
- function R(e, t) {
225
+ function A(e, t) {
231
226
  for (const n of t)
232
- if (Oe[n](e))
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 = R(e, n);
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 = R(t[s], n), o)
239
+ if (o = A(t[s], n), o)
245
240
  return o;
246
241
  }
247
- function Te(e, t, n) {
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 De = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
251
+ const qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
257
252
  __proto__: null,
258
- NODE_SQL_PARSER_DATABASES: G,
259
- SQL_FORMATTER_LANGUAGES: C,
260
- embedder: we,
261
- name: xe,
262
- option: _e
263
- }, Symbol.toStringTag, { value: "Module" })), W = "embeddedXml";
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 Ne = {
265
+ const Ee = {
271
266
  parse(e) {
272
- const { lexErrors: t, parseErrors: n, cst: o } = Y(e);
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: ke, hardline: je, line: Ae, group: T, indent: Le } = E, { mapDoc: Ie } = N, Ue = async (e, t, n, o, r) => {
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
- 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}`
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 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: W
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)
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
- u = u.replaceAll(/([\\`]|\${)/g, "\\$1"), i.push(u);
324
+ c = c.replaceAll(/([\\`]|\${)/g, "\\$1"), i.push(c);
330
325
  } else {
331
- const f = Number(u);
332
- i.push(_[f]);
326
+ const m = Number(c);
327
+ i.push(_[m]);
333
328
  }
334
329
  }
335
330
  return i;
336
- }), $ = o.xmlWhitespaceSensitivity === "ignore" ? je : d && x ? Ae : null;
337
- return $ ? T([
331
+ }), y = o.xmlWhitespaceSensitivity === "ignore" ? we : u && $ ? Oe : null;
332
+ return y ? w([
338
333
  "`",
339
- Le([$, T(h)]),
340
- $,
334
+ Te([y, w(h)]),
335
+ y,
341
336
  "`"
342
- ]) : ke(
337
+ ]) : Se(
343
338
  { hug: !1 },
344
- T([
339
+ w([
345
340
  "`",
346
- d,
347
- T(h),
348
- x,
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
- }, Re = {
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
- }, Be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
356
+ }, je = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
362
357
  __proto__: null,
363
- embedder: Ue,
364
- name: W,
365
- option: Re,
366
- parser: Ne
367
- }, Symbol.toStringTag, { value: "Module" })), M = [], 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
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(Fe).forEach(({ name: e, parser: t, embedder: n, option: o }) => {
374
- de(M, e, P), t && (z[e] = t), n && (V[e] = n), Q[e] = o;
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 Je = {
371
+ const Qe = {
377
372
  // parsers from internal
378
373
  // TODO: find out which parsers are required and which are optional
379
- ...H.parsers,
374
+ ...Q.parsers,
375
+ ...U.parsers,
380
376
  ...X.parsers,
381
- ...J.parsers,
382
- ...K.parsers,
377
+ ...H.parsers,
378
+ ...V.parsers,
383
379
  // parsers from this plugin
384
- ...z
385
- }, { estree: D } = Z, Pe = function(e, t) {
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 M) {
386
+ for (const r of I) {
391
387
  const s = t[r];
392
388
  if (!s)
393
389
  continue;
394
- const a = Ce(
390
+ const a = Be(
395
391
  e,
396
392
  s,
397
393
  t.noEmbeddedDetectionByComment ?? []
398
- ) ?? Ge(e, s, t.noEmbeddedDetectionByTag ?? []);
394
+ ) ?? Fe(e, s, t.noEmbeddedDetectionByTag ?? []);
399
395
  if (a === void 0)
400
396
  continue;
401
- const b = V[r];
402
- if (!b)
397
+ const g = R[r];
398
+ if (!g)
403
399
  return null;
404
- const d = e.node;
405
- return d.quasis.length === 1 && d.quasis[0].value.raw.trim() === "" ? "``" : async (...y) => {
406
- const g = await b(...y, a, s);
407
- return E.label(
408
- { embed: !0, ...g.label },
409
- g
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 = D.embed) == null ? void 0 : o.call(D, e, t)) ?? null;
409
+ return ((o = O.embed) == null ? void 0 : o.call(O, e, t)) ?? null;
414
410
  };
415
- function Ce({ node: e, parent: t }, n, o) {
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 (!(s.type !== "Block" || !s.leading)) {
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 Ge({ node: e, parent: t }, n, o) {
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 Ke = {
438
+ const Ue = {
436
439
  estree: {
437
- ...D,
438
- embed: Pe
440
+ ...O,
441
+ embed: Ae
439
442
  }
440
- }, Ye = {
441
- ...Q,
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
- V as embeddedEmbedders,
459
- M as embeddedNames,
460
- Q as embeddedOptions,
461
- z as embeddedParsers,
462
- Ye as options,
463
- Je as parsers,
464
- Ke as printers
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 "prettier" {
4
- interface Options {
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
@@ -1,5 +1,6 @@
1
1
  export declare const parsers: {
2
2
  embeddedXml: import("prettier").Parser<any>;
3
+ meriyah: import("prettier").Parser<any>;
3
4
  typescript: import("prettier").Parser<any>;
4
5
  flow: import("prettier").Parser<any>;
5
6
  acorn: import("prettier").Parser<any>;
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.4",
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",