I previously tried an approach to scope bindings from var to scope but it didn't catch all cases. This is evident in this bug: https://phabricator.babeljs.io/T2892 Where even after transforming a const to a var we still get an error that it's read-only. This approach will go through and delete every existing let and const binding and creates a new one with the kind "var"
babel-core
Babel compiler core.
Install
$ npm install babel-core
Usage
import babel from 'babel-core';
const code = `class Example {}`;
const result = babel.transform(code, { /* options */ });
result.code; // Generated code
result.map; // Sourcemap
result.ast; // AST
For more in depth documentation see: http://babeljs.io/docs/usage/api/