compiler: simplified function toJavaScript()

Removed nested function visit() and made its body the body of
toJavaScript()