babel-plugin-jsx-underscore

0.1.0 • Public • Published

Babel Plugin for generating Underscore JavaScript Templates

Overview

This plugin produces Underscore Templates output of given JSX source. Currently For Babel 5

Installation

npm install babel-plugin-jsx-underscore

Usage

Basic usage look like this:

babel.transform(code, {
  plugins: ['babel-plugin-jsx-underscore'],
  blacklist: ['react']
});

or any other way described here.

Options and combinations

There is some number of options, first and main option is captureScope:

  • captureScope [boolean] - when enabled plugin looks for current scope to find same variables as JSX source tags. For example, this code <div></div> will produce { tag: 'div', ... } when capture is disabled and { tag: ['div', div], ...} when capture is enabled -- plugin captures variable for feature use by runtime.
  • builtins [Array] - only has effect when captureScope is true. This options allows number of built-ins tags so plugin won't need to look for when in the scope. Usage of this options assumes that renderer knows how to handle listed built-in tags. If this option is provided and used tag is not a built-in and it's not in the current scope when compilation error will be thrown.
  • throwOnMissing [boolean] - only has effect when captureScope and builtins options are used simultaneously. By default this is true, setting it to false means that plugin won't throw compilation error for missed tags, instead it will produce normal scope output and if variable is missing you will get an runtime error.

Examples

Example of input

    <a class="anchor" href={"<%= data.href %>"}>
        {"<%= data.content %>"}
    </a>

Example of output

function (data) {
    var __t,
        __p = '',
        __j = Array.prototype.join,
        print = function print() {
        __p += __j.call(arguments, '');
    };__p += '<a class=\'chemical-anchor\'href=\'' + ((__t = data.href) == null ? '' : __t) + '\'>' + ((__t = data.content) == null ? '' : __t) + '</a>';return __p;
};

License

MIT

Package Sidebar

Install

npm i babel-plugin-jsx-underscore

Weekly Downloads

6

Version

0.1.0

License

MIT

Last publish

Collaborators

  • toxigenicpoem