@@ -21,12 +21,6 @@ struct HTMLElement : ExpressionMacro {
21
21
}
22
22
}
23
23
24
- /*extension HTMLElement : BodyMacro {
25
- static func expansion(of node: AttributeSyntax, providingBodyFor declaration: some DeclSyntaxProtocol & WithOptionalCodeBlockSyntax, in context: some MacroExpansionContext) throws -> [CodeBlockItemSyntax] {
26
- return ["test: String? = nil,"]
27
- }
28
- }*/
29
-
30
24
private extension HTMLElement {
31
25
static func parse_arguments( elementType: HTMLElementType , arguments: LabeledExprListSyntax ) -> ElementData {
32
26
var attributes : [ String ] = [ ] , innerHTML : [ String ] = [ ]
@@ -87,34 +81,32 @@ private extension HTMLElement {
87
81
if let float: String = expression. as ( FloatLiteralExprSyntax . self) ? . literal. text {
88
82
return yup ( float)
89
83
}
90
- // TODO: fix: [HTMLElementAttribute.controlslist], [HTMLElementAttribute.sandbox]
91
- if let value: String = expression. as ( ArrayExprSyntax . self) ? . elements. map ( {
92
- $0. expression. as ( StringLiteralExprSyntax . self) ? . string
93
- ?? $0. expression. as ( IntegerLiteralExprSyntax . self) !. literal. text
84
+ func enumName( ) -> String {
85
+ switch elementType. rawValue + key { // better performance than switching key, than switching elementType
86
+ case " buttontype " : return " buttontype "
87
+ case " inputtype " : return " inputmode "
88
+ case " oltype " : return " numberingtype "
89
+ case " scripttype " : return " scripttype "
90
+ default : return key
91
+ }
92
+ }
93
+ if let value: String = expression. as ( ArrayExprSyntax . self) ? . elements. compactMap ( {
94
+ if let string: String = $0. expression. as ( StringLiteralExprSyntax . self) ? . string {
95
+ return string
96
+ }
97
+ if let string: String = $0. expression. as ( IntegerLiteralExprSyntax . self) ? . literal. text {
98
+ return string
99
+ }
100
+ if let string: String = $0. expression. as ( MemberAccessExprSyntax . self) ? . declName. baseName. text {
101
+ return HTMLElementAttribute . htmlValue ( enumName: enumName ( ) , for: string)
102
+ }
103
+ return nil
94
104
} ) . joined ( separator: get_separator ( key: key) ) {
95
105
return yup ( value)
96
106
}
97
107
func member( _ value: String ) -> String {
98
- let enumName : String
99
- switch elementType. rawValue + key { // better performance than switching key, than switching elementType
100
- case " buttontype " :
101
- enumName = " buttontype "
102
- break
103
- case " inputtype " :
104
- enumName = " inputmode "
105
- break
106
- case " oltype " :
107
- enumName = " numberingtype "
108
- break
109
- case " scripttype " :
110
- enumName = " scripttype "
111
- break
112
- default :
113
- enumName = key
114
- break
115
- }
116
108
var string : String = String ( value [ value. index ( after: value. startIndex) ... ] )
117
- string = HTMLElementAttribute . htmlValue ( enumName: enumName, for: string)
109
+ string = HTMLElementAttribute . htmlValue ( enumName: enumName ( ) , for: string)
118
110
return yup ( string)
119
111
}
120
112
if let function: FunctionCallExprSyntax = expression. as ( FunctionCallExprSyntax . self) {
0 commit comments