How would you know the "correct" output is :
Code:
This \textit{is} \textbf{\textit{in}deed} a strange idea!
and not:
Code:
This \textit{is \textbf{in}}\textbf{deed} a strange idea!
?
Of course, the real output, after a LaTeX run, would be indistinguishable. (Note that whether the whitespace must be italic or not may be debatable, but you should probably keep whatever was in the input file)
I don't know what would be the "canonical" way of dealing with this, but I'd say you'll have to check proper nesting when generating LaTeX code: Whenever a feature is deactivated, check if it's the innermost feature (the last one to have been activated; if it is, close the brace, if it isn't, close the the inner features' braces, close the brace, and open the inner features again.