-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add '--retain-codable-properties' option
- Loading branch information
Showing
7 changed files
with
72 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
Sources/PeripheryKit/SourceGraph/Mutators/CodablePropertyRetainer.swift
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,25 @@ | ||
import Foundation | ||
import Shared | ||
|
||
final class CodablePropertyRetainer: SourceGraphMutator { | ||
private let graph: SourceGraph | ||
private let configuration: Configuration | ||
|
||
required init(graph: SourceGraph, configuration: Configuration) { | ||
self.graph = graph | ||
self.configuration = configuration | ||
} | ||
|
||
func mutate() { | ||
guard configuration.retainCodableProperties else { return } | ||
|
||
for decl in graph.declarations(ofKinds: Declaration.Kind.discreteConformableKinds) { | ||
guard graph.isCodable(decl) else { continue } | ||
|
||
for decl in decl.declarations { | ||
guard decl.kind == .varInstance else { continue } | ||
graph.markRetained(decl) | ||
} | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
Tests/Fixtures/RetentionFixtures/testRetainsCodableProperties.swift
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,9 @@ | ||
import Foundation | ||
|
||
public struct FixtureStruct14: Codable { | ||
let unused: Int | ||
|
||
init(unused: Int) { | ||
self.unused = unused | ||
} | ||
} |
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