Refactor JS compilation