- # Turn “window_properties” into “swallows” expressions.
- my $swallows = {};
- for my $property (keys %{$tree->{window_properties}}) {
- $swallows->{$property} = '^' . quotemeta($tree->{window_properties}->{$property}) . '$';
+ # Turn “window_properties” into “swallows” expressions, but only for leaf
+ # nodes. It only makes sense for leaf nodes to swallow anything.
+ if (leaf_node($tree)) {
+ my $swallows = {};
+ for my $property (keys %{$tree->{window_properties}}) {
+ $swallows->{$property} = '^' . quotemeta($tree->{window_properties}->{$property}) . '$';
+ }
+ $tree->{swallows} = [ $swallows ];