Skip to content

Fix comment on expandBodyMacro #2392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private func expandAccessorMacroWithoutExistingAccessors(

// `expandAttachedMacro` adds the `{` and `}` to wrap the accessor block and
// then indents it.
// Remove any indentaiton from the first line using `drop(while:)` and then
// Remove any indentation from the first line using `drop(while:)` and then
// prepend a space to separate it from the variable declaration
let indentedSource = " " + expanded.indented(by: attachedTo.indentationOfFirstLine).drop(while: { $0.isWhitespace })
return "\(raw: indentedSource)"
Expand Down Expand Up @@ -409,10 +409,11 @@ private func expandBodyMacro(
return nil
}

// `expandAttachedMacro` adds the `{` and `}` to wrap the accessor block and
// then indents it.
// Remove any indentaiton from the first line using `drop(while:)` and then
// prepend a space to separate it from the variable declaration
// `expandAttachedMacro` adds the `{` and `}` to wrap the body and then
// indents it.
// Remove any indentation from the first line using `drop(while:)` and then
// prepend a space when it's being introduced on a declaration that has no
// body yet.
let leadingWhitespace = decl.body == nil ? " " : ""
let indentedSource = leadingWhitespace + expanded.indented(by: decl.indentationOfFirstLine).drop(while: { $0.isWhitespace })
return "\(raw: indentedSource)"
Expand Down