-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add backwards compatible initialisers for
Text
and `LocalizedString…
…sKey` (#82) * Generate Text.init(localizable:) * Generate LocalizedStringKey.init(localizable:) * Generate with correct access levels and add static method accesors * Add better documentation to generated code * Update docc documentation * Update README.md * Fix warnings in Package.swift * Always use LocalizedStringResource when possible
- Loading branch information
1 parent
616763c
commit cbe577e
Showing
28 changed files
with
1,677 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
|
||
extension IfExprSyntax { | ||
init( | ||
availability: AvailabilityArgumentListSyntax, | ||
body: CodeBlockSyntax, | ||
elseBody: CodeBlockSyntax? = nil | ||
) { | ||
self.init( | ||
conditions: ConditionElementListSyntax { | ||
AvailabilityConditionSyntax(availabilityKeyword: .poundAvailableToken(), availabilityArguments: availability) | ||
}, | ||
body: body, | ||
elseKeyword: elseBody.flatMap { _ in .keyword(.else) }, | ||
elseBody: elseBody.flatMap { .codeBlock($0) } | ||
) | ||
} | ||
|
||
init( | ||
availability: AvailabilityArgumentListSyntax, | ||
@CodeBlockItemListBuilder bodyBuilder: () -> CodeBlockItemListSyntax | ||
) { | ||
self.init( | ||
availability: availability, | ||
body: CodeBlockSyntax(statements: bodyBuilder()) | ||
) | ||
} | ||
|
||
init( | ||
availability: AvailabilityArgumentListSyntax, | ||
@CodeBlockItemListBuilder bodyBuilder: () -> CodeBlockItemListSyntax, | ||
@CodeBlockItemListBuilder elseBodyBuilder: () -> CodeBlockItemListSyntax | ||
) { | ||
self.init( | ||
availability: availability, | ||
body: CodeBlockSyntax(statements: bodyBuilder()), | ||
elseBody: CodeBlockSyntax(statements: elseBodyBuilder()) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
|
||
struct IfCanImportSnippet { | ||
let module: TokenSyntax.Module | ||
let items: CodeBlockItemListSyntax | ||
} | ||
|
||
extension IfCanImportSnippet { | ||
init( | ||
module: TokenSyntax.Module, | ||
@CodeBlockItemListBuilder itemsBuilder: () -> CodeBlockItemListSyntax | ||
) { | ||
self.init(module: module, items: itemsBuilder()) | ||
} | ||
} | ||
|
||
extension IfCanImportSnippet: Snippet { | ||
var syntax: some DeclSyntaxProtocol { | ||
IfConfigDeclSyntax( | ||
clauses: IfConfigClauseListSyntax { | ||
IfConfigClauseSyntax( | ||
poundKeyword: .poundIfToken(), | ||
condition: CanImportExprSyntax(importPath: .module(module)), | ||
elements: .statements(items) | ||
) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.