[AST Babel] Babel Template
Template babel AST
2023-09-14 09:00:48 时间
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) } } }; }
相关文章
- JDBC连接池、JDBC Template使用
- Failed to mount component: template or render function not defined.
- zen cart template zencart模板修改[通俗易懂]
- variadic template总述
- Django之Template介绍及日常应用
- ORA-23439: refresh group template already exists ORACLE 报错 故障修复 远程处理
- ORA-23442: object already exists for the refresh group template ORACLE 报错 故障修复 远程处理
- ORA-23445: missing template site ORACLE 报错 故障修复 远程处理
- ORA-23471: template not authorized for user ORACLE 报错 故障修复 远程处理
- ORA-23501: refresh template cannot be instantiated for database with compatibilty equal to or less than 8.0 ORACLE 报错 故障修复 远程处理
- ORA-14604: During CREATE TABLE time it is illegal to specify SUBPARTITIONS or STORE IN once a SUBPARTITION TEMPLATE has been specified ORACLE 报错 故障修复 远程处理
- ORA-14608: Tablespace was specified for the previous lob segments of column string in template but is not specified for string ORACLE 报错 故障修复 远程处理
- SharePoint server 2016中文版导出list template,在另外一个环境不能显示详解程序员
- SAP Smartform中table和template的区别详解编程语言
- php设计模式Template(模板模式)