@@ -177,6 +177,19 @@ struct FunctionMacro: ExpressionMacro {
177
177
}
178
178
}
179
179
180
+ /// Replace the label of the first element in the tuple with the given
181
+ /// new label.
182
+ private func replaceFirstLabel(
183
+ of tuple: TupleExprElementListSyntax , with newLabel: String
184
+ ) -> TupleExprElementListSyntax {
185
+ guard let firstElement = tuple. first else {
186
+ return tuple
187
+ }
188
+
189
+ return tuple. replacing (
190
+ childAt: 0 , with: firstElement. withLabel ( . identifier( newLabel) ) )
191
+ }
192
+
180
193
struct ColorLiteralMacro : ExpressionMacro {
181
194
static var name : String { " colorLiteral " }
182
195
@@ -188,14 +201,17 @@ struct ColorLiteralMacro: ExpressionMacro {
188
201
static var signature : TypeSyntax =
189
202
"""
190
203
(
191
- _colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float
204
+ red: Float, green: Float, blue: Float, alpha: Float
192
205
) -> T
193
206
"""
194
207
195
208
static func apply(
196
209
_ macro: MacroExpansionExprSyntax , in context: MacroEvaluationContext
197
210
) -> MacroResult < ExprSyntax > {
198
- let initSyntax : ExprSyntax = " .init( \( macro. argumentList) ) "
211
+ let argList = replaceFirstLabel (
212
+ of: macro. argumentList, with: " _colorLiteralRed "
213
+ )
214
+ let initSyntax : ExprSyntax = " .init( \( argList) ) "
199
215
if let leadingTrivia = macro. leadingTrivia {
200
216
return MacroResult ( initSyntax. withLeadingTrivia ( leadingTrivia) )
201
217
}
@@ -212,12 +228,15 @@ struct FileLiteralMacro: ExpressionMacro {
212
228
"""
213
229
214
230
static var signature : TypeSyntax =
215
- " (fileReferenceLiteralResourceName path: String) -> T "
231
+ " (resourceName path: String) -> T "
216
232
217
233
static func apply(
218
234
_ macro: MacroExpansionExprSyntax , in context: MacroEvaluationContext
219
235
) -> MacroResult < ExprSyntax > {
220
- let initSyntax : ExprSyntax = " .init( \( macro. argumentList) ) "
236
+ let argList = replaceFirstLabel (
237
+ of: macro. argumentList, with: " fileReferenceLiteralResourceName "
238
+ )
239
+ let initSyntax : ExprSyntax = " .init( \( argList) ) "
221
240
if let leadingTrivia = macro. leadingTrivia {
222
241
return MacroResult ( initSyntax. withLeadingTrivia ( leadingTrivia) )
223
242
}
@@ -234,12 +253,15 @@ struct ImageLiteralMacro: ExpressionMacro {
234
253
"""
235
254
236
255
static var signature : TypeSyntax =
237
- " (imageLiteralResourceName path: String) -> T "
256
+ " (resourceName path: String) -> T "
238
257
239
258
static func apply(
240
259
_ macro: MacroExpansionExprSyntax , in context: MacroEvaluationContext
241
260
) -> MacroResult < ExprSyntax > {
242
- let initSyntax : ExprSyntax = " .init( \( macro. argumentList) ) "
261
+ let argList = replaceFirstLabel (
262
+ of: macro. argumentList, with: " imageLiteralResourceName "
263
+ )
264
+ let initSyntax : ExprSyntax = " .init( \( argList) ) "
243
265
if let leadingTrivia = macro. leadingTrivia {
244
266
return MacroResult ( initSyntax. withLeadingTrivia ( leadingTrivia) )
245
267
}
0 commit comments