Optional methods use ? tokens like this:
interface X { y?(): z; }
It seems easiest to detect and disambiguate these
from ternary expressions by checking if the code
is in a declaration context. Turns out that that
didn't quite work properly for interfaces in Java
and JS, and for JS file root contexts.
Note that this change is unrelated, I just stumbled across this code and found it hard to read with all those boolean clauses. Might be useful to go over this and add comments explaining the individual parts at some point.