@contember/react-multipass-rendering 2.1.0-alpha.30 → 2.1.0-alpha.36

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.
Files changed (114) hide show
  1. package/package.json +8 -3
  2. package/src/ChildrenAnalyzer.ts +26 -25
  3. package/src/helpers/wrapError.ts +2 -3
  4. package/src/nodeSpecs/BranchNode.ts +5 -5
  5. package/src/nodeSpecs/Leaf.ts +3 -7
  6. package/src/nodeSpecs/types/UnconstrainedLeafRepresentationFactory.ts +2 -2
  7. package/tests/cases/unit/childrenAnalyzer.spec.tsx +1 -3
  8. package/dist/development/index.cjs +0 -11
  9. package/dist/development/index.cjs.map +0 -1
  10. package/dist/development/index.js +0 -11
  11. package/dist/development/index.js.map +0 -1
  12. package/dist/development/src/ChildrenAnalyzer.cjs +0 -167
  13. package/dist/development/src/ChildrenAnalyzer.cjs.map +0 -1
  14. package/dist/development/src/ChildrenAnalyzer.js +0 -167
  15. package/dist/development/src/ChildrenAnalyzer.js.map +0 -1
  16. package/dist/development/src/ChildrenAnalyzerError.cjs +0 -14
  17. package/dist/development/src/ChildrenAnalyzerError.cjs.map +0 -1
  18. package/dist/development/src/ChildrenAnalyzerError.js +0 -14
  19. package/dist/development/src/ChildrenAnalyzerError.js.map +0 -1
  20. package/dist/development/src/helpers/getErrorMessage.cjs +0 -7
  21. package/dist/development/src/helpers/getErrorMessage.cjs.map +0 -1
  22. package/dist/development/src/helpers/getErrorMessage.js +0 -7
  23. package/dist/development/src/helpers/getErrorMessage.js.map +0 -1
  24. package/dist/development/src/helpers/wrapError.cjs +0 -51
  25. package/dist/development/src/helpers/wrapError.cjs.map +0 -1
  26. package/dist/development/src/helpers/wrapError.js +0 -51
  27. package/dist/development/src/helpers/wrapError.js.map +0 -1
  28. package/dist/development/src/nodeSpecs/BranchNode.cjs +0 -38
  29. package/dist/development/src/nodeSpecs/BranchNode.cjs.map +0 -1
  30. package/dist/development/src/nodeSpecs/BranchNode.js +0 -38
  31. package/dist/development/src/nodeSpecs/BranchNode.js.map +0 -1
  32. package/dist/development/src/nodeSpecs/Leaf.cjs +0 -24
  33. package/dist/development/src/nodeSpecs/Leaf.cjs.map +0 -1
  34. package/dist/development/src/nodeSpecs/Leaf.js +0 -24
  35. package/dist/development/src/nodeSpecs/Leaf.js.map +0 -1
  36. package/dist/production/index.cjs +0 -11
  37. package/dist/production/index.cjs.map +0 -1
  38. package/dist/production/index.js +0 -11
  39. package/dist/production/index.js.map +0 -1
  40. package/dist/production/src/ChildrenAnalyzer.cjs +0 -167
  41. package/dist/production/src/ChildrenAnalyzer.cjs.map +0 -1
  42. package/dist/production/src/ChildrenAnalyzer.js +0 -167
  43. package/dist/production/src/ChildrenAnalyzer.js.map +0 -1
  44. package/dist/production/src/ChildrenAnalyzerError.cjs +0 -14
  45. package/dist/production/src/ChildrenAnalyzerError.cjs.map +0 -1
  46. package/dist/production/src/ChildrenAnalyzerError.js +0 -14
  47. package/dist/production/src/ChildrenAnalyzerError.js.map +0 -1
  48. package/dist/production/src/helpers/getErrorMessage.cjs +0 -7
  49. package/dist/production/src/helpers/getErrorMessage.cjs.map +0 -1
  50. package/dist/production/src/helpers/getErrorMessage.js +0 -7
  51. package/dist/production/src/helpers/getErrorMessage.js.map +0 -1
  52. package/dist/production/src/helpers/wrapError.cjs +0 -51
  53. package/dist/production/src/helpers/wrapError.cjs.map +0 -1
  54. package/dist/production/src/helpers/wrapError.js +0 -51
  55. package/dist/production/src/helpers/wrapError.js.map +0 -1
  56. package/dist/production/src/nodeSpecs/BranchNode.cjs +0 -38
  57. package/dist/production/src/nodeSpecs/BranchNode.cjs.map +0 -1
  58. package/dist/production/src/nodeSpecs/BranchNode.js +0 -38
  59. package/dist/production/src/nodeSpecs/BranchNode.js.map +0 -1
  60. package/dist/production/src/nodeSpecs/Leaf.cjs +0 -24
  61. package/dist/production/src/nodeSpecs/Leaf.cjs.map +0 -1
  62. package/dist/production/src/nodeSpecs/Leaf.js +0 -24
  63. package/dist/production/src/nodeSpecs/Leaf.js.map +0 -1
  64. package/dist/types/BranchNodeList.d.ts +0 -3
  65. package/dist/types/BranchNodeList.d.ts.map +0 -1
  66. package/dist/types/ChildrenAnalyzer.d.ts +0 -15
  67. package/dist/types/ChildrenAnalyzer.d.ts.map +0 -1
  68. package/dist/types/ChildrenAnalyzerError.d.ts +0 -8
  69. package/dist/types/ChildrenAnalyzerError.d.ts.map +0 -1
  70. package/dist/types/ChildrenAnalyzerOptions.d.ts +0 -10
  71. package/dist/types/ChildrenAnalyzerOptions.d.ts.map +0 -1
  72. package/dist/types/ErrorMessageFactory.d.ts +0 -3
  73. package/dist/types/ErrorMessageFactory.d.ts.map +0 -1
  74. package/dist/types/LeafList.d.ts +0 -3
  75. package/dist/types/LeafList.d.ts.map +0 -1
  76. package/dist/types/helpers/getErrorMessage.d.ts +0 -4
  77. package/dist/types/helpers/getErrorMessage.d.ts.map +0 -1
  78. package/dist/types/helpers/index.d.ts +0 -2
  79. package/dist/types/helpers/index.d.ts.map +0 -1
  80. package/dist/types/helpers/wrapError.d.ts +0 -3
  81. package/dist/types/helpers/wrapError.d.ts.map +0 -1
  82. package/dist/types/index.d.ts +0 -5
  83. package/dist/types/index.d.ts.map +0 -1
  84. package/dist/types/nodeSpecs/BranchNode.d.ts +0 -23
  85. package/dist/types/nodeSpecs/BranchNode.d.ts.map +0 -1
  86. package/dist/types/nodeSpecs/BranchNodeOptions.d.ts +0 -5
  87. package/dist/types/nodeSpecs/BranchNodeOptions.d.ts.map +0 -1
  88. package/dist/types/nodeSpecs/Leaf.d.ts +0 -20
  89. package/dist/types/nodeSpecs/Leaf.d.ts.map +0 -1
  90. package/dist/types/nodeSpecs/RawNodeRepresentation.d.ts +0 -2
  91. package/dist/types/nodeSpecs/RawNodeRepresentation.d.ts.map +0 -1
  92. package/dist/types/nodeSpecs/index.d.ts +0 -6
  93. package/dist/types/nodeSpecs/index.d.ts.map +0 -1
  94. package/dist/types/nodeSpecs/types/ChildrenRepresentationReducer.d.ts +0 -2
  95. package/dist/types/nodeSpecs/types/ChildrenRepresentationReducer.d.ts.map +0 -1
  96. package/dist/types/nodeSpecs/types/ConstrainedLeafRepresentationFactory.d.ts +0 -3
  97. package/dist/types/nodeSpecs/types/ConstrainedLeafRepresentationFactory.d.ts.map +0 -1
  98. package/dist/types/nodeSpecs/types/DeclarationSiteNodeRepresentationFactory.d.ts +0 -2
  99. package/dist/types/nodeSpecs/types/DeclarationSiteNodeRepresentationFactory.d.ts.map +0 -1
  100. package/dist/types/nodeSpecs/types/RepresentationFactorySite.d.ts +0 -2
  101. package/dist/types/nodeSpecs/types/RepresentationFactorySite.d.ts.map +0 -1
  102. package/dist/types/nodeSpecs/types/StaticContextFactory.d.ts +0 -2
  103. package/dist/types/nodeSpecs/types/StaticContextFactory.d.ts.map +0 -1
  104. package/dist/types/nodeSpecs/types/SyntheticChildrenFactory.d.ts +0 -3
  105. package/dist/types/nodeSpecs/types/SyntheticChildrenFactory.d.ts.map +0 -1
  106. package/dist/types/nodeSpecs/types/UnconstrainedLeafRepresentationFactory.d.ts +0 -3
  107. package/dist/types/nodeSpecs/types/UnconstrainedLeafRepresentationFactory.d.ts.map +0 -1
  108. package/dist/types/nodeSpecs/types/UseSiteBranchNodeRepresentationFactory.d.ts +0 -3
  109. package/dist/types/nodeSpecs/types/UseSiteBranchNodeRepresentationFactory.d.ts.map +0 -1
  110. package/dist/types/nodeSpecs/types/ValidFactoryName.d.ts +0 -2
  111. package/dist/types/nodeSpecs/types/ValidFactoryName.d.ts.map +0 -1
  112. package/dist/types/nodeSpecs/types/index.d.ts +0 -10
  113. package/dist/types/nodeSpecs/types/index.d.ts.map +0 -1
  114. package/dist/types/tsconfig.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/react-multipass-rendering",
