Twig does not vary the cache based on the debug mode. So this needs to be checked at render time, not at compile time.
See https://github.com/fabpot/Twig-extensions/blob/master/lib/Twig/Extensions/Node/Debug.php for an example in the Twig deprecated ``debug`` tag