From 73580c3afecad8c59e14ea7252dcedd8034e6c3a Mon Sep 17 00:00:00 2001 From: 4qwerty7 <5781325+qwerty472123@users.noreply.github.com> Date: Wed, 15 Aug 2018 22:45:58 +0800 Subject: [PATCH] To fit a case that WX's code generater have a bug --- README.md | 1 + package.json | 5 +++-- wuWxml.js | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c7274c31..1b75b6df 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Android 手机最近使用过的微信小程序所对应的 wxapkg 包文件都 npm install vm2 -g npm install uglify-es -g npm install js-beautify -g + npm install escodegen -g 此外,这些 node.js 程序之间也有一定的依赖关系,比如他们都依赖于 wuLib.js 。 diff --git a/package.json b/package.json index 4dec211e..fc282712 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,10 @@ "dependencies": { "css-tree": "^1.0.0-alpha.28", "cssbeautify": "^0.3.1", + "escodegen": "^1.11.0", "esprima": "^4.0.0", + "js-beautify": "^1.7.5", "uglify-es": "^3.3.9", - "vm2": "^3.6.0", - "js-beautify": "^1.7.5" + "vm2": "^3.6.0" } } diff --git a/wuWxml.js b/wuWxml.js index 859e3af0..e53d890f 100644 --- a/wuWxml.js +++ b/wuWxml.js @@ -5,6 +5,7 @@ const fs=require('fs'); const path=require("path"); const esprima=require('esprima'); const {VM}=require('vm2'); +const escodegen=require('escodegen'); function analyze(core,z,namePool,xPool,fakePool={},zMulName="0"){ function anaRecursion(core,fakePool={}){ return analyze(core,z,namePool,xPool,fakePool,zMulName); @@ -38,7 +39,7 @@ function analyze(core,z,namePool,xPool,fakePool={},zMulName="0"){ let item=f.arguments[6].value;//def:item let index=f.arguments[7].value;//def:index let data=z[f.arguments[0].value]; - let key=f.arguments[8].value;//def:"" + let key=escodegen.generate(f.arguments[8]).slice(1,-1);//f.arguments[8].value;//def:"" let obj=namePool[f.arguments[5].name]; let gen=namePool[f.arguments[1].name]; if(gen.tag=="gen"){ @@ -56,7 +57,7 @@ function analyze(core,z,namePool,xPool,fakePool={},zMulName="0"){ let item=f.arguments[7].value;//def:item let index=f.arguments[8].value;//def:index let data=z.mul[zMulName][f.arguments[1].value]; - let key=f.arguments[9].value;//def:"" + let key=escodegen.generate(f.arguments[9]).slice(1,-1);//f.arguments[9].value;//def:"" let obj=namePool[f.arguments[6].name]; let gen=namePool[f.arguments[2].name]; if(gen.tag=="gen"){ @@ -237,7 +238,7 @@ function analyze(core,z,namePool,xPool,fakePool={},zMulName="0"){ } } function wxmlify(str,isText){ - if(typeof str=="undefined"||str===null)throw Error("Empty str in "+(isText?"text":"prop")); + if(typeof str=="undefined"||str===null)return "Empty";//throw Error("Empty str in "+(isText?"text":"prop")); if(isText)return str;//may have some bugs in some specific case(undocumented by tx) else return str.replace(/"/g, '\\"'); }