Skip to content

A wxml code generator from AST parsed by @wxml/parser

Notifications You must be signed in to change notification settings

wxmlfile/wxml-generator

Repository files navigation

@wxml/generator

npm version

A wxml code generator from AST parsed by @wxml/parser. traverse has Updated to wxml-traverse

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 } = 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);

贡献者

About

A wxml code generator from AST parsed by @wxml/parser

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published