Skip to content

Commit abcc952

Browse files
authored
Merge pull request #2138 from ahoppen/ahoppen/macroexpansion-renames
Rename some properties on `FreestandingMacroExpansionSyntax`
2 parents 9e798fa + a16fd42 commit abcc952

File tree

15 files changed

+55
-25
lines changed

15 files changed

+55
-25
lines changed

CodeGeneration/Sources/SyntaxSupport/Traits.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public let TRAITS: [Trait] = [
6262
Trait(
6363
traitName: "FreestandingMacroExpansion",
6464
children: [
65-
Child(name: "poundToken", kind: .token(choices: [.token(.pound)])),
66-
Child(name: "macro", kind: .token(choices: [.token(.identifier)])),
65+
Child(name: "pound", deprecatedName: "poundToken", kind: .token(choices: [.token(.pound)])),
66+
Child(name: "macroName", deprecatedName: "macro", kind: .token(choices: [.token(.identifier)])),
6767
Child(name: "genericArgumentClause", kind: .node(kind: .genericArgumentClause), isOptional: true),
6868
Child(name: "leftParen", kind: .token(choices: [.token(.leftParen)]), isOptional: true),
69-
Child(name: "argumentList", kind: .node(kind: .labeledExprList)),
69+
Child(name: "arguments", deprecatedName: "argumentList", kind: .node(kind: .labeledExprList)),
7070
Child(name: "rightParen", kind: .token(choices: [.token(.rightParen)]), isOptional: true),
7171
Child(name: "trailingClosure", kind: .node(kind: .closureExpr), isOptional: true),
7272
Child(name: "additionalTrailingClosures", kind: .node(kind: .multipleTrailingClosureElementList)),

Examples/Sources/ExamplePlugin/Macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct EchoExpressionMacro: ExpressionMacro {
1111
of node: Node,
1212
in context: Context
1313
) throws -> ExprSyntax {
14-
let expr: ExprSyntax = node.argumentList.first!.expression
14+
let expr: ExprSyntax = node.arguments.first!.expression
1515
return expr.with(\.leadingTrivia, [.blockComment("/* echo */")])
1616
}
1717
}
@@ -137,7 +137,7 @@ struct PrintAnyMacro: CodeItemMacro {
137137
of node: some FreestandingMacroExpansionSyntax,
138138
in context: some MacroExpansionContext
139139
) throws -> [CodeBlockItemSyntax] {
140-
guard let expr = node.argumentList.first?.expression else {
140+
guard let expr = node.arguments.first?.expression else {
141141
return []
142142
}
143143
return ["print(\(expr))"]

Examples/Sources/MacroExamples/Implementation/AddBlocker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ public struct AddBlocker: ExpressionMacro {
101101
context.diagnose(diag)
102102
}
103103

104-
return result.asProtocol(FreestandingMacroExpansionSyntax.self)!.argumentList.first!.expression
104+
return result.asProtocol(FreestandingMacroExpansionSyntax.self)!.arguments.first!.expression
105105
}
106106
}

Examples/Sources/MacroExamples/Implementation/FontLiteralMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct FontLiteralMacro: ExpressionMacro {
2222
in context: some MacroExpansionContext
2323
) -> ExprSyntax {
2424
let argList = replaceFirstLabel(
25-
of: macro.argumentList,
25+
of: macro.arguments,
2626
with: "fontLiteralName"
2727
)
2828
return ".init(\(argList))"

Examples/Sources/MacroExamples/Implementation/StringifyMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct StringifyMacro: ExpressionMacro {
2828
of node: some FreestandingMacroExpansionSyntax,
2929
in context: some MacroExpansionContext
3030
) -> ExprSyntax {
31-
guard let argument = node.argumentList.first?.expression else {
31+
guard let argument = node.arguments.first?.expression else {
3232
fatalError("compiler bug: the macro does not have any arguments")
3333
}
3434

Examples/Sources/MacroExamples/Implementation/URLMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct URLMacro: ExpressionMacro {
2222
in context: some MacroExpansionContext
2323
) throws -> ExprSyntax {
2424

25-
guard let argument = node.argumentList.first?.expression,
25+
guard let argument = node.arguments.first?.expression,
2626
let segments = argument.as(StringLiteralExprSyntax.self)?.segments,
2727
segments.count == 1,
2828
case .stringSegment(let literalSegment)? = segments.first

Examples/Sources/MacroExamples/Implementation/WarningMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct WarningMacro: ExpressionMacro {
2121
of macro: some FreestandingMacroExpansionSyntax,
2222
in context: some MacroExpansionContext
2323
) throws -> ExprSyntax {
24-
guard let firstElement = macro.argumentList.first,
24+
guard let firstElement = macro.arguments.first,
2525
let stringLiteral = firstElement.expression
2626
.as(StringLiteralExprSyntax.self),
2727
stringLiteral.segments.count == 1,

Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ public extension DeclGroupSyntax {
5151
}
5252

5353
public extension FreestandingMacroExpansionSyntax {
54+
@available(*, deprecated, renamed: "pound")
55+
public var poundToken: TokenSyntax {
56+
get {
57+
return pound
58+
}
59+
set {
60+
pound = newValue
61+
}
62+
}
63+
64+
@available(*, deprecated, renamed: "macroName")
65+
public var macro: TokenSyntax {
66+
get {
67+
return macroName
68+
}
69+
set {
70+
macroName = newValue
71+
}
72+
}
73+
5474
@available(*, deprecated, renamed: "genericArgumentClause")
5575
var genericArguments: GenericArgumentClauseSyntax? {
5676
get {
@@ -60,6 +80,16 @@ public extension FreestandingMacroExpansionSyntax {
6080
genericArgumentClause = newValue
6181
}
6282
}
83+
84+
@available(*, deprecated, renamed: "arguments")
85+
public var argumentList: LabeledExprListSyntax {
86+
get {
87+
return arguments
88+
}
89+
set {
90+
arguments = newValue
91+
}
92+
}
6393
}
6494

6595
extension GenericRequirementSyntax {

Sources/SwiftSyntax/generated/SyntaxTraits.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ public extension SyntaxProtocol {
173173

174174

175175
public protocol FreestandingMacroExpansionSyntax: SyntaxProtocol {
176-
var poundToken: TokenSyntax {
176+
var pound: TokenSyntax {
177177
get
178178
set
179179
}
180180

181-
var macro: TokenSyntax {
181+
var macroName: TokenSyntax {
182182
get
183183
set
184184
}
@@ -193,7 +193,7 @@ public protocol FreestandingMacroExpansionSyntax: SyntaxProtocol {
193193
set
194194
}
195195

196-
var argumentList: LabeledExprListSyntax {
196+
var arguments: LabeledExprListSyntax {
197197
get
198198
set
199199
}

Sources/SwiftSyntaxMacroExpansion/MacroReplacement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ extension MacroDeclSyntax {
278278
replacements: [MacroDefinition.Replacement]
279279
) -> ExprSyntax {
280280
return expand(
281-
argumentList: node.argumentList,
281+
argumentList: node.arguments,
282282
definition: definition,
283283
replacements: replacements
284284
)

0 commit comments

Comments
 (0)