From 81d4eeec76b91af7d1ec2cbd60a1566dd7edab5d Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Wed, 27 Oct 2021 18:12:27 +0200 Subject: [PATCH] Use simpler version of declaration visitor if there is no expression visitor --- src/Review/Rule.elm | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Review/Rule.elm b/src/Review/Rule.elm index 69c898ca..10d1949c 100644 --- a/src/Review/Rule.elm +++ b/src/Review/Rule.elm @@ -1317,19 +1317,28 @@ mergeModuleVisitors initialProjectContext maybeModuleContextCreator visitors = fromModuleRuleSchemaToRunnableModuleVisitor : ModuleRuleSchema schemaState moduleContext -> RunnableModuleVisitor moduleContext fromModuleRuleSchemaToRunnableModuleVisitor (ModuleRuleSchema schema) = let - expressionVisitor : Maybe (Node Expression -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext )) - expressionVisitor = + maybeExpressionVisitor : Maybe (Node Expression -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext )) + maybeExpressionVisitor = createExpressionVisitor schema declarationAndExpressionVisitor : List (Node Declaration) -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext ) declarationAndExpressionVisitor = if shouldVisitDeclarationsAndExpressions schema then - accumulateList - (visitDeclaration - (List.reverse schema.declarationVisitorsOnEnter) - schema.declarationVisitorsOnExit - (Maybe.withDefault (\_ errorsAndContext -> errorsAndContext) expressionVisitor) - ) + case maybeExpressionVisitor of + Just expressionVisitor -> + accumulateList + (visitDeclaration + (List.reverse schema.declarationVisitorsOnEnter) + schema.declarationVisitorsOnExit + expressionVisitor + ) + + Nothing -> + accumulateList + (visitOnlyDeclaration + (List.reverse schema.declarationVisitorsOnEnter) + schema.declarationVisitorsOnExit + ) else \_ errorsAndContext -> errorsAndContext @@ -4451,6 +4460,18 @@ visitDeclaration declarationVisitorsOnEnter declarationVisitorsOnExit expression |> 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 : ExpressionRelatedVisitors moduleContext -> Node Expression