@contember/react-multipass-rendering
Advanced tools
Comparing version 1.0.0 to 1.1.0-alpha.0
@@ -9,2 +9,3 @@ var __defProp = Object.defineProperty; | ||
import { ChildrenAnalyzerError } from "./ChildrenAnalyzerError.js"; | ||
import { wrapError } from "./helpers/wrapError.js"; | ||
import { getErrorMessage } from "./helpers/getErrorMessage.js"; | ||
@@ -26,7 +27,7 @@ const _ChildrenAnalyzer = class { | ||
processChildren(children, initialStaticContext) { | ||
const processed = this.processNode(children, initialStaticContext); | ||
const processed = this.processNode(children, initialStaticContext, []); | ||
const rawResult = Array.isArray(processed) ? processed : [processed]; | ||
return rawResult.filter((item) => item !== void 0); | ||
} | ||
processNode(node, staticContext) { | ||
processNode(node, staticContext, componentPath) { | ||
if (!node || typeof node === "string" || typeof node === "number" || typeof node === "boolean") { | ||
@@ -59,3 +60,3 @@ for (const leaf of this.leaves) { | ||
for (const subNode of node) { | ||
const processed = this.processNode(subNode, staticContext); | ||
const processed = this.processNode(subNode, staticContext, componentPath); | ||
if (processed !== void 0) { | ||
@@ -73,17 +74,26 @@ if (Array.isArray(processed)) { | ||
if (!("type" in node)) { | ||
return this.processNode(children, staticContext); | ||
return this.processNode(children, staticContext, componentPath); | ||
} | ||
children = node.props.children; | ||
if (typeof node.type === "symbol") { | ||
return this.processNode(children, staticContext); | ||
return this.processNode(children, staticContext, componentPath); | ||
} | ||
const treeNode = node.type; | ||
componentPath = [...componentPath, node]; | ||
if (typeof treeNode !== "string") { | ||
if (this.options.staticContextFactoryName in treeNode) { | ||
const staticContextFactory = treeNode[this.options.staticContextFactoryName]; | ||
staticContext = staticContextFactory(node.props, staticContext); | ||
try { | ||
staticContext = staticContextFactory(node.props, staticContext); | ||
} catch (e) { | ||
wrapError(e, treeNode.displayName ?? "???", this.options.staticContextFactoryName, componentPath); | ||
} | ||
} | ||
if (this.options.staticRenderFactoryName in treeNode) { | ||
const factory = treeNode[this.options.staticRenderFactoryName]; | ||
children = factory(node.props, staticContext); | ||
try { | ||
children = factory(node.props, staticContext); | ||
} catch (e) { | ||
wrapError(e, treeNode.displayName ?? "???", this.options.staticRenderFactoryName, componentPath); | ||
} | ||
} | ||
@@ -113,3 +123,3 @@ } | ||
} | ||
const processedChildren = this.processNode(children, staticContext); | ||
const processedChildren = this.processNode(children, staticContext, componentPath); | ||
for (const branchNode of this.branchNodes) { | ||
@@ -116,0 +126,0 @@ const specification = branchNode.specification; |
@@ -0,4 +1,19 @@ | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
class ChildrenAnalyzerError extends Error { | ||
constructor(message, options) { | ||
super(message); | ||
__publicField(this, "cause"); | ||
__publicField(this, "details"); | ||
this.details = options?.details; | ||
if (typeof options === "object" && "cause" in options) { | ||
this.cause = options.cause; | ||
} | ||
} | ||
} | ||
export { ChildrenAnalyzerError }; | ||
//# sourceMappingURL=ChildrenAnalyzerError.js.map |
@@ -9,2 +9,3 @@ var __defProp = Object.defineProperty; | ||
import { ChildrenAnalyzerError } from "./ChildrenAnalyzerError.js"; | ||
import { wrapError } from "./helpers/wrapError.js"; | ||
import { getErrorMessage } from "./helpers/getErrorMessage.js"; | ||
@@ -26,7 +27,7 @@ const _ChildrenAnalyzer = class { | ||
processChildren(children, initialStaticContext) { | ||
const processed = this.processNode(children, initialStaticContext); | ||
const processed = this.processNode(children, initialStaticContext, []); | ||
const rawResult = Array.isArray(processed) ? processed : [processed]; | ||
return rawResult.filter((item) => item !== void 0); | ||
} | ||
processNode(node, staticContext) { | ||
processNode(node, staticContext, componentPath) { | ||
if (!node || typeof node === "string" || typeof node === "number" || typeof node === "boolean") { | ||
@@ -59,3 +60,3 @@ for (const leaf of this.leaves) { | ||
for (const subNode of node) { | ||
const processed = this.processNode(subNode, staticContext); | ||
const processed = this.processNode(subNode, staticContext, componentPath); | ||
if (processed !== void 0) { | ||
@@ -73,17 +74,26 @@ if (Array.isArray(processed)) { | ||
if (!("type" in node)) { | ||
return this.processNode(children, staticContext); | ||
return this.processNode(children, staticContext, componentPath); | ||
} | ||
children = node.props.children; | ||
if (typeof node.type === "symbol") { | ||
return this.processNode(children, staticContext); | ||
return this.processNode(children, staticContext, componentPath); | ||
} | ||
const treeNode = node.type; | ||
componentPath = [...componentPath, node]; | ||
if (typeof treeNode !== "string") { | ||
if (this.options.staticContextFactoryName in treeNode) { | ||
const staticContextFactory = treeNode[this.options.staticContextFactoryName]; | ||
staticContext = staticContextFactory(node.props, staticContext); | ||
try { | ||
staticContext = staticContextFactory(node.props, staticContext); | ||
} catch (e) { | ||
wrapError(e, treeNode.displayName ?? "???", this.options.staticContextFactoryName, componentPath); | ||
} | ||
} | ||
if (this.options.staticRenderFactoryName in treeNode) { | ||
const factory = treeNode[this.options.staticRenderFactoryName]; | ||
children = factory(node.props, staticContext); | ||
try { | ||
children = factory(node.props, staticContext); | ||
} catch (e) { | ||
wrapError(e, treeNode.displayName ?? "???", this.options.staticRenderFactoryName, componentPath); | ||
} | ||
} | ||
@@ -113,3 +123,3 @@ } | ||
} | ||
const processedChildren = this.processNode(children, staticContext); | ||
const processedChildren = this.processNode(children, staticContext, componentPath); | ||
for (const branchNode of this.branchNodes) { | ||
@@ -116,0 +126,0 @@ const specification = branchNode.specification; |
@@ -0,4 +1,19 @@ | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
class ChildrenAnalyzerError extends Error { | ||
constructor(message, options) { | ||
super(message); | ||
__publicField(this, "cause"); | ||
__publicField(this, "details"); | ||
this.details = options?.details; | ||
if (typeof options === "object" && "cause" in options) { | ||
this.cause = options.cause; | ||
} | ||
} | ||
} | ||
export { ChildrenAnalyzerError }; | ||
//# sourceMappingURL=ChildrenAnalyzerError.js.map |
export declare class ChildrenAnalyzerError extends Error { | ||
cause?: unknown; | ||
details?: string; | ||
constructor(message: string, options?: { | ||
cause: unknown; | ||
details?: string; | ||
}); | ||
} | ||
//# sourceMappingURL=ChildrenAnalyzerError.d.ts.map |
{ | ||
"name": "@contember/react-multipass-rendering", | ||
"license": "Apache-2.0", | ||
"version": "1.0.0", | ||
"version": "1.1.0-alpha.0", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "sideEffects": false, |
@@ -1,2 +0,2 @@ | ||
import type { ElementType, ReactNode } from 'react' | ||
import type { ElementType, ReactElement, ReactNode } from 'react' | ||
import { assertNever } from './assertNever' | ||
@@ -11,3 +11,2 @@ import type { BranchNodeList } from './BranchNodeList' | ||
RawNodeRepresentation, | ||
RepresentationFactorySite, | ||
StaticContextFactory, | ||
@@ -18,2 +17,3 @@ SyntheticChildrenFactory, | ||
} from './nodeSpecs' | ||
import { wrapError } from './helpers/wrapError' | ||
@@ -71,3 +71,3 @@ export class ChildrenAnalyzer< | ||
): Array<AllLeavesRepresentation | AllBranchNodesRepresentation> { | ||
const processed = this.processNode(children, initialStaticContext) | ||
const processed = this.processNode(children, initialStaticContext, []) | ||
@@ -88,2 +88,3 @@ const rawResult: Array<AllLeavesRepresentation | AllBranchNodesRepresentation | undefined> = Array.isArray( | ||
staticContext: StaticContext, | ||
componentPath: ReactElement[], | ||
): RawNodeRepresentation<AllLeavesRepresentation, AllBranchNodesRepresentation> { | ||
@@ -121,3 +122,3 @@ if (!node || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean') { | ||
for (const subNode of node) { | ||
const processed = this.processNode(subNode, staticContext) | ||
const processed = this.processNode(subNode, staticContext, componentPath) | ||
@@ -139,3 +140,3 @@ if (processed !== undefined) { | ||
if (!('type' in node)) { | ||
return this.processNode(children, staticContext) | ||
return this.processNode(children, staticContext, componentPath) | ||
} | ||
@@ -146,3 +147,3 @@ children = node.props.children | ||
// Fragment, Portal or other non-component | ||
return this.processNode(children, staticContext) | ||
return this.processNode(children, staticContext, componentPath) | ||
} | ||
@@ -168,2 +169,3 @@ // if (typeof node.type === 'string') { | ||
componentPath = [...componentPath, node] | ||
if (typeof treeNode !== 'string') { | ||
@@ -175,3 +177,7 @@ if (this.options.staticContextFactoryName in treeNode) { | ||
> | ||
staticContext = staticContextFactory(node.props, staticContext) | ||
try { | ||
staticContext = staticContextFactory(node.props, staticContext) | ||
} catch (e) { | ||
wrapError(e, treeNode.displayName ?? '???', this.options.staticContextFactoryName, componentPath) | ||
} | ||
} | ||
@@ -181,3 +187,7 @@ | ||
const factory = treeNode[this.options.staticRenderFactoryName] as SyntheticChildrenFactory<any, StaticContext> | ||
children = factory(node.props, staticContext) | ||
try { | ||
children = factory(node.props, staticContext) | ||
} catch (e) { | ||
wrapError(e, treeNode.displayName ?? '???', this.options.staticRenderFactoryName, componentPath) | ||
} | ||
} | ||
@@ -214,3 +224,3 @@ } | ||
const processedChildren = this.processNode(children, staticContext) | ||
const processedChildren = this.processNode(children, staticContext, componentPath) | ||
@@ -217,0 +227,0 @@ for (const branchNode of this.branchNodes) { |
@@ -1,1 +0,12 @@ | ||
export class ChildrenAnalyzerError extends Error {} | ||
export class ChildrenAnalyzerError extends Error { | ||
public cause?: unknown | ||
public details?: string | ||
constructor(message: string, options?: { cause: unknown, details?: string }) { | ||
super(message) | ||
this.details = options?.details | ||
if ((typeof options === 'object' && 'cause' in options)) { | ||
this.cause = options.cause | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
114
1295
136898
2