Tagged template string function for AST.
npm install tagged-template-to-asttoAST template tagged function that inline AST Node to source code.
Combine source code with AST Node.
for more information about tagged template strings and see developer.mozilla.org/docs/Web/JavaScript/Reference/template_strings
npm install tagged-template-to-ast
toAST tag function help to inline AST Node to source code.
``jsvar foo = ${ASTNode}
toAST; // return AST`
Example:
`jsfunction(){}
import toAST from "tagged-template-to-ast"
// expressionvar a = ${nodeForInline};
var nodeForInline = {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": []
},
"generator": false,
"expression": false
};
var astNode = toAST;var a = function (){};
// astNode is the AST of `
Combine code with AST Node.
`jsvar a = ${nodeForInline}
import {parse} from "esprima"
import toAST from "tagged-template-to-ast"
var nodeForInline = parse('"string"');
var astNode = toAST;var a = "string";
// astNode is the AST of `
Could inline to body block too!
`jsif(true){
import {parse} from "esprima"
import toAST from "tagged-template-to-ast"
import astEqual from "ast-equal"
var aNodeForBody = parse("sum(1);");
var astNode = toAST
${aNodeForBody}
};if(true){
var expected =
sum(1);
};`
// test helper to assert JavaScript AST equality.
// https://github.com/azu/ast-equal
astEqual(astNode, expected);
npm test
1. Fork it!
2. Create your feature branch: git checkout -b my-new-featuregit commit -am 'Add some feature'
3. Commit your changes: git push origin my-new-feature`
4. Push to the branch:
5. Submit a pull request :D
MIT