@propero/typescript-transformer-source-templates
v1.1.0
Published
Generate fresh ASTs from source strings
Downloads
4
Readme
@propero/typescript-transformer-source-templates
Generate fresh ASTs from source strings
npm i @propero/typescript-transformer-source-templates
Example Usage
import { template } from "@propero/typescript-transformer-source-templates";
const aggregationTemplate = template(`
let VARIABLE = control.getAggregation("AGGREGATION");
if (!Array.isArray(VARIABLE)) VARIABLE = VARIABLE == null ? [] : [VARIABLE];
VARIABLE.forEach(it => rm.renderControl(it));
`);
const headerNodes = aggregationTemplate.statements({ AGGREGATION: 'header', VARIABLE: "_header" });
const contentNodes = aggregationTemplate.statements({ AGGREGATION: 'content', VARIABLE: () => "_content" });
const footerNodes = aggregationTemplate.statements({ AGGREGATION: 'footer' });
Casting and member templates
import { template } from "@propero/typescript-transformer-source-templates";
import { MethodDeclaration } from "typescript";
const methodTemplate = template("render() {RENDER_CODE}");
const render = methodTemplate.objectMember<MethodDeclaration>({ RENDER_CODE: "return 'hello world';" });