3
3
  "license": "Apache-2.0",
4
- "version": "2.1.0-alpha.30",
4
+ "version": "2.1.0-alpha.36",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/production/index.js",
@@ -29,9 +29,14 @@
29
29
  "ae:test": "api-extractor run"
30
30
  },
31
31
  "dependencies": {
32
- "@contember/utilities": "2.1.0-alpha.30"
32
+ "@contember/utilities": "workspace:*"
33
33
  },
34
34
  "peerDependencies": {
35
- "react": "^18 || ^19"
35
+ "react": "catalog:"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/contember/contember.git",
40
+ "directory": "packages/react-multipass-rendering"
36
41
  }
37
42
  }
@@ -69,8 +69,8 @@ export class ChildrenAnalyzer<
69
69
  const processed = this.processNode(children, initialStaticContext, [])
70
70
 
71
71
  const rawResult: Array<AllLeavesRepresentation | AllBranchNodesRepresentation | undefined> = Array.isArray(
72
- processed,
73
- )
72
+ processed,
73
+ )
74
74
  ? processed
75
75
  : [processed]
76
76
 
@@ -84,7 +84,7 @@ export class ChildrenAnalyzer<
84
84
  staticContext: StaticContext,
85
85
  componentPath: ReactElement[],
86
86
  ): RawNodeRepresentation<AllLeavesRepresentation, AllBranchNodesRepresentation> {
87
- if (!node || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean') {
87
+ if (!node || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean' || typeof node === 'bigint') {
88
88
  for (const leaf of this.leaves) {
89
89
  const specification = leaf.specification
90
90
  if (specification.type === 'useSite') {
@@ -129,12 +129,13 @@ export class ChildrenAnalyzer<
129
129
  return mapped
130
130
  }
131
131
 
132
- let children: ReactNode = undefined
132
+ let children: ReactNode
133
133
 
134
- if (!('type' in node)) {
134
+ if (typeof node !== 'object' || !('type' in node)) {
135
135
  return this.processNode(children, staticContext, componentPath)
136
136
  }
137
- children = node.props.children
137
+ const props = node.props as Record<string, any>
138
+ children = props.children
138
139
 
139
140
  if (typeof node.type === 'symbol') {
140
141
  // Fragment, Portal or other non-component
@@ -150,14 +151,15 @@ export class ChildrenAnalyzer<
150
151
 
151
152
  // Component, PureComponent, FunctionComponent
152
153
 
153
- const treeNode = node.type as ElementType &
154
- {
155
- [staticMethod in ValidFactoryName]:
156
- | StaticContextFactory<any, StaticContext>
157
- | SyntheticChildrenFactory<any, StaticContext>
158
- | UnconstrainedLeafRepresentationFactory<any, AllLeavesRepresentation, StaticContext>
159
- | DeclarationSiteNodeRepresentationFactory<any, unknown, AllBranchNodesRepresentation, StaticContext>
160
- }
154
+ const treeNode = node.type as
155
+ & ElementType
156
+ & {
157
+ [staticMethod in ValidFactoryName]:
158
+ | StaticContextFactory<any, StaticContext>
159
+ | SyntheticChildrenFactory<any, StaticContext>
160
+ | UnconstrainedLeafRepresentationFactory<any, AllLeavesRepresentation, StaticContext>
161
+ | DeclarationSiteNodeRepresentationFactory<any, unknown, AllBranchNodesRepresentation, StaticContext>
162
+ }
161
163
 
162
164
  componentPath = [...componentPath, node]
163
165
  if (typeof treeNode !== 'string') {
@@ -167,7 +169,7 @@ export class ChildrenAnalyzer<
167
169
  StaticContext
168
170
  >
169
171
  try {
170
- staticContext = staticContextFactory(node.props, staticContext)
172
+ staticContext = staticContextFactory(props, staticContext)
171
173
  } catch (e) {
172
174
  wrapError(e, treeNode.displayName ?? '???', this.options.staticContextFactoryName, componentPath)
173
175
  }
@@ -176,7 +178,7 @@ export class ChildrenAnalyzer<
176
178
  if (this.options.staticRenderFactoryName in treeNode) {
177
179
  const factory = treeNode[this.options.staticRenderFactoryName] as SyntheticChildrenFactory<any, StaticContext>
178
180
  try {
179
- children = factory(node.props, staticContext)
181
+ children = factory(props, staticContext)
180
182
  } catch (e) {
181
183
  wrapError(e, treeNode.displayName ?? '???', this.options.staticRenderFactoryName, componentPath)
182
184
  }
@@ -190,12 +192,11 @@ export class ChildrenAnalyzer<
190
192
  const { factoryMethodName } = specification
191
193
 
192
194
  if (typeof treeNode !== 'string' && factoryMethodName in treeNode) {
193
- const factory = treeNode[factoryMethodName] as UnconstrainedLeafRepresentationFactory<
194
- any,
195
- AllBranchNodesRepresentation | AllLeavesRepresentation,
196
- StaticContext
197
- >
198
- return factory(node.props, staticContext)
195
+ const factory = treeNode[factoryMethodName] as (
196
+ props: any,
197
+ staticContext: StaticContext,
198
+ ) => AllBranchNodesRepresentation | AllLeavesRepresentation
199
+ return factory(props, staticContext)
199
200
  }
200
201
  break
201
202
  }
@@ -229,7 +230,7 @@ export class ChildrenAnalyzer<
229
230
  AllBranchNodesRepresentation | AllLeavesRepresentation,
230
231
  StaticContext
231
232
  >
232
- return factory(node.props, childrenRepresentationReducer(processedChildren), staticContext)
233
+ return factory(props, childrenRepresentationReducer(processedChildren), staticContext)
233
234
  }
234
235
  break
235
236
  }
@@ -249,8 +250,8 @@ export class ChildrenAnalyzer<
249
250
  }
250
251
 
251
252
  if (
252
- !this.options.ignoreUnhandledNodes &&
253
- !(typeof treeNode !== 'string' && this.options.staticRenderFactoryName in treeNode)
253
+ !this.options.ignoreUnhandledNodes
254
+ && !(typeof treeNode !== 'string' && this.options.staticRenderFactoryName in treeNode)
254
255
  ) {
255
256
  throw new ChildrenAnalyzerError(getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext))
256
257
  }
@@ -7,7 +7,7 @@ export const wrapError = (e: unknown, currentComponentName: string, methodName:
7
7
  }
8
8
 
9
9
  const componentPath = path.map((it, index) => {
10
- const { children, ...props } = it.props
10
+ const { children, ...props } = it.props as Record<string, any>
11
11
  const printProps = (props: any) => {
12
12
  let result = ''
13
13
  for (const [key, value] of Object.entries(props)) {
@@ -23,8 +23,7 @@ export const wrapError = (e: unknown, currentComponentName: string, methodName:
23
23
  return '(react element)'
24
24
  }
25
25
  return value
26
- },
27
- )
26
+ })
28
27
  result += ` ${key}=${valuePrinted}`
29
28
  } catch {
30
29
  result += ` ${key}=(failed to print a value)`
@@ -89,15 +89,15 @@ namespace BranchNode {
89
89
  type: 'declarationSite'
90
90
  factoryMethodName: FactoryMethodName
91
91
  childrenRepresentationReducer: ChildrenRepresentationReducer<
92
- ChildrenRepresentation,
93
- ReducedChildrenRepresentation
94
- >
95
- }
92
+ ChildrenRepresentation,
93
+ ReducedChildrenRepresentation
94
+ >
95
+ }
96
96
  | {
97
97
  type: 'useSite'
98
98
  factory: UseSiteBranchNodeRepresentationFactory<Props, ChildrenRepresentation, Representation, StaticContext>
99
99
  ComponentType?: ElementType<Props>
100
- }
100
+ }
101
101
  }
