-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add support for parsing registrations wrapped in #if conditions #96
Conversation
@@ -32,6 +36,10 @@ public struct Registration: Equatable, Codable { | |||
self.getterConfig = getterConfig | |||
} | |||
|
|||
private enum CodingKeys: CodingKey { | |||
case service, name, accessLevel, arguments, isForwarded, getterConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring the ifConfigExpression for now. If it's needed in the future we will need to add custom encoding logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you add a small comment that the list is there just to exclude the ifConfigCondition
property?
63a7c7e
to
6a2dc3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice tests ✨
6a2dc3b
to
8149bcb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀 and thanks for the test coverage
// Allowing for #else creates a link between the registration inside the #if and those in the #else | ||
// This greatly increases the complexity of handling #if so raise an error when #else is used | ||
if node.poundKeyword.text.contains("#else") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think this is reasonable. Folks that really need it can still work around by making multiple #if blocks
@@ -32,6 +36,10 @@ public struct Registration: Equatable, Codable { | |||
self.getterConfig = getterConfig | |||
} | |||
|
|||
private enum CodingKeys: CodingKey { | |||
case service, name, accessLevel, arguments, isForwarded, getterConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you add a small comment that the list is there just to exclude the ifConfigCondition
property?
XCTAssertEqual(config.registrations[1].service, "B") | ||
XCTAssertEqual(config.registrations[1].ifConfigCondition?.description, "SOME_FLAG && !ANOTHER_FLAG") | ||
|
||
XCTAssertEqual(config.registrations[2].service, "C") | ||
XCTAssertEqual(config.registrations[2].ifConfigCondition?.description, "SOME_FLAG && !ANOTHER_FLAG") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
8149bcb
to
c4afc54
Compare
This resolves an issue I found where a type I registered was only available behind a conditional build flag. References to this type were being put into the type safety and unit tests which would fail depending on the build configuration.
This change identifies
#if
statements, stores the condition and then wraps any generated code related to the registration with the original#if
.Limitations
#else
is not supported to prevent creating relationships between registrations.#if
statements are not supported only due to the extra parsing complexity. This can be added in the future.