6.26.0 • Published 8 years ago

babel-template v6.26.0

Weekly downloads
4,304,084
License
MIT
Repository
github
Last release
8 years ago

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.

babel-corebabel-helper-replace-supersbabel-helper-function-namebabel-helpersbabel-plugin-transform-es2015-modules-amdbabel-plugin-transform-es2015-modules-commonjsbabel-plugin-transform-es2015-modules-umdbabel-plugin-transform-es2015-parametersbabel-plugin-transform-es2015-block-scopingbabel-plugin-transform-es2015-classesbabel-plugin-transform-es2015-computed-propertiesbabel-plugin-transform-es2015-modules-systemjsbabel-helper-remap-async-to-generatorbabel-plugin-transform-class-propertiesarchetype-library@withdouble/babel-plugin-promisify-async-callback@arisageha/react-lazyload@arisageha/react-lazyload-fix@sirius-black/taro-cli@cashremit/cr-streamline-icons@kadr/staticfreshpaint-react-nativejsbuggg@phil8795/pecuniarius-apidxp-cloud-local-npm-scriptsares-nextwenke-babel-corebabel-plugin-transform-inline-nearleybabel-plugin-transform-inline-vue-templatesxyj_taro_cli@cloudkite/nextjaibascriptalex-frontend-sdk-stagingcthpb-plugin-socialbabel-plugin-catch-reportermrd-ui5-jsx-rmuinz-notification@mink-opn/build-tokens@infinitebrahmanuniverse/nolb-babel-t@everything-registry/sub-chunk-1207@explodingcamera/nextydw-babeldemo@clearkard/babel-preset-extendscripttarojs-clitarojs-cli-s4ssymphony-joytest-carosello-campusteadanteawinx-form-winxwinsen-cliweex-vue-migrationwebpack_component_fundworkflowjswow.js-juziwh-auto-trycatchwy-micro-pluginteawhitescteagreenscreenteanandenandetearedscsuperchao-lib-atechfox-icontechfox-react-feathertemplate-page-creatorspet-ui5-jsx-rmtest-test-43h4h29423teste_cegidtextfield-sampletestxyhthen-puguu-servervcloudcam-playkit-js-hlsvue-dev-clone@dongnl/pawjs@doctorwork/dw-cli@cross2d/next@ct-note/delimiter@d-bigfish/cli@dingyun/babel-plugin-custom-import@borealisswap/borealis-swap-lib@blueeast/bluerain-cli-plugin@caneco/siema@rtarojs/taroizejdseal-cliivanpantekistanbul-middleware-ryjsxlatejs-profileintegral-moshisv-ali-babel-coreisv-babel-plugin-dynamic-transform-definekafirchain-tetrislaravel-bassetkwasniew-parcel-bundlerbabel-plugin-transform-class-construtor-callstyle9-jsx-propstart-starwars-libsugaryjssunesimonsen-babel-plugin-inline-react-svgstrikingly-taro-cli
7.0.0-beta.3

8 years ago

7.0.0-beta.2

8 years ago

7.0.0-beta.1

8 years ago

7.0.0-beta.0

8 years ago

7.0.0-alpha.20

8 years ago

6.26.0

8 years ago

7.0.0-alpha.19

8 years ago

7.0.0-alpha.18

8 years ago

7.0.0-alpha.17

8 years ago

7.0.0-alpha.16

8 years ago

7.0.0-alpha.15

8 years ago

7.0.0-alpha.14

8 years ago

6.25.0

8 years ago

7.0.0-alpha.12

8 years ago

7.0.0-alpha.11

8 years ago

7.0.0-alpha.10

8 years ago

7.0.0-alpha.9

8 years ago

7.0.0-alpha.8

8 years ago

6.24.1

8 years ago

7.0.0-alpha.7

8 years ago

7.0.0-alpha.3

8 years ago

7.0.0-alpha.1

8 years ago

6.23.0

8 years ago

6.22.0

8 years ago

6.16.0

9 years ago

6.15.0

9 years ago

6.14.0

9 years ago

6.9.0

9 years ago

6.8.0

9 years ago

6.7.0

9 years ago

6.6.5

9 years ago

6.6.4

9 years ago

6.6.0

9 years ago

6.5.0-1

9 years ago

6.5.0

9 years ago

6.3.13

10 years ago

6.3.0

10 years ago

6.2.4

10 years ago

6.2.0

10 years ago

6.1.18

10 years ago

6.1.17

10 years ago

6.0.16

10 years ago

6.0.15

10 years ago

6.0.14

10 years ago

6.0.12

10 years ago

6.0.2

10 years ago