@jamestalmage/babel-template
v6.3.13
Published
Generate an AST from a string template.
Downloads
5
Readme
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');