-
Notifications
You must be signed in to change notification settings - Fork 94
Support elseif/else directive #328
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
base: master
Are you sure you want to change the base?
Conversation
…as structured Import type.
…conditional imports.
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.
[self review]
Except for Import, all nodes within IfDeclConfigSyntax are stored in IfMacroModel's entities.
However, import statement is not represented as one of them, rather it is represented as ImportContent.
| /// Represents a single clause in a conditional compilation block | ||
| struct Clause { | ||
| let type: ClauseType | ||
| let condition: String? // nil for #else | ||
| let entities: [(String, Model)] | ||
| } |
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.
[self review]
Now entities property is moved from IfMacroModel to IfMacroModel.Clause so that we can know which compiler directive stores them.
Because IfMacroModel self is also Model, this recursively stores.
|
|
||
| /// A structure defining an "import" statement parsed by `Generator`, including various modifiers. | ||
| struct Import: CustomStringConvertible { | ||
| public struct Import: CustomStringConvertible { |
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.
[self review]
Because other types such as ImportMap are public scope, Import should be public as well.
Note
This PR is made after this closed PR that has some faults for parsing complicated if-compiler-directive.
Motivation
Mockolo didn't support elseif compiler directive as of v2.3.1.
There are some bugs that mockolo faces with:
Approach
This PR's main updates consist of two parts:
ImportMapmore structured by introducingParsedImportstype.IfMacroModeltoClausetype and store entities toClausetype rather thanIfMacroModel.Detail
ImportHandler
mockolo provides a feature that user can inject any import statement via mockolo CLI what we call
customImports.This is one of the reason that we can't collect all imports just leveraging swift-syntax.
Operation to merge all-imports is performed in
handleImportsfunction, and the function removes duplicated imports and recursively renders conditional import statements.IfMacroModel
This PR added
Clausetype toIfMacroModelthat representsif compiler directivein@mockableentity, and now entities are stored byClausetype.The order of
if-elseif-elseis decided by index ofIfConfigDeclSyntax.clauses.enumerated(), andcompilerDirectiveKeyin previous PR was not actually needed.