Socket
Socket
Sign inDemoInstall

prettier-plugin-embed

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-embed - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

dist/embedded/index.d.ts

2

dist/index.d.ts
export { parsers } from "./parsers.js";
export { printers } from "./printers.js";
export { options } from "./options.js";
export type * from "./options.js";
export type * from "./types.js";

@@ -1,146 +0,319 @@

import L from "prettier/parser-babel";
import R from "prettier/parser-espree";
import S from "prettier/parser-flow";
import k from "prettier/parser-typescript";
import { printers as A } from "prettier/plugins/estree.mjs";
import { builders as $, utils as V } from "prettier/doc";
const oe = {
...L.parsers,
...R.parsers,
...S.parsers,
...k.parsers
import P from "prettier/parser-babel";
import F from "prettier/parser-espree";
import W from "prettier/parser-flow";
import _ from "prettier/parser-typescript";
import { parse as j } from "@xml-tools/parser";
import { builders as S, utils as I } from "prettier/doc";
import { printers as B } from "prettier/plugins/estree.mjs";
const q = "embeddedXml";
function L(e, t) {
const r = new SyntaxError(
e + " (" + t.loc.start.line + ":" + t.loc.start.column + ")"
);
return Object.assign(r, t);
}
const G = {
parse(e) {
const { lexErrors: t, parseErrors: r, cst: o } = j(e);
if (t.length > 0) {
const n = t[0];
throw L(n.message, {
loc: {
start: { line: n.line, column: n.column },
end: {
line: n.line,
column: n.column + n.length
}
}
});
}
if (r.length > 0) {
const n = r[0];
throw L(n.message, {
loc: {
start: {
line: n.token.startLine ?? NaN,
column: n.token.startColumn ?? NaN
},
end: {
line: n.token.endLine ?? NaN,
column: n.token.endColumn ?? NaN
}
}
});
}
return o;
},
astFormat: "xml",
locStart(e) {
return e.location.startOffset;
},
locEnd(e) {
return e.location.endOffset ?? NaN;
}
};
let f;
const q = new Uint8Array(16);
function C() {
if (!f && (f = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !f))
let $;
const V = new Uint8Array(16);
function Q() {
if (!$ && ($ = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !$))
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
return f(q);
return $(V);
}
const o = [];
const s = [];
for (let e = 0; e < 256; ++e)
o.push((e + 256).toString(16).slice(1));
function H(e, n = 0) {
return o[e[n + 0]] + o[e[n + 1]] + o[e[n + 2]] + o[e[n + 3]] + "-" + o[e[n + 4]] + o[e[n + 5]] + "-" + o[e[n + 6]] + o[e[n + 7]] + "-" + o[e[n + 8]] + o[e[n + 9]] + "-" + o[e[n + 10]] + o[e[n + 11]] + o[e[n + 12]] + o[e[n + 13]] + o[e[n + 14]] + o[e[n + 15]];
s.push((e + 256).toString(16).slice(1));
function z(e, t = 0) {
return s[e[t + 0]] + s[e[t + 1]] + s[e[t + 2]] + s[e[t + 3]] + "-" + s[e[t + 4]] + s[e[t + 5]] + "-" + s[e[t + 6]] + s[e[t + 7]] + "-" + s[e[t + 8]] + s[e[t + 9]] + "-" + s[e[t + 10]] + s[e[t + 11]] + s[e[t + 12]] + s[e[t + 13]] + s[e[t + 14]] + s[e[t + 15]];
}
const W = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), v = {
randomUUID: W
const M = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), U = {
randomUUID: M
};
function _(e, n, r) {
if (v.randomUUID && !n && !e)
return v.randomUUID();
function O(e, t, r) {
if (U.randomUUID && !t && !e)
return U.randomUUID();
e = e || {};
const t = e.random || (e.rng || C)();
if (t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128, n) {
const o = e.random || (e.rng || Q)();
if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, t) {
r = r || 0;
for (let s = 0; s < 16; ++s)
n[r + s] = t[s];
return n;
for (let n = 0; n < 16; ++n)
t[r + n] = o[n];
return t;
}
return H(t);
return z(o);
}
const { label: j, softline: I, hardline: B, line: F, group: a, indent: h, lineSuffixBoundary: G } = $, { mapDoc: N } = V, T = _(), O = new RegExp(T + "-(\\d+)", "g");
async function X(e, n, r, t) {
const { group: X, indent: H, softline: k, lineSuffixBoundary: J } = S;
function K(e, t) {
var n;
const { node: r } = e;
let o = t();
return (n = r == null ? void 0 : r.comments) != null && n.length && (o = X([H([k, o]), k])), ["${", o, J, "}"];
}
function C(e, t) {
return e.map(
(r) => K(r, t),
"expressions"
);
}
const { label: Y, hardline: Z, line: ee, group: E, indent: te } = S, { mapDoc: ne } = I, re = async (e, t, r, o) => {
try {
const { node: s } = r, i = s.quasis.map(
(u, p, { length: g }) => p === g - 1 ? u.value.cooked : u.value.cooked + J(p)
).join(""), d = z(r, n), U = 0, m = await e(i, {
parser: "xml"
}), l = N(m, (u) => {
if (typeof u != "string")
return u;
const p = [], g = u.split(O);
for (let y = 0; y < g.length; y++) {
let c = g[y];
if (y % 2 == 0) {
c && (c = c.replaceAll(/([\\`]|\${)/g, "\\$1"), t.__embeddedInHtml && (c = c.replaceAll(/<\/(?=script\b)/gi, "<\\/")), p.push(c));
continue;
const n = O(), { node: i } = r, p = i.quasis.map(
(l, c, { length: u }) => c === u - 1 ? l.value.cooked : l.value.cooked + `${n}-${c}`
).join("");
let d = "", g = 0;
const f = /^\s+/.exec(p);
f && (g = f.index + f[0].length, d = " ");
const y = /\s$/.test(p) ? " " : "", b = C(r, t), N = await e(p.slice(g), {
parser: q
}), x = ne(N, (l) => {
if (typeof l != "string")
return l;
const c = [], u = l.split(new RegExp(n + "-(\\d+)", "g"));
for (let m = 0; m < u.length; m++) {
let a = u[m];
if (m % 2 == 0) {
if (!a)
continue;
a = a.replaceAll(/([\\`]|\${)/g, "\\$1"), c.push(a);
} else {
const T = Number(a);
c.push(b[T]);
}
const w = Number(c);
p.push(d[w]);
}
return p;
}), E = /^\s/.test(i) ? " " : "", D = /\s$/.test(i) ? " " : "", x = t.xmlWhitespaceSensitivity === "ignore" ? B : E && D ? F : null;
return x ? a([
return c;
}), h = o.xmlWhitespaceSensitivity === "ignore" ? Z : d && y ? ee : null;
return h ? E([
"`",
h([x, a(l)]),
x,
te([h, E(x)]),
h,
"`"
]) : j(
]) : Y(
{ hug: !1 },
a([
E([
"`",
E,
U > 1 ? h(a(l)) : a(l),
D,
d,
E(x),
y,
"`"
])
);
} catch (s) {
throw console.error(s), s;
} catch (n) {
throw console.error(n), n;
}
}
function J(e) {
return T + "-" + e;
}
function P(e, n) {
var s;
}, oe = {
category: "Global",
type: "string",
array: !0,
default: [{ value: ["xml", "svg"] }],
description: "Config embedded XML formatting. This requires @prettier/plugin-xml"
}, D = "embeddedSql", A = [
"sql",
"bigquery",
"hive",
"mariadb",
"mysql",
"postgresql",
"db2",
"plsql",
"n1ql",
"redshift",
"singlestoredb",
"spark",
"sqlite",
"transactsql",
"tsql",
"trino"
], R = [
"bigquery",
"db2",
"hive",
"mariadb",
"mysql",
"postgresql",
"transactsql",
"flinksql"
], { label: se, hardline: ie, group: w } = S, { mapDoc: le } = I, ce = async (e, t, r, o, n) => {
try {
const i = "p" + O().replaceAll("-", ""), { node: p } = r, d = p.quasis.map(
(l, c, { length: u }) => c === u - 1 ? l.value.cooked : l.value.cooked + `${i}${c}`
).join(""), g = /^\s/.test(d) ? " " : "", f = /\s$/.test(d) ? " " : "", y = C(r, t);
n = n.toLowerCase();
let b = {};
if (o.formatter === "sql-formatter")
if (A.includes(n))
b = {
formatter: "sql-formatter",
language: n
};
else if (R.includes(n))
b = {
formatter: "node-sql-parser",
database: n
};
else
throw new SyntaxError(`Unrecognized language: ${n}`);
else if (R.includes(n))
b = {
formatter: "node-sql-parser",
database: n
};
else if (A.includes(n))
b = {
formatter: "sql-formatter",
language: n
};
else
throw new SyntaxError(`Unrecognized language: ${n}`);
const N = await e(d, {
parser: "sql",
...b
}), x = le(N, (l) => {
if (typeof l != "string")
return l;
const c = [], u = l.split(new RegExp(i + "(\\d+)", "g"));
for (let m = 0; m < u.length; m++) {
let a = u[m];
if (m % 2 == 0) {
if (!a)
continue;
a = a.replaceAll(/([\\`]|\${)/g, "\\$1"), c.push(a);
} else {
const T = Number(a);
c.push(y[T]);
}
}
return c;
}), h = ie;
return h ? w(["`", h, w(x), h, "`"]) : se(
{ hug: !1 },
w([
"`",
g,
w(x),
f,
"`"
])
);
} catch (i) {
throw console.error(i), i;
}
}, ae = {
category: "Global",
type: "string",
array: !0,
default: [{ value: ["sql"] }],
description: "Config embedded SQL formatting. This requires prettier-plugin-sql"
}, de = [
q,
D
], ue = {
[q]: G
}, me = {
[q]: re,
[D]: ce
}, pe = {
[q]: oe,
[D]: ae
}, ve = {
// parsers from internal
...P.parsers,
...F.parsers,
...W.parsers,
..._.parsers,
// parsers from plugin
...ue
}, { estree: v } = B, ge = function(e, t) {
var o;
const { node: r } = e;
let t = n();
return (s = r == null ? void 0 : r.comments) != null && s.length && (t = a([h([I, t]), I])), ["${", t, G, "}"];
}
function z(e, n) {
return e.map(
(r) => P(r, n),
"expressions"
);
}
const K = {
xml: X
}, { estree: b } = A, M = function(e, n) {
var t;
const { node: r } = e;
if (r.type !== "TemplateLiteral" || r.quasis.some(({ value: { cooked: s } }) => s === null))
if (r.type !== "TemplateLiteral" || r.quasis.some(({ value: { cooked: n } }) => n === null))
return null;
for (const { comment: s, tag: i, embedder: d } of JSON.parse(
n.embeddedLanguages ?? "[]"
)) {
if (!Q(e, typeof i == "string" ? [i] : i))
for (const n of de) {
const i = t[n];
if (!i)
continue;
let m;
if (typeof d == "string") {
m = K[d];
const l = e.node;
if (l.quasis.length === 1 && l.quasis[0].value.raw.trim() === "")
return "``";
} else
m = d ?? null;
return m;
const p = fe(e, i) ?? ye(e, i);
if (p === void 0)
continue;
const d = me[n], g = e.node;
return g.quasis.length === 1 && g.quasis[0].value.raw.trim() === "" ? "``" : async (...f) => {
const y = await d(...f, p);
return S.label(
{ embed: !0, ...y.label },
y
);
};
}
return ((t = b.embed) == null ? void 0 : t.call(b, e, n)) ?? null;
return ((o = v.embed) == null ? void 0 : o.call(v, e, t)) ?? null;
};
function Q({ node: e, parent: n }, r) {
for (const t of r)
if (e.type === "TemplateLiteral" && (n == null ? void 0 : n.type) === "TaggedTemplateExpression" && n.tag.type === "Identifier" && n.tag.name === t)
return !0;
return !1;
function fe({ node: e, parent: t }, r) {
if (r.length === 0 || e.type !== "TemplateLiteral")
return;
const o = e.comments ?? (t == null ? void 0 : t.comments);
if (!o)
return;
const n = o[o.length - 1];
if (!(n.type !== "Block" || !n.leading)) {
for (const i of r)
if (` ${i} ` === n.value)
return i;
}
}
const se = {
function ye({ node: e, parent: t }, r) {
if (r.length !== 0 && !(e.type !== "TemplateLiteral" || (t == null ? void 0 : t.type) !== "TaggedTemplateExpression" || t.tag.type !== "Identifier")) {
for (const o of r)
if (t.tag.name === o)
return o;
}
}
const Se = {
estree: {
...b,
embed: M
...v,
embed: ge
}
}, ie = {
embeddedLanguages: {
category: "Global",
type: "string",
array: !1,
default: "[]",
description: "Config embedded languages formatting supported by this plugin."
}
}, Ne = {
...pe
};
export {
ie as options,
oe as parsers,
se as printers
Ne as options,
ve as parsers,
Se as printers
};
import type { SupportOptions } from "prettier";
export declare const options: SupportOptions;
export interface EmbeddedLanguage {
tag: string | string[];
comment: string | string[];
embedder?: string | null;
}
export interface PrettierPluginEmbedOptions {
embeddedLanguages?: string;
}

@@ -1,2 +0,2 @@

import type { Plugin } from "prettier";
import { type Plugin } from "prettier";
export declare const printers: Plugin["printers"];

@@ -5,3 +5,3 @@ {

"private": false,
"version": "0.0.1",
"version": "0.0.2",
"type": "module",

@@ -59,3 +59,6 @@ "files": [

"peerDependencies": {
"prettier": "^3.0.3"
"@xml-tools/parser": "^1.0.11",
"prettier": "^3.0.3",
"@prettier/plugin-xml": "^3.2.1",
"prettier-plugin-sql": "^0.15.1"
},

@@ -65,8 +68,7 @@ "devDependencies": {

"@commitlint/config-conventional": "^17.7.0",
"@prettier/plugin-xml": "^3.2.1",
"@semantic-release/git": "^10.0.1",
"@types/estree": "^1.0.2",
"@types/uuid": "^9.0.4",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"@vitest/browser": "^0.34.6",

@@ -81,3 +83,3 @@ "@vitest/coverage-istanbul": "^0.34.6",

"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite": "^4.4.10",
"vitest": "^0.34.6"

@@ -84,0 +86,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc