You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// - we add `content`, which is the original string form of the template
80
+
// - we add `meta.jsutils`, which gives AST transform plugins access to methods for manipulating the surrounding javascript scope. See "JSUtils" below.
80
81
// - we have special parsing for `scope` which becomes `locals` when passed
81
82
// to your precompile
82
83
// - anything else the user passes to `precompileTemplate` will be passed
@@ -98,6 +99,45 @@ import * as babel from '@babel/core';
# JSUtils: Manipulating Javascript from within AST transforms
103
+
104
+
AST transforms are plugins for modifying HBS templates at build time. Because those templates are embedded in Javascript and can access the Javascript scope, an AST plugin may want to introduce some new things into Javascript scope. That is what the JSUtils API is for.
105
+
106
+
Your AST transform can access the JSUtils API via `env.meta.jsutils`. Here's an example transform.
107
+
108
+
```js
109
+
functionmyAstTransform(env) {
110
+
return {
111
+
name:'my-ast-transform',
112
+
visitor: {
113
+
PathExpression(node, path) {
114
+
if (node.original==='onePlusOne') {
115
+
let name =env.meta.jsutils.bindExpression('1+1', path, { nameHint:'two' });
0 commit comments