JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22076
  • Score
    100M100P100Q149737F
  • License MIT

Template functions to generate TypeScript AST.

Package Exports

  • talt

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (talt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Talt

github actions npm version GitHub license

Template functions to generate TypeScript AST, inspired from @babel/template .

Install

$ npm i talt typescript

Usage

import ts from "typescript";
import { template } from "talt";

const typeNode = template.typeNode("{ readonly hoge: string }")();

// You can use `template` as tag function.
const typeNodeUsingTagFn = template.typeNode`
  {
    readonly hoge: string;
  }
`();

// The following returns ts.BinaryExpression
const binaryExpression = template.expression<ts.BinaryExpression>("60 * 1000")();

// You can use identifier placeholder.
const compiledFn = template.expression`
  60 * SOME_PLACEHOLDER_KEY
`;
const generatedAst = compiledFn({
  SOME_PLACEHOLDER_KEY: binaryExpression,
}); // returns expression node, `60 * 60 * 1000`

const generetedOtherNode = compiledFn({
  SOME_PLACEHOLDER_KEY: ts.factory.createNumericLiteral("200"),
}); // returns expression node, `60 * 200`

API

template has the following tag functions. Each tag function compiles and provides corresponding type AST.

  • template.typeNode
  • template.expression
  • template.statement
  • template.sourceFile
  • template.jsxAttribute

License

MIT