Skip to content

Commit a4f12a5

Browse files
committed
Rename detach() to detached
1 parent ee682e5 commit a4f12a5

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ open class BasicFormat: SyntaxRewriter {
437437
return token
438438
}
439439

440-
return token.detach().with(\.leadingTrivia, leadingTrivia).with(\.trailingTrivia, trailingTrivia)
440+
return token.detached.with(\.leadingTrivia, leadingTrivia).with(\.trailingTrivia, trailingTrivia)
441441
}
442442
}
443443

Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ public extension NamedOpaqueReturnTypeSyntax {
329329
}
330330
}
331331

332+
public extension SyntaxProtocol {
333+
@available(*, deprecated, message: "Use detached computed property instead.")
334+
func detach() -> Self {
335+
return detached
336+
}
337+
}
338+
332339
public extension TupleExprSyntax {
333340
@available(*, deprecated, renamed: "unexpectedBetweenLeftParenAndElements")
334341
var unexpectedBetweenLeftParenAndElementList: UnexpectedNodesSyntax? {

Sources/SwiftSyntax/Syntax.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ extension SyntaxProtocol {
225225

226226
/// Return this subtree with this node as the root, ie. detach this node
227227
/// from its parent.
228-
public func detach() -> Self {
228+
public var detached: Self {
229229
return Syntax(raw: self.raw).cast(Self.self)
230230
}
231231

Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extension BasicMacroExpansionContext {
8080

8181
/// Detach the given node, and record where it came from.
8282
public func detach<Node: SyntaxProtocol>(_ node: Node) -> Node {
83-
let detached = node.detach()
83+
let detached = node.detached
8484

8585
if let rootSourceFile = node.root.as(SourceFileSyntax.self) {
8686
addDisconnected(detached, at: node.position, in: rootSourceFile)

Sources/SwiftSyntaxMacros/Syntax+MacroEvaluation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension SyntaxProtocol {
2121
return basicContext.detach(self)
2222
}
2323

24-
return self.detach()
24+
return self.detached
2525
}
2626
}
2727

Tests/SwiftSyntaxTest/SyntaxTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public class SyntaxTests: XCTestCase {
3838
)
3939
}
4040

41-
public func testDetach() {
41+
public func testDetached() {
4242
let s = StructDeclSyntax(
4343
structKeyword: .keyword(.struct),
4444
identifier: .identifier("someStruct"),
4545
memberBlock: MemberDeclBlockSyntax(leftBrace: .leftBraceToken(), members: [], rightBrace: .rightBraceToken())
4646
)
4747

4848
XCTAssertEqual(Syntax(s), s.memberBlock.parent)
49-
XCTAssertNil(s.memberBlock.detach().parent)
49+
XCTAssertNil(s.memberBlock.detached.parent)
5050
}
5151

5252
public func testCasting() {

0 commit comments

Comments
 (0)