From 1d465c61ef036648fef592b08e98f0660b42e290 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 24 Jun 2021 13:59:20 +0400 Subject: [PATCH] slight refacter --- src/lib/jsx-map.tsx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/lib/jsx-map.tsx b/src/lib/jsx-map.tsx index 1355d56..15572a9 100644 --- a/src/lib/jsx-map.tsx +++ b/src/lib/jsx-map.tsx @@ -32,18 +32,17 @@ export function psJSXMap(ps: T.PsJSX, target: "p" | "f", dealWithString: (ps: T. p: (target === "p" ? base : sec).props.children, f: (target === "p" ? sec : base).props.children, }) - : base.props.children.map((x: string | JSX.Element, i: number) => { - if (typeof x === "string") { - return dealWithString({ + : base.props.children.map((x: string | JSX.Element, i: number) => ( + (typeof x === "string") + ? dealWithString({ p: (target === "p" ? x : sec.props.children[i]), f: (target === "p" ? sec.props.children[i] : x), - }); - } - return psJSXMap({ - p: (target === "p" ? x : sec.props.children[i]), - f: (target === "p" ? sec.props.children[i] : x), - }, target, dealWithString); - }), + }) + : psJSXMap({ + p: (target === "p" ? x : sec.props.children[i]), + f: (target === "p" ? sec.props.children[i] : x), + }, target, dealWithString) + )), }, }; } catch (e) { @@ -68,12 +67,9 @@ export function JSXMap(e: JSX.Element, f: (s: string) => string): JSX.Element { ...e.props, children: typeof e.props.children === "string" ? f(e.props.children) - : e.props.children.map((x: string | JSX.Element) => { - if (typeof x === "string") { - return f(x); - } - return JSXMap(x, f); - }), + : e.props.children.map((x: string | JSX.Element) => ( + (typeof x === "string") ? f(x) : JSXMap(x, f) + )), }, }; } \ No newline at end of file