102
102
 
103
103
  export { BranchNode }
@@ -1,9 +1,5 @@
1
1
  import type { ElementType } from 'react'
2
- import type {
3
- ConstrainedLeafRepresentationFactory,
4
- UnconstrainedLeafRepresentationFactory,
5
- ValidFactoryName,
6
- } from './types'
2
+ import type { ConstrainedLeafRepresentationFactory, UnconstrainedLeafRepresentationFactory, ValidFactoryName } from './types'
7
3
 
8
4
  class Leaf<
9
5
  Props extends {} = {},
@@ -48,12 +44,12 @@ namespace Leaf {
48
44
  | {
49
45
  type: 'declarationSite'
50
46
  factoryMethodName: FactoryMethodName
51
- }
47
+ }
52
48
  | {
53
49
  type: 'useSite'
54
50
  factory: UnconstrainedLeafRepresentationFactory<Props, Representation, StaticContext>
55
51
  ComponentType?: ElementType<Props>
56
- }
52
+ }
57
53
  }
58
54
 
59
55
  export { Leaf }
@@ -1,6 +1,6 @@
1
- import type { ReactElement, ReactText } from 'react'
1
+ import type { ReactElement } from 'react'
2
2
 
3
3
  export type UnconstrainedLeafRepresentationFactory<Props extends {}, Representation, StaticContext> = (
4
- node: ReactText | ReactElement<Props, any> | boolean | null | undefined,
4
+ node: string | number | bigint | ReactElement<Props, any> | boolean | null | undefined,
5
5
  staticContext: StaticContext,
6
6
  ) => Representation
