@@ -15,32 +15,28 @@ import SwiftSyntaxBuilder
15
15
import SyntaxSupport
16
16
import Utils
17
17
18
- let childNameForKeyPathFile = SourceFileSyntax ( leadingTrivia: copyrightHeader) {
19
- try ! FunctionDeclSyntax (
20
- """
21
- /// If the keyPath is one from a layout structure, return the property name
22
- /// of it.
23
- @_spi(RawSyntax)
24
- public func childName(_ keyPath: AnyKeyPath) -> String?
25
- """
26
- ) {
27
- try ! SwitchExprSyntax ( " switch keyPath " ) {
28
- for node in NON_BASE_SYNTAX_NODES . compactMap ( \. layoutNode) {
29
- for child in node. children {
30
- SwitchCaseSyntax (
31
- """
32
- case \\ \( node. type. syntaxBaseName) . \( child. memberCallName) :
33
- return \( literal: child. identifier. description)
34
- """
35
- )
18
+ let childNameForKeyPathFile = try ! SourceFileSyntax ( leadingTrivia: copyrightHeader) {
19
+ try ExtensionDeclSyntax ( " extension SyntaxLayoutProperty " ) {
20
+ try VariableDeclSyntax (
21
+ """
22
+ /// Property name if this is a valid property.
23
+ /// 'nil' if the `baseKind` is not a layout syntax, or the index is out of range.
24
+ @_spi(RawSyntax)
25
+ public var name: String?
26
+ """
27
+ ) {
28
+ try SwitchExprSyntax ( " switch (self.baseKind, self.index.value) " ) {
29
+ for node in NON_BASE_SYNTAX_NODES {
30
+ if let layoutNode = node. layoutNode {
31
+ for (index, child) in layoutNode. children. enumerated ( ) {
32
+ SwitchCaseSyntax ( " case (. \( node. enumCaseCallName) , \( literal: index) ): " ) {
33
+ StmtSyntax ( " return \( literal: child. identifier. description) " )
34
+ }
35
+ }
36
+ }
36
37
}
38
+ SwitchCaseSyntax ( " default: return nil " )
37
39
}
38
- SwitchCaseSyntax (
39
- """
40
- default:
41
- return nil
42
- """
43
- )
44
40
}
45
41
}
46
42
}
0 commit comments