Skip to content

Commit f8c0d0c

Browse files
committed
convert vdom func usages too
1 parent 79bd0ff commit f8c0d0c

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/idom/_console/update_html_usages.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,31 @@ def generate_rewrite(file: Path, source: str) -> None:
7171
name = func.id
7272
case _:
7373
name = ""
74-
if hasattr(html, name):
74+
if hasattr(html, name) or name == "vdom":
75+
if name == "vdom":
76+
# first arg is the tag name
77+
node_args_pre = node.args[:1]
78+
node.args = node.args[1:]
79+
else:
80+
node_args_pre = []
81+
7582
match node.args:
7683
case [ast.Dict(keys, values), *_]:
7784
new_kwargs = list(node.keywords)
7885
for k, v in zip(keys, values):
7986
if isinstance(k, ast.Constant) and isinstance(k.value, str):
87+
if k.value == "tagName":
88+
# this is a vdom dict declaration
89+
break
8090
new_kwargs.append(
8191
ast.keyword(arg=conv_attr_name(k.value), value=v)
8292
)
8393
else:
8494
new_kwargs = [ast.keyword(arg=None, value=node.args[0])]
85-
break
86-
node.args = node.args[1:]
87-
node.keywords = new_kwargs
88-
changed.append((node, *parents))
95+
else:
96+
node.args = node_args_pre + node.args[1:]
97+
node.keywords = new_kwargs
98+
changed.append((node, *parents))
8999
case [
90100
ast.Call(
91101
func=ast.Name(id="dict", ctx=ast.Load()),
@@ -99,6 +109,9 @@ def generate_rewrite(file: Path, source: str) -> None:
99109
*node.keywords,
100110
]
101111
for kw in kwargs:
112+
if kw.arg == "tagName":
113+
# this is a vdom dict declaration
114+
break
102115
if kw.arg is not None:
103116
new_kwargs.append(
104117
ast.keyword(
@@ -107,9 +120,10 @@ def generate_rewrite(file: Path, source: str) -> None:
107120
)
108121
else:
109122
new_kwargs.append(kw)
110-
node.args = node.args[1:]
111-
node.keywords = new_kwargs
112-
changed.append((node, *parents))
123+
else:
124+
node.args = node_args_pre + node.args[1:]
125+
node.keywords = new_kwargs
126+
changed.append((node, *parents))
113127

114128
case _:
115129
pass

tests/test__console/test_update_html_usages.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def test_update_html_usages(tmp_path):
2929
'html.div({"className": "test"})',
3030
"html.div(class_name='test')",
3131
),
32+
(
33+
'vdom("div", {"className": "test"})',
34+
"vdom('div', class_name='test')",
35+
),
3236
(
3337
'html.div({class_name: "test", **other})',
3438
"html.div(**{class_name: 'test', **other})",
@@ -68,6 +72,10 @@ def test_update_html_usages(tmp_path):
6872
'html.div(ignore, {"className": "test"})',
6973
None,
7074
),
75+
(
76+
'html.div({"tagName": "test"})',
77+
None,
78+
),
7179
# avoid unnecessary changes
7280
(
7381
"""

0 commit comments

Comments
 (0)