Skip to content

Rename detach() to detached #1745

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
Jun 9, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/SwiftBasicFormat/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ open class BasicFormat: SyntaxRewriter {
return token
}

return token.detach().with(\.leadingTrivia, leadingTrivia).with(\.trailingTrivia, trailingTrivia)
return token.detached.with(\.leadingTrivia, leadingTrivia).with(\.trailingTrivia, trailingTrivia)
}
}

Expand Down
7 changes: 7 additions & 0 deletions Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ public extension NamedOpaqueReturnTypeSyntax {
}
}

public extension SyntaxProtocol {
@available(*, deprecated, message: "Use detached computed property instead.")
func detach() -> Self {
return detached
}
}

public extension TupleExprSyntax {
@available(*, deprecated, renamed: "unexpectedBetweenLeftParenAndElements")
var unexpectedBetweenLeftParenAndElementList: UnexpectedNodesSyntax? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/Syntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ extension SyntaxProtocol {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension BasicMacroExpansionContext {

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

if let rootSourceFile = node.root.as(SourceFileSyntax.self) {
addDisconnected(detached, at: node.position, in: rootSourceFile)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxMacros/Syntax+MacroEvaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension SyntaxProtocol {
return basicContext.detach(self)
}

return self.detach()
return self.detached
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftSyntaxTest/SyntaxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public class SyntaxTests: XCTestCase {
)
}

public func testDetach() {
public func testDetached() {
let s = StructDeclSyntax(
structKeyword: .keyword(.struct),
identifier: .identifier("someStruct"),
memberBlock: MemberDeclBlockSyntax(leftBrace: .leftBraceToken(), members: [], rightBrace: .rightBraceToken())
)

XCTAssertEqual(Syntax(s), s.memberBlock.parent)
XCTAssertNil(s.memberBlock.detach().parent)
XCTAssertNil(s.memberBlock.detached.parent)
}

public func testCasting() {
Expand Down