@@ -1,4 +1,4 @@
1
- import { expect, it, describe } from 'bun:test'
1
+ import { describe, expect, it } from 'bun:test'
2
2
  import type { FunctionComponent, ReactElement, ReactNode } from 'react'
3
3
  import * as React from 'react'
4
4
  import { BranchNode, ChildrenAnalyzer, Leaf, RawNodeRepresentation } from '../../../src'
@@ -197,10 +197,8 @@ describe('children analyzer', () => {
197
197
  123,
198
198
  { foo: '123', baz: 123 },
199
199
  'bar',
200
- // eslint-disable-next-line react/jsx-key
201
200
  <a href="#baz">baz</a>,
202
201
  { foo: '456', baz: 456 },
203
- // eslint-disable-next-line react/jsx-key
204
202
  <br />,
205
203
  { foo: '789', baz: 789 },
206
204
  ])
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const ChildrenAnalyzer = require("./src/ChildrenAnalyzer.cjs");
4
- const ChildrenAnalyzerError = require("./src/ChildrenAnalyzerError.cjs");
5
- const BranchNode = require("./src/nodeSpecs/BranchNode.cjs");
6
- const Leaf = require("./src/nodeSpecs/Leaf.cjs");
7
- exports.ChildrenAnalyzer = ChildrenAnalyzer.ChildrenAnalyzer;
8
- exports.ChildrenAnalyzerError = ChildrenAnalyzerError.ChildrenAnalyzerError;
9
- exports.BranchNode = BranchNode.BranchNode;
10
- exports.Leaf = Leaf.Leaf;
11
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -1,11 +0,0 @@
1
- import { ChildrenAnalyzer } from "./src/ChildrenAnalyzer.js";
2
- import { ChildrenAnalyzerError } from "./src/ChildrenAnalyzerError.js";
3
- import { BranchNode } from "./src/nodeSpecs/BranchNode.js";
4
- import { Leaf } from "./src/nodeSpecs/Leaf.js";
5
- export {
6
- BranchNode,
7
- ChildrenAnalyzer,
8
- ChildrenAnalyzerError,
9
- Leaf
10
- };
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,167 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const utilities = require("@contember/utilities");
4
- const ChildrenAnalyzerError = require("./ChildrenAnalyzerError.cjs");
5
- const wrapError = require("./helpers/wrapError.cjs");
6
- const getErrorMessage = require("./helpers/getErrorMessage.cjs");
7
- var __defProp = Object.defineProperty;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- const _ChildrenAnalyzer = class _ChildrenAnalyzer2 {
11
- constructor(leaves, decider = [], options = {}) {
12
- __publicField(this, "leaves");
13
- __publicField(this, "branchNodes");
14
- __publicField(this, "options");
15
- this.leaves = leaves;
16
- if (Array.isArray(decider)) {
17
- this.branchNodes = decider;
18
- } else {
19
- this.branchNodes = [];
20
- options = decider;
21
- }
22
- this.options = { ..._ChildrenAnalyzer2.defaultOptions, ...options };
23
- }
24
- processChildren(children, initialStaticContext) {
25
- const processed = this.processNode(children, initialStaticContext, []);
26
- const rawResult = Array.isArray(
27
- processed
28
- ) ? processed : [processed];
29
- return rawResult.filter(
30
- (item) => item !== void 0
31
- );
32
- }
33
- processNode(node, staticContext, componentPath) {
34
- if (!node || typeof node === "string" || typeof node === "number" || typeof node === "boolean") {
35
- for (const leaf of this.leaves) {
36
- const specification = leaf.specification;
37
- if (specification.type === "useSite") {
38
- const { ComponentType, factory } = specification;
39
- if (ComponentType === void 0) {
40
- return factory(node, staticContext);
41
- }
42
- }
43
- }
44
- if (node === false || node === void 0 || node === null) {
45
- return void 0;
46
- }
47
- if (!this.options.ignoreUnhandledNodes) {
48
- throw new ChildrenAnalyzerError.ChildrenAnalyzerError(getErrorMessage.getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext));
49
- }
50
- return void 0;
51
- }
52
- if (typeof node === "function") {
53
- if (this.options.ignoreRenderProps) {
54
- return void 0;
55
- }
56
- throw new ChildrenAnalyzerError.ChildrenAnalyzerError(getErrorMessage.getErrorMessage(this.options.renderPropsErrorMessage, node, staticContext));
57
- }
58
- if (Array.isArray(node)) {
59
- let mapped = [];
60
- for (const subNode of node) {
61
- const processed = this.processNode(subNode, staticContext, componentPath);
62
- if (processed !== void 0) {
63
- if (Array.isArray(processed)) {
64
- mapped = mapped.concat(processed);
65
- } else {
66
- mapped.push(processed);
67
- }
68
- }
69
- }
70
- return mapped;
71
- }
72
- let children = void 0;
73
- if (!("type" in node)) {
74
- return this.processNode(children, staticContext, componentPath);
75
- }
76
- children = node.props.children;
77
- if (typeof node.type === "symbol") {
78
- return this.processNode(children, staticContext, componentPath);
79
- }
80
- const treeNode = node.type;
81
- componentPath = [...componentPath, node];
82
- if (typeof treeNode !== "string") {
83
- if (this.options.staticContextFactoryName in treeNode) {
84
- const staticContextFactory = treeNode[this.options.staticContextFactoryName];
85
- try {
86
- staticContext = staticContextFactory(node.props, staticContext);
87
- } catch (e) {
88
- wrapError.wrapError(e, treeNode.displayName ?? "???", this.options.staticContextFactoryName, componentPath);
89
- }
90
- }
91
- if (this.options.staticRenderFactoryName in treeNode) {
92
- const factory = treeNode[this.options.staticRenderFactoryName];
93
- try {
94
- children = factory(node.props, staticContext);
95
- } catch (e) {
96
- wrapError.wrapError(e, treeNode.displayName ?? "???", this.options.staticRenderFactoryName, componentPath);
97
- }
98
- }
99
- }
100
- for (const leaf of this.leaves) {
101
- const specification = leaf.specification;
102
- switch (specification.type) {
103
- case "declarationSite": {
104
- const { factoryMethodName } = specification;
105
- if (typeof treeNode !== "string" && factoryMethodName in treeNode) {
106
- const factory = treeNode[factoryMethodName];
107
- return factory(node.props, staticContext);
108
- }
109
- break;
110
- }
111
- case "useSite": {
112
- const { ComponentType, factory } = specification;
113
- if (ComponentType === void 0 || node.type === ComponentType) {
114
- return factory(node, staticContext);
115
- }
116
- break;
117
- }
118
- default:
119
- return utilities.assertNever(specification);
120
- }
121
- }
122
- const processedChildren = this.processNode(children, staticContext, componentPath);
123
- for (const branchNode of this.branchNodes) {
124
- const specification = branchNode.specification;
125
- switch (specification.type) {
126
- case "declarationSite": {
127
- const { factoryMethodName, childrenRepresentationReducer } = specification;
128
- if (typeof treeNode !== "string" && factoryMethodName in treeNode) {
129
- if (processedChildren === void 0 && !branchNode.options.childrenAreOptional) {
130
- throw new ChildrenAnalyzerError.ChildrenAnalyzerError(branchNode.options.childrenAbsentErrorMessage);
131
- }
132
- const factory = treeNode[factoryMethodName];
133
- return factory(node.props, childrenRepresentationReducer(processedChildren), staticContext);
134
- }
135
- break;
136
- }
137
- case "useSite": {
138
- const { factory, ComponentType } = specification;
139
- if (ComponentType === void 0 || node.type === ComponentType) {
140
- if (processedChildren === void 0 && !branchNode.options.childrenAreOptional) {
141
- throw new ChildrenAnalyzerError.ChildrenAnalyzerError(branchNode.options.childrenAbsentErrorMessage);
142
- }
143
- return factory(node, processedChildren, staticContext);
144
- }
145
- break;
146
- }
147
- default:
148
- return utilities.assertNever(specification);
149
- }
150
- }
151
- if (!this.options.ignoreUnhandledNodes && !(typeof treeNode !== "string" && this.options.staticRenderFactoryName in treeNode)) {
152
- throw new ChildrenAnalyzerError.ChildrenAnalyzerError(getErrorMessage.getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext));
153
- }
154
- return processedChildren;
155
- }
156
- };
157
- __publicField(_ChildrenAnalyzer, "defaultOptions", {
158
- ignoreRenderProps: true,
159
- renderPropsErrorMessage: "Render props (functions as React component children) are not supported.",
160
- ignoreUnhandledNodes: true,
161
- unhandledNodeErrorMessage: "Encountered an unknown child.",
162
- staticContextFactoryName: "getStaticContext",
163
- staticRenderFactoryName: "staticRender"
164
- });
165
- let ChildrenAnalyzer = _ChildrenAnalyzer;
166
- exports.ChildrenAnalyzer = ChildrenAnalyzer;
167
- //# sourceMappingURL=ChildrenAnalyzer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChildrenAnalyzer.cjs","sources":["../../../../packages/react-multipass-rendering/src/ChildrenAnalyzer.ts"],"sourcesContent":["import { assertNever } from '@contember/utilities'\nimport type { ElementType, ReactElement, ReactNode } from 'react'\nimport type { BranchNodeList } from './BranchNodeList'\nimport { ChildrenAnalyzerError } from './ChildrenAnalyzerError'\nimport type { ChildrenAnalyzerOptions } from './ChildrenAnalyzerOptions'\nimport type { LeafList } from './LeafList'\nimport { getErrorMessage } from './helpers'\nimport { wrapError } from './helpers/wrapError'\nimport type {\n\tDeclarationSiteNodeRepresentationFactory,\n\tRawNodeRepresentation,\n\tStaticContextFactory,\n\tSyntheticChildrenFactory,\n\tUnconstrainedLeafRepresentationFactory,\n\tValidFactoryName,\n} from './nodeSpecs'\n\nexport class ChildrenAnalyzer<\n\tAllLeavesRepresentation = any,\n\tAllBranchNodesRepresentation = never,\n\tStaticContext = undefined,\n> {\n\tprivate static defaultOptions: ChildrenAnalyzerOptions = {\n\t\tignoreRenderProps: true,\n\t\trenderPropsErrorMessage: 'Render props (functions as React component children) are not supported.',\n\n\t\tignoreUnhandledNodes: true,\n\t\tunhandledNodeErrorMessage: 'Encountered an unknown child.',\n\n\t\tstaticContextFactoryName: 'getStaticContext',\n\t\tstaticRenderFactoryName: 'staticRender',\n\t}\n\n\tprivate readonly leaves: LeafList<AllLeavesRepresentation, StaticContext>\n\tprivate readonly branchNodes: BranchNodeList<AllLeavesRepresentation, AllBranchNodesRepresentation, StaticContext>\n\tprivate readonly options: ChildrenAnalyzerOptions<StaticContext>\n\n\tpublic constructor(\n\t\tleaves: LeafList<AllLeavesRepresentation, StaticContext>,\n\t\toptions?: Partial<ChildrenAnalyzerOptions>,\n\t)\n\tpublic constructor(\n\t\tleaves: LeafList<AllLeavesRepresentation, StaticContext>,\n\t\tbranchNodes: BranchNodeList<AllLeavesRepresentation, AllBranchNodesRepresentation, StaticContext>,\n\t\toptions?: Partial<ChildrenAnalyzerOptions>,\n\t)\n\tpublic constructor(\n\t\tleaves: LeafList<AllLeavesRepresentation, StaticContext>,\n\t\tdecider:\n\t\t\t| Partial<ChildrenAnalyzerOptions>\n\t\t\t| BranchNodeList<AllLeavesRepresentation, AllBranchNodesRepresentation, StaticContext> = [],\n\t\toptions: Partial<ChildrenAnalyzerOptions> = {},\n\t) {\n\t\tthis.leaves = leaves\n\n\t\tif (Array.isArray(decider)) {\n\t\t\tthis.branchNodes = decider\n\t\t} else {\n\t\t\tthis.branchNodes = []\n\t\t\toptions = decider\n\t\t}\n\t\tthis.options = { ...ChildrenAnalyzer.defaultOptions, ...options }\n\t}\n\n\tpublic processChildren(\n\t\tchildren: ReactNode,\n\t\tinitialStaticContext: StaticContext,\n\t): Array<AllLeavesRepresentation | AllBranchNodesRepresentation> {\n\t\tconst processed = this.processNode(children, initialStaticContext, [])\n\n\t\tconst rawResult: Array<AllLeavesRepresentation | AllBranchNodesRepresentation | undefined> = Array.isArray(\n\t\t\tprocessed,\n\t\t)\n\t\t\t? processed\n\t\t\t: [processed]\n\n\t\treturn rawResult.filter(\n\t\t\t(item): item is AllLeavesRepresentation | AllBranchNodesRepresentation => item !== undefined,\n\t\t)\n\t}\n\n\tprivate processNode(\n\t\tnode: ReactNode,\n\t\tstaticContext: StaticContext,\n\t\tcomponentPath: ReactElement[],\n\t): RawNodeRepresentation<AllLeavesRepresentation, AllBranchNodesRepresentation> {\n\t\tif (!node || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean') {\n\t\t\tfor (const leaf of this.leaves) {\n\t\t\t\tconst specification = leaf.specification\n\t\t\t\tif (specification.type === 'useSite') {\n\t\t\t\t\tconst { ComponentType, factory } = specification\n\t\t\t\t\tif (ComponentType === undefined) {\n\t\t\t\t\t\treturn factory(node, staticContext)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (node === false || node === undefined || node === null) {\n\t\t\t\t// This adds seamless support for conditionals and such.\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tif (!this.options.ignoreUnhandledNodes) {\n\t\t\t\tthrow new ChildrenAnalyzerError(getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext))\n\t\t\t}\n\t\t\treturn undefined\n\t\t}\n\n\t\tif (typeof node === 'function') {\n\t\t\tif (this.options.ignoreRenderProps) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tthrow new ChildrenAnalyzerError(getErrorMessage(this.options.renderPropsErrorMessage, node, staticContext))\n\t\t}\n\n\t\tif (Array.isArray(node)) {\n\t\t\tlet mapped: Array<AllLeavesRepresentation | AllBranchNodesRepresentation> = []\n\n\t\t\tfor (const subNode of node) {\n\t\t\t\tconst processed = this.processNode(subNode, staticContext, componentPath)\n\n\t\t\t\tif (processed !== undefined) {\n\t\t\t\t\tif (Array.isArray(processed)) {\n\t\t\t\t\t\tmapped = mapped.concat(processed)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmapped.push(processed)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mapped\n\t\t}\n\n\t\tlet children: ReactNode = undefined\n\n\t\tif (!('type' in node)) {\n\t\t\treturn this.processNode(children, staticContext, componentPath)\n\t\t}\n\t\tchildren = node.props.children\n\n\t\tif (typeof node.type === 'symbol') {\n\t\t\t// Fragment, Portal or other non-component\n\t\t\treturn this.processNode(children, staticContext, componentPath)\n\t\t}\n\t\t// if (typeof node.type === 'string') {\n\t\t// \t// Typically a host component\n\t\t// \tif (!this.options.ignoreUnhandledNodes) {\n\t\t// \t\tthrow new ChildrenAnalyzerError(getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext))\n\t\t// \t}\n\t\t// \treturn this.processNode(children, staticContext)\n\t\t// }\n\n\t\t// Component, PureComponent, FunctionComponent\n\n\t\tconst treeNode = node.type as ElementType &\n\t\t{\n\t\t\t[staticMethod in ValidFactoryName]:\n\t\t\t| StaticContextFactory<any, StaticContext>\n\t\t\t| SyntheticChildrenFactory<any, StaticContext>\n\t\t\t| UnconstrainedLeafRepresentationFactory<any, AllLeavesRepresentation, StaticContext>\n\t\t\t| DeclarationSiteNodeRepresentationFactory<any, unknown, AllBranchNodesRepresentation, StaticContext>\n\t\t}\n\n\t\tcomponentPath = [...componentPath, node]\n\t\tif (typeof treeNode !== 'string') {\n\t\t\tif (this.options.staticContextFactoryName in treeNode) {\n\t\t\t\tconst staticContextFactory = treeNode[this.options.staticContextFactoryName] as StaticContextFactory<\n\t\t\t\t\tany,\n\t\t\t\t\tStaticContext\n\t\t\t\t>\n\t\t\t\ttry {\n\t\t\t\t\tstaticContext = staticContextFactory(node.props, staticContext)\n\t\t\t\t} catch (e) {\n\t\t\t\t\twrapError(e, treeNode.displayName ?? '???', this.options.staticContextFactoryName, componentPath)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.options.staticRenderFactoryName in treeNode) {\n\t\t\t\tconst factory = treeNode[this.options.staticRenderFactoryName] as SyntheticChildrenFactory<any, StaticContext>\n\t\t\t\ttry {\n\t\t\t\t\tchildren = factory(node.props, staticContext)\n\t\t\t\t} catch (e) {\n\t\t\t\t\twrapError(e, treeNode.displayName ?? '???', this.options.staticRenderFactoryName, componentPath)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const leaf of this.leaves) {\n\t\t\tconst specification = leaf.specification\n\t\t\tswitch (specification.type) {\n\t\t\t\tcase 'declarationSite': {\n\t\t\t\t\tconst { factoryMethodName } = specification\n\n\t\t\t\t\tif (typeof treeNode !== 'string' && factoryMethodName in treeNode) {\n\t\t\t\t\t\tconst factory = treeNode[factoryMethodName] as UnconstrainedLeafRepresentationFactory<\n\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\tAllBranchNodesRepresentation | AllLeavesRepresentation,\n\t\t\t\t\t\t\tStaticContext\n\t\t\t\t\t\t>\n\t\t\t\t\t\treturn factory(node.props, staticContext)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'useSite': {\n\t\t\t\t\tconst { ComponentType, factory } = specification\n\t\t\t\t\tif (ComponentType === undefined || node.type === ComponentType) {\n\t\t\t\t\t\treturn factory(node, staticContext)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(specification)\n\t\t\t}\n\t\t}\n\n\t\tconst processedChildren = this.processNode(children, staticContext, componentPath)\n\n\t\tfor (const branchNode of this.branchNodes) {\n\t\t\tconst specification = branchNode.specification\n\t\t\tswitch (specification.type) {\n\t\t\t\tcase 'declarationSite': {\n\t\t\t\t\tconst { factoryMethodName, childrenRepresentationReducer } = specification\n\n\t\t\t\t\tif (typeof treeNode !== 'string' && factoryMethodName in treeNode) {\n\t\t\t\t\t\tif (processedChildren === undefined && !branchNode.options.childrenAreOptional) {\n\t\t\t\t\t\t\tthrow new ChildrenAnalyzerError(branchNode.options.childrenAbsentErrorMessage)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst factory = treeNode[factoryMethodName] as DeclarationSiteNodeRepresentationFactory<\n\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tAllBranchNodesRepresentation | AllLeavesRepresentation,\n\t\t\t\t\t\t\tStaticContext\n\t\t\t\t\t\t>\n\t\t\t\t\t\treturn factory(node.props, childrenRepresentationReducer(processedChildren), staticContext)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'useSite': {\n\t\t\t\t\tconst { factory, ComponentType } = specification\n\t\t\t\t\tif (ComponentType === undefined || node.type === ComponentType) {\n\t\t\t\t\t\tif (processedChildren === undefined && !branchNode.options.childrenAreOptional) {\n\t\t\t\t\t\t\tthrow new ChildrenAnalyzerError(branchNode.options.childrenAbsentErrorMessage)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn factory(node, processedChildren, staticContext)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(specification)\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t!this.options.ignoreUnhandledNodes &&\n\t\t\t!(typeof treeNode !== 'string' && this.options.staticRenderFactoryName in treeNode)\n\t\t) {\n\t\t\tthrow new ChildrenAnalyzerError(getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext))\n\t\t}\n\n\t\treturn processedChildren\n\t}\n}\n"],"names":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AAS,cAAA,IAAkB;AACnC,cAAI,kBAAkB,UAAa,KAAK,SAAS,eAAe;AAC/D,gBAAI,sBAAsB,UAAa,CAAC,WAAW,QAAQ,qBAAqB;AAC/E,oBAAM,IAAIA,sBAAA,sBAAsB,WAAW,QAAQ,0BAA0B;AAAA,YAAA;AAEvE,mBAAA,QAAQ,MAAM,mBAAmB,aAAa;AAAA,UAAA;AAEtD;AAAA,QAAA;AAAA,QAED;AACC,iBAAOG,UAAAA,YAAY,aAAa;AAAA,MAAA;AAAA,IAClC;AAIA,QAAA,CAAC,KAAK,QAAQ,wBACd,EAAE,OAAO,aAAa,YAAY,KAAK,QAAQ,2BAA2B,WACzE;AACK,YAAA,IAAIH,sBAAAA,sBAAsBC,gBAAAA,gBAAgB,KAAK,QAAQ,2BAA2B,MAAM,aAAa,CAAC;AAAA,IAAA;AAGtG,WAAA;AAAA,EAAA;AAET;AA7OC,cALY,mBAKG,kBAA0C;AAAA,EACxD,mBAAmB;AAAA,EACnB,yBAAyB;AAAA,EAEzB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA,EAE3B,0BAA0B;AAAA,EAC1B,yBAAyB;AAC1B,CAAA;AAdM,IAAM,mBAAN;;"}
@@ -1,167 +0,0 @@
1
- import { assertNever } from "@contember/utilities";
2
- import { ChildrenAnalyzerError } from "./ChildrenAnalyzerError.js";
3
- import { wrapError } from "./helpers/wrapError.js";
4
- import { getErrorMessage } from "./helpers/getErrorMessage.js";
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
- const _ChildrenAnalyzer = class _ChildrenAnalyzer2 {
9
- constructor(leaves, decider = [], options = {}) {
10
- __publicField(this, "leaves");
11
- __publicField(this, "branchNodes");
12
- __publicField(this, "options");
13
- this.leaves = leaves;
14
- if (Array.isArray(decider)) {
15
- this.branchNodes = decider;
16
- } else {
17
- this.branchNodes = [];
18
- options = decider;
19
- }
20
- this.options = { ..._ChildrenAnalyzer2.defaultOptions, ...options };
21
- }
22
- processChildren(children, initialStaticContext) {
23
- const processed = this.processNode(children, initialStaticContext, []);
24
- const rawResult = Array.isArray(
25
- processed
26
- ) ? processed : [processed];
27
- return rawResult.filter(
28
- (item) => item !== void 0
29
- );
30
- }
31
- processNode(node, staticContext, componentPath) {
32
- if (!node || typeof node === "string" || typeof node === "number" || typeof node === "boolean") {
33
- for (const leaf of this.leaves) {
34
- const specification = leaf.specification;
35
- if (specification.type === "useSite") {
36
- const { ComponentType, factory } = specification;
37
- if (ComponentType === void 0) {
38
- return factory(node, staticContext);
39
- }
40
- }
41
- }
42
- if (node === false || node === void 0 || node === null) {
43
- return void 0;
44
- }
45
- if (!this.options.ignoreUnhandledNodes) {
46
- throw new ChildrenAnalyzerError(getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext));
47
- }
48
- return void 0;
49
- }
50
- if (typeof node === "function") {
51
- if (this.options.ignoreRenderProps) {
52
- return void 0;
53
- }
54
- throw new ChildrenAnalyzerError(getErrorMessage(this.options.renderPropsErrorMessage, node, staticContext));
55
- }
56
- if (Array.isArray(node)) {
57
- let mapped = [];
58
- for (const subNode of node) {
59
- const processed = this.processNode(subNode, staticContext, componentPath);
60
- if (processed !== void 0) {
61
- if (Array.isArray(processed)) {
62
- mapped = mapped.concat(processed);
63
- } else {
64
- mapped.push(processed);
65
- }
66
- }
67
- }
68
- return mapped;
69
- }
70
- let children = void 0;
71
- if (!("type" in node)) {
72
- return this.processNode(children, staticContext, componentPath);
73
- }
74
- children = node.props.children;
75
- if (typeof node.type === "symbol") {
76
- return this.processNode(children, staticContext, componentPath);
77
- }
78
- const treeNode = node.type;
79
- componentPath = [...componentPath, node];
80
- if (typeof treeNode !== "string") {
81
- if (this.options.staticContextFactoryName in treeNode) {
82
- const staticContextFactory = treeNode[this.options.staticContextFactoryName];
83
- try {
84
- staticContext = staticContextFactory(node.props, staticContext);
85
- } catch (e) {
86
- wrapError(e, treeNode.displayName ?? "???", this.options.staticContextFactoryName, componentPath);
87
- }
88
- }
89
- if (this.options.staticRenderFactoryName in treeNode) {
90
- const factory = treeNode[this.options.staticRenderFactoryName];
91
- try {
92
- children = factory(node.props, staticContext);
93
- } catch (e) {
94
- wrapError(e, treeNode.displayName ?? "???", this.options.staticRenderFactoryName, componentPath);
95
- }
96
- }
97
- }
98
- for (const leaf of this.leaves) {
99
- const specification = leaf.specification;
100
- switch (specification.type) {
101
- case "declarationSite": {
102
- const { factoryMethodName } = specification;
103
- if (typeof treeNode !== "string" && factoryMethodName in treeNode) {
104
- const factory = treeNode[factoryMethodName];
105
- return factory(node.props, staticContext);
106
- }
107
- break;
108
- }
109
- case "useSite": {
110
- const { ComponentType, factory } = specification;
111
- if (ComponentType === void 0 || node.type === ComponentType) {
112
- return factory(node, staticContext);
113
- }
114
- break;
115
- }
116
- default:
117
- return assertNever(specification);
118
- }
119
- }
120
- const processedChildren = this.processNode(children, staticContext, componentPath);
121
- for (const branchNode of this.branchNodes) {
122
- const specification = branchNode.specification;
123
- switch (specification.type) {
124
- case "declarationSite": {
125
- const { factoryMethodName, childrenRepresentationReducer } = specification;
126
- if (typeof treeNode !== "string" && factoryMethodName in treeNode) {
127
- if (processedChildren === void 0 && !branchNode.options.childrenAreOptional) {
128
- throw new ChildrenAnalyzerError(branchNode.options.childrenAbsentErrorMessage);
129
- }
130
- const factory = treeNode[factoryMethodName];
131
- return factory(node.props, childrenRepresentationReducer(processedChildren), staticContext);
132
- }
133
- break;
134
- }
135
- case "useSite": {
136
- const { factory, ComponentType } = specification;
137
- if (ComponentType === void 0 || node.type === ComponentType) {
138
- if (processedChildren === void 0 && !branchNode.options.childrenAreOptional) {
139
- throw new ChildrenAnalyzerError(branchNode.options.childrenAbsentErrorMessage);
140
- }
141
- return factory(node, processedChildren, staticContext);
142
- }
143
- break;
144
- }
145
- default:
146
- return assertNever(specification);
147
- }
148
- }
149
- if (!this.options.ignoreUnhandledNodes && !(typeof treeNode !== "string" && this.options.staticRenderFactoryName in treeNode)) {
150
- throw new ChildrenAnalyzerError(getErrorMessage(this.options.unhandledNodeErrorMessage, node, staticContext));
151
- }
152
- return processedChildren;
153
- }
154
- };
155
- __publicField(_ChildrenAnalyzer, "defaultOptions", {
156
- ignoreRenderProps: true,
157
- renderPropsErrorMessage: "Render props (functions as React component children) are not supported.",
158
- ignoreUnhandledNodes: true,
159
- unhandledNodeErrorMessage: "Encountered an unknown child.",
160
- staticContextFactoryName: "getStaticContext",
161
- staticRenderFactoryName: "staticRender"
162
- });
163
- let ChildrenAnalyzer = _ChildrenAnalyzer;
164
- export {
165
- ChildrenAnalyzer
166
- };
167
- //# sourceMappingURL=ChildrenAnalyzer.js.map