html转百度小程序,百度小程序转换工具

CV or Not CV, isn't a question, Just CV!

一、Babel

1460000021549373

解析 → 转换 → 生成

//解析 → 转换 → 生成

//babylon(解析)、babel-traverse(转换)、babel-generator(生成)、@babel/types(辅助)

解析(词法 → 语法)

//词法分析阶段把字符串形式的代码转换为tokens令牌流

{

type:"paren",value:"(",

type:"name",value:"foo",

...//tokens令牌

}

//语法分析阶段则会把一个令牌流转换成 AST的形式

// https://astexplorer.net/

demo

{'#frontend'}

{'#backend'}

JSXExpressionContainer(path, state) {

if (path.node.expression.value.startsWith("#")) {

path.replaceWith(

t.JSXOpeningElement(

t.JSXIdentifier("Iyourcar"),

[

t.JSXAttribute(

t.JSXIdentifier("id"),

t.StringLiteral(

path.node.expression.value.replace("#", "")

)

)

],

true

)

);

}

}

二、转换js

//先转换api、__router__、getExtConfigSync,再转wx前缀

三、转换wxml

// unified 一个流式的创建插入内容的工具。工作原理

| ........................ process ........................... |

| .......... parse ... | ... run ... | ... stringify ..........|

+--------+ +----------+

Input ->- | Parser | ->- Syntax Tree ->- | Compiler | ->- Output

+--------+ | +----------+

X

|

+--------------+

| Transformers |

+--------------+

// htmlparser2可以用来处理HTML / XML / RSS的解析器。

{ type: 'tag',

name: Symbol(fake-root),

attribs: {},

children:

[ { type: 'tag',

name: 'yc-navbar',

attribs: [Object],

children: [],

singleQuoteAttribs: {},

selfclose: true },

{ data: '\n', type: 'text' },

{ data: ' loading ', type: 'comment' },

{ data: '\n', type: 'text' },

{ type: 'tag',

name: 'loading',

attribs: [Object],

children: [],

singleQuoteAttribs: {},

selfclose: false },

]

}

四、转换wxs

//百度小程序对应的是filter与sjs。但是filter已弃用,sjs有bug

//对于wxml中的wxs

function tranformWxs(node, file, options){

const attribs = node.attribs;

node.name="import-sjs"

if (attribs && attribs.src) {

let src = attribs.src.replace(/\.wxs$/i, '.sjs');

return {

...node,

attribs: {

...attribs,

src: src

}

};

}

return node;

}

//.wxs文件 → 重命名 .sjs

function renameFileExt(filePath) {

if (/xml|wxml/.test(filePath)) {

return filePath.replace(/xml|wxml$/, swanFileSuffix);

}

else if (/\.wxs/.test(filePath)) {

return filePath.replace(/\.wxs$/, wxsFileSuffix);

}

else {

return filePath;

}

}

Thanks...

bVbCy2U

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值