babel/packages/babel-template
Daniel Lo Nigro 0076204f80 Fix Flow.
Removed `@flow` annotation from files that don't actually pass Flow check at the moment. These will be added back file by file once the files are properly converted to use Flow.

Closes #3064
2015-11-15 21:30:22 -08:00
..
2015-11-15 21:30:22 -08:00
2015-10-30 23:45:42 +00:00
2015-11-12 13:46:30 -08:00
2015-10-29 21:19:55 -07:00

babel-template

Generate an AST from a string template.

Install

$ npm install babel-template

Usage

import template from 'babel-template';
import generate from 'babel-generator';
import * as t from 'babel-types';

const buildRequire = template(`
  var IMPORT_NAME = require(SOURCE);
`);

const ast = buildRequire({
  IMPORT_NAME: t.identifier('myModule'),
  SOURCE: t.stringLiteral('my-module')
});

console.log(generate(ast).code);
var myModule = require('my-module');