@recursive-robot/react-jsx-parser 1.42.0 → 2.0.1
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/components/JsxParser.d.ts +34 -32
- package/dist/constants/attributeNames.d.ts +2 -2
- package/dist/constants/specialTags.d.ts +4 -4
- package/dist/helpers/camelCase.d.ts +7 -7
- package/dist/helpers/errorUtilities.d.ts +43 -0
- package/dist/helpers/functionProxy.d.ts +5 -5
- package/dist/helpers/functionUtilities.d.ts +8 -7
- package/dist/helpers/hash.d.ts +10 -10
- package/dist/helpers/parseStyle.d.ts +8 -8
- package/dist/helpers/resolvePath.d.ts +9 -9
- package/dist/index.d.ts +6 -5
- package/dist/react-jsx-parser.js +7588 -0
- package/dist/react-jsx-parser.js.map +1 -0
- package/package.json +38 -58
- package/dist/cjs/react-jsx-parser.min.js +0 -2
- package/dist/cjs/react-jsx-parser.min.js.map +0 -1
- package/dist/demo.d.ts +0 -1
- package/dist/es5/react-jsx-parser.min.js +0 -2
- package/dist/es5/react-jsx-parser.min.js.map +0 -1
- package/dist/umd/react-jsx-parser.min.js +0 -2
- package/dist/umd/react-jsx-parser.min.js.map +0 -1
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
import React,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
import { default as React, ComponentType, ExoticComponent } from 'react';
|
|
2
|
+
import { JsxParserError } from '../helpers/errorUtilities';
|
|
3
|
+
export type TProps = {
|
|
4
|
+
allowUnknownElements?: boolean;
|
|
5
|
+
autoCloseVoidElements?: boolean;
|
|
6
|
+
bindings?: {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
blacklistedAttrs?: Array<string | RegExp>;
|
|
10
|
+
blacklistedTags?: string[];
|
|
11
|
+
className?: string;
|
|
12
|
+
components?: Record<string, ComponentType | ExoticComponent>;
|
|
13
|
+
componentsOnly?: boolean;
|
|
14
|
+
disableFragments?: boolean;
|
|
15
|
+
disableKeyGeneration?: boolean;
|
|
16
|
+
fileName?: string;
|
|
17
|
+
jsx?: string;
|
|
18
|
+
onError?: (error: JsxParserError) => void;
|
|
19
|
+
showWarnings?: boolean;
|
|
20
|
+
renderError?: (props: {
|
|
21
|
+
error: string;
|
|
22
|
+
}) => React.JSX.Element | null;
|
|
23
|
+
renderInWrapper?: boolean;
|
|
24
|
+
renderUnrecognized?: (tagName: string) => React.JSX.Element | null;
|
|
25
|
+
};
|
|
26
|
+
export default class JsxParser extends React.Component<TProps> {
|
|
27
|
+
#private;
|
|
28
|
+
static displayName: string;
|
|
29
|
+
static defaultProps: TProps;
|
|
30
|
+
private ParsedChildren;
|
|
31
|
+
private lastAttributeName;
|
|
32
|
+
jsx: string;
|
|
33
|
+
render: () => React.JSX.Element;
|
|
34
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: Record<string, string>;
|
|
2
|
-
export default _default;
|
|
1
|
+
declare const _default: Record<string, string>;
|
|
2
|
+
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const VOID_ELEMENTS: string[];
|
|
2
|
-
export default VOID_ELEMENTS;
|
|
3
|
-
export declare function canHaveChildren(tagName: string): boolean;
|
|
4
|
-
export declare function canHaveWhitespace(tagName: string): boolean;
|
|
1
|
+
declare const VOID_ELEMENTS: string[];
|
|
2
|
+
export default VOID_ELEMENTS;
|
|
3
|
+
export declare function canHaveChildren(tagName: string): boolean;
|
|
4
|
+
export declare function canHaveWhitespace(tagName: string): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a string from other cases to camelCase
|
|
3
|
-
* @param string the value to camelCase
|
|
4
|
-
* @example
|
|
5
|
-
* camelCase('foo-bar') // 'fooBar'
|
|
6
|
-
*/
|
|
7
|
-
export declare const camelCase: (string: string) => string;
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string from other cases to camelCase
|
|
3
|
+
* @param string the value to camelCase
|
|
4
|
+
* @example
|
|
5
|
+
* camelCase('foo-bar') // 'fooBar'
|
|
6
|
+
*/
|
|
7
|
+
export declare const camelCase: (string: string) => string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type JsxParserErrorType = 'parse' | 'unsupported-function' | 'function-parse' | 'function-runtime' | 'call' | 'chain' | 'member-access' | 'blacklisted-tag' | 'unrecognized-component' | 'unrecognized-tag';
|
|
2
|
+
export interface JsxParserErrorLocation {
|
|
3
|
+
line: number;
|
|
4
|
+
column?: number;
|
|
5
|
+
startOffset?: number;
|
|
6
|
+
endOffset?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class JsxParserError extends Error {
|
|
9
|
+
type: JsxParserErrorType;
|
|
10
|
+
location?: JsxParserErrorLocation;
|
|
11
|
+
fileName?: string;
|
|
12
|
+
snippet?: string;
|
|
13
|
+
source?: string;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
constructor(message: string, fields: {
|
|
16
|
+
type: JsxParserErrorType;
|
|
17
|
+
location?: JsxParserErrorLocation;
|
|
18
|
+
fileName?: string;
|
|
19
|
+
snippet?: string;
|
|
20
|
+
source?: string;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export declare function trimExcessLeadingWhitespaceFromCodeLines(lines: string[]): string[];
|
|
25
|
+
export declare function buildErrorFromOffsets({ type, message, source, start, end, fileName, cause }: {
|
|
26
|
+
type: JsxParserErrorType;
|
|
27
|
+
message: string;
|
|
28
|
+
source: string;
|
|
29
|
+
start: number;
|
|
30
|
+
end: number;
|
|
31
|
+
fileName?: string;
|
|
32
|
+
cause?: unknown;
|
|
33
|
+
}): JsxParserError;
|
|
34
|
+
export declare function buildErrorFromLine(opts: {
|
|
35
|
+
type: JsxParserErrorType;
|
|
36
|
+
message: string;
|
|
37
|
+
bodyLines: string[];
|
|
38
|
+
line: number;
|
|
39
|
+
functionName?: string;
|
|
40
|
+
fileName?: string;
|
|
41
|
+
cause?: unknown;
|
|
42
|
+
}): JsxParserError;
|
|
43
|
+
export declare function sanitizeHtml(html: string): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
scope?: Record<string, any>;
|
|
3
|
-
};
|
|
4
|
-
export
|
|
5
|
-
export declare function createFunctionProxy(fn: ScopedFunction, scope: Record<string, any>): FunctionProxy;
|
|
1
|
+
export type ScopedFunction = Function & {
|
|
2
|
+
scope?: Record<string, any>;
|
|
3
|
+
};
|
|
4
|
+
export type FunctionProxy = ProxyHandler<ScopedFunction>;
|
|
5
|
+
export declare function createFunctionProxy(fn: ScopedFunction, scope: Record<string, any>): FunctionProxy;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
1
|
+
import { JsxParserError } from './errorUtilities';
|
|
2
|
+
import * as AcornJSX from 'acorn-jsx';
|
|
3
|
+
export declare function isSpreadElement(node: AcornJSX.BaseExpression): node is AcornJSX.SpreadElement;
|
|
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>) => any): (args: Record<string, any>) => any;
|
|
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>) => any): [string, Record<string, any>];
|
|
8
|
+
export declare function constructFunction(paramNames: string[], body: string, name?: string, onError?: (error: JsxParserError) => void, fileName?: string): (...args: any[]) => any;
|
package/dist/helpers/hash.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hashes a value
|
|
3
|
-
* @param value the value to hash
|
|
4
|
-
* @param radix the base-n to hash into (default 16)
|
|
5
|
-
*/
|
|
6
|
-
export declare const hash: (value?: string, radix?: number) => string;
|
|
7
|
-
/**
|
|
8
|
-
* Hashes a Math.random() value, returning it in base16
|
|
9
|
-
*/
|
|
10
|
-
export declare const randomHash: () => string;
|
|
1
|
+
/**
|
|
2
|
+
* Hashes a value
|
|
3
|
+
* @param value the value to hash
|
|
4
|
+
* @param radix the base-n to hash into (default 16)
|
|
5
|
+
*/
|
|
6
|
+
export declare const hash: (value?: string, radix?: number) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Hashes a Math.random() value, returning it in base16
|
|
9
|
+
*/
|
|
10
|
+
export declare const randomHash: () => string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Converts a CSS Style string
|
|
4
|
-
* @param {string | Partial<CSSStyleDeclaration>} style A string to convert, or object to return
|
|
5
|
-
* @returns {Partial<CSSStyleDeclaration>} a partial CSSStyleDeclaration
|
|
6
|
-
*/
|
|
7
|
-
export declare const parseStyle: (style: Style) => Partial<CSSStyleDeclaration> | undefined;
|
|
8
|
-
export {};
|
|
1
|
+
type Style = string | Partial<CSSStyleDeclaration>;
|
|
2
|
+
/**
|
|
3
|
+
* Converts a CSS Style string
|
|
4
|
+
* @param {string | Partial<CSSStyleDeclaration>} style A string to convert, or object to return
|
|
5
|
+
* @returns {Partial<CSSStyleDeclaration>} a partial CSSStyleDeclaration
|
|
6
|
+
*/
|
|
7
|
+
export declare const parseStyle: (style: Style) => Partial<CSSStyleDeclaration> | undefined;
|
|
8
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the result of a path query from an object
|
|
3
|
-
* @param {any} object the object to search
|
|
4
|
-
* @param {string} path the path, whose value will be retrieved
|
|
5
|
-
* @returns {any} the value (undefined if the path doesn't exist)
|
|
6
|
-
* @example
|
|
7
|
-
* resolvePath({ foo: { bar: { baz: 3 } } }, 'foo.bar.baz') // 3
|
|
8
|
-
*/
|
|
9
|
-
export declare const resolvePath: (object: any, path: string) => any;
|
|
1
|
+
/**
|
|
2
|
+
* Returns the result of a path query from an object
|
|
3
|
+
* @param {any} object the object to search
|
|
4
|
+
* @param {string} path the path, whose value will be retrieved
|
|
5
|
+
* @returns {any} the value (undefined if the path doesn't exist)
|
|
6
|
+
* @example
|
|
7
|
+
* resolvePath({ foo: { bar: { baz: 3 } } }, 'foo.bar.baz') // 3
|
|
8
|
+
*/
|
|
9
|
+
export declare const resolvePath: (object: any, path: string) => any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type {
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
import { default as JsxParser } from './components/JsxParser';
|
|
2
|
+
export type { TProps } from './components/JsxParser';
|
|
3
|
+
export type { ScopedFunction, FunctionProxy } from './helpers/functionProxy';
|
|
4
|
+
export { JsxParserError } from './helpers/errorUtilities';
|
|
5
|
+
export type { JsxParserErrorType, JsxParserErrorLocation } from './helpers/errorUtilities';
|
|
6
|
+
export default JsxParser;
|