@vickbk/tests 0.1.0 → 0.2.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/CHANGELOG.md +45 -21
- package/LICENSE +21 -21
- package/README.md +226 -192
- package/dist/console-Cf1taTRK.mjs +39 -0
- package/dist/console-Cf1taTRK.mjs.map +1 -0
- package/dist/dom-DeHbD1ni.mjs +459 -0
- package/dist/dom-DeHbD1ni.mjs.map +1 -0
- package/dist/index-CKsosUpb.d.mts +249 -0
- package/dist/index-CKsosUpb.d.mts.map +1 -0
- package/dist/index-DtGBqDev.d.mts +25 -0
- package/dist/index-DtGBqDev.d.mts.map +1 -0
- package/dist/pattern-to-regex-BrMJtzu8.cjs.map +1 -1
- package/dist/pattern-to-regex-CO5Y0oDU.mjs.map +1 -1
- package/dist/playwright.cjs.map +1 -1
- package/dist/playwright.mjs.map +1 -1
- package/dist/promises.cjs +45 -0
- package/dist/promises.cjs.map +1 -0
- package/dist/promises.d.cts +34 -0
- package/dist/promises.d.cts.map +1 -0
- package/dist/promises.d.mts +34 -0
- package/dist/promises.d.mts.map +1 -0
- package/dist/promises.mjs +43 -0
- package/dist/promises.mjs.map +1 -0
- package/dist/react.cjs +26 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +26 -1
- package/dist/react.mjs.map +1 -1
- package/dist/vitest/console.d.mts +2 -0
- package/dist/vitest/console.mjs +1 -0
- package/dist/vitest/dom.d.mts +2 -0
- package/dist/vitest/dom.mjs +1 -0
- package/dist/vitest.d.mts +14 -270
- package/dist/vitest.d.mts.map +1 -1
- package/dist/vitest.mjs +13 -490
- package/dist/vitest.mjs.map +1 -1
- package/package.json +23 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promises.mjs","names":[],"sources":["../src/features/promises/utils/resolvedPromise.ts","../src/features/promises/utils/rejectedPromise.ts"],"sourcesContent":["/**\n * Creates a fulfilled promise augmented with Vitest's fulfilled-promise metadata.\n *\n * @param value The value with which the promise is fulfilled.\n * @returns A fulfilled Promise<T> with `status: \"fulfilled\"` and its `value`.\n * @example\n * ```ts\n * const payload = await resolvedPromise({ id: 1 });\n * expect(payload).toEqual({ id: 1 });\n * ```\n */\nexport function resolvedPromise<T>(\n value: T,\n): Promise<T> & { status: \"fulfilled\"; value: T } {\n const promise = Promise.resolve(value);\n return Object.assign(promise, { status: \"fulfilled\" as const, value });\n}\n","/**\n * Creates a rejected promise augmented with Vitest's rejected-promise metadata.\n *\n * @param reason The rejection reason, preserved as an unknown value; defaults to `undefined`.\n * @returns A rejected Promise<never> with `status: \"rejected\"` and its `reason`.\n * @example\n * ```ts\n * await expect(rejectedPromise(new Error(\"Request failed\"))).rejects.toThrow(\"Request failed\");\n * ```\n */\nexport function rejectedPromise(\n reason: unknown = undefined,\n): Promise<never> & { status: \"rejected\"; reason: unknown } {\n const promise = Promise.reject<never>(reason);\n\n promise.catch((error) => error);\n\n return Object.assign(promise, { status: \"rejected\" as const, reason });\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,gBACd,OACgD;CAChD,MAAM,UAAU,QAAQ,QAAQ,KAAK;CACrC,OAAO,OAAO,OAAO,SAAS;EAAE,QAAQ;EAAsB;CAAM,CAAC;AACvE;;;;;;;;;;;;;ACNA,SAAgB,gBACd,SAAkB,KAAA,GACwC;CAC1D,MAAM,UAAU,QAAQ,OAAc,MAAM;CAE5C,QAAQ,OAAO,UAAU,KAAK;CAE9B,OAAO,OAAO,OAAO,SAAS;EAAE,QAAQ;EAAqB;CAAO,CAAC;AACvE"}
|
package/dist/react.cjs
CHANGED
|
@@ -58,6 +58,31 @@ async function executeServerComponent(type, props) {
|
|
|
58
58
|
return await type(props);
|
|
59
59
|
}
|
|
60
60
|
//#endregion
|
|
61
|
+
//#region src/features/react/utils/mayUseHooks.ts
|
|
62
|
+
/**
|
|
63
|
+
* Determines whether a function's source appears to contain a React hook call.
|
|
64
|
+
*
|
|
65
|
+
* Recognizes calls whose names are `use` or begin with `use` followed by an
|
|
66
|
+
* uppercase letter, digit, or underscore. It also supports transformed calls
|
|
67
|
+
* where a closing parenthesis appears between the hook name and its opening
|
|
68
|
+
* call parenthesis, such as `(0, imported.useState)(initialValue)`.
|
|
69
|
+
*
|
|
70
|
+
* Comments are removed before matching to reduce false positives from
|
|
71
|
+
* hook-like text in comments.
|
|
72
|
+
*
|
|
73
|
+
* This is a heuristic, not a complete JavaScript parser. In particular,
|
|
74
|
+
* comment-like sequences inside strings or template literals can confuse
|
|
75
|
+
* comment removal, and hook calls can be missed or falsely detected when
|
|
76
|
+
* source code is transformed or contains hook-like text in string literals.
|
|
77
|
+
*
|
|
78
|
+
* @param type - The function whose source should be inspected.
|
|
79
|
+
* @returns `true` if the source matches a likely hook call; otherwise `false`.
|
|
80
|
+
*/
|
|
81
|
+
function mayUseHooks(type) {
|
|
82
|
+
const withoutComments = Function.prototype.toString.call(type).replace(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, "");
|
|
83
|
+
return /\buse(?:[A-Z0-9_]\w*)?\s*\)?\s*\(/.test(withoutComments);
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
61
86
|
//#region src/features/react/utils/isClientComponent.ts
|
|
62
87
|
/**
|
|
63
88
|
* Determines whether a component should be kept behind a client boundary.
|
|
@@ -75,7 +100,7 @@ function isClientComponent(type) {
|
|
|
75
100
|
if (type === null || typeof type !== "function" && typeof type !== "object") return false;
|
|
76
101
|
const reference = type;
|
|
77
102
|
if (reference.$$typeof === Symbol.for("react.client.reference") || reference.$$typeof === Symbol.for("react.module.reference") || typeof reference.$$id === "string") return true;
|
|
78
|
-
return typeof type === "function" &&
|
|
103
|
+
return typeof type === "function" && mayUseHooks(type);
|
|
79
104
|
}
|
|
80
105
|
//#endregion
|
|
81
106
|
//#region src/features/react/utils/resolveProps.ts
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","names":["React","ClassComponent","FunctionComponent","React","React","React"],"sources":["../src/features/react/utils/resolveArrayChild.ts","../src/features/react/utils/isClassComponent.ts","../src/features/react/utils/executeServerComponent.ts","../src/features/react/utils/isClientComponent.ts","../src/features/react/utils/resolveProps.ts","../src/features/react/utils/resolveElement.ts","../src/features/react/utils/traverseTree.ts","../src/features/react/utils/resolveRscTree.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\r\nimport * as React from \"react\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Resolves one array child and supplies a stable key when the result is an\r\n * element without one.\r\n *\r\n * @param child - The child value to resolve.\r\n * @param index - The child's position in its containing array.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns The resolved child.\r\n * @example\r\n * ```ts\r\n * await resolveArrayChild(<Page />, 0, resolveRscTree);\r\n * ```\r\n */\r\nexport async function resolveArrayChild(\r\n child: ReactNode,\r\n index: number,\r\n resolveTree: ResolveTree,\r\n): Promise<ReactNode> {\r\n const resolvedChild = await resolveTree(child);\r\n if (React.isValidElement(resolvedChild)) {\r\n const keyToUse =\r\n resolvedChild.key ??\r\n (child as { key?: string })?.key ??\r\n `rsc-key-${index}`;\r\n return React.cloneElement(resolvedChild, { key: keyToUse });\r\n }\r\n return resolvedChild;\r\n}\r\n","/**\r\n * Determines whether a component type is a React class component.\r\n *\r\n * @param type - The value to inspect.\r\n * @returns `true` when the value is a React class component.\r\n * @example\r\n * ```ts\r\n * isClassComponent(MyClassComponent); // true\r\n * ```\r\n */\r\nexport function isClassComponent(type: unknown): boolean {\r\n return (\r\n typeof type === \"function\" &&\r\n Boolean(\r\n (type as { prototype?: { isReactComponent?: unknown } }).prototype\r\n ?.isReactComponent,\r\n )\r\n );\r\n}\r\n","import type * as React from \"react\";\r\nimport type { ReactNode } from \"react\";\r\nimport { isClassComponent } from \"./isClassComponent\";\r\n\r\n/**\r\n * Executes a server component and awaits an asynchronous result when present.\r\n * Component errors intentionally propagate to the caller.\r\n *\r\n * @param type - The server component to execute.\r\n * @param props - Props passed to the component.\r\n * @returns The component's resolved render result.\r\n * @example\r\n * ```ts\r\n * await executeServerComponent(Page, { title: \"Hello\" });\r\n * ```\r\n */\r\nexport async function executeServerComponent(\r\n type: React.ComponentType<Record<string, unknown>>,\r\n props: Record<string, unknown>,\r\n): Promise<ReactNode> {\r\n if (isClassComponent(type)) {\r\n const ClassComponent = type as React.ComponentClass<\r\n Record<string, unknown>\r\n >;\r\n return new ClassComponent(props).render();\r\n }\r\n\r\n const FunctionComponent = type as React.FunctionComponent<\r\n Record<string, unknown>\r\n >;\r\n return await FunctionComponent(props);\r\n}\r\n","/**\r\n * Determines whether a component should be kept behind a client boundary.\r\n * React client/module references and functions containing hook calls are not\r\n * invoked directly by the resolver.\r\n *\r\n * @param type - The React element type to inspect.\r\n * @returns `true` when the type represents a client boundary.\r\n * @example\r\n * ```ts\r\n * isClientComponent({ $$typeof: Symbol.for(\"react.client.reference\") }); // true\r\n * ```\r\n */\r\nexport function isClientComponent(type: unknown): boolean {\r\n if (type === null || (typeof type !== \"function\" && typeof type !== \"object\")) {\r\n return false;\r\n }\r\n\r\n const reference = type as { $$typeof?: symbol; $$id?: unknown };\r\n if (\r\n reference.$$typeof === Symbol.for(\"react.client.reference\") ||\r\n reference.$$typeof === Symbol.for(\"react.module.reference\") ||\r\n typeof reference.$$id === \"string\"\r\n ) {\r\n return true;\r\n }\r\n\r\n return (\r\n typeof type === \"function\" &&\r\n /\\buse[A-Z0-9_]\\w*\\s*\\(/.test(Function.prototype.toString.call(type))\r\n );\r\n}\r\n","import * as React from \"react\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Resolves React elements and arrays nested in a component's props.\r\n *\r\n * @param props - The component props to inspect.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns Updated props and whether any prop value changed.\r\n * @example\r\n * ```ts\r\n * const result = await resolveProps({ children: <Page /> }, resolveRscTree);\r\n * ```\r\n */\r\nexport async function resolveProps(\r\n props: Record<string, unknown>,\r\n resolveTree: ResolveTree,\r\n): Promise<{ newProps: Record<string, unknown>; hasChanged: boolean }> {\r\n const newProps: Record<string, unknown> = { ...props };\r\n let hasChanged = false;\r\n\r\n for (const key of Object.keys(newProps)) {\r\n const value = newProps[key];\r\n if (React.isValidElement(value) || Array.isArray(value)) {\r\n const resolved = await resolveTree(value as React.ReactNode);\r\n if (resolved !== value) {\r\n newProps[key] = resolved;\r\n hasChanged = true;\r\n }\r\n }\r\n }\r\n\r\n return { newProps, hasChanged };\r\n}\r\n","import type { ReactNode } from \"react\";\r\nimport * as React from \"react\";\r\nimport { executeServerComponent } from \"./executeServerComponent\";\r\nimport { isClientComponent } from \"./isClientComponent\";\r\nimport { resolveProps } from \"./resolveProps\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Resolves a server component element or recursively updates its element props.\r\n * Client component boundaries remain untouched and component errors propagate.\r\n *\r\n * @param node - The React element to resolve.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns The resolved render result or the updated original element.\r\n * @example\r\n * ```ts\r\n * await resolveElement(<ServerPage />, resolveRscTree);\r\n * ```\r\n */\r\nexport async function resolveElement(\r\n node: React.ReactElement,\r\n resolveTree: ResolveTree,\r\n): Promise<ReactNode> {\r\n const { type, props } = node;\r\n\r\n if (typeof type === \"function\" && !isClientComponent(type)) {\r\n const serverResult = await executeServerComponent(\r\n type as React.ComponentType<Record<string, unknown>>,\r\n props as Record<string, unknown>,\r\n );\r\n return resolveTree(serverResult);\r\n }\r\n\r\n if (props && typeof props === \"object\") {\r\n const { newProps, hasChanged } = await resolveProps(\r\n props as Record<string, unknown>,\r\n resolveTree,\r\n );\r\n if (hasChanged) {\r\n return React.cloneElement(node, newProps);\r\n }\r\n }\r\n\r\n return node;\r\n}\r\n","import * as React from \"react\";\r\nimport type { ReactNode } from \"react\";\r\nimport { resolveArrayChild } from \"./resolveArrayChild\";\r\nimport { resolveElement } from \"./resolveElement\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Traverses arrays and React elements, delegating component resolution.\r\n *\r\n * @param node - The tree value to visit.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns The traversed value with server components resolved.\r\n * @example\r\n * ```ts\r\n * await traverseTree(tree, resolveRscTree);\r\n * ```\r\n */\r\nexport async function traverseTree(\r\n node: ReactNode,\r\n resolveTree: ResolveTree,\r\n): Promise<ReactNode> {\r\n if (!node || typeof node !== \"object\") return node;\r\n\r\n if (Array.isArray(node)) {\r\n return Promise.all(\r\n node.map((child, index) => resolveArrayChild(child, index, resolveTree)),\r\n );\r\n }\r\n\r\n if (React.isValidElement(node)) {\r\n return resolveElement(node, resolveTree);\r\n }\r\n\r\n return node;\r\n}\r\n","import type { ReactNode } from \"react\";\r\nimport { traverseTree } from \"./traverseTree\";\r\n\r\n/**\r\n * Recursively resolves synchronous and asynchronous React Server Components.\r\n * Client component boundaries are preserved, and component errors are allowed\r\n * to reject the returned promise.\r\n *\r\n * @param node - The React node or tree to resolve.\r\n * @returns A promise for the resolved React tree.\r\n * @example\r\n * ```ts\r\n * const resolved = await resolveRscTree(<ServerPage />);\r\n * ```\r\n */\r\nexport async function resolveRscTree(node: ReactNode): Promise<ReactNode> {\r\n return traverseTree(node, resolveRscTree);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,kBACpB,OACA,OACA,aACoB;CACpB,MAAM,gBAAgB,MAAM,YAAY,KAAK;CAC7C,IAAIA,MAAM,eAAe,aAAa,GAAG;EACvC,MAAM,WACJ,cAAc,OACb,OAA4B,OAC7B,WAAW;EACb,OAAOA,MAAM,aAAa,eAAe,EAAE,KAAK,SAAS,CAAC;CAC5D;CACA,OAAO;AACT;;;;;;;;;;;;;ACrBA,SAAgB,iBAAiB,MAAwB;CACvD,OACE,OAAO,SAAS,cAChB,QACG,KAAwD,WACrD,gBACN;AAEJ;;;;;;;;;;;;;;;ACFA,eAAsB,uBACpB,MACA,OACoB;CACpB,IAAI,iBAAiB,IAAI,GAIvB,OA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AAO;CAE9C,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,QAAQ,IACb,KAAK,KAAK,OAAO,UAAU,kBAAkB,OAAO,OAAO,WAAW,CAAC,CACzE;CAGF,IAAIC,MAAM,eAAe,IAAI,GAC3B,OAAO,eAAe,MAAM,WAAW;CAGzC,OAAO;AACT;;;;;;;;;;;;;;;ACnBA,eAAsB,eAAe,MAAqC;CACxE,OAAO,aAAa,MAAM,cAAc;AAC1C"}
|
|
1
|
+
{"version":3,"file":"react.cjs","names":["React","ClassComponent","FunctionComponent","React","React","React"],"sources":["../src/features/react/utils/resolveArrayChild.ts","../src/features/react/utils/isClassComponent.ts","../src/features/react/utils/executeServerComponent.ts","../src/features/react/utils/mayUseHooks.ts","../src/features/react/utils/isClientComponent.ts","../src/features/react/utils/resolveProps.ts","../src/features/react/utils/resolveElement.ts","../src/features/react/utils/traverseTree.ts","../src/features/react/utils/resolveRscTree.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport * as React from \"react\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Resolves one array child and supplies a stable key when the result is an\n * element without one.\n *\n * @param child - The child value to resolve.\n * @param index - The child's position in its containing array.\n * @param resolveTree - The recursive tree resolver.\n * @returns The resolved child.\n * @example\n * ```ts\n * await resolveArrayChild(<Page />, 0, resolveRscTree);\n * ```\n */\nexport async function resolveArrayChild(\n child: ReactNode,\n index: number,\n resolveTree: ResolveTree,\n): Promise<ReactNode> {\n const resolvedChild = await resolveTree(child);\n if (React.isValidElement(resolvedChild)) {\n const keyToUse =\n resolvedChild.key ??\n (child as { key?: string })?.key ??\n `rsc-key-${index}`;\n return React.cloneElement(resolvedChild, { key: keyToUse });\n }\n return resolvedChild;\n}\n","/**\n * Determines whether a component type is a React class component.\n *\n * @param type - The value to inspect.\n * @returns `true` when the value is a React class component.\n * @example\n * ```ts\n * isClassComponent(MyClassComponent); // true\n * ```\n */\nexport function isClassComponent(type: unknown): boolean {\n return (\n typeof type === \"function\" &&\n Boolean(\n (type as { prototype?: { isReactComponent?: unknown } }).prototype\n ?.isReactComponent,\n )\n );\n}\n","import type * as React from \"react\";\nimport type { ReactNode } from \"react\";\nimport { isClassComponent } from \"./isClassComponent\";\n\n/**\n * Executes a server component and awaits an asynchronous result when present.\n * Component errors intentionally propagate to the caller.\n *\n * @param type - The server component to execute.\n * @param props - Props passed to the component.\n * @returns The component's resolved render result.\n * @example\n * ```ts\n * await executeServerComponent(Page, { title: \"Hello\" });\n * ```\n */\nexport async function executeServerComponent(\n type: React.ComponentType<Record<string, unknown>>,\n props: Record<string, unknown>,\n): Promise<ReactNode> {\n if (isClassComponent(type)) {\n const ClassComponent = type as React.ComponentClass<\n Record<string, unknown>\n >;\n return new ClassComponent(props).render();\n }\n\n const FunctionComponent = type as React.FunctionComponent<\n Record<string, unknown>\n >;\n return await FunctionComponent(props);\n}\n","/**\n * Determines whether a function's source appears to contain a React hook call.\n *\n * Recognizes calls whose names are `use` or begin with `use` followed by an\n * uppercase letter, digit, or underscore. It also supports transformed calls\n * where a closing parenthesis appears between the hook name and its opening\n * call parenthesis, such as `(0, imported.useState)(initialValue)`.\n *\n * Comments are removed before matching to reduce false positives from\n * hook-like text in comments.\n *\n * This is a heuristic, not a complete JavaScript parser. In particular,\n * comment-like sequences inside strings or template literals can confuse\n * comment removal, and hook calls can be missed or falsely detected when\n * source code is transformed or contains hook-like text in string literals.\n *\n * @param type - The function whose source should be inspected.\n * @returns `true` if the source matches a likely hook call; otherwise `false`.\n */\nexport function mayUseHooks(type: (...args: never[]) => unknown): boolean {\n const source = Function.prototype.toString.call(type);\n\n const withoutComments = source.replace(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*/g, \"\");\n\n return /\\buse(?:[A-Z0-9_]\\w*)?\\s*\\)?\\s*\\(/.test(withoutComments);\n}\n","import { mayUseHooks } from \"./mayUseHooks\";\n\n/**\n * Determines whether a component should be kept behind a client boundary.\n * React client/module references and functions containing hook calls are not\n * invoked directly by the resolver.\n *\n * @param type - The React element type to inspect.\n * @returns `true` when the type represents a client boundary.\n * @example\n * ```ts\n * isClientComponent({ $$typeof: Symbol.for(\"react.client.reference\") }); // true\n * ```\n */\nexport function isClientComponent(type: unknown): boolean {\n if (\n type === null ||\n (typeof type !== \"function\" && typeof type !== \"object\")\n ) {\n return false;\n }\n\n const reference = type as { $$typeof?: symbol; $$id?: unknown };\n if (\n reference.$$typeof === Symbol.for(\"react.client.reference\") ||\n reference.$$typeof === Symbol.for(\"react.module.reference\") ||\n typeof reference.$$id === \"string\"\n ) {\n return true;\n }\n\n return typeof type === \"function\" && mayUseHooks(type as never);\n}\n","import * as React from \"react\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Resolves React elements and arrays nested in a component's props.\n *\n * @param props - The component props to inspect.\n * @param resolveTree - The recursive tree resolver.\n * @returns Updated props and whether any prop value changed.\n * @example\n * ```ts\n * const result = await resolveProps({ children: <Page /> }, resolveRscTree);\n * ```\n */\nexport async function resolveProps(\n props: Record<string, unknown>,\n resolveTree: ResolveTree,\n): Promise<{ newProps: Record<string, unknown>; hasChanged: boolean }> {\n const newProps: Record<string, unknown> = { ...props };\n let hasChanged = false;\n\n for (const key of Object.keys(newProps)) {\n const value = newProps[key];\n if (React.isValidElement(value) || Array.isArray(value)) {\n const resolved = await resolveTree(value as React.ReactNode);\n if (resolved !== value) {\n newProps[key] = resolved;\n hasChanged = true;\n }\n }\n }\n\n return { newProps, hasChanged };\n}\n","import type { ReactNode } from \"react\";\nimport * as React from \"react\";\nimport { executeServerComponent } from \"./executeServerComponent\";\nimport { isClientComponent } from \"./isClientComponent\";\nimport { resolveProps } from \"./resolveProps\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Resolves a server component element or recursively updates its element props.\n * Client component boundaries remain untouched and component errors propagate.\n *\n * @param node - The React element to resolve.\n * @param resolveTree - The recursive tree resolver.\n * @returns The resolved render result or the updated original element.\n * @example\n * ```ts\n * await resolveElement(<ServerPage />, resolveRscTree);\n * ```\n */\nexport async function resolveElement(\n node: React.ReactElement,\n resolveTree: ResolveTree,\n): Promise<ReactNode> {\n const { type, props } = node;\n\n if (typeof type === \"function\" && !isClientComponent(type)) {\n const serverResult = await executeServerComponent(\n type as React.ComponentType<Record<string, unknown>>,\n props as Record<string, unknown>,\n );\n return resolveTree(serverResult);\n }\n\n if (props && typeof props === \"object\") {\n const { newProps, hasChanged } = await resolveProps(\n props as Record<string, unknown>,\n resolveTree,\n );\n if (hasChanged) {\n return React.cloneElement(node, newProps);\n }\n }\n\n return node;\n}\n","import * as React from \"react\";\nimport type { ReactNode } from \"react\";\nimport { resolveArrayChild } from \"./resolveArrayChild\";\nimport { resolveElement } from \"./resolveElement\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Traverses arrays and React elements, delegating component resolution.\n *\n * @param node - The tree value to visit.\n * @param resolveTree - The recursive tree resolver.\n * @returns The traversed value with server components resolved.\n * @example\n * ```ts\n * await traverseTree(tree, resolveRscTree);\n * ```\n */\nexport async function traverseTree(\n node: ReactNode,\n resolveTree: ResolveTree,\n): Promise<ReactNode> {\n if (!node || typeof node !== \"object\") return node;\n\n if (Array.isArray(node)) {\n return Promise.all(\n node.map((child, index) => resolveArrayChild(child, index, resolveTree)),\n );\n }\n\n if (React.isValidElement(node)) {\n return resolveElement(node, resolveTree);\n }\n\n return node;\n}\n","import type { ReactNode } from \"react\";\nimport { traverseTree } from \"./traverseTree\";\n\n/**\n * Recursively resolves synchronous and asynchronous React Server Components.\n * Client component boundaries are preserved, and component errors are allowed\n * to reject the returned promise.\n *\n * @param node - The React node or tree to resolve.\n * @returns A promise for the resolved React tree.\n * @example\n * ```ts\n * const resolved = await resolveRscTree(<ServerPage />);\n * ```\n */\nexport async function resolveRscTree(node: ReactNode): Promise<ReactNode> {\n return traverseTree(node, resolveRscTree);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,kBACpB,OACA,OACA,aACoB;CACpB,MAAM,gBAAgB,MAAM,YAAY,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AO;IAChB,aAAa;GACf;EACF;CACF;CAEA,OAAO;EAAE;EAAU;CAAW;AAChC;;;;;;;;;;;;;;;ACdA,eAAsB,eACpB,MACA,aACoB;CACpB,MAAM,EAAE,MAAM,UAAU;CAExB,IAAI,OAAO,SAAS,cAAc,CAAC,kBAAkB,IAAI,GAKvD,OAAO,YAAY,MAJQ,uBACzB,MACA,KACF,CAC+B;CAGjC,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,EAAE,UAAU,eAAe,MAAM,aACrC,OACA,WACF;EACA,IAAI,YACF,OAAOC,MAAM,aAAa,MAAM,QAAQ;CAE5C;CAEA,OAAO;AACT;;;;;;;;;;;;;;AC3BA,eAAsB,aACpB,MACA,aACoB;CACpB,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU,OAAO;CAE9C,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,QAAQ,IACb,KAAK,KAAK,OAAO,UAAU,kBAAkB,OAAO,OAAO,WAAW,CAAC,CACzE;CAGF,IAAIC,MAAM,eAAe,IAAI,GAC3B,OAAO,eAAe,MAAM,WAAW;CAGzC,OAAO;AACT;;;;;;;;;;;;;;;ACnBA,eAAsB,eAAe,MAAqC;CACxE,OAAO,aAAa,MAAM,cAAc;AAC1C"}
|
package/dist/react.mjs
CHANGED
|
@@ -55,6 +55,31 @@ async function executeServerComponent(type, props) {
|
|
|
55
55
|
return await type(props);
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
+
//#region src/features/react/utils/mayUseHooks.ts
|
|
59
|
+
/**
|
|
60
|
+
* Determines whether a function's source appears to contain a React hook call.
|
|
61
|
+
*
|
|
62
|
+
* Recognizes calls whose names are `use` or begin with `use` followed by an
|
|
63
|
+
* uppercase letter, digit, or underscore. It also supports transformed calls
|
|
64
|
+
* where a closing parenthesis appears between the hook name and its opening
|
|
65
|
+
* call parenthesis, such as `(0, imported.useState)(initialValue)`.
|
|
66
|
+
*
|
|
67
|
+
* Comments are removed before matching to reduce false positives from
|
|
68
|
+
* hook-like text in comments.
|
|
69
|
+
*
|
|
70
|
+
* This is a heuristic, not a complete JavaScript parser. In particular,
|
|
71
|
+
* comment-like sequences inside strings or template literals can confuse
|
|
72
|
+
* comment removal, and hook calls can be missed or falsely detected when
|
|
73
|
+
* source code is transformed or contains hook-like text in string literals.
|
|
74
|
+
*
|
|
75
|
+
* @param type - The function whose source should be inspected.
|
|
76
|
+
* @returns `true` if the source matches a likely hook call; otherwise `false`.
|
|
77
|
+
*/
|
|
78
|
+
function mayUseHooks(type) {
|
|
79
|
+
const withoutComments = Function.prototype.toString.call(type).replace(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, "");
|
|
80
|
+
return /\buse(?:[A-Z0-9_]\w*)?\s*\)?\s*\(/.test(withoutComments);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
58
83
|
//#region src/features/react/utils/isClientComponent.ts
|
|
59
84
|
/**
|
|
60
85
|
* Determines whether a component should be kept behind a client boundary.
|
|
@@ -72,7 +97,7 @@ function isClientComponent(type) {
|
|
|
72
97
|
if (type === null || typeof type !== "function" && typeof type !== "object") return false;
|
|
73
98
|
const reference = type;
|
|
74
99
|
if (reference.$$typeof === Symbol.for("react.client.reference") || reference.$$typeof === Symbol.for("react.module.reference") || typeof reference.$$id === "string") return true;
|
|
75
|
-
return typeof type === "function" &&
|
|
100
|
+
return typeof type === "function" && mayUseHooks(type);
|
|
76
101
|
}
|
|
77
102
|
//#endregion
|
|
78
103
|
//#region src/features/react/utils/resolveProps.ts
|
package/dist/react.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.mjs","names":["ClassComponent","FunctionComponent"],"sources":["../src/features/react/utils/resolveArrayChild.ts","../src/features/react/utils/isClassComponent.ts","../src/features/react/utils/executeServerComponent.ts","../src/features/react/utils/isClientComponent.ts","../src/features/react/utils/resolveProps.ts","../src/features/react/utils/resolveElement.ts","../src/features/react/utils/traverseTree.ts","../src/features/react/utils/resolveRscTree.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\r\nimport * as React from \"react\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Resolves one array child and supplies a stable key when the result is an\r\n * element without one.\r\n *\r\n * @param child - The child value to resolve.\r\n * @param index - The child's position in its containing array.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns The resolved child.\r\n * @example\r\n * ```ts\r\n * await resolveArrayChild(<Page />, 0, resolveRscTree);\r\n * ```\r\n */\r\nexport async function resolveArrayChild(\r\n child: ReactNode,\r\n index: number,\r\n resolveTree: ResolveTree,\r\n): Promise<ReactNode> {\r\n const resolvedChild = await resolveTree(child);\r\n if (React.isValidElement(resolvedChild)) {\r\n const keyToUse =\r\n resolvedChild.key ??\r\n (child as { key?: string })?.key ??\r\n `rsc-key-${index}`;\r\n return React.cloneElement(resolvedChild, { key: keyToUse });\r\n }\r\n return resolvedChild;\r\n}\r\n","/**\r\n * Determines whether a component type is a React class component.\r\n *\r\n * @param type - The value to inspect.\r\n * @returns `true` when the value is a React class component.\r\n * @example\r\n * ```ts\r\n * isClassComponent(MyClassComponent); // true\r\n * ```\r\n */\r\nexport function isClassComponent(type: unknown): boolean {\r\n return (\r\n typeof type === \"function\" &&\r\n Boolean(\r\n (type as { prototype?: { isReactComponent?: unknown } }).prototype\r\n ?.isReactComponent,\r\n )\r\n );\r\n}\r\n","import type * as React from \"react\";\r\nimport type { ReactNode } from \"react\";\r\nimport { isClassComponent } from \"./isClassComponent\";\r\n\r\n/**\r\n * Executes a server component and awaits an asynchronous result when present.\r\n * Component errors intentionally propagate to the caller.\r\n *\r\n * @param type - The server component to execute.\r\n * @param props - Props passed to the component.\r\n * @returns The component's resolved render result.\r\n * @example\r\n * ```ts\r\n * await executeServerComponent(Page, { title: \"Hello\" });\r\n * ```\r\n */\r\nexport async function executeServerComponent(\r\n type: React.ComponentType<Record<string, unknown>>,\r\n props: Record<string, unknown>,\r\n): Promise<ReactNode> {\r\n if (isClassComponent(type)) {\r\n const ClassComponent = type as React.ComponentClass<\r\n Record<string, unknown>\r\n >;\r\n return new ClassComponent(props).render();\r\n }\r\n\r\n const FunctionComponent = type as React.FunctionComponent<\r\n Record<string, unknown>\r\n >;\r\n return await FunctionComponent(props);\r\n}\r\n","/**\r\n * Determines whether a component should be kept behind a client boundary.\r\n * React client/module references and functions containing hook calls are not\r\n * invoked directly by the resolver.\r\n *\r\n * @param type - The React element type to inspect.\r\n * @returns `true` when the type represents a client boundary.\r\n * @example\r\n * ```ts\r\n * isClientComponent({ $$typeof: Symbol.for(\"react.client.reference\") }); // true\r\n * ```\r\n */\r\nexport function isClientComponent(type: unknown): boolean {\r\n if (type === null || (typeof type !== \"function\" && typeof type !== \"object\")) {\r\n return false;\r\n }\r\n\r\n const reference = type as { $$typeof?: symbol; $$id?: unknown };\r\n if (\r\n reference.$$typeof === Symbol.for(\"react.client.reference\") ||\r\n reference.$$typeof === Symbol.for(\"react.module.reference\") ||\r\n typeof reference.$$id === \"string\"\r\n ) {\r\n return true;\r\n }\r\n\r\n return (\r\n typeof type === \"function\" &&\r\n /\\buse[A-Z0-9_]\\w*\\s*\\(/.test(Function.prototype.toString.call(type))\r\n );\r\n}\r\n","import * as React from \"react\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Resolves React elements and arrays nested in a component's props.\r\n *\r\n * @param props - The component props to inspect.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns Updated props and whether any prop value changed.\r\n * @example\r\n * ```ts\r\n * const result = await resolveProps({ children: <Page /> }, resolveRscTree);\r\n * ```\r\n */\r\nexport async function resolveProps(\r\n props: Record<string, unknown>,\r\n resolveTree: ResolveTree,\r\n): Promise<{ newProps: Record<string, unknown>; hasChanged: boolean }> {\r\n const newProps: Record<string, unknown> = { ...props };\r\n let hasChanged = false;\r\n\r\n for (const key of Object.keys(newProps)) {\r\n const value = newProps[key];\r\n if (React.isValidElement(value) || Array.isArray(value)) {\r\n const resolved = await resolveTree(value as React.ReactNode);\r\n if (resolved !== value) {\r\n newProps[key] = resolved;\r\n hasChanged = true;\r\n }\r\n }\r\n }\r\n\r\n return { newProps, hasChanged };\r\n}\r\n","import type { ReactNode } from \"react\";\r\nimport * as React from \"react\";\r\nimport { executeServerComponent } from \"./executeServerComponent\";\r\nimport { isClientComponent } from \"./isClientComponent\";\r\nimport { resolveProps } from \"./resolveProps\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Resolves a server component element or recursively updates its element props.\r\n * Client component boundaries remain untouched and component errors propagate.\r\n *\r\n * @param node - The React element to resolve.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns The resolved render result or the updated original element.\r\n * @example\r\n * ```ts\r\n * await resolveElement(<ServerPage />, resolveRscTree);\r\n * ```\r\n */\r\nexport async function resolveElement(\r\n node: React.ReactElement,\r\n resolveTree: ResolveTree,\r\n): Promise<ReactNode> {\r\n const { type, props } = node;\r\n\r\n if (typeof type === \"function\" && !isClientComponent(type)) {\r\n const serverResult = await executeServerComponent(\r\n type as React.ComponentType<Record<string, unknown>>,\r\n props as Record<string, unknown>,\r\n );\r\n return resolveTree(serverResult);\r\n }\r\n\r\n if (props && typeof props === \"object\") {\r\n const { newProps, hasChanged } = await resolveProps(\r\n props as Record<string, unknown>,\r\n resolveTree,\r\n );\r\n if (hasChanged) {\r\n return React.cloneElement(node, newProps);\r\n }\r\n }\r\n\r\n return node;\r\n}\r\n","import * as React from \"react\";\r\nimport type { ReactNode } from \"react\";\r\nimport { resolveArrayChild } from \"./resolveArrayChild\";\r\nimport { resolveElement } from \"./resolveElement\";\r\nimport type { ResolveTree } from \"./types\";\r\n\r\n/**\r\n * Traverses arrays and React elements, delegating component resolution.\r\n *\r\n * @param node - The tree value to visit.\r\n * @param resolveTree - The recursive tree resolver.\r\n * @returns The traversed value with server components resolved.\r\n * @example\r\n * ```ts\r\n * await traverseTree(tree, resolveRscTree);\r\n * ```\r\n */\r\nexport async function traverseTree(\r\n node: ReactNode,\r\n resolveTree: ResolveTree,\r\n): Promise<ReactNode> {\r\n if (!node || typeof node !== \"object\") return node;\r\n\r\n if (Array.isArray(node)) {\r\n return Promise.all(\r\n node.map((child, index) => resolveArrayChild(child, index, resolveTree)),\r\n );\r\n }\r\n\r\n if (React.isValidElement(node)) {\r\n return resolveElement(node, resolveTree);\r\n }\r\n\r\n return node;\r\n}\r\n","import type { ReactNode } from \"react\";\r\nimport { traverseTree } from \"./traverseTree\";\r\n\r\n/**\r\n * Recursively resolves synchronous and asynchronous React Server Components.\r\n * Client component boundaries are preserved, and component errors are allowed\r\n * to reject the returned promise.\r\n *\r\n * @param node - The React node or tree to resolve.\r\n * @returns A promise for the resolved React tree.\r\n * @example\r\n * ```ts\r\n * const resolved = await resolveRscTree(<ServerPage />);\r\n * ```\r\n */\r\nexport async function resolveRscTree(node: ReactNode): Promise<ReactNode> {\r\n return traverseTree(node, resolveRscTree);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,eAAsB,kBACpB,OACA,OACA,aACoB;CACpB,MAAM,gBAAgB,MAAM,YAAY,KAAK;CAC7C,IAAI,MAAM,eAAe,aAAa,GAAG;EACvC,MAAM,WACJ,cAAc,OACb,OAA4B,OAC7B,WAAW;EACb,OAAO,MAAM,aAAa,eAAe,EAAE,KAAK,SAAS,CAAC;CAC5D;CACA,OAAO;AACT;;;;;;;;;;;;;ACrBA,SAAgB,iBAAiB,MAAwB;CACvD,OACE,OAAO,SAAS,cAChB,QACG,KAAwD,WACrD,gBACN;AAEJ;;;;;;;;;;;;;;;ACFA,eAAsB,uBACpB,MACA,OACoB;CACpB,IAAI,iBAAiB,IAAI,GAIvB,OAAO,IAAIA,KAAe,KAAK,CAAC,CAAC,OAAO;CAM1C,OAAO,MAAMC,KAAkB,KAAK;AACtC;;;;;;;;;;;;;;;ACnBA,SAAgB,kBAAkB,MAAwB;CACxD,IAAI,SAAS,QAAS,OAAO,SAAS,cAAc,OAAO,SAAS,UAClE,OAAO;CAGT,MAAM,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;;;;;;;;;;ACnBA,eAAsB,eAAe,MAAqC;CACxE,OAAO,aAAa,MAAM,cAAc;AAC1C"}
|
|
1
|
+
{"version":3,"file":"react.mjs","names":["ClassComponent","FunctionComponent"],"sources":["../src/features/react/utils/resolveArrayChild.ts","../src/features/react/utils/isClassComponent.ts","../src/features/react/utils/executeServerComponent.ts","../src/features/react/utils/mayUseHooks.ts","../src/features/react/utils/isClientComponent.ts","../src/features/react/utils/resolveProps.ts","../src/features/react/utils/resolveElement.ts","../src/features/react/utils/traverseTree.ts","../src/features/react/utils/resolveRscTree.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport * as React from \"react\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Resolves one array child and supplies a stable key when the result is an\n * element without one.\n *\n * @param child - The child value to resolve.\n * @param index - The child's position in its containing array.\n * @param resolveTree - The recursive tree resolver.\n * @returns The resolved child.\n * @example\n * ```ts\n * await resolveArrayChild(<Page />, 0, resolveRscTree);\n * ```\n */\nexport async function resolveArrayChild(\n child: ReactNode,\n index: number,\n resolveTree: ResolveTree,\n): Promise<ReactNode> {\n const resolvedChild = await resolveTree(child);\n if (React.isValidElement(resolvedChild)) {\n const keyToUse =\n resolvedChild.key ??\n (child as { key?: string })?.key ??\n `rsc-key-${index}`;\n return React.cloneElement(resolvedChild, { key: keyToUse });\n }\n return resolvedChild;\n}\n","/**\n * Determines whether a component type is a React class component.\n *\n * @param type - The value to inspect.\n * @returns `true` when the value is a React class component.\n * @example\n * ```ts\n * isClassComponent(MyClassComponent); // true\n * ```\n */\nexport function isClassComponent(type: unknown): boolean {\n return (\n typeof type === \"function\" &&\n Boolean(\n (type as { prototype?: { isReactComponent?: unknown } }).prototype\n ?.isReactComponent,\n )\n );\n}\n","import type * as React from \"react\";\nimport type { ReactNode } from \"react\";\nimport { isClassComponent } from \"./isClassComponent\";\n\n/**\n * Executes a server component and awaits an asynchronous result when present.\n * Component errors intentionally propagate to the caller.\n *\n * @param type - The server component to execute.\n * @param props - Props passed to the component.\n * @returns The component's resolved render result.\n * @example\n * ```ts\n * await executeServerComponent(Page, { title: \"Hello\" });\n * ```\n */\nexport async function executeServerComponent(\n type: React.ComponentType<Record<string, unknown>>,\n props: Record<string, unknown>,\n): Promise<ReactNode> {\n if (isClassComponent(type)) {\n const ClassComponent = type as React.ComponentClass<\n Record<string, unknown>\n >;\n return new ClassComponent(props).render();\n }\n\n const FunctionComponent = type as React.FunctionComponent<\n Record<string, unknown>\n >;\n return await FunctionComponent(props);\n}\n","/**\n * Determines whether a function's source appears to contain a React hook call.\n *\n * Recognizes calls whose names are `use` or begin with `use` followed by an\n * uppercase letter, digit, or underscore. It also supports transformed calls\n * where a closing parenthesis appears between the hook name and its opening\n * call parenthesis, such as `(0, imported.useState)(initialValue)`.\n *\n * Comments are removed before matching to reduce false positives from\n * hook-like text in comments.\n *\n * This is a heuristic, not a complete JavaScript parser. In particular,\n * comment-like sequences inside strings or template literals can confuse\n * comment removal, and hook calls can be missed or falsely detected when\n * source code is transformed or contains hook-like text in string literals.\n *\n * @param type - The function whose source should be inspected.\n * @returns `true` if the source matches a likely hook call; otherwise `false`.\n */\nexport function mayUseHooks(type: (...args: never[]) => unknown): boolean {\n const source = Function.prototype.toString.call(type);\n\n const withoutComments = source.replace(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*/g, \"\");\n\n return /\\buse(?:[A-Z0-9_]\\w*)?\\s*\\)?\\s*\\(/.test(withoutComments);\n}\n","import { mayUseHooks } from \"./mayUseHooks\";\n\n/**\n * Determines whether a component should be kept behind a client boundary.\n * React client/module references and functions containing hook calls are not\n * invoked directly by the resolver.\n *\n * @param type - The React element type to inspect.\n * @returns `true` when the type represents a client boundary.\n * @example\n * ```ts\n * isClientComponent({ $$typeof: Symbol.for(\"react.client.reference\") }); // true\n * ```\n */\nexport function isClientComponent(type: unknown): boolean {\n if (\n type === null ||\n (typeof type !== \"function\" && typeof type !== \"object\")\n ) {\n return false;\n }\n\n const reference = type as { $$typeof?: symbol; $$id?: unknown };\n if (\n reference.$$typeof === Symbol.for(\"react.client.reference\") ||\n reference.$$typeof === Symbol.for(\"react.module.reference\") ||\n typeof reference.$$id === \"string\"\n ) {\n return true;\n }\n\n return typeof type === \"function\" && mayUseHooks(type as never);\n}\n","import * as React from \"react\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Resolves React elements and arrays nested in a component's props.\n *\n * @param props - The component props to inspect.\n * @param resolveTree - The recursive tree resolver.\n * @returns Updated props and whether any prop value changed.\n * @example\n * ```ts\n * const result = await resolveProps({ children: <Page /> }, resolveRscTree);\n * ```\n */\nexport async function resolveProps(\n props: Record<string, unknown>,\n resolveTree: ResolveTree,\n): Promise<{ newProps: Record<string, unknown>; hasChanged: boolean }> {\n const newProps: Record<string, unknown> = { ...props };\n let hasChanged = false;\n\n for (const key of Object.keys(newProps)) {\n const value = newProps[key];\n if (React.isValidElement(value) || Array.isArray(value)) {\n const resolved = await resolveTree(value as React.ReactNode);\n if (resolved !== value) {\n newProps[key] = resolved;\n hasChanged = true;\n }\n }\n }\n\n return { newProps, hasChanged };\n}\n","import type { ReactNode } from \"react\";\nimport * as React from \"react\";\nimport { executeServerComponent } from \"./executeServerComponent\";\nimport { isClientComponent } from \"./isClientComponent\";\nimport { resolveProps } from \"./resolveProps\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Resolves a server component element or recursively updates its element props.\n * Client component boundaries remain untouched and component errors propagate.\n *\n * @param node - The React element to resolve.\n * @param resolveTree - The recursive tree resolver.\n * @returns The resolved render result or the updated original element.\n * @example\n * ```ts\n * await resolveElement(<ServerPage />, resolveRscTree);\n * ```\n */\nexport async function resolveElement(\n node: React.ReactElement,\n resolveTree: ResolveTree,\n): Promise<ReactNode> {\n const { type, props } = node;\n\n if (typeof type === \"function\" && !isClientComponent(type)) {\n const serverResult = await executeServerComponent(\n type as React.ComponentType<Record<string, unknown>>,\n props as Record<string, unknown>,\n );\n return resolveTree(serverResult);\n }\n\n if (props && typeof props === \"object\") {\n const { newProps, hasChanged } = await resolveProps(\n props as Record<string, unknown>,\n resolveTree,\n );\n if (hasChanged) {\n return React.cloneElement(node, newProps);\n }\n }\n\n return node;\n}\n","import * as React from \"react\";\nimport type { ReactNode } from \"react\";\nimport { resolveArrayChild } from \"./resolveArrayChild\";\nimport { resolveElement } from \"./resolveElement\";\nimport type { ResolveTree } from \"./types\";\n\n/**\n * Traverses arrays and React elements, delegating component resolution.\n *\n * @param node - The tree value to visit.\n * @param resolveTree - The recursive tree resolver.\n * @returns The traversed value with server components resolved.\n * @example\n * ```ts\n * await traverseTree(tree, resolveRscTree);\n * ```\n */\nexport async function traverseTree(\n node: ReactNode,\n resolveTree: ResolveTree,\n): Promise<ReactNode> {\n if (!node || typeof node !== \"object\") return node;\n\n if (Array.isArray(node)) {\n return Promise.all(\n node.map((child, index) => resolveArrayChild(child, index, resolveTree)),\n );\n }\n\n if (React.isValidElement(node)) {\n return resolveElement(node, resolveTree);\n }\n\n return node;\n}\n","import type { ReactNode } from \"react\";\nimport { traverseTree } from \"./traverseTree\";\n\n/**\n * Recursively resolves synchronous and asynchronous React Server Components.\n * Client component boundaries are preserved, and component errors are allowed\n * to reject the returned promise.\n *\n * @param node - The React node or tree to resolve.\n * @returns A promise for the resolved React tree.\n * @example\n * ```ts\n * const resolved = await resolveRscTree(<ServerPage />);\n * ```\n */\nexport async function resolveRscTree(node: ReactNode): Promise<ReactNode> {\n return traverseTree(node, resolveRscTree);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,eAAsB,kBACpB,OACA,OACA,aACoB;CACpB,MAAM,gBAAgB,MAAM,YAAY,KAAK;CAC7C,IAAI,MAAM,eAAe,aAAa,GAAG;EACvC,MAAM,WACJ,cAAc,OACb,OAA4B,OAC7B,WAAW;EACb,OAAO,MAAM,aAAa,eAAe,EAAE,KAAK,SAAS,CAAC;CAC5D;CACA,OAAO;AACT;;;;;;;;;;;;;ACrBA,SAAgB,iBAAiB,MAAwB;CACvD,OACE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,MACA,KACF,CAC+B;CAGjC,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,EAAE,UAAU,eAAe,MAAM,aACrC,OACA,WACF;EACA,IAAI,YACF,OAAO,MAAM,aAAa,MAAM,QAAQ;CAE5C;CAEA,OAAO;AACT;;;;;;;;;;;;;;AC3BA,eAAsB,aACpB,MACA,aACoB;CACpB,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU,OAAO;CAE9C,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,QAAQ,IACb,KAAK,KAAK,OAAO,UAAU,kBAAkB,OAAO,OAAO,WAAW,CAAC,CACzE;CAGF,IAAI,MAAM,eAAe,IAAI,GAC3B,OAAO,eAAe,MAAM,WAAW;CAGzC,OAAO;AACT;;;;;;;;;;;;;;;ACnBA,eAAsB,eAAe,MAAqC;CACxE,OAAO,aAAa,MAAM,cAAc;AAC1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as resetConsole, n as shutConsole } from "../console-Cf1taTRK.mjs";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as shouldSee, c as shouldHaveTestId, d as isChecked, f as clickLabelInput, h as ToggleState, i as togglePopover, l as shouldHaveAttributes, m as ToggleConfig, n as userTypes, o as shouldNotSee, p as fireEvent, r as userClicks, s as shouldNotHaveTestId, t as userTypesMultiple, u as isNotChecked } from "../index-CKsosUpb.mjs";
|
|
2
|
+
export { type ToggleConfig, type ToggleState, clickLabelInput, fireEvent, isChecked, isNotChecked, shouldHaveAttributes, shouldHaveTestId, shouldNotHaveTestId, shouldNotSee, shouldSee, togglePopover, userClicks, userTypes, userTypesMultiple };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { f as clickLabelInput, p as fireEvent, d as isChecked, u as isNotChecked, l as shouldHaveAttributes, c as shouldHaveTestId, s as shouldNotHaveTestId, o as shouldNotSee, a as shouldSee, i as togglePopover, r as userClicks, n as userTypes, t as userTypesMultiple } from "../dom-DeHbD1ni.mjs";
|
package/dist/vitest.d.mts
CHANGED
|
@@ -1,251 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Possible states for a disclosure or popover toggle transition.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const nextState: ToggleState = "open";
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
type ToggleState = "open" | "closed";
|
|
12
|
-
/**
|
|
13
|
-
* The previous and next states dispatched by the toggle-event polyfill.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const transition: ToggleConfig = { oldState: "closed", newState: "open" };
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
type ToggleConfig = Record<"oldState" | "newState", ToggleState>;
|
|
21
|
-
/**
|
|
22
|
-
* Internal shape added to Testing Library's `fireEvent` by its type augmentation.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* installToggleEvent();
|
|
27
|
-
* fireEvent.toggle(document.body, { newState: "open" });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
type ToggleFireEventExtensions = {
|
|
31
|
-
toggle: (element: Document | Element | Window | Node, initDict?: Partial<ToggleConfig>) => boolean;
|
|
32
|
-
};
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/features/vitest/modules/dom/modules/toggle-event/utils/fireEvent.d.ts
|
|
35
|
-
/**
|
|
36
|
-
* Testing Library's fireEvent API with an additional `toggle` event helper.
|
|
37
|
-
*
|
|
38
|
-
* The exported object copies the standard `fireEvent` properties and adds
|
|
39
|
-
* `toggle`, which dispatches the toggle event through `togglePolyfill`.
|
|
40
|
-
* It does not install the extension onto Testing Library's original export.
|
|
41
|
-
*
|
|
42
|
-
* Standard Testing Library event helpers remain available, including
|
|
43
|
-
* `click`, `change`, `input`, `submit`, `focus`, and keyboard/mouse events.
|
|
44
|
-
*
|
|
45
|
-
* @remarks
|
|
46
|
-
* The `toggle` helper defaults to a transition from `closed` to `open`.
|
|
47
|
-
* Call-specific configuration overrides those defaults. This helper does
|
|
48
|
-
* not maintain state between calls.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* import { fireEvent } from "@vickbk/tests/vitest";
|
|
53
|
-
*
|
|
54
|
-
* const disclosure = document.querySelector("details")!;
|
|
55
|
-
*
|
|
56
|
-
* fireEvent.toggle(disclosure);
|
|
57
|
-
* fireEvent.toggle(disclosure, { newState: "closed" });
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```ts
|
|
62
|
-
* import { fireEvent } from "@vickbk/tests/vitest";
|
|
63
|
-
*
|
|
64
|
-
* const button = document.querySelector("button")!;
|
|
65
|
-
*
|
|
66
|
-
* fireEvent.click(button);
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
export declare const fireEvent: typeof fireEvent$1 & ToggleFireEventExtensions;
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/shared/regex/types.d.ts
|
|
72
|
-
type TEXT_PATTERN = RegExp | string;
|
|
73
|
-
type TEXT_WITH_NTH = [TEXT_PATTERN, number];
|
|
74
|
-
type TEXT_MATCHER = TEXT_PATTERN | TEXT_WITH_NTH;
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/features/vitest/modules/dom/utils/clickLabelInput.d.ts
|
|
77
|
-
/**
|
|
78
|
-
* Simulates clicking an input found by its label or placeholder.
|
|
79
|
-
*
|
|
80
|
-
* @param label Label or placeholder text/regular expression identifying the input.
|
|
81
|
-
* @param container Optional element that limits the input search.
|
|
82
|
-
* @returns A promise that resolves after the click interaction completes.
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* await clickLabelInput("Email address");
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export declare function clickLabelInput(label: TEXT_PATTERN, container?: HTMLElement): Promise<void>;
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/features/vitest/modules/dom/utils/isChecked.d.ts
|
|
91
|
-
/**
|
|
92
|
-
* Asserts that the radio button or checkbox matching the accessible name is checked.
|
|
93
|
-
*
|
|
94
|
-
* @param selector Accessible label text or regular expression for the control.
|
|
95
|
-
* @param container Optional element that limits the control search.
|
|
96
|
-
* @returns Nothing; throws an assertion error if the control is absent or unchecked.
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* isChecked("Accept terms");
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export declare function isChecked(selector: TEXT_PATTERN, container?: HTMLElement): void;
|
|
103
|
-
//#endregion
|
|
104
|
-
//#region src/features/vitest/modules/dom/utils/isNotChecked.d.ts
|
|
105
|
-
/**
|
|
106
|
-
* Asserts that the radio button or checkbox matching the accessible name is unchecked.
|
|
107
|
-
*
|
|
108
|
-
* @param selector Accessible label text or regular expression for the control.
|
|
109
|
-
* @param container Optional element that limits the control search.
|
|
110
|
-
* @returns Nothing; throws an assertion error if the control is absent or checked.
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* isNotChecked("Subscribe to updates");
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export declare function isNotChecked(selector: TEXT_PATTERN, container?: HTMLElement): void;
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/features/vitest/modules/dom/utils/shouldHaveAttributes.d.ts
|
|
119
|
-
/**
|
|
120
|
-
* Asserts that an HTMLElement possesses the expected set of DOM attributes and values.
|
|
121
|
-
*
|
|
122
|
-
* Handles string/numeric values, boolean attributes (true = present, false = absent),
|
|
123
|
-
* and null/undefined values (absent).
|
|
124
|
-
*
|
|
125
|
-
* @param element The DOM element whose attributes will be checked.
|
|
126
|
-
* @param attributes Attribute names mapped to their expected values.
|
|
127
|
-
* @returns Nothing; throws an assertion error when any attribute does not match.
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* shouldHaveAttributes(input, { required: true, "aria-label": "Email" });
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
export declare function shouldHaveAttributes(element: HTMLElement, attributes: Record<string, unknown>): void;
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/features/vitest/modules/dom/utils/shouldHaveTestId.d.ts
|
|
136
|
-
/**
|
|
137
|
-
* Asserts that elements with all supplied test IDs are present in the document.
|
|
138
|
-
*
|
|
139
|
-
* @param ids One or more `data-testid` values to locate.
|
|
140
|
-
* @returns The elements found, in the same order as the supplied IDs.
|
|
141
|
-
* @example
|
|
142
|
-
* ```ts
|
|
143
|
-
* const [submitButton] = shouldHaveTestId("submit-button");
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
export declare function shouldHaveTestId(...ids: string[]): HTMLElement[];
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/features/vitest/modules/dom/utils/shouldNotHaveTestId.d.ts
|
|
149
|
-
/**
|
|
150
|
-
* Asserts that elements with all supplied test IDs are absent from the document.
|
|
151
|
-
*
|
|
152
|
-
* @param ids One or more `data-testid` values to verify are absent.
|
|
153
|
-
* @returns The query results (`null` for each absent element), in ID order.
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* shouldNotHaveTestId("loading-spinner");
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
export declare function shouldNotHaveTestId(...ids: string[]): (HTMLElement | null)[];
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/features/vitest/modules/dom/utils/shouldNotSee.d.ts
|
|
162
|
-
/**
|
|
163
|
-
* Asserts that none of the supplied text matchers appear in the document.
|
|
164
|
-
*
|
|
165
|
-
* @param texts Text strings or regular expressions that must be absent.
|
|
166
|
-
* @returns Nothing; throws an assertion error if any text is found.
|
|
167
|
-
* @example
|
|
168
|
-
* ```ts
|
|
169
|
-
* shouldNotSee("Error", /failed/i);
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
export declare const shouldNotSee: (...texts: (string | RegExp)[]) => void;
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/features/vitest/modules/dom/utils/shouldSee.d.ts
|
|
175
|
-
/**
|
|
176
|
-
* Asserts that each requested text matcher is present in the document.
|
|
177
|
-
*
|
|
178
|
-
* @param texts Text strings, regular expressions, or `[matcher, occurrenceIndex]` pairs.
|
|
179
|
-
* @returns The matching elements in the same order as the supplied matchers.
|
|
180
|
-
* @example
|
|
181
|
-
* ```ts
|
|
182
|
-
* const [heading] = shouldSee("Welcome");
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
export declare const shouldSee: (...texts: TEXT_MATCHER[]) => HTMLElement[];
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/features/vitest/modules/dom/utils/togglePopover.d.ts
|
|
188
|
-
/**
|
|
189
|
-
* Dispatches a toggle event on the first element matching a selector.
|
|
190
|
-
*
|
|
191
|
-
* @param options Selector, optional search container, and target open/closed state.
|
|
192
|
-
* @returns The matched element, or `undefined` when no matching element exists.
|
|
193
|
-
* @example
|
|
194
|
-
* ```ts
|
|
195
|
-
* const popover = togglePopover({ selector: "#help", newState: "open" });
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
export declare function togglePopover({ container, selector, newState }: {
|
|
199
|
-
container?: HTMLElement;
|
|
200
|
-
selector: string;
|
|
201
|
-
newState?: ToggleState;
|
|
202
|
-
}): Element | undefined;
|
|
203
|
-
//#endregion
|
|
204
|
-
//#region src/features/vitest/modules/dom/utils/userClicks.d.ts
|
|
205
|
-
/**
|
|
206
|
-
* Simulates a user click on a button with the requested name, or matching text.
|
|
207
|
-
*
|
|
208
|
-
* @param target Button accessible name or text string/regular expression.
|
|
209
|
-
* @param container Optional element that limits the target search.
|
|
210
|
-
* @returns A promise that resolves after the click interaction completes.
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* await userClicks("Save");
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
export declare const userClicks: (target: string | RegExp, container?: HTMLElement) => Promise<void>;
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/features/vitest/modules/dom/utils/userTypes.d.ts
|
|
219
|
-
/**
|
|
220
|
-
* Replaces the value of a textbox found by its label, placeholder, or textbox name.
|
|
221
|
-
*
|
|
222
|
-
* @param target Accessible label, placeholder, or textbox name as text or a regex.
|
|
223
|
-
* @param text Text to type after clearing the existing value.
|
|
224
|
-
* @param container Optional element that limits the textbox search.
|
|
225
|
-
* @param user User-event instance used for the interaction; defaults to a new instance.
|
|
226
|
-
* @returns A promise resolving to the textbox that was updated.
|
|
227
|
-
* @example
|
|
228
|
-
* ```ts
|
|
229
|
-
* const emailInput = await userTypes("Email", "person@example.com");
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
export declare const userTypes: (target: TEXT_PATTERN, text: string, container?: HTMLElement, user?: import("@testing-library/user-event").UserEvent) => Promise<HTMLElement>;
|
|
233
|
-
//#endregion
|
|
234
|
-
//#region src/features/vitest/modules/dom/utils/userTypesMultiple.d.ts
|
|
235
|
-
/**
|
|
236
|
-
* Replaces the values of multiple textboxes, located by their respective selectors.
|
|
237
|
-
*
|
|
238
|
-
* @param inputs Object mapping each textbox label/placeholder to the text to enter.
|
|
239
|
-
* @param container Optional element that limits all textbox searches.
|
|
240
|
-
* @returns A promise resolving to an object mapping each selector to its updated textbox.
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts
|
|
243
|
-
* const fields = await userTypesMultiple({ Email: "person@example.com", Name: "Pat" });
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
export declare function userTypesMultiple(inputs: Record<string, string>, container?: HTMLElement): Promise<Record<string, HTMLElement>>;
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/features/vitest/modules/promises/utils/resolvedPromise.d.ts
|
|
1
|
+
import { n as shutConsole, t as resetConsole } from "./index-DtGBqDev.mjs";
|
|
2
|
+
import { a as shouldSee, c as shouldHaveTestId, d as isChecked, f as clickLabelInput, h as ToggleState, i as togglePopover, l as shouldHaveAttributes, m as ToggleConfig, n as userTypes, o as shouldNotSee, p as fireEvent, r as userClicks, s as shouldNotHaveTestId, t as userTypesMultiple, u as isNotChecked } from "./index-CKsosUpb.mjs";
|
|
3
|
+
//#region src/features/promises/utils/resolvedPromise.d.ts
|
|
249
4
|
/**
|
|
250
5
|
* Creates a fulfilled promise augmented with Vitest's fulfilled-promise metadata.
|
|
251
6
|
*
|
|
@@ -257,12 +12,12 @@ export declare function userTypesMultiple(inputs: Record<string, string>, contai
|
|
|
257
12
|
* expect(payload).toEqual({ id: 1 });
|
|
258
13
|
* ```
|
|
259
14
|
*/
|
|
260
|
-
|
|
15
|
+
declare function resolvedPromise$1<T>(value: T): Promise<T> & {
|
|
261
16
|
status: "fulfilled";
|
|
262
17
|
value: T;
|
|
263
18
|
};
|
|
264
19
|
//#endregion
|
|
265
|
-
//#region src/features/
|
|
20
|
+
//#region src/features/promises/utils/rejectedPromise.d.ts
|
|
266
21
|
/**
|
|
267
22
|
* Creates a rejected promise augmented with Vitest's rejected-promise metadata.
|
|
268
23
|
*
|
|
@@ -273,33 +28,22 @@ export declare function resolvedPromise<T>(value: T): Promise<T> & {
|
|
|
273
28
|
* await expect(rejectedPromise(new Error("Request failed"))).rejects.toThrow("Request failed");
|
|
274
29
|
* ```
|
|
275
30
|
*/
|
|
276
|
-
|
|
31
|
+
declare function rejectedPromise$1(reason?: unknown): Promise<never> & {
|
|
277
32
|
status: "rejected";
|
|
278
33
|
reason: unknown;
|
|
279
34
|
};
|
|
280
35
|
//#endregion
|
|
281
|
-
//#region src/features/vitest/
|
|
36
|
+
//#region src/features/vitest/index.d.ts
|
|
282
37
|
/**
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* ```ts
|
|
287
|
-
* beforeEach(shutConsole);
|
|
288
|
-
* afterEach(resetConsole);
|
|
289
|
-
* ```
|
|
38
|
+
* @deprecated Import `rejectedPromise` from `@vickbk/tests/promises` instead.
|
|
39
|
+
* This re-export is retained for backward compatibility.
|
|
290
40
|
*/
|
|
291
|
-
export declare
|
|
41
|
+
export declare const rejectedPromise: typeof rejectedPromise$1;
|
|
292
42
|
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* @example
|
|
296
|
-
* ```ts
|
|
297
|
-
* shutConsole();
|
|
298
|
-
* // Run code whose console output should be ignored.
|
|
299
|
-
* resetConsole();
|
|
300
|
-
* ```
|
|
43
|
+
* @deprecated Import `resolvedPromise` from `@vickbk/tests/promises` instead.
|
|
44
|
+
* This re-export is retained for backward compatibility.
|
|
301
45
|
*/
|
|
302
|
-
export declare
|
|
46
|
+
export declare const resolvedPromise: typeof resolvedPromise$1;
|
|
303
47
|
//#endregion
|
|
304
|
-
export type
|
|
48
|
+
export { type ToggleConfig, type ToggleState, clickLabelInput, fireEvent, isChecked, isNotChecked, resetConsole, shouldHaveAttributes, shouldHaveTestId, shouldNotHaveTestId, shouldNotSee, shouldSee, shutConsole, togglePopover, userClicks, userTypes, userTypesMultiple };
|
|
305
49
|
//# sourceMappingURL=vitest.d.mts.map
|
package/dist/vitest.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.d.mts","names":["
|
|
1
|
+
{"version":3,"file":"vitest.d.mts","names":["resolvedPromise","rejectedPromise","_rejectedPromise","_resolvedPromise"],"sources":["../src/features/promises/utils/resolvedPromise.ts","../src/features/promises/utils/rejectedPromise.ts","../src/features/vitest/index.ts"],"mappings":";;;;;;;;;;;;;;iBAWgBA,kBAAgB,GAC9B,OAAO,IACN,QAAQ;EAAO;EAAqB,OAAO;;;;;;;;;;;;;;iBCH9BC,kBACd,mBACC;EAAmB;EAAoB;;;;;;;;qBCC7B,wBAAeC;;;;;qBAMf,wBAAeC"}
|