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