@@ -16,14 +16,15 @@ extension HTMLKitUtilities {
16
16
context: HTMLExpansionContext ,
17
17
expression: ExprSyntax
18
18
) -> 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
27
28
}
28
29
guard var returnType = extractLiteral ( context: context, expression: expression) else {
29
30
return nil
@@ -138,18 +139,20 @@ extension HTMLKitUtilities {
138
139
context: HTMLExpansionContext ,
139
140
expression: ExprSyntax
140
141
) -> 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!
145
148
let string = stringLiteral. string ( encoding: context. encoding)
146
149
if stringLiteral. segments. count ( where: { $0. is ( ExpressionSegmentSyntax . self) } ) == 0 {
147
150
return . string( string)
148
151
} else {
149
152
return . interpolation( string)
150
153
}
151
- }
152
- if let function = expression. functionCall {
154
+ case . functionCallExpr :
155
+ let function = expression. functionCall!
153
156
if let decl = function. calledExpression. declRef? . baseName. text {
154
157
switch decl {
155
158
case " StaticString " :
@@ -160,11 +163,7 @@ extension HTMLKitUtilities {
160
163
}
161
164
}
162
165
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:
168
167
let separator : String
169
168
switch context. key {
170
169
case " accept " , " coords " , " exportparts " , " imagesizes " , " imagesrcset " , " sizes " , " srcset " :
@@ -175,7 +174,7 @@ extension HTMLKitUtilities {
175
174
separator = " "
176
175
}
177
176
var results : [ Sendable ] = [ ]
178
- for element in array. elements {
177
+ for element in expression . array! . elements {
179
178
if let attribute = HTMLAttribute . Extra. parse ( context: context, expr: element. expression) {
180
179
results. append ( attribute)
181
180
} else if let literal = parseLiteralValue ( context: context, expression: element. expression) {
@@ -194,12 +193,12 @@ extension HTMLKitUtilities {
194
193
}
195
194
}
196
195
return . array( results)
197
- }
198
- if let decl = expression. declRef {
196
+ case . declReferenceExpr:
199
197
warnInterpolation ( context: context, node: expression)
200
- return . interpolation( decl. baseName. text)
198
+ return . interpolation( expression. declRef!. baseName. text)
199
+ default :
200
+ return nil
201
201
}
202
- return nil
203
202
}
204
203
}
205
204
0 commit comments