Use simpler version of declaration visitor if there is no expression visitor

This commit is contained in:
Jeroen Engels 2021-10-27 18:12:27 +02:00
parent ec104687a6
commit 81d4eeec76

View File

@ -1317,19 +1317,28 @@ mergeModuleVisitors initialProjectContext maybeModuleContextCreator visitors =
fromModuleRuleSchemaToRunnableModuleVisitor : ModuleRuleSchema schemaState moduleContext -> RunnableModuleVisitor moduleContext fromModuleRuleSchemaToRunnableModuleVisitor : ModuleRuleSchema schemaState moduleContext -> RunnableModuleVisitor moduleContext
fromModuleRuleSchemaToRunnableModuleVisitor (ModuleRuleSchema schema) = fromModuleRuleSchemaToRunnableModuleVisitor (ModuleRuleSchema schema) =
let let
expressionVisitor : Maybe (Node Expression -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext )) maybeExpressionVisitor : Maybe (Node Expression -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext ))
expressionVisitor = maybeExpressionVisitor =
createExpressionVisitor schema createExpressionVisitor schema
declarationAndExpressionVisitor : List (Node Declaration) -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext ) declarationAndExpressionVisitor : List (Node Declaration) -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext )
declarationAndExpressionVisitor = declarationAndExpressionVisitor =
if shouldVisitDeclarationsAndExpressions schema then if shouldVisitDeclarationsAndExpressions schema then
accumulateList case maybeExpressionVisitor of
(visitDeclaration Just expressionVisitor ->
(List.reverse schema.declarationVisitorsOnEnter) accumulateList
schema.declarationVisitorsOnExit (visitDeclaration
(Maybe.withDefault (\_ errorsAndContext -> errorsAndContext) expressionVisitor) (List.reverse schema.declarationVisitorsOnEnter)
) schema.declarationVisitorsOnExit
expressionVisitor
)
Nothing ->
accumulateList
(visitOnlyDeclaration
(List.reverse schema.declarationVisitorsOnEnter)
schema.declarationVisitorsOnExit
)
else else
\_ errorsAndContext -> errorsAndContext \_ errorsAndContext -> errorsAndContext
@ -4451,6 +4460,18 @@ visitDeclaration declarationVisitorsOnEnter declarationVisitorsOnExit expression
|> visitWithListOfVisitors declarationVisitorsOnExit node |> visitWithListOfVisitors declarationVisitorsOnExit node
visitOnlyDeclaration :
List (Visitor Declaration moduleContext)
-> List (Visitor Declaration moduleContext)
-> Node Declaration
-> moduleContext
-> ( List (Error {}), moduleContext )
visitOnlyDeclaration declarationVisitorsOnEnter declarationVisitorsOnExit node moduleContext =
( [], moduleContext )
|> visitWithListOfVisitors declarationVisitorsOnEnter node
|> visitWithListOfVisitors declarationVisitorsOnExit node
visitExpression : visitExpression :
ExpressionRelatedVisitors moduleContext ExpressionRelatedVisitors moduleContext
-> Node Expression -> Node Expression