@recursive-robot/react-jsx-parser 2.0.1 → 2.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/react-jsx-parser.js
CHANGED
|
@@ -7010,13 +7010,11 @@ var Ht = /* @__PURE__ */ u(((e, t) => {
|
|
|
7010
7010
|
}
|
|
7011
7011
|
})))(), 1), Gt = class e extends Error {
|
|
7012
7012
|
type;
|
|
7013
|
-
|
|
7014
|
-
fileName;
|
|
7013
|
+
sourceInfo;
|
|
7015
7014
|
snippet;
|
|
7016
|
-
source;
|
|
7017
7015
|
cause;
|
|
7018
7016
|
constructor(t, n) {
|
|
7019
|
-
super(t), this.name = "JsxParserError", this.type = n.type, this.
|
|
7017
|
+
super(t), this.name = "JsxParserError", this.type = n.type, this.sourceInfo = n.sourceInfo, this.snippet = n.snippet, this.cause = n.cause, Object.setPrototypeOf(this, e.prototype);
|
|
7020
7018
|
}
|
|
7021
7019
|
};
|
|
7022
7020
|
function Kt(e) {
|
|
@@ -7036,34 +7034,46 @@ function qt(e, t) {
|
|
|
7036
7034
|
function Jt(e, t, n) {
|
|
7037
7035
|
return `**${e}**\n\n${t}\n${n}`;
|
|
7038
7036
|
}
|
|
7039
|
-
function Yt(
|
|
7040
|
-
let
|
|
7041
|
-
return
|
|
7037
|
+
function Yt(e, t, n) {
|
|
7038
|
+
let r = Math.max(0, t), i = e.slice(0, r);
|
|
7039
|
+
return {
|
|
7040
|
+
line: i.split("\n").length,
|
|
7041
|
+
column: r - (i.lastIndexOf("\n") + 1),
|
|
7042
|
+
startOffset: r,
|
|
7043
|
+
endOffset: Math.max(r, n)
|
|
7044
|
+
};
|
|
7045
|
+
}
|
|
7046
|
+
function Xt({ type: e, message: t, source: n, start: r, end: i, fileName: a, cause: o, astNode: s, loopIndex: c }) {
|
|
7047
|
+
let l = Yt(n, r, i), u = qt(n.split("\n"), l.line);
|
|
7048
|
+
return new Gt(Jt(t, `Error occurred at line \`${l.line}\`${a ? ` of \`${a}\`` : ""}:`, u), {
|
|
7042
7049
|
type: e,
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
cause: o
|
|
7050
|
+
snippet: u,
|
|
7051
|
+
cause: o,
|
|
7052
|
+
sourceInfo: {
|
|
7053
|
+
fileName: a,
|
|
7054
|
+
source: n.slice(l.startOffset, l.endOffset),
|
|
7055
|
+
location: l,
|
|
7056
|
+
loopIndex: c,
|
|
7057
|
+
astNode: s
|
|
7058
|
+
}
|
|
7053
7059
|
});
|
|
7054
7060
|
}
|
|
7055
|
-
function
|
|
7061
|
+
function Zt(e) {
|
|
7056
7062
|
let { type: t, message: n, bodyLines: r, line: i, functionName: a, fileName: o, cause: s } = e, c = qt(r, i), l = `line \`${i}\`${o ? ` of \`${o}\`` : ""}`;
|
|
7057
7063
|
return new Gt(Jt(n, a ? `Error occurred in dynamic function \`${a}\` at ${l}:` : `Error occurred at ${l}:`, c), {
|
|
7058
7064
|
type: t,
|
|
7059
|
-
location: { line: i },
|
|
7060
|
-
fileName: o,
|
|
7061
7065
|
snippet: c,
|
|
7062
|
-
|
|
7063
|
-
|
|
7066
|
+
cause: s,
|
|
7067
|
+
sourceInfo: {
|
|
7068
|
+
fileName: o,
|
|
7069
|
+
source: r[i - 1],
|
|
7070
|
+
location: { line: i },
|
|
7071
|
+
loopIndex: void 0,
|
|
7072
|
+
astNode: void 0
|
|
7073
|
+
}
|
|
7064
7074
|
});
|
|
7065
7075
|
}
|
|
7066
|
-
function
|
|
7076
|
+
function Qt(e) {
|
|
7067
7077
|
let t = {
|
|
7068
7078
|
"&": "&",
|
|
7069
7079
|
"<": "<",
|
|
@@ -7075,10 +7085,10 @@ function Zt(e) {
|
|
|
7075
7085
|
}
|
|
7076
7086
|
//#endregion
|
|
7077
7087
|
//#region source/helpers/functionUtilities.ts
|
|
7078
|
-
function
|
|
7088
|
+
function $t(e) {
|
|
7079
7089
|
return e.type === "SpreadElement";
|
|
7080
7090
|
}
|
|
7081
|
-
function
|
|
7091
|
+
function en(e) {
|
|
7082
7092
|
let t = /* @__PURE__ */ new Set(), n = (e, r = /* @__PURE__ */ new Set()) => {
|
|
7083
7093
|
if (e) switch (e.type) {
|
|
7084
7094
|
case "Identifier":
|
|
@@ -7086,7 +7096,7 @@ function $t(e) {
|
|
|
7086
7096
|
break;
|
|
7087
7097
|
case "ArrayExpression":
|
|
7088
7098
|
(e.elements || []).forEach((e) => {
|
|
7089
|
-
if (
|
|
7099
|
+
if ($t(e)) {
|
|
7090
7100
|
n(e.argument, r);
|
|
7091
7101
|
return;
|
|
7092
7102
|
}
|
|
@@ -7158,7 +7168,7 @@ function $t(e) {
|
|
|
7158
7168
|
break;
|
|
7159
7169
|
case "ObjectExpression":
|
|
7160
7170
|
(e.properties || []).forEach((e) => {
|
|
7161
|
-
if (
|
|
7171
|
+
if ($t(e)) {
|
|
7162
7172
|
n(e.argument, r);
|
|
7163
7173
|
return;
|
|
7164
7174
|
}
|
|
@@ -7174,14 +7184,14 @@ function $t(e) {
|
|
|
7174
7184
|
};
|
|
7175
7185
|
return n(e), Array.from(t.values());
|
|
7176
7186
|
}
|
|
7177
|
-
function
|
|
7178
|
-
let
|
|
7179
|
-
return (
|
|
7187
|
+
function tn(e, t, n, r = 0) {
|
|
7188
|
+
let i = I.extend(Wt.default({ autoCloseVoidElements: !0 })).parse(e, { ecmaVersion: "latest" });
|
|
7189
|
+
return (a) => n(e, i.body[0], {
|
|
7180
7190
|
...t,
|
|
7181
|
-
...
|
|
7182
|
-
});
|
|
7191
|
+
...a
|
|
7192
|
+
}, r);
|
|
7183
7193
|
}
|
|
7184
|
-
function
|
|
7194
|
+
function nn(e) {
|
|
7185
7195
|
let t = I.extend(Wt.default({ autoCloseVoidElements: !0 })).parse(`function dummy() ${e}`, { ecmaVersion: "latest" }), n = [], r = (e) => {
|
|
7186
7196
|
if (e) switch (e.type) {
|
|
7187
7197
|
case "JSXElement":
|
|
@@ -7199,18 +7209,18 @@ function tn(e) {
|
|
|
7199
7209
|
};
|
|
7200
7210
|
return r(t), n;
|
|
7201
7211
|
}
|
|
7202
|
-
function
|
|
7203
|
-
let
|
|
7204
|
-
if (
|
|
7205
|
-
let
|
|
7206
|
-
|
|
7207
|
-
}), !
|
|
7208
|
-
let
|
|
7209
|
-
return
|
|
7210
|
-
|
|
7211
|
-
}), [
|
|
7212
|
+
function rn(e, t, n, r = (e) => e) {
|
|
7213
|
+
let i = {}, a = [];
|
|
7214
|
+
if (nn(e).forEach((o, s) => {
|
|
7215
|
+
let c = `renderJSXElementWrapper_${s}`;
|
|
7216
|
+
i[c] = tn(e.slice(o.start, o.end), t, n, r(o.start)), a.push([`${e.slice(o.start, o.end)}`, `__jsxRenderContext__.${c}({ ${en(o).join(", ")} })`]);
|
|
7217
|
+
}), !a.length) return [e, {}];
|
|
7218
|
+
let o = `{ const __jsxRenderContext__ = this;\r\n${e.slice(1)}`;
|
|
7219
|
+
return a.forEach(([e, t]) => {
|
|
7220
|
+
o = o.replace(e, t);
|
|
7221
|
+
}), [o, i];
|
|
7212
7222
|
}
|
|
7213
|
-
function
|
|
7223
|
+
function an(e, t, n = "anonymous", r, i) {
|
|
7214
7224
|
let a = `dynamic-${n}-${Math.random().toString(36).substring(2, 9)}.js`, o = t.match(/^\{{1}([\S\s]*)\}{1}$/)?.[1] ?? t;
|
|
7215
7225
|
o = o.replace(/^\n+|\n+$/g, "");
|
|
7216
7226
|
let s = `//# sourceURL=${a}\n${o}`, c = Function(...e, s);
|
|
@@ -7218,7 +7228,7 @@ function rn(e, t, n = "anonymous", r, i) {
|
|
|
7218
7228
|
try {
|
|
7219
7229
|
return c.apply(this, e);
|
|
7220
7230
|
} catch (e) {
|
|
7221
|
-
let t = e.stack.split("\n").find((e) => e.includes(a)), s = parseInt(t?.match(/:(\d+):/)?.[1], 10) - 3, c = Kt(o.split("\n")), l =
|
|
7231
|
+
let t = e.stack.split("\n").find((e) => e.includes(a)), s = parseInt(t?.match(/:(\d+):/)?.[1], 10) - 3, c = Kt(o.split("\n")), l = Zt({
|
|
7222
7232
|
type: "function-runtime",
|
|
7223
7233
|
message: e.message,
|
|
7224
7234
|
bodyLines: c,
|
|
@@ -7237,13 +7247,13 @@ function rn(e, t, n = "anonymous", r, i) {
|
|
|
7237
7247
|
}
|
|
7238
7248
|
//#endregion
|
|
7239
7249
|
//#region source/constants/attributeNames.ts
|
|
7240
|
-
var
|
|
7250
|
+
var on = {
|
|
7241
7251
|
class: "className",
|
|
7242
7252
|
for: "htmlFor",
|
|
7243
7253
|
maxlength: "maxLength",
|
|
7244
7254
|
colspan: "colSpan",
|
|
7245
7255
|
rowspan: "rowSpan"
|
|
7246
|
-
},
|
|
7256
|
+
}, sn = [
|
|
7247
7257
|
"area",
|
|
7248
7258
|
"base",
|
|
7249
7259
|
"br",
|
|
@@ -7260,45 +7270,45 @@ var an = {
|
|
|
7260
7270
|
"source",
|
|
7261
7271
|
"track",
|
|
7262
7272
|
"wbr"
|
|
7263
|
-
],
|
|
7273
|
+
], cn = [
|
|
7264
7274
|
"table",
|
|
7265
7275
|
"tbody",
|
|
7266
7276
|
"tfoot",
|
|
7267
7277
|
"thead",
|
|
7268
7278
|
"tr"
|
|
7269
7279
|
];
|
|
7270
|
-
function cn(e) {
|
|
7271
|
-
return on.indexOf(e.toLowerCase()) === -1;
|
|
7272
|
-
}
|
|
7273
7280
|
function ln(e) {
|
|
7274
|
-
return sn.indexOf(e.toLowerCase())
|
|
7281
|
+
return sn.indexOf(e.toLowerCase()) === -1;
|
|
7282
|
+
}
|
|
7283
|
+
function un(e) {
|
|
7284
|
+
return cn.indexOf(e.toLowerCase()) !== -1;
|
|
7275
7285
|
}
|
|
7276
7286
|
//#endregion
|
|
7277
7287
|
//#region source/helpers/hash.ts
|
|
7278
|
-
var
|
|
7288
|
+
var dn = (e = "", t = 16) => {
|
|
7279
7289
|
let n = String(e), r = 0;
|
|
7280
7290
|
return n.split("").forEach((e) => {
|
|
7281
7291
|
r = (r << 5) - r + e.charCodeAt(0), r &= r;
|
|
7282
7292
|
}), Math.abs(r).toString(t);
|
|
7283
|
-
},
|
|
7293
|
+
}, fn = () => dn(Math.random().toString()), pn = (e) => e.replace(/([A-Z])([A-Z])/g, "$1 $2").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[^a-zA-Z\u00C0-\u00ff]/g, " ").toLowerCase().split(" ").filter((e) => e).map((e, t) => t > 0 ? e[0].toUpperCase() + e.slice(1) : e).join(""), mn = (e) => {
|
|
7284
7294
|
switch (typeof e) {
|
|
7285
7295
|
case "string": return e.split(";").filter((e) => e).reduce((e, t) => {
|
|
7286
7296
|
let n = t.slice(0, t.indexOf(":")).trim(), r = t.slice(t.indexOf(":") + 1).trim();
|
|
7287
7297
|
return {
|
|
7288
7298
|
...e,
|
|
7289
|
-
[
|
|
7299
|
+
[pn(n)]: r
|
|
7290
7300
|
};
|
|
7291
7301
|
}, {});
|
|
7292
7302
|
case "object": return e;
|
|
7293
7303
|
default: return;
|
|
7294
7304
|
}
|
|
7295
|
-
},
|
|
7305
|
+
}, hn = (e) => e == null || e === "" ? [] : e.split("."), gn = (e, t) => {
|
|
7296
7306
|
let [n, ...r] = t;
|
|
7297
|
-
if (!(e == null || n == null)) return r.length === 0 ? e[n] :
|
|
7298
|
-
},
|
|
7307
|
+
if (!(e == null || n == null)) return r.length === 0 ? e[n] : gn(e[n], r);
|
|
7308
|
+
}, _n = (e, t) => gn(e, hn(t));
|
|
7299
7309
|
//#endregion
|
|
7300
7310
|
//#region source/helpers/functionProxy.ts
|
|
7301
|
-
function
|
|
7311
|
+
function vn(e, t) {
|
|
7302
7312
|
let n = e;
|
|
7303
7313
|
return n.scope = t, new Proxy(n, { apply: (e, t, n) => Reflect.apply(e, {
|
|
7304
7314
|
...e.scope,
|
|
@@ -7307,7 +7317,7 @@ function _n(e, t) {
|
|
|
7307
7317
|
}
|
|
7308
7318
|
//#endregion
|
|
7309
7319
|
//#region source/components/JsxParser.tsx
|
|
7310
|
-
var
|
|
7320
|
+
var yn = 6, bn = class i extends e.Component {
|
|
7311
7321
|
static displayName = "JsxParser";
|
|
7312
7322
|
static defaultProps = {
|
|
7313
7323
|
allowUnknownElements: !0,
|
|
@@ -7333,27 +7343,50 @@ var vn = 6, yn = class i extends e.Component {
|
|
|
7333
7343
|
jsx = "";
|
|
7334
7344
|
#e = "";
|
|
7335
7345
|
#t = 0;
|
|
7336
|
-
#n =
|
|
7337
|
-
#r = (e
|
|
7346
|
+
#n = [];
|
|
7347
|
+
#r = (e) => this.jsx.slice(e.start, e.end);
|
|
7348
|
+
#i = () => this.#n.length ? this.#n[this.#n.length - 1] : void 0;
|
|
7349
|
+
#a = (e) => {
|
|
7350
|
+
let t = 0;
|
|
7351
|
+
return new Proxy(e, { apply: (e, n, r) => {
|
|
7352
|
+
let i = t;
|
|
7353
|
+
t += 1, this.#n.push(i);
|
|
7354
|
+
try {
|
|
7355
|
+
return Reflect.apply(e, n, r);
|
|
7356
|
+
} finally {
|
|
7357
|
+
this.#n.pop();
|
|
7358
|
+
}
|
|
7359
|
+
} });
|
|
7360
|
+
};
|
|
7361
|
+
#o = (e) => ({
|
|
7362
|
+
fileName: this.props.fileName,
|
|
7363
|
+
source: this.#r(e),
|
|
7364
|
+
location: Yt(this.#e || this.jsx, e.start - this.#t, e.end - this.#t),
|
|
7365
|
+
loopIndex: this.#i(),
|
|
7366
|
+
astNode: e
|
|
7367
|
+
});
|
|
7368
|
+
#s = (e, t, n, r) => Xt({
|
|
7338
7369
|
type: e,
|
|
7339
7370
|
message: t,
|
|
7340
7371
|
source: this.#e || this.jsx,
|
|
7341
7372
|
start: n.start - this.#t,
|
|
7342
7373
|
end: n.end - this.#t,
|
|
7343
7374
|
fileName: this.props.fileName,
|
|
7344
|
-
cause: r
|
|
7375
|
+
cause: r,
|
|
7376
|
+
astNode: n,
|
|
7377
|
+
loopIndex: this.#i()
|
|
7345
7378
|
});
|
|
7346
|
-
#
|
|
7379
|
+
#c = (e) => {
|
|
7347
7380
|
let t = I.extend(Wt.default({ autoCloseVoidElements: this.props.autoCloseVoidElements })), n = `<root>${e}</root>`;
|
|
7348
|
-
this.jsx = n, this.#e = e, this.#t =
|
|
7381
|
+
this.jsx = n, this.#e = e, this.#t = yn, this.#n = [];
|
|
7349
7382
|
let r = [];
|
|
7350
7383
|
try {
|
|
7351
|
-
return r = t.parse(n, { ecmaVersion: "latest" }), r = r.body[0].expression.children || [], r.map((e) => this.#
|
|
7384
|
+
return r = t.parse(n, { ecmaVersion: "latest" }), r = r.body[0].expression.children || [], r.map((e) => this.#l(e)).filter(Boolean);
|
|
7352
7385
|
} catch (t) {
|
|
7353
7386
|
this.props.showWarnings && console.warn(t);
|
|
7354
|
-
let n = typeof t?.pos == "number" ? t.pos - this.#t : 0, r =
|
|
7387
|
+
let n = typeof t?.pos == "number" ? t.pos - this.#t : 0, r = Xt({
|
|
7355
7388
|
type: "parse",
|
|
7356
|
-
message:
|
|
7389
|
+
message: Qt(String(t)),
|
|
7357
7390
|
source: e,
|
|
7358
7391
|
start: n,
|
|
7359
7392
|
end: n,
|
|
@@ -7363,189 +7396,189 @@ var vn = 6, yn = class i extends e.Component {
|
|
|
7363
7396
|
return this.props.onError && this.props.onError(r), this.props.renderError ? this.props.renderError({ error: String(r) }) : null;
|
|
7364
7397
|
}
|
|
7365
7398
|
};
|
|
7366
|
-
#
|
|
7399
|
+
#l = (e, n) => {
|
|
7367
7400
|
switch (e.type) {
|
|
7368
|
-
case "JSXAttribute": return e.value === null ? !0 : (this.lastAttributeName = e.name.name, this.#
|
|
7401
|
+
case "JSXAttribute": return e.value === null ? !0 : (this.lastAttributeName = e.name.name, this.#l(e.value, n));
|
|
7369
7402
|
case "JSXElement":
|
|
7370
|
-
case "JSXFragment": return this.lastAttributeName = void 0, this.#
|
|
7371
|
-
case "JSXExpressionContainer": return this.#
|
|
7403
|
+
case "JSXFragment": return this.lastAttributeName = void 0, this.#f(e, n);
|
|
7404
|
+
case "JSXExpressionContainer": return this.#l(e.expression, n);
|
|
7372
7405
|
case "JSXText":
|
|
7373
|
-
let a = this.props.disableKeyGeneration ? void 0 :
|
|
7406
|
+
let a = this.props.disableKeyGeneration ? void 0 : fn();
|
|
7374
7407
|
return this.props.disableFragments ? e.value : /* @__PURE__ */ r(t, { children: e.value }, a);
|
|
7375
7408
|
case "ArrayExpression":
|
|
7376
7409
|
let o = [];
|
|
7377
7410
|
return (e.elements || []).forEach((e) => {
|
|
7378
|
-
if (
|
|
7379
|
-
let t = this.#
|
|
7411
|
+
if ($t(e)) {
|
|
7412
|
+
let t = this.#l(e.argument, n);
|
|
7380
7413
|
t && o.push(...t);
|
|
7381
7414
|
return;
|
|
7382
7415
|
}
|
|
7383
|
-
let t = this.#
|
|
7416
|
+
let t = this.#l(e, n);
|
|
7384
7417
|
t !== void 0 && o.push(t);
|
|
7385
7418
|
}), o;
|
|
7386
7419
|
case "ArrowFunctionExpression":
|
|
7387
|
-
if ((e.async || e.generator) && this.props.onError?.(this.#
|
|
7420
|
+
if ((e.async || e.generator) && this.props.onError?.(this.#s("unsupported-function", "Async and generator arrow functions are not supported.", e)), e.body.type === "BlockStatement") {
|
|
7388
7421
|
let t = e.params.map((e, t) => {
|
|
7389
7422
|
switch (e.type) {
|
|
7390
7423
|
case "Identifier": return e.name;
|
|
7391
7424
|
case "RestElement": return `...${e.argument.name}`;
|
|
7392
7425
|
default: return `arg_${t}`;
|
|
7393
7426
|
}
|
|
7394
|
-
}), r = e.params.some((e) => e.type !== "Identifier") ? `{ return (${this.#
|
|
7427
|
+
}), r = e.params.some((e) => e.type !== "Identifier"), a = r ? `{ return (${this.#r(e)})(${t.join(", ")}); }` : this.#r(e.body), o = this.#t, s = r ? (t) => e.start + (t - 10) - o : (t) => e.body.start + t - o;
|
|
7395
7428
|
try {
|
|
7396
|
-
let [e,
|
|
7429
|
+
let [e, r] = rn(a, {
|
|
7397
7430
|
...this.props.bindings,
|
|
7398
7431
|
...n
|
|
7399
|
-
}, (e, t, n) => {
|
|
7400
|
-
let
|
|
7401
|
-
return
|
|
7402
|
-
});
|
|
7403
|
-
return
|
|
7432
|
+
}, (e, t, n, r = 0) => {
|
|
7433
|
+
let a = new i(this.props);
|
|
7434
|
+
return a.jsx = e, a.#e = this.#e, a.#t = -r, a.#n = this.#n, a.#l(t, n);
|
|
7435
|
+
}, s);
|
|
7436
|
+
return this.#a(vn(an(t, e, this.lastAttributeName, this.props.onError, this.props.fileName), {
|
|
7404
7437
|
...this.props.bindings,
|
|
7405
7438
|
...n,
|
|
7406
|
-
...
|
|
7407
|
-
});
|
|
7439
|
+
...r
|
|
7440
|
+
}));
|
|
7408
7441
|
} catch (t) {
|
|
7409
|
-
this.props.onError?.(this.#
|
|
7442
|
+
this.props.onError?.(this.#s("function-parse", `Unable to parse function \`${this.lastAttributeName ?? this.#r(e)}\` => ${t}.`, e, t));
|
|
7410
7443
|
return;
|
|
7411
7444
|
}
|
|
7412
7445
|
}
|
|
7413
|
-
return (...t) => {
|
|
7414
|
-
let r = this.#
|
|
7415
|
-
return this.#
|
|
7416
|
-
};
|
|
7446
|
+
return this.#a((...t) => {
|
|
7447
|
+
let r = this.#p(n, e, t);
|
|
7448
|
+
return this.#l(e.body, r);
|
|
7449
|
+
});
|
|
7417
7450
|
case "BinaryExpression":
|
|
7418
7451
|
switch (e.operator) {
|
|
7419
|
-
case "-": return this.#
|
|
7420
|
-
case "!=": return this.#
|
|
7421
|
-
case "!==": return this.#
|
|
7422
|
-
case "*": return this.#
|
|
7423
|
-
case "**": return this.#
|
|
7424
|
-
case "/": return this.#
|
|
7425
|
-
case "%": return this.#
|
|
7426
|
-
case "+": return this.#
|
|
7427
|
-
case "<": return this.#
|
|
7428
|
-
case "<=": return this.#
|
|
7429
|
-
case "==": return this.#
|
|
7430
|
-
case "===": return this.#
|
|
7431
|
-
case ">": return this.#
|
|
7432
|
-
case ">=": return this.#
|
|
7452
|
+
case "-": return this.#l(e.left, n) - this.#l(e.right, n);
|
|
7453
|
+
case "!=": return this.#l(e.left, n) != this.#l(e.right, n);
|
|
7454
|
+
case "!==": return this.#l(e.left, n) !== this.#l(e.right, n);
|
|
7455
|
+
case "*": return this.#l(e.left, n) * this.#l(e.right, n);
|
|
7456
|
+
case "**": return this.#l(e.left, n) ** this.#l(e.right, n);
|
|
7457
|
+
case "/": return this.#l(e.left, n) / this.#l(e.right, n);
|
|
7458
|
+
case "%": return this.#l(e.left, n) % this.#l(e.right, n);
|
|
7459
|
+
case "+": return this.#l(e.left, n) + this.#l(e.right, n);
|
|
7460
|
+
case "<": return this.#l(e.left, n) < this.#l(e.right, n);
|
|
7461
|
+
case "<=": return this.#l(e.left, n) <= this.#l(e.right, n);
|
|
7462
|
+
case "==": return this.#l(e.left, n) == this.#l(e.right, n);
|
|
7463
|
+
case "===": return this.#l(e.left, n) === this.#l(e.right, n);
|
|
7464
|
+
case ">": return this.#l(e.left, n) > this.#l(e.right, n);
|
|
7465
|
+
case ">=": return this.#l(e.left, n) >= this.#l(e.right, n);
|
|
7433
7466
|
}
|
|
7434
7467
|
return;
|
|
7435
7468
|
case "CallExpression":
|
|
7436
|
-
let s = this.#
|
|
7469
|
+
let s = this.#l(e.callee, n);
|
|
7437
7470
|
if (s === void 0) {
|
|
7438
|
-
this.props.showWarnings && console.warn(`The expression \`${this.#
|
|
7471
|
+
this.props.showWarnings && console.warn(`The expression \`${this.#r(e)}\` could not be resolved, resulting in an undefined return value.`);
|
|
7439
7472
|
return;
|
|
7440
7473
|
}
|
|
7441
7474
|
try {
|
|
7442
|
-
let t = e.arguments.map((e) => this.#
|
|
7475
|
+
let t = e.arguments.map((e) => this.#l(e, n)), r = {
|
|
7443
7476
|
...this.props.bindings,
|
|
7444
7477
|
...n
|
|
7445
7478
|
};
|
|
7446
7479
|
return Reflect.apply(s, r, t);
|
|
7447
7480
|
} catch (t) {
|
|
7448
|
-
this.props.onError?.(this.#
|
|
7481
|
+
this.props.onError?.(this.#s("call", `Unable to call expression \`${this.#r(e)}\` => ${t}.`, e, t));
|
|
7449
7482
|
return;
|
|
7450
7483
|
}
|
|
7451
7484
|
case "ChainExpression": try {
|
|
7452
|
-
return this.#
|
|
7485
|
+
return this.#l(e.expression, n);
|
|
7453
7486
|
} catch (t) {
|
|
7454
|
-
this.props.onError?.(this.#
|
|
7487
|
+
this.props.onError?.(this.#s("chain", `Unable to call expression \`${this.#r(e)}\` => ${t}.`, e, t));
|
|
7455
7488
|
return;
|
|
7456
7489
|
}
|
|
7457
|
-
case "ConditionalExpression": return this.#
|
|
7458
|
-
case "ExpressionStatement": return this.#
|
|
7490
|
+
case "ConditionalExpression": return this.#l(e.test, n) ? this.#l(e.consequent, n) : this.#l(e.alternate, n);
|
|
7491
|
+
case "ExpressionStatement": return this.#l(e.expression, n);
|
|
7459
7492
|
case "Identifier": return n?.[e.name] ?? this.props.bindings?.[e.name] ?? window[e.name];
|
|
7460
7493
|
case "Literal": return e.value;
|
|
7461
7494
|
case "LogicalExpression":
|
|
7462
|
-
let c = this.#
|
|
7495
|
+
let c = this.#l(e.left, n), l = () => this.#l(e.right, n);
|
|
7463
7496
|
switch (e.operator) {
|
|
7464
7497
|
case "||": return c || l();
|
|
7465
7498
|
case "&&": return c && l();
|
|
7466
7499
|
case "??": return c ?? l();
|
|
7467
7500
|
default: return !1;
|
|
7468
7501
|
}
|
|
7469
|
-
case "MemberExpression": return this.#
|
|
7502
|
+
case "MemberExpression": return this.#u(e, n);
|
|
7470
7503
|
case "NewExpression":
|
|
7471
|
-
let u = this.#
|
|
7504
|
+
let u = this.#l(e.callee, n);
|
|
7472
7505
|
if (u === void 0) {
|
|
7473
|
-
this.props.showWarnings && console.warn(`The expression \`${this.#
|
|
7506
|
+
this.props.showWarnings && console.warn(`The expression \`${this.#r(e)}\` could not be resolved, resulting in an undefined return value.`);
|
|
7474
7507
|
return;
|
|
7475
7508
|
}
|
|
7476
|
-
return new u(...e.arguments.map((e) => this.#
|
|
7509
|
+
return new u(...e.arguments.map((e) => this.#l(e, n)));
|
|
7477
7510
|
case "ObjectExpression":
|
|
7478
7511
|
let d = {};
|
|
7479
7512
|
return e.properties.forEach((e) => {
|
|
7480
|
-
if (
|
|
7481
|
-
let t = this.#
|
|
7513
|
+
if ($t(e)) {
|
|
7514
|
+
let t = this.#l(e.argument, n);
|
|
7482
7515
|
Object.entries(t || {}).forEach(([e, t]) => {
|
|
7483
7516
|
d[e] = t;
|
|
7484
7517
|
});
|
|
7485
7518
|
} else {
|
|
7486
7519
|
let t = e.key.name || e.key.value;
|
|
7487
|
-
d[t] = this.#
|
|
7520
|
+
d[t] = this.#l(e.value, n);
|
|
7488
7521
|
}
|
|
7489
7522
|
}), d;
|
|
7490
7523
|
case "TemplateElement": return e.value.cooked;
|
|
7491
|
-
case "TemplateLiteral": return [...e.expressions, ...e.quasis].sort((e, t) => e.start < t.start ? -1 : 1).map((e) => this.#
|
|
7524
|
+
case "TemplateLiteral": return [...e.expressions, ...e.quasis].sort((e, t) => e.start < t.start ? -1 : 1).map((e) => this.#l(e, n)).join("");
|
|
7492
7525
|
case "ThisExpression": return this.props.bindings;
|
|
7493
7526
|
case "UnaryExpression":
|
|
7494
7527
|
switch (e.operator) {
|
|
7495
|
-
case "+": return +this.#
|
|
7496
|
-
case "-": return -this.#
|
|
7497
|
-
case "!": return !this.#
|
|
7528
|
+
case "+": return +this.#l(e.argument, n);
|
|
7529
|
+
case "-": return -this.#l(e.argument, n);
|
|
7530
|
+
case "!": return !this.#l(e.argument, n);
|
|
7498
7531
|
}
|
|
7499
7532
|
return;
|
|
7500
7533
|
}
|
|
7501
7534
|
};
|
|
7502
|
-
#
|
|
7503
|
-
let { object: n } = e, r = [((e) => e.computed ? this.#
|
|
7535
|
+
#u = (e, t) => {
|
|
7536
|
+
let { object: n } = e, r = [((e) => e.computed ? this.#l(e.property, t) : e.property?.name)(e)];
|
|
7504
7537
|
if (e.object.type !== "Literal") for (; n && ["MemberExpression", "Literal"].includes(n?.type);) {
|
|
7505
7538
|
let { property: e } = n;
|
|
7506
|
-
n.computed ? r.unshift(this.#
|
|
7539
|
+
n.computed ? r.unshift(this.#l(e, t)) : r.unshift(e?.name ?? JSON.parse(e?.raw ?? "\"\"")), n = n.object;
|
|
7507
7540
|
}
|
|
7508
|
-
let i = this.#
|
|
7541
|
+
let i = this.#l(n, t);
|
|
7509
7542
|
try {
|
|
7510
7543
|
let e = i, t = r.reduce((t, n) => (e = t, t?.[n]), i);
|
|
7511
7544
|
return typeof t == "function" ? t.bind(e) : t;
|
|
7512
7545
|
} catch (t) {
|
|
7513
7546
|
let i = n?.name || "unknown";
|
|
7514
|
-
this.props.onError?.(this.#
|
|
7547
|
+
this.props.onError?.(this.#s("member-access", `Unable to parse \`${i}["${r.join("\"][\"")}"]\``, e, t));
|
|
7515
7548
|
}
|
|
7516
7549
|
};
|
|
7517
|
-
#
|
|
7518
|
-
#
|
|
7519
|
-
let { allowUnknownElements: i, components: a, componentsOnly: o, onError: s } = this.props, { children: c = [] } = n, l = n.type === "JSXElement" ? n.openingElement : n.openingFragment, { attributes: u = [] } = l, d = n.type === "JSXElement" ? this.#
|
|
7520
|
-
if (/^(html|head|body)$/i.test(d)) return c.map((e) => this.#
|
|
7550
|
+
#d = (e) => e.type === "JSXIdentifier" ? e.name : `${this.#d(e.object)}.${this.#d(e.property)}`;
|
|
7551
|
+
#f = (n, r) => {
|
|
7552
|
+
let { allowUnknownElements: i, components: a, componentsOnly: o, onError: s } = this.props, { children: c = [] } = n, l = n.type === "JSXElement" ? n.openingElement : n.openingFragment, { attributes: u = [] } = l, d = n.type === "JSXElement" ? this.#d(l.name) : "", f = (this.props.blacklistedAttrs || []).map((e) => e instanceof RegExp ? e : new RegExp(e, "i")), p = (this.props.blacklistedTags || []).map((e) => e.trim().toLowerCase()).filter(Boolean);
|
|
7553
|
+
if (/^(html|head|body)$/i.test(d)) return c.map((e) => this.#f(e, r));
|
|
7521
7554
|
let m = d.trim().toLowerCase();
|
|
7522
|
-
if (p.indexOf(m) !== -1) return s(this.#
|
|
7523
|
-
if (d !== "" && !
|
|
7524
|
-
if (o) return s(this.#
|
|
7525
|
-
if (!i && document.createElement(d) instanceof HTMLUnknownElement) return s(this.#
|
|
7555
|
+
if (p.indexOf(m) !== -1) return s(this.#s("blacklisted-tag", `The tag \`<${d}>\` is blacklisted, and will not be rendered.`, n)), null;
|
|
7556
|
+
if (d !== "" && !_n(a, d)) {
|
|
7557
|
+
if (o) return s(this.#s("unrecognized-component", `The component \`<${d}>\` is unrecognized, and will not be rendered.`, n)), this.props.renderUnrecognized(d);
|
|
7558
|
+
if (!i && document.createElement(d) instanceof HTMLUnknownElement) return s(this.#s("unrecognized-tag", `The tag \`<${d}>\` is unrecognized in this browser, and will not be rendered.`, n)), this.props.renderUnrecognized(d);
|
|
7526
7559
|
}
|
|
7527
|
-
let h, g = n.type === "JSXElement" ?
|
|
7528
|
-
(g ||
|
|
7560
|
+
let h, g = n.type === "JSXElement" ? _n(a, d) : t;
|
|
7561
|
+
(g || ln(d)) && (h = c.map((e) => this.#l(e, r)), !g && !un(d) && (h = h.filter((e) => typeof e != "string" || !/^\s*$/.test(e))), h.length === 0 ? h = void 0 : h.length === 1 ? [h] = h : h.length > 1 && !this.props.disableKeyGeneration && (h = h.map((e, t) => e?.type && !e?.key ? {
|
|
7529
7562
|
...e,
|
|
7530
7563
|
key: e.key || t
|
|
7531
7564
|
} : e)));
|
|
7532
|
-
let _ = { key: this.props.disableKeyGeneration ? void 0 :
|
|
7565
|
+
let _ = { key: this.props.disableKeyGeneration ? void 0 : fn() };
|
|
7533
7566
|
u.forEach((e) => {
|
|
7534
7567
|
if (e.type === "JSXAttribute") {
|
|
7535
|
-
let t = e.name.name, n =
|
|
7568
|
+
let t = e.name.name, n = on[t] || t, i = this.#l(e, r);
|
|
7536
7569
|
f.filter((e) => e.test(n)).length === 0 && (_[n] = i);
|
|
7537
7570
|
} else if (e.type === "JSXSpreadAttribute") {
|
|
7538
|
-
let t = e.argument, n = this.#
|
|
7571
|
+
let t = e.argument, n = this.#l(t, r);
|
|
7539
7572
|
typeof n == "object" && Object.keys(n || {}).forEach((e) => {
|
|
7540
|
-
let t =
|
|
7573
|
+
let t = on[e] || e;
|
|
7541
7574
|
f.filter((e) => e.test(t)).length === 0 && (_[t] = n[e]);
|
|
7542
7575
|
});
|
|
7543
7576
|
}
|
|
7544
|
-
}), typeof _.style == "string" && (_.style =
|
|
7577
|
+
}), typeof _.style == "string" && (_.style = mn(_.style)), g && g.injectSourceInfo && (_.sourceInfo = this.#o(n));
|
|
7545
7578
|
let ee = d.toLowerCase();
|
|
7546
7579
|
return ee === "option" && (h = h.props.children), e.createElement(g || ee, _, h);
|
|
7547
7580
|
};
|
|
7548
|
-
#
|
|
7581
|
+
#p = (e, t, n) => {
|
|
7549
7582
|
let r = e ?? {};
|
|
7550
7583
|
return t.params.forEach((t, i) => {
|
|
7551
7584
|
switch (t.type) {
|
|
@@ -7563,7 +7596,7 @@ var vn = 6, yn = class i extends e.Component {
|
|
|
7563
7596
|
});
|
|
7564
7597
|
break;
|
|
7565
7598
|
case "AssignmentPattern":
|
|
7566
|
-
let a = () => this.#
|
|
7599
|
+
let a = () => this.#l(t.right, e);
|
|
7567
7600
|
r[t.left.name] = n[i] === void 0 ? a() : n[i];
|
|
7568
7601
|
break;
|
|
7569
7602
|
case "RestElement":
|
|
@@ -7574,7 +7607,7 @@ var vn = 6, yn = class i extends e.Component {
|
|
|
7574
7607
|
};
|
|
7575
7608
|
render = () => {
|
|
7576
7609
|
let e = (this.props.jsx || "").trim().replace(/<!DOCTYPE([^>]*)>/g, "");
|
|
7577
|
-
this.ParsedChildren = this.#
|
|
7610
|
+
this.ParsedChildren = this.#c(e);
|
|
7578
7611
|
let t = [.../* @__PURE__ */ new Set(["jsx-parser", ...String(this.props.className).split(" ")])].filter(Boolean).join(" ");
|
|
7579
7612
|
return this.props.renderInWrapper ? /* @__PURE__ */ r("div", {
|
|
7580
7613
|
className: t,
|
|
@@ -7583,6 +7616,6 @@ var vn = 6, yn = class i extends e.Component {
|
|
|
7583
7616
|
};
|
|
7584
7617
|
};
|
|
7585
7618
|
//#endregion
|
|
7586
|
-
export { Gt as JsxParserError,
|
|
7619
|
+
export { Gt as JsxParserError, bn as default };
|
|
7587
7620
|
|
|
7588
7621
|
//# sourceMappingURL=react-jsx-parser.js.map
|