Skip to content

jstransformers/jstransformer-babel

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

jstransformer-babel

Babel support for JSTransformers.

Build Status Coverage Status Dependency Status NPM version

Installation

npm install jstransformer-babel

API

var babel = require('jstransformer')(require('jstransformer-babel'))

var src = 'let a = 0'
var transformed = babel.render(src, {presets: ['es2015']})
//=> '"use strict";\n\nvar a = 0;'

Only render method is implemented, which means that through the JSTransformer architecture all render* APIs are available.

Passing options to Babel is supported as well, and all options unsupported by Babel are filtered out before passing them to Babel.

In babel@6 (jstransformer-babel@2), the default of transpiling from ES2015 is removed. As a result, in order to transpile from ES2015 just like in jstransformer-babel@2, pass in ['es2015'] as the value of the presets option, just like in the example above. If that is too laborious, you can look into using a .babelrc file.

Babel configuration files like .babelrc are also supported. They can only be detected if you use the renderFile* APIs or manually pass in a filename option.

License

MIT