Make optimizer handle both strings and string-like type objects.

NodeWithToken is a string-like type produced by the parser during 'embed
tokens' mode, which allows us to track line numbers.