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.
@@ -1,2 +1,2 @@
1
1
  export * from "./register.js";
2
- export type { EmbeddedNames, EmbeddedParsers, EmbeddedEmbedders, EmbeddedOptions, } from "./types.js";
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
- 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
- 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
- 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
  }
@@ -1,5 +1,9 @@
1
- import type { EmbeddedEmbedders, EmbeddedNames, EmbeddedParsers, EmbeddedOptions } from "./types.js";
2
- export declare const embeddedNames: 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
- 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
- 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: 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
- export type EmbeddedNames = keyof EmbeddedNamesHolder;
15
+ export type EmbeddedName = keyof EmbeddedNamesHolder;
16
+ export interface PrettierPluginEmbedOptions {
17
+ }
18
+ declare module "prettier" {
19
+ interface Options extends PrettierPluginEmbedOptions {
20
+ }
21
+ }
22
+ export {};
@@ -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
- 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,46 @@
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 = {
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
- }, te = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
14
+ }, Y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
15
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))
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 = le([ce([U, o]), U])), ["${", o, ae, "}"];
23
+ return (r = n == null ? void 0 : n.comments) != null && r.length && (o = ee([te([j, o]), j])), ["${", o, ne, "}"];
54
24
  }
55
- function j(e, t) {
25
+ function D(e, t) {
56
26
  return e.map(
57
- (n) => ue(n, t),
27
+ (n) => re(n, t),
58
28
  "expressions"
59
29
  );
60
30
  }
61
- function A(e, t, n) {
31
+ function N(e, t, n) {
62
32
  var o;
63
- if (!(((o = t.plugins) == null ? void 0 : o.map((r) => r.name)) ?? []).includes(e))
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 de(e, t, n) {
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
- const { label: pe, hardline: me, line: ge, group: w, indent: fe } = E, { mapDoc: be } = N, ye = async (e, t, n, o, r) => {
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
- 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}`
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 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), {
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 $ = be(q, (i) => {
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 = [], 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)
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
- f = f.replaceAll(/([\\`]|\${)/g, "\\$1"), l.push(f);
100
+ m = m.replaceAll(/([\\`]|\${)/g, "\\$1"), l.push(m);
107
101
  } else {
108
- const v = Number(f);
109
- l.push(_[v]);
102
+ const x = Number(m);
103
+ l.push(_[x]);
110
104
  }
111
105
  }
112
106
  return l;
113
- }), p = h ? me : d && x ? ge : null;
114
- return p ? w([
107
+ }), d = h ? ie : u && $ ? le : null;
108
+ return d ? E([
115
109
  "`",
116
- fe([p, w($)]),
117
- p,
110
+ ae([d, E(y)]),
111
+ d,
118
112
  "`"
119
- ]) : pe(
113
+ ]) : se(
120
114
  { hug: !1 },
121
- w([
115
+ E([
122
116
  "`",
123
- d,
124
- w([$]),
125
- x,
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
- }, he = {
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
- }, $e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
132
+ }, pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
139
133
  __proto__: null,
140
- embedder: ye,
141
- name: ne,
142
- option: he
143
- }, Symbol.toStringTag, { value: "Module" })), xe = "embeddedSql", _e = {
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
- }, G = [
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
- ], W = [
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: ve, hardline: R, group: O, line: qe, indent: Ee } = E, { mapDoc: Se } = N, we = async (e, t, n, o, r, s) => {
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
- 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);
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 q = await e(d, {
177
+ const v = await e(u, {
184
178
  parser: "sql",
185
179
  ..._
186
180
  });
187
181
  let h = !1;
188
- const $ = Se(q, (i) => {
182
+ const y = ye(v, (i) => {
189
183
  if (typeof i != "string")
190
184
  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)
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
- f = f.replaceAll(/([\\`]|\${)/g, "\\$1"), f.split(/(\n)/).forEach(
198
- (v) => v === `
199
- ` ? (h = !0, l.push(R)) : l.push(v)
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 v = Number(f);
203
- l.push(x[v]);
196
+ const x = Number(m);
197
+ l.push($[x]);
204
198
  }
205
199
  }
206
200
  return l;
207
- }), p = h ? R : y && g ? qe : null;
208
- return p ? O([
201
+ }), d = h ? A : b && f ? be : null;
202
+ return d ? S([
209
203
  "`",
210
- Ee([p, O($)]),
211
- p,
204
+ he([d, S(y)]),
205
+ d,
212
206
  "`"
213
- ]) : ve(
207
+ ]) : ge(
214
208
  { hug: !1 },
215
- O([
209
+ S([
216
210
  "`",
217
- y,
218
- O($),
219
- g,
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
- }, Oe = {
227
- "sql-formatter": (e) => G.includes(e),
228
- "node-sql-parser": (e) => W.includes(e)
220
+ }, _e = {
221
+ "sql-formatter": (e) => C.includes(e),
222
+ "node-sql-parser": (e) => G.includes(e)
229
223
  };
230
- function B(e, t) {
224
+ function L(e, t) {
231
225
  for (const n of t)
232
- if (Oe[n](e))
226
+ if (_e[n](e))
233
227
  return {
234
228
  formatter: n,
235
229
  language: e
236
230
  };
237
231
  }
238
- function F(e, t, n) {
239
- let o = B(e, n);
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 = B(t[s], n), o)
238
+ if (o = L(t[s], n), o)
245
239
  return o;
246
240
  }
247
- function Te(e, t, n) {
248
- return e.formatter === "sql-formatter" ? F(t, n, [
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
- ]) : F(t, n, [
245
+ ]) : B(t, n, [
252
246
  "node-sql-parser",
253
247
  "sql-formatter"
254
248
  ]);
255
249
  }
256
- const De = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
250
+ const ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
257
251
  __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) {
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 Ne = {
264
+ const qe = {
271
265
  parse(e) {
272
- const { lexErrors: t, parseErrors: n, cst: o } = Y(e);
266
+ const { lexErrors: t, parseErrors: n, cst: o } = V(e);
273
267
  if (t.length > 0) {
274
268
  const r = t[0];
275
- throw P(r.message, {
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 P(r.message, {
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: ke, hardline: je, line: Ae, group: T, indent: Le } = E, { mapDoc: Ie } = N, Ue = async (e, t, n, o, r) => {
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
- 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}`
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 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)
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
- u = u.replaceAll(/([\\`]|\${)/g, "\\$1"), i.push(u);
323
+ c = c.replaceAll(/([\\`]|\${)/g, "\\$1"), i.push(c);
330
324
  } else {
331
- const f = Number(u);
332
- i.push(_[f]);
325
+ const m = Number(c);
326
+ i.push(_[m]);
333
327
  }
334
328
  }
335
329
  return i;
336
- }), $ = o.xmlWhitespaceSensitivity === "ignore" ? je : d && x ? Ae : null;
337
- return $ ? T([
330
+ }), y = o.xmlWhitespaceSensitivity === "ignore" ? Se : u && $ ? we : null;
331
+ return y ? w([
338
332
  "`",
339
- Le([$, T(h)]),
340
- $,
333
+ Oe([y, w(h)]),
334
+ y,
341
335
  "`"
342
- ]) : ke(
336
+ ]) : Ee(
343
337
  { hug: !1 },
344
- T([
338
+ w([
345
339
  "`",
346
- d,
347
- T(h),
348
- x,
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
- }, Re = {
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
- }, Be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
355
+ }, ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
362
356
  __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
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(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;
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 Je = {
370
+ const Re = {
377
371
  // parsers from internal
378
372
  // TODO: find out which parsers are required and which are optional
379
- ...H.parsers,
373
+ ...Q.parsers,
374
+ ...U.parsers,
380
375
  ...X.parsers,
381
- ...J.parsers,
382
- ...K.parsers,
376
+ ...H.parsers,
383
377
  // parsers from this plugin
384
- ...z
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 L) {
384
+ for (const r of M) {
393
385
  const s = t[r];
394
386
  if (!s)
395
387
  continue;
396
- const a = Ce(
388
+ const a = Le(
397
389
  e,
398
390
  s,
399
- t.disableEmbeddedDetectionByComment ?? []
400
- ) ?? Ge(e, s, t.disableEmbeddedDetectionByTag ?? []);
391
+ t.noEmbeddedDetectionByComment ?? []
392
+ ) ?? Be(e, s, t.noEmbeddedDetectionByTag ?? []);
401
393
  if (a === void 0)
402
394
  continue;
403
- const b = V[r];
404
- if (!b)
395
+ const g = R[r];
396
+ if (!g)
405
397
  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
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 = D.embed) == null ? void 0 : o.call(D, e, t)) ?? null;
407
+ return ((o = O.embed) == null ? void 0 : o.call(O, e, t)) ?? null;
416
408
  };
417
- function Ce({ node: e, parent: t }, n, o) {
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 Ge({ node: e, parent: t }, n, o) {
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 Ke = {
429
+ const ze = {
438
430
  estree: {
439
- ...D,
440
- embed: Pe
431
+ ...O,
432
+ embed: Ae
441
433
  }
442
- }, Ye = {
443
- ...Q,
444
- disableEmbeddedDetectionByComment: {
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
- disableEmbeddedDetectionByTag: {
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
- 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
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
@@ -1,4 +1,4 @@
1
- import { Options, Doc, AstPath } from "prettier";
1
+ import type { Options, Doc, AstPath } from "prettier";
2
2
  import type { Node as EsTreeNode, TemplateLiteral, Comment } from "estree";
3
3
  export type PrettierNode = EsTreeNode & {
4
4
  comments?: (Comment & {
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.3",
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
- "postbuild": "tsc",
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"