Refactoring js generation