@@ -189,6 +189,19 @@ struct FunctionMacro: ExpressionMacro {
189
189
}
190
190
}
191
191
192
+ /// Replace the label of the first element in the tuple with the given
193
+ /// new label.
194
+ private func replaceFirstLabel(
195
+ of tuple: TupleExprElementListSyntax , with newLabel: String
196
+ ) -> TupleExprElementListSyntax {
197
+ guard let firstElement = tuple. first else {
198
+ return tuple
199
+ }
200
+
201
+ return tuple. replacing (
202
+ childAt: 0 , with: firstElement. withLabel ( . identifier( newLabel) ) )
203
+ }
204
+
192
205
struct ColorLiteralMacro : ExpressionMacro {
193
206
static var name : String { " colorLiteral " }
194
207
@@ -204,14 +217,17 @@ struct ColorLiteralMacro: ExpressionMacro {
204
217
static var signature : TypeSyntax =
205
218
"""
206
219
(
207
- _colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float
220
+ red: Float, green: Float, blue: Float, alpha: Float
208
221
) -> T
209
222
"""
210
223
211
224
static func apply(
212
225
_ macro: MacroExpansionExprSyntax , in context: MacroEvaluationContext
213
226
) -> MacroResult < ExprSyntax > {
214
- let initSyntax : ExprSyntax = " .init( \( macro. argumentList) ) "
227
+ let argList = replaceFirstLabel (
228
+ of: macro. argumentList, with: " _colorLiteralRed "
229
+ )
230
+ let initSyntax : ExprSyntax = " .init( \( argList) ) "
215
231
if let leadingTrivia = macro. leadingTrivia {
216
232
return MacroResult ( initSyntax. withLeadingTrivia ( leadingTrivia) )
217
233
}
@@ -232,12 +248,15 @@ struct FileLiteralMacro: ExpressionMacro {
232
248
"""
233
249
234
250
static var signature : TypeSyntax =
235
- " (fileReferenceLiteralResourceName path: String) -> T "
251
+ " (resourceName path: String) -> T "
236
252
237
253
static func apply(
238
254
_ macro: MacroExpansionExprSyntax , in context: MacroEvaluationContext
239
255
) -> MacroResult < ExprSyntax > {
240
- let initSyntax : ExprSyntax = " .init( \( macro. argumentList) ) "
256
+ let argList = replaceFirstLabel (
257
+ of: macro. argumentList, with: " fileReferenceLiteralResourceName "
258
+ )
259
+ let initSyntax : ExprSyntax = " .init( \( argList) ) "
241
260
if let leadingTrivia = macro. leadingTrivia {
242
261
return MacroResult ( initSyntax. withLeadingTrivia ( leadingTrivia) )
243
262
}
@@ -258,12 +277,15 @@ struct ImageLiteralMacro: ExpressionMacro {
258
277
"""
259
278
260
279
static var signature : TypeSyntax =
261
- " (imageLiteralResourceName path: String) -> T "
280
+ " (resourceName path: String) -> T "
262
281
263
282
static func apply(
264
283
_ macro: MacroExpansionExprSyntax , in context: MacroEvaluationContext
265
284
) -> MacroResult < ExprSyntax > {
266
- let initSyntax : ExprSyntax = " .init( \( macro. argumentList) ) "
285
+ let argList = replaceFirstLabel (
286
+ of: macro. argumentList, with: " imageLiteralResourceName "
287
+ )
288
+ let initSyntax : ExprSyntax = " .init( \( argList) ) "
267
289
if let leadingTrivia = macro. leadingTrivia {
268
290
return MacroResult ( initSyntax. withLeadingTrivia ( leadingTrivia) )
269
291
}
0 commit comments