babel-template
Generate an AST from a string template.
Last updated 2 years ago by hzoo .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install babel-template 
SYNC missed versions from official npm registry.

babel-template

Generate an AST from a string template.

In computer science, this is known as an implementation of quasiquotes.

Install

npm install --save-dev 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);
const myModule = require("my-module");

API

template(code, [opts])

code

Type: string

options

babel-template accepts all of the options from babylon, and specifies some defaults of its own:

  • allowReturnOutsideFunction is set to true by default.
  • allowSuperOutsideMethod is set to true by default.
preserveComments

Type: boolean Default: false

Set this to true to preserve any comments from the code parameter.

Return value

babel-template returns a function which is invoked with an optional object of replacements. See the usage section for an example.

Current Tags

  • 6.26.0                                ...           latest (2 years ago)
  • 7.0.0-beta.3                                ...           next (2 years ago)

46 Versions

  • 7.0.0-beta.3                                ...           2 years ago
  • 7.0.0-beta.2                                ...           2 years ago
  • 7.0.0-beta.1                                ...           2 years ago
  • 7.0.0-beta.0                                ...           2 years ago
  • 7.0.0-alpha.20                                ...           2 years ago
  • 6.26.0                                ...           2 years ago
  • 7.0.0-alpha.19                                ...           2 years ago
  • 7.0.0-alpha.18                                ...           2 years ago
  • 7.0.0-alpha.17                                ...           2 years ago
  • 7.0.0-alpha.16                                ...           2 years ago
  • 7.0.0-alpha.15                                ...           2 years ago
  • 7.0.0-alpha.14                                ...           2 years ago
  • 6.25.0                                ...           2 years ago
  • 7.0.0-alpha.12                                ...           2 years ago
  • 7.0.0-alpha.11                                ...           2 years ago
  • 7.0.0-alpha.10                                ...           2 years ago
  • 7.0.0-alpha.9                                ...           3 years ago
  • 7.0.0-alpha.8                                ...           3 years ago
  • 6.24.1                                ...           3 years ago
  • 7.0.0-alpha.7                                ...           3 years ago
  • 7.0.0-alpha.3                                ...           3 years ago
  • 7.0.0-alpha.1                                ...           3 years ago
  • 6.23.0                                ...           3 years ago
  • 6.22.0                                ...           3 years ago
  • 6.16.0                                ...           3 years ago
  • 6.15.0                                ...           3 years ago
  • 6.14.0                                ...           3 years ago
  • 6.9.0                                ...           4 years ago
  • 6.8.0                                ...           4 years ago
  • 6.7.0                                ...           4 years ago
  • 6.6.5                                ...           4 years ago
  • 6.6.4                                ...           4 years ago
  • 6.6.0                                ...           4 years ago
  • 6.5.0-1                                ...           4 years ago
  • 6.5.0                                ...           4 years ago
  • 6.3.13                                ...           4 years ago
  • 6.3.0                                ...           4 years ago
  • 6.2.4                                ...           4 years ago
  • 6.2.0                                ...           4 years ago
  • 6.1.18                                ...           4 years ago
  • 6.1.17                                ...           4 years ago
  • 6.0.16                                ...           4 years ago
  • 6.0.15                                ...           4 years ago
  • 6.0.14                                ...           4 years ago
  • 6.0.12                                ...           4 years ago
  • 6.0.2                                ...           4 years ago
Downloads
Today 3,953
This Week 3,953
This Month 177,226
Last Day 3,556
Last Week 75,305
Last Month 302,811
Dependencies (5)
Dev Dependencies (0)
None
Dependents (660)

Copyright 2014 - 2016 © taobao.org |