Skip to content

Commit 6d171c6

Browse files
committed
remove execissive new lines
1 parent 8fe368e commit 6d171c6

File tree

5 files changed

+29
-43
lines changed

5 files changed

+29
-43
lines changed

reflex/compiler/templates.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ def render_tag(component: Mapping[str, Any]) -> str:
9393
if child
9494
]
9595

96-
return f"jsx(\n{name},\n{props},\n{contents + ',' if contents else ''}\n{''.join([_RenderUtils.render(child) + ',' for child in rendered_children])}\n)"
96+
return f"jsx({name},{props},{contents + ',' if contents else ''}{','.join([_RenderUtils.render(child) for child in rendered_children])})"
9797

9898
@staticmethod
9999
def render_condition_tag(component: Any) -> str:
100-
return f"({component['cond_state']} ? ({_RenderUtils.render(component['true_value'])}) : ({_RenderUtils.render(component['false_value'])}))"
100+
return f"({component['cond_state']}?({_RenderUtils.render(component['true_value'])}):({_RenderUtils.render(component['false_value'])}))"
101101

102102
@staticmethod
103103
def render_iterable_tag(component: Any) -> str:
@@ -108,7 +108,7 @@ def render_iterable_tag(component: Any) -> str:
108108

109109
@staticmethod
110110
def render_props(props: list[str]) -> str:
111-
return "{" + ",".join(props) + "}"
111+
return f"{{{','.join(props)}}}"
112112

113113
@staticmethod
114114
def render_match_tag(component: Any) -> str:
@@ -131,13 +131,15 @@ def render_match_tag(component: Any) -> str:
131131
@staticmethod
132132
def get_import(module: _ImportDict) -> str:
133133
if module.get("default") and module.get("rest"):
134-
rest_imports = ", ".join(sorted(module["rest"]))
135-
return f'import {module["default"]}, {{ {rest_imports} }} from "{module["lib"]}"'
134+
rest_imports = ",".join(sorted(module["rest"]))
135+
return (
136+
f'import {module["default"]}, {{{rest_imports}}} from "{module["lib"]}"'
137+
)
136138
if module.get("default"):
137139
return f'import {module["default"]} from "{module["lib"]}"'
138140
if module.get("rest"):
139-
rest_imports = ", ".join(sorted(module["rest"]))
140-
return f'import {{ {rest_imports} }} from "{module["lib"]}"'
141+
rest_imports = ",".join(sorted(module["rest"]))
142+
return f'import {{{rest_imports}}} from "{module["lib"]}"'
141143
return f'import "{module["lib"]}"'
142144

143145

@@ -236,11 +238,8 @@ def app_root_template(
236238
];
237239
238240
function AppWrap({{children}}) {{
239-
{_render_hooks(hooks)}
240-
241-
return (
242-
{_RenderUtils.render(render)}
243-
)
241+
{_render_hooks(hooks)}
242+
return ({_RenderUtils.render(render)})
244243
}}
245244
246245

tests/units/components/core/test_match.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def test_match_case_tuple_elements(match_case):
269269
([1, 2], rx.text("third value")),
270270
rx.text("default value"),
271271
),
272-
'Match cases should have the same return types. Case 3 with return value `jsx( RadixThemesText, {as:"p"}, "first value", )` '
272+
'Match cases should have the same return types. Case 3 with return value `jsx(RadixThemesText,{as:"p"},"first value")` '
273273
"of type <class 'reflex.components.radix.themes.typography.text.Text'> is not <class 'reflex.vars.base.Var'>",
274274
),
275275
],

tests/units/components/markdown/test_markdown.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_create_map_fn_var_subclass(cls, fn_body, fn_args, explicit_return, expe
146146
(
147147
"code",
148148
{},
149-
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(SyntaxHighlighter,{children:((Array.isArray(children)) ? children.join("\n") : children),css:({ ["marginTop"] : "1em", ["marginBottom"] : "1em" }),language:_language,style:((resolvedColorMode === "light") ? oneLight : oneDark),wrapLongLines:true,...props},) ); })""",
149+
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children) ) : ( jsx(SyntaxHighlighter,{children:((Array.isArray(children)) ? children.join("\n") : children),css:({ ["marginTop"] : "1em", ["marginBottom"] : "1em" }),language:_language,style:((resolvedColorMode === "light") ? oneLight : oneDark),wrapLongLines:true,...props},) ); })""",
150150
),
151151
(
152152
"code",
@@ -155,7 +155,7 @@ def test_create_map_fn_var_subclass(cls, fn_body, fn_args, explicit_return, expe
155155
value, **props
156156
)
157157
},
158-
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(RadixThemesBox,{css:({ ["pre"] : ({ ["margin"] : "0", ["padding"] : "24px", ["background"] : "transparent", ["overflowX"] : "auto", ["borderRadius"] : "6px" }) }),...props},jsx(ShikiCode,{code:((Array.isArray(children)) ? children.join("\n") : children),decorations:[],language:_language,theme:((resolvedColorMode === "light") ? "one-light" : "one-dark-pro"),transformers:[]},),) ); })""",
158+
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children) ) : ( jsx(RadixThemesBox,{css:({ ["pre"] : ({ ["margin"] : "0", ["padding"] : "24px", ["background"] : "transparent", ["overflowX"] : "auto", ["borderRadius"] : "6px" }) }),...props},jsx(ShikiCode,{code:((Array.isArray(children)) ? children.join("\n") : children),decorations:[],language:_language,theme:((resolvedColorMode === "light") ? "one-light" : "one-dark-pro"),transformers:[]},)) ); })""",
159159
),
160160
(
161161
"h1",
@@ -164,12 +164,12 @@ def test_create_map_fn_var_subclass(cls, fn_body, fn_args, explicit_return, expe
164164
Heading.create(value, as_="h1", size="6", margin_y="0.5em")
165165
)
166166
},
167-
"""(({custom_node, custom_children, custom_props}) => (jsx(CustomMarkdownComponent,{...props},jsx(RadixThemesHeading,{as:"h1",css:({ ["marginTop"] : "0.5em", ["marginBottom"] : "0.5em" }),size:"6"},children,),)))""",
167+
"""(({custom_node, custom_children, custom_props}) => (jsx(CustomMarkdownComponent,{...props},jsx(RadixThemesHeading,{as:"h1",css:({ ["marginTop"] : "0.5em", ["marginBottom"] : "0.5em" }),size:"6"},children))))""",
168168
),
169169
(
170170
"code",
171171
{"codeblock": syntax_highlighter_memoized_component(CodeBlock)},
172-
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(CodeBlock,{codeRxMemo:((Array.isArray(children)) ? children.join("\n") : children),languageRxMemo:_language,...props},) ); })""",
172+
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children) ) : ( jsx(CodeBlock,{codeRxMemo:((Array.isArray(children)) ? children.join("\n") : children),languageRxMemo:_language,...props},) ); })""",
173173
),
174174
(
175175
"code",
@@ -178,7 +178,7 @@ def test_create_map_fn_var_subclass(cls, fn_body, fn_args, explicit_return, expe
178178
ShikiHighLevelCodeBlock
179179
)
180180
},
181-
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(CodeBlock,{codeRxMemo:((Array.isArray(children)) ? children.join("\n") : children),languageRxMemo:_language,...props},) ); })""",
181+
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children) ) : ( jsx(CodeBlock,{codeRxMemo:((Array.isArray(children)) ? children.join("\n") : children),languageRxMemo:_language,...props},) ); })""",
182182
),
183183
],
184184
)

