module JMESPath
  # @api private
  module Nodes
    class Projection < Node
      def initialize(target, projection)
        @target = target
        @projection = projection
      end

      def visit(value)
        if (targets = extract_targets(@target.visit(value)))
          list = []
          targets.each do |v|
            if (vv = @projection.visit(v))
              list << vv
            end
          end
          list
        end
      end

      def optimize
        if @projection.is_a?(Current)
          fast_instance
        else
          self
        end
      end

      private

      def extract_targets(left_value)
        nil
      end
    end

    module FastProjector
      def visit(value)
        if (targets = extract_targets(@target.visit(value)))
          targets.compact
        end
      end
    end

    class ArrayProjection < Projection
      def extract_targets(target)
        if Array === target
          target
        else
          nil
        end
      end

      def fast_instance
        FastArrayProjection.new(@target, @projection)
      end
    end

    class FastArrayProjection < ArrayProjection
      include FastProjector
    end

    class ObjectProjection < Projection
      EMPTY_ARRAY = [].freeze

      def extract_targets(target)
        if hash_like?(target)
          target.values
        elsif target == EMPTY_ARRAY
          EMPTY_ARRAY
        else
          nil
        end
      end

      def fast_instance
        FastObjectProjection.new(@target, @projection)
      end
    end

    class FastObjectProjection < ObjectProjection
      include FastProjector
    end
  end
end

module JMESPath
  # @api private
  module Nodes
    class Projection < Node
      def initialize(target, projection)
        @target = target
        @projection = projection
      end

      def visit(value)
        if (targets = extract_targets(@target.visit(value)))
          list = []
          targets.each do |v|
            vv = @projection.visit(v)
            unless vv.nil?
              list << vv
            end
          end
          list
        end
      end

      def optimize
        if @projection.is_a?(Current)
          fast_instance
        else
          self
        end
      end

      private

      def extract_targets(left_value)
        nil
      end
    end

    module FastProjector
      def visit(value)
        if (targets = extract_targets(@target.visit(value)))
          targets.compact
        end
      end
    end

    class ArrayProjection < Projection
      def extract_targets(target)
        if Array === target
          target
        else
          nil
        end
      end

      def fast_instance
        FastArrayProjection.new(@target, @projection)
      end
    end

    class FastArrayProjection < ArrayProjection
      include FastProjector
    end

    class ObjectProjection < Projection
      EMPTY_ARRAY = [].freeze

      def extract_targets(target)
        if hash_like?(target)
          target.values
        elsif target == EMPTY_ARRAY
          EMPTY_ARRAY
        else
          nil
        end
      end

      def fast_instance
        FastObjectProjection.new(@target, @projection)
      end
    end

    class FastObjectProjection < ObjectProjection
      include FastProjector
    end
  end
end

Fix a bug in Projection
Fix a bug in Projection

It shouldn't skip false values, just nil values
