Skip to content

Conversation

@fummicc1
Copy link
Collaborator

@fummicc1 fummicc1 commented Nov 30, 2025

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:

  • Both of poundIf and poundElseIf are treated as poundIf
  • poundElse is ignored.

Approach

This PR's main updates consist of two parts:

  1. Make ImportMap more structured by introducing ParsedImports type.
  2. Add IfMacroModel to Clause type and store entities to Clause type rather than IfMacroModel.

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 handleImports function, and the function removes duplicated imports and recursively renders conditional import statements.

IfMacroModel

This PR added Clause type to IfMacroModel that represents if compiler directive in @mockable entity, and now entities are stored by Clause type.
The order of if-elseif-else is decided by index of IfConfigDeclSyntax.clauses.enumerated(), and compilerDirectiveKey in previous PR was not actually needed.

Copy link
Collaborator Author

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.

Comment on lines +37 to +42
/// Represents a single clause in a conditional compilation block
struct Clause {
let type: ClauseType
let condition: String? // nil for #else
let entities: [(String, Model)]
}
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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.

@fummicc1 fummicc1 marked this pull request as ready for review November 30, 2025 11:10
@uber uber deleted a comment from Roshankumar350 Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant