@@ -71,35 +71,9 @@ private extension HTMLElementMacro {
7171 return parse_inner_html ( context: context, elementType: elementType, child: child, lookupFiles: [ ] )
7272 } ) . joined ( )
7373 }
74- let tag : String , isVoid : Bool
75- var children : Slice < SyntaxChildren >
76- if elementType == . custom {
77- tag = childs. first ( where: { $0. labeled? . label? . text == " tag " } ) !. labeled!. expression. stringLiteral!. string
78- isVoid = childs. first ( where: { $0. labeled? . label? . text == " isVoid " } ) !. labeled!. expression. booleanLiteral!. literal. text == " true "
79- children = childs. dropFirst ( ) // tag
80- children. removeFirst ( ) // isVoid
81- } else {
82- tag = elementType. rawValue. starts ( with: " html " ) ? " html " : elementType. rawValue
83- isVoid = elementType. isVoid
84- children = childs. prefix ( childs. count)
85- }
74+ let children : Slice < SyntaxChildren > = childs. prefix ( childs. count)
8675 let ( attributes, innerHTML, trailingSlash) : ( String , String , Bool ) = parse_arguments ( context: context, elementType: elementType, children: children)
8776 return innerHTML
88-
89- var string : String = ( tag == " html " ? " <!DOCTYPE html> " : " " ) + " < " + tag + attributes
90- if trailingSlash {
91- if isVoid {
92- string += " / "
93- } else {
94- context. diagnose ( Diagnostic ( node: macro, message: DiagnosticMsg ( id: " trailingSlashGlobalAttributeMisused " , message: " Trailing Slash global attribute can only be applied to void elements. " ) ) )
95- return " "
96- }
97- }
98- string += " > " + innerHTML
99- if !isVoid {
100- string += " </ " + tag + " > "
101- }
102- return string
10377 }
10478 // MARK: Parse Arguments
10579 static func parse_arguments(
@@ -261,13 +235,7 @@ private extension HTMLElementMacro {
261235 child: LabeledExprSyntax ,
262236 lookupFiles: Set < String >
263237 ) -> String ? {
264- if let macro: MacroExpansionExprSyntax = child. expression. macroExpansion {
265- var string : String = expand_macro ( context: context, macro: macro)
266- if elementType == . escapeHTML {
267- string. escapeHTML ( escapeAttributes: false )
268- }
269- return string
270- } else if let string: String = parse_element ( expr: child. expression) {
238+ if let string: String = parse_element ( expr: child. expression) {
271239 return string
272240 } else if var string: String = parse_literal_value ( context: context, elementType: elementType, key: " " , expression: child. expression, lookupFiles: lookupFiles) ? . value {
273241 string. escapeHTML ( escapeAttributes: false )
@@ -288,22 +256,6 @@ private extension HTMLElementMacro {
288256 ] ) )
289257 }
290258
291- static func enumName( elementType: HTMLElementType , key: String ) -> String {
292- switch elementType. rawValue + key {
293- case " buttontype " : return " buttontype "
294- case " formenctype " : return " formenctype "
295- case " inputtype " : return " inputtype "
296- case " metahttp-equiv " : return " httpequiv "
297- case " oltype " : return " numberingtype "
298- case " scripttype " : return " scripttype "
299- default :
300- if key. hasPrefix ( " aria- " ) {
301- return " ariaattribute "
302- }
303- return key
304- }
305- }
306-
307259 // MARK: Parse Attribute
308260 static func parse_attribute(
309261 context: some MacroExpansionContext ,
@@ -326,10 +278,6 @@ private extension HTMLElementMacro {
326278 return key + " = \\ \" " + string + " \\ \" "
327279 }
328280 }
329- if let function: FunctionCallExprSyntax = expression. functionCall {
330- let string : String = " \( function) "
331- return HTMLElementAttribute . Extra. htmlValue ( enumName: enumName ( elementType: elementType, key: key) , for: String ( string [ string. index ( after: string. startIndex) ... ] ) )
332- }
333281 return nil
334282 }
335283 // MARK: Parse element
@@ -394,10 +342,7 @@ private extension HTMLElementMacro {
394342 if let function: FunctionCallExprSyntax = expression. functionCall {
395343 let enums : Set < String > = [ " command " , " download " , " height " , " width " ]
396344 if enums. contains ( key) || key. hasPrefix ( " aria- " ) {
397- var value : String = " \( function) "
398- value = String ( value [ value. index ( after: value. startIndex) ... ] )
399- value = HTMLElementAttribute . Extra. htmlValue ( enumName: enumName ( elementType: elementType, key: key) , for: value)
400- return ( value, . enumCase)
345+ return ( " " , . enumCase)
401346 } else {
402347 if let decl: String = function. calledExpression. as ( DeclReferenceExprSyntax . self) ? . baseName. text {
403348 switch decl {
@@ -420,10 +365,7 @@ private extension HTMLElementMacro {
420365 }
421366 }
422367 if let member: MemberAccessExprSyntax = expression. memberAccess {
423- if let _: ExprSyntax = member. base {
424- return ( " \( member) " , . interpolation)
425- }
426- return ( HTMLElementAttribute . Extra. htmlValue ( enumName: enumName ( elementType: elementType, key: key) , for: member. declName. baseName. text) , . enumCase)
368+ return ( " \( member) " , . interpolation)
427369 }
428370 if let array: ArrayExprSyntax = expression. array {
429371 let separator : Character , separator_string : String
@@ -451,9 +393,6 @@ private extension HTMLElementMacro {
451393 if let string: String = element. expression. integerLiteral? . literal. text ?? element. expression. floatLiteral? . literal. text {
452394 result += string + separator_string
453395 }
454- if let string: String = element. expression. memberAccess? . declName. baseName. text {
455- result += HTMLElementAttribute . Extra. htmlValue ( enumName: enumName ( elementType: elementType, key: key) , for: string) + separator_string
456- }
457396 }
458397 if !result. isEmpty {
459398 result. removeLast ( )
@@ -558,28 +497,6 @@ extension StringLiteralExprSyntax {
558497}
559498
560499extension HTMLElementAttribute . Extra {
561- static func htmlValue( enumName: String , for enumCase: String ) -> String { // only need to check the ones where the htmlValue is different from the rawValue
562- switch enumName {
563- case " ariaattribute " : return ariaattribute ( rawValue: enumCase) ? . htmlValue ?? " ??? "
564- case " command " : return command ( rawValue: enumCase) !. htmlValue!
565- case " contenteditable " : return contenteditable ( rawValue: enumCase) !. htmlValue!
566- case " crossorigin " : return crossorigin ( rawValue: enumCase) !. htmlValue!
567- case " download " : return download ( rawValue: enumCase) !. htmlValue!
568- case " formenctype " : return formenctype ( rawValue: enumCase) !. htmlValue!
569- case " hidden " : return hidden ( rawValue: enumCase) !. htmlValue!
570- case " httpequiv " : return httpequiv ( rawValue: enumCase) !. htmlValue!
571- case " inputtype " : return inputtype ( rawValue: enumCase) !. htmlValue!
572- case " numberingtype " : return numberingtype ( rawValue: enumCase) !. htmlValue!
573- case " referrerpolicy " : return referrerpolicy ( rawValue: enumCase) !. htmlValue!
574- case " rel " : return rel ( rawValue: enumCase) !. htmlValue!
575- case " sandbox " : return sandbox ( rawValue: enumCase) !. htmlValue!
576- case " height " , " width " :
577- let values : [ Substring ] = enumCase. split ( separator: " ( " ) , key : String = String ( values [ 0 ] ) , value : String = String ( values [ 1 ] )
578- return value [ value. startIndex..< value. index ( before: value. endIndex) ] + CSSUnitType( rawValue: key) !. suffix
579- default : return enumCase
580- }
581- }
582-
583500 enum CSSUnitType : String {
584501 case centimeters
585502 case millimeters
0 commit comments