Skip to content

Commit 211e927

Browse files
added ariaattribute global attribute, and...
- renamed `role` enum in `HTMLElementAttribute.Extra` to `ariarole` - added more roles to `ariarole`
1 parent 757e5b5 commit 211e927

File tree

3 files changed

+411
-90
lines changed

3 files changed

+411
-90
lines changed

Sources/HTMLKitMacros/HTMLElement.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ private extension HTMLElement {
177177
}
178178
break
179179
default:
180+
if key == "ariaattribute" {
181+
key = "aria-" + first_expression.functionCall!.calledExpression.memberAccess!.declName.baseName.text
182+
}
180183
if let string:String = parse_attribute(context: context, elementType: elementType, key: key, expression: first_expression, lookupFiles: lookupFiles) {
181184
value = string
182185
}
@@ -246,7 +249,11 @@ private extension HTMLElement {
246249
case "metahttp-equiv": return "httpequiv"
247250
case "oltype": return "numberingtype"
248251
case "scripttype": return "scripttype"
249-
default: return key
252+
default:
253+
if key.hasPrefix("aria-") {
254+
return "ariaattribute"
255+
}
256+
return key
250257
}
251258
}
252259

@@ -327,13 +334,13 @@ private extension HTMLElement {
327334
return (stringLiteral.string, return_type)
328335
}
329336
if let function:FunctionCallExprSyntax = expression.functionCall {
330-
switch key {
331-
case "command", "download", "height", "width":
337+
let enums:Set<String> = ["command", "download", "height", "width"]
338+
if enums.contains(key) || key.hasPrefix("aria-") {
332339
var value:String = "\(function)"
333340
value = String(value[value.index(after: value.startIndex)...])
334341
value = HTMLElementAttribute.Extra.htmlValue(enumName: enumName(elementType: elementType, key: key), for: value)
335342
return (value, .enumCase)
336-
default:
343+
} else {
337344
if function.calledExpression.as(DeclReferenceExprSyntax.self)?.baseName.text == "StaticString" {
338345
return (function.arguments.first!.expression.stringLiteral!.string, .string)
339346
}
@@ -635,6 +642,7 @@ extension StringLiteralExprSyntax {
635642
extension HTMLElementAttribute.Extra {
636643
static func htmlValue(enumName: String, for enumCase: String) -> String { // only need to check the ones where the htmlValue is different from the rawValue
637644
switch enumName {
645+
case "ariaattribute": return ariaattribute(rawValue: enumCase)?.htmlValue ?? "???"
638646
case "command": return command(rawValue: enumCase)!.htmlValue
639647
case "contenteditable": return contenteditable(rawValue: enumCase)!.htmlValue
640648
case "crossorigin": return crossorigin(rawValue: enumCase)!.htmlValue

0 commit comments

Comments
 (0)