@@ -20,10 +20,10 @@ private extension HTMLElement {
2020 static func parse_arguments( context: some MacroExpansionContext , elementType: HTMLElementType , children: Slice < SyntaxChildren > ) -> ElementData {
2121 var attributes : [ String ] = [ ] , innerHTML : [ String ] = [ ]
2222 for element in children {
23- if let child: LabeledExprSyntax = element. as ( LabeledExprSyntax . self ) {
23+ if let child: LabeledExprSyntax = element. labeled {
2424 if var key: String = child. label? . text {
2525 if key == " attributes " {
26- attributes. append ( contentsOf: parse_global_attributes ( context: context, elementType: elementType, array: child. expression. as ( ArrayExprSyntax . self ) !) )
26+ attributes. append ( contentsOf: parse_global_attributes ( context: context, elementType: elementType, array: child. expression. array !) )
2727 } else {
2828 if key == " acceptCharset " {
2929 key = " accept-charset "
@@ -32,11 +32,11 @@ private extension HTMLElement {
3232 attributes. append ( key + ( string. isEmpty ? " " : " = \\ \" " + string + " \\ \" " ) )
3333 }
3434 }
35- } else if let array: ArrayElementListSyntax = child. expression. as ( ArrayExprSyntax . self ) ? . elements { // inner html
35+ } else if let array: ArrayElementListSyntax = child. expression. array ? . elements { // inner html
3636 for yoink in array {
37- if let macro: MacroExpansionExprSyntax = yoink. expression. as ( MacroExpansionExprSyntax . self ) {
37+ if let macro: MacroExpansionExprSyntax = yoink. expression. macroExpansion {
3838 innerHTML. append ( parse_element_macro ( context: context, expression: macro) )
39- } else if let string: String = yoink. expression. as ( StringLiteralExprSyntax . self ) ? . string {
39+ } else if let string: String = yoink. expression. stringLiteral ? . string {
4040 innerHTML. append ( string)
4141 }
4242 }
@@ -49,7 +49,7 @@ private extension HTMLElement {
4949 var keys : Set < String > = [ ] , attributes : [ String ] = [ ]
5050 for element in array. elements {
5151 let function : FunctionCallExprSyntax = element. expression. as ( FunctionCallExprSyntax . self) !, key_element : ExprSyntax = function. arguments. first!. expression
52- var key : String = function. calledExpression. as ( MemberAccessExprSyntax . self ) !. declName. baseName. text, value : String ? = nil
52+ var key : String = function. calledExpression. memberAccess !. declName. baseName. text, value : String ? = nil
5353 switch key {
5454 case " custom " , " data " :
5555 var ( literalValue, returnType) : ( String , LiteralReturnType ) = parse_literal_value ( elementType: elementType, key: key, expression: function. arguments. last!. expression) !
@@ -58,14 +58,14 @@ private extension HTMLElement {
5858 }
5959 value = literalValue
6060 if key == " custom " {
61- key = key_element. as ( StringLiteralExprSyntax . self ) !. string
61+ key = key_element. stringLiteral !. string
6262 } else {
63- key += " - \( key_element. as ( StringLiteralExprSyntax . self ) !. string) "
63+ key += " - \( key_element. stringLiteral !. string) "
6464 }
6565 break
6666 case " event " :
67- key = " on " + key_element. as ( MemberAccessExprSyntax . self ) !. declName. baseName. text
68- value = function. arguments. last!. expression. as ( StringLiteralExprSyntax . self ) !. string
67+ key = " on " + key_element. memberAccess !. declName. baseName. text
68+ value = function. arguments. last!. expression. stringLiteral !. string
6969 break
7070 default :
7171 if let string: String = parse_attribute ( elementType: elementType, key: key, expression: key_element) {
@@ -92,8 +92,8 @@ private extension HTMLElement {
9292 let tag : String , isVoid : Bool
9393 var children : Slice < SyntaxChildren >
9494 if elementType == . custom {
95- tag = childs. first ( where: { $0. as ( LabeledExprSyntax . self ) ? . label? . text == " tag " } ) !. as ( LabeledExprSyntax . self ) !. expression. as ( StringLiteralExprSyntax . self ) !. string
96- isVoid = childs. first ( where: { $0. as ( LabeledExprSyntax . self ) ? . label? . text == " isVoid " } ) !. as ( LabeledExprSyntax . self ) !. expression. as ( BooleanLiteralExprSyntax . self ) !. literal. text == " true "
95+ tag = childs. first ( where: { $0. labeled ? . label? . text == " tag " } ) !. labeled !. expression. stringLiteral !. string
96+ isVoid = childs. first ( where: { $0. labeled ? . label? . text == " isVoid " } ) !. labeled !. expression. booleanLiteral !. literal. text == " true "
9797 children = childs. dropFirst ( ) // tag
9898 children. removeFirst ( ) // isVoid
9999 } else {
@@ -136,14 +136,14 @@ private extension HTMLElement {
136136 case . interpolation: return " \\ ( " + string + " ) "
137137 }
138138 }
139- if let value: String = expression. as ( ArrayExprSyntax . self ) ? . elements. compactMap ( {
139+ if let value: String = expression. array ? . elements. compactMap ( {
140140 if let string: String = $0. expression. stringLiteral? . string {
141141 return string
142142 }
143143 if let string: String = $0. expression. integerLiteral? . literal. text {
144144 return string
145145 }
146- if let string: String = $0. expression. as ( MemberAccessExprSyntax . self ) ? . declName. baseName. text {
146+ if let string: String = $0. expression. memberAccess ? . declName. baseName. text {
147147 return HTMLElementAttribute . Extra. htmlValue ( enumName: enumName ( elementType: elementType, key: key) , for: string)
148148 }
149149 return nil
@@ -190,7 +190,7 @@ private extension HTMLElement {
190190 return ( " \( function) " , . interpolation)
191191 }
192192 }
193- if let member: MemberAccessExprSyntax = expression. as ( MemberAccessExprSyntax . self ) {
193+ if let member: MemberAccessExprSyntax = expression. memberAccess {
194194 let decl : String = member. declName. baseName. text
195195 if let base: ExprSyntax = member. base {
196196 if let integer: String = base. integerLiteral? . literal. text {
@@ -366,6 +366,12 @@ extension ExprSyntax {
366366 var stringLiteral : StringLiteralExprSyntax ? { self . as ( StringLiteralExprSyntax . self) }
367367 var integerLiteral : IntegerLiteralExprSyntax ? { self . as ( IntegerLiteralExprSyntax . self) }
368368 var floatLiteral : FloatLiteralExprSyntax ? { self . as ( FloatLiteralExprSyntax . self) }
369+ var array : ArrayExprSyntax ? { self . as ( ArrayExprSyntax . self) }
370+ var memberAccess : MemberAccessExprSyntax ? { self . as ( MemberAccessExprSyntax . self) }
371+ var macroExpansion : MacroExpansionExprSyntax ? { self . as ( MacroExpansionExprSyntax . self) }
372+ }
373+ extension SyntaxChildren . Element {
374+ var labeled : LabeledExprSyntax ? { self . as ( LabeledExprSyntax . self) }
369375}
370376extension StringLiteralExprSyntax {
371377 var string : String { " \( segments) " }
0 commit comments