tests/units/components/test_component.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,10 +1152,10 @@ def test_component_with_only_valid_children(fixture, request):
11521152
@pytest.mark.parametrize(
11531153
("component", "rendered"),
11541154
[
1155-
(rx.text("hi"), 'jsx(\nRadixThemesText,\n{as:"p"},\n\n"hi",\n)'),
1155+
(rx.text("hi"), 'jsx(RadixThemesText,{as:"p"},"hi")'),
11561156
(
11571157
rx.box(rx.heading("test", size="3")),
1158-
'jsx(\nRadixThemesBox,\n{},\n\njsx(\nRadixThemesHeading,\n{size:"3"},\n\n"test",\n),\n)',
1158+
'jsx(RadixThemesBox,{},jsx(RadixThemesHeading,{size:"3"},"test"))',
11591159
),
11601160
],
11611161
)

tests/units/test_app.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,13 +1362,9 @@ def test_app_wrap_compile_theme(
13621362
app_js_contents = (
13631363
web_dir / constants.Dirs.PAGES / constants.PageNames.APP_ROOT
13641364
).read_text()
1365-
app_js_lines = [
1366-
line.strip() for line in app_js_contents.splitlines() if line.strip()
1367-
]
1368-
lines = "".join(app_js_lines)
13691365
expected = (
1370-
"function AppWrap({children}) {"
1371-
"const [addEvents, connectErrors] = useContext(EventLoopContext);"
1366+
"function AppWrap({children}) {\n"
1367+
"const [addEvents, connectErrors] = useContext(EventLoopContext);\n\n\n\n"
13721368
"return ("
13731369
+ ("jsx(StrictMode,{}," if react_strict_mode else "")
13741370
+ "jsx(ErrorBoundary,{"
@@ -1382,16 +1378,11 @@ def test_app_wrap_compile_theme(
13821378
"jsx(Fragment,{},"
13831379
"jsx(MemoizedToastProvider,{},),"
13841380
"jsx(Fragment,{},"
1385-
"children,"
1386-
"),"
1387-
"),"
1388-
"),"
1389-
"),"
1390-
"),"
1391-
")" + (",)" if react_strict_mode else "") + ")"
1392-
"}"
1381+
"children"
1382+
"))))))" + (")" if react_strict_mode else "") + ")"
1383+
"\n}"
13931384
)
1394-
assert expected in lines
1385+
assert expected in app_js_contents
13951386

13961387

13971388
@pytest.mark.parametrize(
@@ -1439,13 +1430,9 @@ def page():
14391430
app_js_contents = (
14401431
web_dir / constants.Dirs.PAGES / constants.PageNames.APP_ROOT
14411432
).read_text()
1442-
app_js_lines = [
1443-
line.strip() for line in app_js_contents.splitlines() if line.strip()
1444-
]
1445-
lines = "".join(app_js_lines)
14461433
expected = (
1447-
"function AppWrap({children}) {"
1448-
"const [addEvents, connectErrors] = useContext(EventLoopContext);"
1434+
"function AppWrap({children}) {\n"
1435+
"const [addEvents, connectErrors] = useContext(EventLoopContext);\n\n\n\n"
14491436
"return ("
14501437
+ ("jsx(StrictMode,{}," if react_strict_mode else "")
14511438
+ "jsx(RadixThemesBox,{},"
@@ -1462,9 +1449,9 @@ def page():
14621449
"jsx(MemoizedToastProvider,{},),"
14631450
"jsx(Fragment,{},"
14641451
"children"
1465-
",),),),),),),)" + (",)" if react_strict_mode else "")
1452+
")))))))" + (")" if react_strict_mode else "")
14661453
)
1467-
assert expected in lines
1454+
assert expected in app_js_contents
14681455

14691456

14701457
def test_app_state_determination():

0 commit comments

Comments
 (0)