[AST Babel] Babel Template
Template babel AST
2023-09-14 08:59:14 时间
For example we want to just conver a VariableDeclaration to
Foo.bar.otherBaz("one", 2);
We can use Babel template to do that:
export default function(babel) { const { types: t, template } = babel; return { name: "ast-transform", // not required visitor: { VariableDeclaration(path) { const templateString = `Foo.bar.BAZ(ONE, TWO)` const callExpressionBuilder = template(templateString) const callExpression = callExpressionBuilder({ FOO: t.identifier('someFoo'), BAZ: t.identifier('otherBaz'), ONE: t.stringLiteral('one'), TWO: t.numericLiteral(2) }) path.replaceWith(callExpression) } } }; }
相关文章
- 设计模式 ( 十九 ) 模板方法模式Template method(类行为型)
- [Python] Template literals f""
- RF-template使用
- [Kotlin Spring boot] Connect template with a backing bean
- [Python] Template literals f""
- CRM Document template for product attachment
- SAP Commerce Cloud CMS page 和 page template 的概念
- Atitit.eclipse comment template注释模板
- SAP Smart Template(现在叫Fiori Element了)进行扩展的一些例子
- 关于 ng-template 通过 @input 传入另一个 Component 不能工作的问题调试
- UI自动化测试框架搭建 —— 借鉴AirTest框架Template定位元素