Fix the resolveName function

The `resolveName` function requires a replacement argument string which in most invocations is provided by calling `identifierToString`. That in turn causes a lot of upfront work to be performed just in case an error needs to be reported. That doesn't make sense, particularly for such a performance critical function.

This PR changes the `nameArg` argument to be a `string | Identifier` such that the `identifierToString` call can be deferred to when it is actually needed. It also gets rid of a nested function that was added to perform certain checks before returning the result (which in turn created a nested function closure on every invocation). These checks are now performed at the end of the function itself.