javascript - Is there any way of converting a string containing es6 to es5? -


i creating application user enter es6 code , application return es5 equivalent. know babel converts es6 es5 there way use strings contain es6 code.

e.g input:

"[1, 2, 3].map(n => n * 2)" 

output:

"[1, 2, 3].map(function(n) { return n * 2; }, this)" 

this called "transpiling". transpilers programs transfers code written in language language @ same level of abstraction. (from wikipedia)

for es6 es5, mention in question, there tool named babel.

from babel's documentation:

var babel = require("babel-core"); 

babel.transform(code, [options])

transforms passed in code. returning object generated code, source map, , ast.

babel.transform(code, [options]) // => { code, map, ast } 

example

var result = babel.transform("code();", options); result.code; result.map; result.ast; 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -