Consider this wikitext:
==A==
{{#if:
==B==
}}
==C==The PHP parser will emit:
<h2>...<a href="/~cananian/mediawiki/index.php?title=CLIParser&action=edit&section=1" title="Edit section: A">edit source</a>...</h2> <h2>...<a href="/~cananian/mediawiki/index.php?title=CLIParser&action=edit&section=3" title="Edit section: C">edit source</a>...</h2>
Note that the section number for C is 3, not 2. This is because the preprocessor assigns section numbers as soon as it sees the heading tokens ==...==, irrespective of whether it is inside a template argument or not.
The preprocessor should instead look at its template nesting tree to determine whether it is in a template argument before assigning section numbers.
Parsoid was updated to match PHP's behavior in T213468; when this bug is fixed in core Parsoid should be re-simplified to match.