A wxml code generator from AST parsed by @wxml/parser.
traverse
has Updated to wxml-traverse
const { parse } = require("@wxml/parser");
const AST = parse(`
<view class="search-contianer">
<view class="search" style="height:{{navHeight}}px;padding-top:{{navTop}}px">
<view class="search-title" src="../../images/actLogo/ytlogo.png">
{{mallName}}
</view>
<input
placeholder-class="search-placeholder"
type="text"
placeholder="please enter keyword for search"
disabled
value="{{name}}"
bindinput="bindinput"
bindtap="goSearch">
</input>
</view>
</view>
`);
const { generate } = require("@wxml/generator");
// const { traverseStatic } = require("@wxml/generator");
// traverseStatic(AST, {
// WXInterpolation(node) {
// if (node.value === 'mallName') {
// node.value = 'somethingNew';
// }
// }
// });
const { traverse } = require('@wxml/traverse');
traverse(AST, {
WXInterpolation(path) {
if (path.node.value === 'mallName') {
path.node.value = 'somethingNew';
}
}
});
const code = generate(AST);
console.log("AST structure: ", AST);
console.log("Code: ", code);