Repository: jg-rp/liquid

Issue:
Static analysis of filters in ternary expressions
When analysing ternary expressions statically, we are failing to report filters that appear before the condition.

Here, `upcase` is missing from analysis results, but `default` and `append` are reported correctly.

```
{{ a | upcase if b.c else d | default: 'x' || append: y }}
```

Discussion:

Solution patch:
diff --git a/CHANGES.md b/CHANGES.md
index ef5e2e5..72970c2 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
 # Python Liquid Change Log
 
+## Version 2.0.2 (unreleased)
+
+- Fixed static analysis of filters in ternary expressions. See [#180](https://github.com/jg-rp/liquid/issues/180).
+
 ## Version 2.0.1
 
 - Fixed bad imports from `typing_extensions`.
diff --git a/liquid/static_analysis.py b/liquid/static_analysis.py
index 32d1a68..f2d391b 100644
--- a/liquid/static_analysis.py
+++ b/liquid/static_analysis.py
@@ -301,19 +301,25 @@ async def _analyze_async(
 def _extract_filters(
     expression: Expression, template_name: str
 ) -> Iterable[tuple[str, Span]]:
-    if (
-        isinstance(expression, (FilteredExpression, TernaryFilteredExpression))
-        and expression.filters
-    ):
-        yield from (
-            (f.name, Span(template_name, f.token.start_index))
-            for f in expression.filters
-        )
+    if isinstance(expression, TernaryFilteredExpression):
+        yield from _extract_filters(expression.left, template_name)
 
-    if isinstance(expression, TernaryFilteredExpression) and expression.tail_filters:
+        if expression.filters:
+            yield from (
+                (f.name, Span(template_name, f.token.start_index))
+                for f in expression.filters
+            )
+
+        if expression.tail_filters:
+            yield from (
+                (f.name, Span(template_name, f.token.start_index))
+                for f in expression.tail_filters
+            )
+
+    if isinstance(expression, FilteredExpression) and expression.filters:
         yield from (
             (f.name, Span(template_name, f.token.start_index))
-            for f in expression.tail_filters
+            for f in expression.filters
         )
 
     for expr in expression.children():


Test patch:
diff --git a/tests/test_static_analysis.py b/tests/test_static_analysis.py
index 1685399..2864b19 100644
--- a/tests/test_static_analysis.py
+++ b/tests/test_static_analysis.py
@@ -151,6 +151,7 @@ def test_analyze_ternary_filters(env: Environment) -> None:
             "y": [Variable(["y"], Span("", 54))],
         },
         filters={
+            "upcase": [Span("", 7)],
             "default": [Span("", 30)],
             "append": [Span("", 46)],
         },