@recursive-robot/react-jsx-parser 2.0.2 → 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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { default as React, ComponentType, ExoticComponent } from 'react';
|
|
2
|
-
import { JsxParserError
|
|
3
|
-
import * as AcornJSX from 'acorn-jsx';
|
|
2
|
+
import { JsxParserError } from '../helpers/errorUtilities';
|
|
4
3
|
export type TProps = {
|
|
5
4
|
allowUnknownElements?: boolean;
|
|
6
5
|
autoCloseVoidElements?: boolean;
|
|
@@ -24,13 +23,6 @@ export type TProps = {
|
|
|
24
23
|
renderInWrapper?: boolean;
|
|
25
24
|
renderUnrecognized?: (tagName: string) => React.JSX.Element | null;
|
|
26
25
|
};
|
|
27
|
-
export interface SourceInfo {
|
|
28
|
-
fileName?: string;
|
|
29
|
-
source: string;
|
|
30
|
-
location: SourceLocation;
|
|
31
|
-
loopIndex: number | undefined;
|
|
32
|
-
astNode: AcornJSX.Expression;
|
|
33
|
-
}
|
|
34
26
|
export default class JsxParser extends React.Component<TProps> {
|
|
35
27
|
#private;
|
|
36
28
|
static displayName: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as AcornJSX from 'acorn-jsx';
|
|
1
2
|
export type JsxParserErrorType = 'parse' | 'unsupported-function' | 'function-parse' | 'function-runtime' | 'call' | 'chain' | 'member-access' | 'blacklisted-tag' | 'unrecognized-component' | 'unrecognized-tag';
|
|
2
3
|
export interface SourceLocation {
|
|
3
4
|
line: number;
|
|
@@ -5,25 +6,28 @@ export interface SourceLocation {
|
|
|
5
6
|
startOffset?: number;
|
|
6
7
|
endOffset?: number;
|
|
7
8
|
}
|
|
9
|
+
export interface SourceInfo {
|
|
10
|
+
fileName?: string;
|
|
11
|
+
source: string;
|
|
12
|
+
location: SourceLocation;
|
|
13
|
+
loopIndex: number | undefined;
|
|
14
|
+
astNode?: AcornJSX.Expression;
|
|
15
|
+
}
|
|
8
16
|
export declare class JsxParserError extends Error {
|
|
9
17
|
type: JsxParserErrorType;
|
|
10
|
-
|
|
11
|
-
fileName?: string;
|
|
18
|
+
sourceInfo: SourceInfo;
|
|
12
19
|
snippet?: string;
|
|
13
|
-
source?: string;
|
|
14
20
|
cause?: unknown;
|
|
15
21
|
constructor(message: string, fields: {
|
|
16
22
|
type: JsxParserErrorType;
|
|
17
|
-
|
|
18
|
-
fileName?: string;
|
|
23
|
+
sourceInfo: SourceInfo;
|
|
19
24
|
snippet?: string;
|
|
20
|
-
source?: string;
|
|
21
25
|
cause?: unknown;
|
|
22
26
|
});
|
|
23
27
|
}
|
|
24
28
|
export declare function trimExcessLeadingWhitespaceFromCodeLines(lines: string[]): string[];
|
|
25
29
|
export declare function getLocationFromOffsets(source: string, start: number, end: number): SourceLocation;
|
|
26
|
-
export declare function buildErrorFromOffsets({ type, message, source, start, end, fileName, cause }: {
|
|
30
|
+
export declare function buildErrorFromOffsets({ type, message, source, start, end, fileName, cause, astNode, loopIndex }: {
|
|
27
31
|
type: JsxParserErrorType;
|
|
28
32
|
message: string;
|
|
29
33
|
source: string;
|
|
@@ -31,6 +35,8 @@ export declare function buildErrorFromOffsets({ type, message, source, start, en
|
|
|
31
35
|
end: number;
|
|
32
36
|
fileName?: string;
|
|
33
37
|
cause?: unknown;
|
|
38
|
+
astNode?: AcornJSX.Expression;
|
|
39
|
+
loopIndex?: number;
|
|
34
40
|
}): JsxParserError;
|
|
35
41
|
export declare function buildErrorFromLine(opts: {
|
|
36
42
|
type: JsxParserErrorType;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as JsxParser } from './components/JsxParser';
|
|
2
|
-
export type { TProps
|
|
2
|
+
export type { TProps } from './components/JsxParser';
|
|
3
3
|
export type { ScopedFunction, FunctionProxy } from './helpers/functionProxy';
|
|
4
4
|
export { JsxParserError } from './helpers/errorUtilities';
|
|
5
|
-
export type { JsxParserErrorType, SourceLocation } from './helpers/errorUtilities';
|
|
5
|
+
export type { JsxParserErrorType, SourceLocation, SourceInfo } from './helpers/errorUtilities';
|
|
6
6
|
export default JsxParser;
|
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) {
|
|
@@ -7045,26 +7043,34 @@ function Yt(e, t, n) {
|
|
|
7045
7043
|
endOffset: Math.max(r, n)
|
|
7046
7044
|
};
|
|
7047
7045
|
}
|
|
7048
|
-
function Xt({ type: e, message: t, source: n, start: r, end: i, fileName: a, cause: o }) {
|
|
7049
|
-
let
|
|
7050
|
-
return new Gt(Jt(t, `Error occurred at line \`${
|
|
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), {
|
|
7051
7049
|
type: e,
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
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
|
+
}
|
|
7057
7059
|
});
|
|
7058
7060
|
}
|
|
7059
7061
|
function Zt(e) {
|
|
7060
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}\`` : ""}`;
|
|
7061
7063
|
return new Gt(Jt(n, a ? `Error occurred in dynamic function \`${a}\` at ${l}:` : `Error occurred at ${l}:`, c), {
|
|
7062
7064
|
type: t,
|
|
7063
|
-
location: { line: i },
|
|
7064
|
-
fileName: o,
|
|
7065
7065
|
snippet: c,
|
|
7066
|
-
|
|
7067
|
-
|
|
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
|
+
}
|
|
7068
7074
|
});
|
|
7069
7075
|
}
|
|
7070
7076
|
function Qt(e) {
|
|
@@ -7366,7 +7372,9 @@ var yn = 6, bn = class i extends e.Component {
|
|
|
7366
7372
|
start: n.start - this.#t,
|
|
7367
7373
|
end: n.end - this.#t,
|
|
7368
7374
|
fileName: this.props.fileName,
|
|
7369
|
-
cause: r
|
|
7375
|
+
cause: r,
|
|
7376
|
+
astNode: n,
|
|
7377
|
+
loopIndex: this.#i()
|
|
7370
7378
|
});
|
|
7371
7379
|
#c = (e) => {
|
|
7372
7380
|
let t = I.extend(Wt.default({ autoCloseVoidElements: this.props.autoCloseVoidElements })), n = `<root>${e}</root>`;
|