JavaScript structural search, replace, and refactor