Skip to content

Commit 4883c65

Browse files
committed
Formatting
1 parent 9d19cc8 commit 4883c65

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

Sources/_SwiftSyntaxMacros/FreestandingDeclarationMacro.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public protocol FreestandingDeclarationMacro: DeclarationMacro {
1616
/// Expand a macro described by the given freestanding macro expansion
1717
/// declaration within the given context to produce a set of declarations.
1818
static func expansion(
19-
of node: MacroExpansionDeclSyntax, in context: inout MacroExpansionContext
19+
of node: MacroExpansionDeclSyntax,
20+
in context: inout MacroExpansionContext
2021
) throws -> [DeclSyntax]
2122
}

Sources/_SwiftSyntaxMacros/MacroSystem.swift

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,21 @@ class MacroApplication: SyntaxRewriter {
8989
// Expand declaration macros that were parsed as macro expansion
9090
// expressions in this context.
9191
if case let .expr(exprItem) = item.item,
92-
let exprExpansion = exprItem.as(MacroExpansionExprSyntax.self),
93-
let macro = macroSystem.macros[exprExpansion.macro.text],
94-
let freestandingMacro = macro as? FreestandingDeclarationMacro.Type {
92+
let exprExpansion = exprItem.as(MacroExpansionExprSyntax.self),
93+
let macro = macroSystem.macros[exprExpansion.macro.text],
94+
let freestandingMacro = macro as? FreestandingDeclarationMacro.Type
95+
{
9596
do {
9697
let expandedDecls = try freestandingMacro.expansion(
97-
of: exprExpansion.asMacroExpansionDecl(), in: &context
98+
of: exprExpansion.asMacroExpansionDecl(),
99+
in: &context
98100
)
99101

100-
newItems.append(contentsOf: expandedDecls.map { decl in
101-
CodeBlockItemSyntax(item: .decl(decl))
102-
})
102+
newItems.append(
103+
contentsOf: expandedDecls.map { decl in
104+
CodeBlockItemSyntax(item: .decl(decl))
105+
}
106+
)
103107
} catch {
104108
// Record the error
105109
context.diagnose(
@@ -124,20 +128,24 @@ class MacroApplication: SyntaxRewriter {
124128
override func visit(_ node: MemberDeclListSyntax) -> MemberDeclListSyntax {
125129
var newItems: [MemberDeclListItemSyntax] = []
126130
for item in node {
127-
// Expand declaration macros, which produce zero or more declarations.
131+
// Expand declaration macros, which produce zero or more declarations.
128132
if let declExpansion = item.decl.as(MacroExpansionDeclSyntax.self),
129-
let macro = macroSystem.macros[declExpansion.macro.text],
130-
let freestandingMacro = macro as? FreestandingDeclarationMacro.Type {
133+
let macro = macroSystem.macros[declExpansion.macro.text],
134+
let freestandingMacro = macro as? FreestandingDeclarationMacro.Type
135+
{
131136
do {
132137
let expandedDecls = try freestandingMacro.expansion(
133-
of: declExpansion, in: &context
138+
of: declExpansion,
139+
in: &context
134140
)
135141

136-
newItems.append(contentsOf: expandedDecls.map { decl in
137-
MemberDeclListItemSyntax(decl: decl)
138-
})
142+
newItems.append(
143+
contentsOf: expandedDecls.map { decl in
144+
MemberDeclListItemSyntax(decl: decl)
145+
}
146+
)
139147
} catch {
140-
// Record the error
148+
// Record the error
141149
context.diagnose(
142150
Diagnostic(
143151
node: Syntax(node),

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ struct DefineBitwidthNumberedStructsMacro: FreestandingDeclarationMacro {
195195
case let .stringSegment(prefix) = stringLiteral.segments[0]
196196
else {
197197
throw CustomError.message(
198-
"#bitwidthNumberedStructs macro requires a string literal")
198+
"#bitwidthNumberedStructs macro requires a string literal"
199+
)
199200
}
200201

201202
return [8, 16, 32, 64].map { bitwidth in

0 commit comments

Comments
 (0)