Skip to content

Commit 1d6ec55

Browse files
committed
element: avoid double tag switch
1 parent 74963d4 commit 1d6ec55

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/browser/dom/element.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ pub const Element = struct {
5959
// in case of null tagname, return the element as it.
6060
return .{ .Element = e };
6161
};
62-
_ = parser.Tag.fromString(tagname) catch {
62+
63+
// TODO SVGElement and MathML are not supported yet.
64+
65+
const tag = parser.Tag.fromString(tagname) catch {
6366
// if the tag is invalid, we don't have an HTMLElement.
6467
return .{ .Element = e };
6568
};
66-
// SVGElement and MathML are not supported yet.
67-
return try HTMLElem.toInterface(T, e);
69+
70+
return HTMLElem.toInterfaceFromTag(T, e, tag);
6871
}
6972

7073
// JS funcs

src/browser/html/elements.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,10 @@ pub fn toInterface(comptime T: type, e: *parser.Element) !T {
11161116
};
11171117
const tag = try parser.Tag.fromString(tagname);
11181118

1119+
return toInterfaceFromTag(T, e, tag);
1120+
}
1121+
1122+
pub fn toInterfaceFromTag(comptime T: type, e: *parser.Element, tag: parser.Tag) !T {
11191123
return switch (tag) {
11201124
.abbr, .acronym, .address, .article, .aside, .b, .basefont, .bdi, .bdo, .bgsound, .big, .center, .cite, .code, .dd, .details, .dfn, .dt, .em, .figcaption, .figure, .footer, .header, .hgroup, .i, .isindex, .keygen, .kbd, .main, .mark, .marquee, .menu, .menuitem, .nav, .nobr, .noframes, .noscript, .rp, .rt, .ruby, .s, .samp, .section, .small, .spacer, .strike, .strong, .sub, .summary, .sup, .tt, .u, .wbr, ._var => .{ .HTMLElement = @as(*parser.ElementHTML, @ptrCast(e)) },
11211125
.a => .{ .HTMLAnchorElement = @as(*parser.Anchor, @ptrCast(e)) },

0 commit comments

Comments
 (0)