@@ -16,14 +16,15 @@ extension HTMLKitUtilities {
1616 context: HTMLExpansionContext ,
1717 expression: ExprSyntax
1818 ) -> LiteralReturnType ? {
19- if let boolean = expression. booleanLiteral? . literal. text {
20- return . boolean( boolean == " true " )
21- }
22- if let string = expression. integerLiteral? . literal. text {
23- return . int( Int ( string) !)
24- }
25- if let string = expression. floatLiteral? . literal. text {
26- return . float( Float ( string) !)
19+ switch expression. kind {
20+ case . booleanLiteralExpr:
21+ return . boolean( expression. booleanLiteral? . literal. text == " true " )
22+ case . integerLiteralExpr:
23+ return . int( Int ( expression. integerLiteral!. literal. text) !)
24+ case . floatLiteralExpr:
25+ return . float( Float ( expression. floatLiteral!. literal. text) !)
26+ default :
27+ break
2728 }
2829 guard var returnType = extractLiteral ( context: context, expression: expression) else {
2930 return nil
@@ -138,18 +139,20 @@ extension HTMLKitUtilities {
138139 context: HTMLExpansionContext ,
139140 expression: ExprSyntax
140141 ) -> LiteralReturnType ? {
141- if let _ = expression. as ( NilLiteralExprSyntax . self) {
142- return nil
143- }
144- if let stringLiteral = expression. stringLiteral {
142+ switch expression. kind {
143+ case . nilLiteralExpr: return nil
144+ case . memberAccessExpr, . forceUnwrapExpr:
145+ return . interpolation( " \( expression) " )
146+ case . stringLiteralExpr:
147+ let stringLiteral = expression. stringLiteral!
145148 let string = stringLiteral. string ( encoding: context. encoding)
146149 if stringLiteral. segments. count ( where: { $0. is ( ExpressionSegmentSyntax . self) } ) == 0 {
147150 return . string( string)
148151 } else {
149152 return . interpolation( string)
150153 }
151- }
152- if let function = expression. functionCall {
154+ case . functionCallExpr :
155+ let function = expression. functionCall!
153156 if let decl = function. calledExpression. declRef? . baseName. text {
154157 switch decl {
155158 case " StaticString " :
@@ -160,11 +163,7 @@ extension HTMLKitUtilities {
160163 }
161164 }
162165 return . interpolation( " \( function) " )
163- }
164- if expression. memberAccess != nil || expression. is ( ForceUnwrapExprSyntax . self) {
165- return . interpolation( " \( expression) " )
166- }
167- if let array = expression. array {
166+ case . arrayExpr:
168167 let separator : String
169168 switch context. key {
170169 case " accept " , " coords " , " exportparts " , " imagesizes " , " imagesrcset " , " sizes " , " srcset " :
@@ -175,7 +174,7 @@ extension HTMLKitUtilities {
175174 separator = " "
176175 }
177176 var results : [ Sendable ] = [ ]
178- for element in array. elements {
177+ for element in expression . array! . elements {
179178 if let attribute = HTMLAttribute . Extra. parse ( context: context, expr: element. expression) {
180179 results. append ( attribute)
181180 } else if let literal = parseLiteralValue ( context: context, expression: element. expression) {
@@ -194,12 +193,12 @@ extension HTMLKitUtilities {
194193 }
195194 }
196195 return . array( results)
197- }
198- if let decl = expression. declRef {
196+ case . declReferenceExpr:
199197 warnInterpolation ( context: context, node: expression)
200- return . interpolation( decl. baseName. text)
198+ return . interpolation( expression. declRef!. baseName. text)
199+ default :
200+ return nil
201201 }
202- return nil
203202 }
204203}
205204
0 commit comments