Skip to content

Commit c0f0ddd

Browse files
committed
Rename Identifier static string initializer parameter. Fix Identifier.isDollarIdentifier behavior for backticked identifiers.
1 parent e166bf6 commit c0f0ddd

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Sources/SwiftLexicalLookup/LookupName.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import SwiftSyntax
8686
/// `self` and `Self` identifers override implicit `self` and `Self` introduced by
8787
/// the `Foo` class declaration.
8888
var identifier: Identifier {
89-
Identifier(staticString: name)
89+
Identifier(canonicalName: name)
9090
}
9191

9292
/// Position of this implicit name.

Sources/SwiftSyntax/Identifier.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public struct Identifier: Equatable, Hashable, Sendable {
1919

2020
/// `true` if the identifier is a dollar identifier.
2121
public var isDollarIdentifier: Bool {
22-
raw.name.hasPrefix(SyntaxText("$"))
22+
raw.original.hasPrefix(SyntaxText("$")) && Int(String(syntaxText: raw.original).dropFirst()) != nil
2323
}
2424

2525
@_spi(RawSyntax)
@@ -49,17 +49,17 @@ public struct Identifier: Equatable, Hashable, Sendable {
4949
}
5050
}
5151

52-
/// Create a new `Identifier` from given `staticString`.
52+
/// Create a new `Identifier` from given `canonicalName`.
5353
///
54-
/// - Precondition: `staticString` is a canonical identifier i.e. doesn't
54+
/// - Precondition: `canonicalName` is a canonical identifier i.e. doesn't
5555
/// use backticks and is not a dollar identifier with leading zeros.
56-
public init(staticString: StaticString) {
56+
public init(canonicalName: StaticString) {
5757
precondition(
58-
Self.isCanonicalRepresentation(staticString),
59-
"\(staticString) is not a canonical identifier."
58+
Self.isCanonicalRepresentation(canonicalName),
59+
"\(canonicalName) is not a canonical identifier."
6060
)
6161

62-
self.raw = RawIdentifier(SyntaxText(staticString))
62+
self.raw = RawIdentifier(SyntaxText(canonicalName))
6363
self.arena = nil
6464
}
6565

@@ -95,10 +95,13 @@ public struct Identifier: Equatable, Hashable, Sendable {
9595

9696
@_spi(RawSyntax)
9797
public struct RawIdentifier: Equatable, Hashable, Sendable {
98+
fileprivate let original: SyntaxText
9899
public let name: SyntaxText
99100

100101
@_spi(RawSyntax)
101102
fileprivate init(_ rawText: SyntaxText) {
103+
self.original = rawText
104+
102105
guard Identifier.hasBackticks(rawText) else {
103106
self.name = rawText
104107
return

0 commit comments

Comments
 (0)