Revert 352

This reverts https://github.com/Shopify/liquid/pull/352, since it caused problems (see https://github.com/Shopify/liquid/pull/377) and I think we should come up with a better (non-state-mutating) solution.

Also adds the regression tests from https://github.com/Shopify/liquid/pull/377.

@tjoyal @arthurnn, please review.
cc @gaiottino