@wxml/generator
v0.1.0
Published
A wxml code generator from AST parsed by @wxml/parser
Downloads
4
Readme
@wxml/generator
A wxml code generator from AST parsed by @wxml/parser.
Basic Usage
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, traverse } = require("@wxml/generator");
traverse(AST, {
WXInterpolation(node) {
if (node.value === 'mallName') {
node.value = 'somethingNew';
}
}
});
const code = generate(AST);
console.log("AST structure: ", AST);
console.log("Code: ", code);