@wxml/generator
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

@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);

Package Sidebar

Install

npm i @wxml/generator

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

10.6 kB

Total Files

10

Last publish

Collaborators

  • dhlolo
  • ichenlei