@@ -21,12 +21,6 @@ struct HTMLElement : ExpressionMacro {
2121 }
2222}
2323
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-
3024private extension HTMLElement {
3125 static func parse_arguments( elementType: HTMLElementType , arguments: LabeledExprListSyntax ) -> ElementData {
3226 var attributes : [ String ] = [ ] , innerHTML : [ String ] = [ ]
@@ -87,34 +81,32 @@ private extension HTMLElement {
8781 if let float: String = expression. as ( FloatLiteralExprSyntax . self) ? . literal. text {
8882 return yup ( float)
8983 }
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
94104 } ) . joined ( separator: get_separator ( key: key) ) {
95105 return yup ( value)
96106 }
97107 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- }
116108 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)
118110 return yup ( string)
119111 }
120112 if let function: FunctionCallExprSyntax = expression. as ( FunctionCallExprSyntax . self) {
0 commit comments