Skip to content

Commit

Permalink
update wuRestoreZ.js to fix an error by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty472123 committed Apr 23, 2018
1 parent 9f109d2 commit 5c7f1b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Android 手机最近使用过的微信小程序所对应的 wxapkg 包文件都
- wxs 文件会将所有的变量如 Math 改为 nv_Math ,这里仅通过字符串替换去除。
- 一些被引用 wxss 文件本身的源文件丢失,因此无法恢复原始目录。
- 有些项目开启了难以复原的`es6转es5`选项,检验本项目结果是否正确时需要关闭项目中的`es6转es5`选项。
- wxml 中一些无法找到正向语句的内容无法还原。

## 依赖

Expand Down
27 changes: 18 additions & 9 deletions wuRestoreZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ function catchZ(code,cb){
vm.run(code);
cb(z);
}
function restoreSingle(ops,withScope=false,par=''){
function restoreSingle(ops,withScope=false){
if(typeof ops=="undefined")return "";
function scope(value){
if(value.startsWith('{')&&value.endsWith('}'))return withScope?value:"{"+value+"}";
return withScope?value:"{{"+value+"}}";
}
function restoreNext(ops,w=withScope,p=par){
return restoreSingle(ops,w,p);
function restoreNext(ops,w=withScope){
return restoreSingle(ops,w);
}
function jsoToWxon(obj){//convert JS Object to Wechat Object Notation(No quotes@key+str)
let ans="";
Expand All @@ -44,9 +44,9 @@ function restoreSingle(ops,withScope=false,par=''){
return "'"+ret.join('"')+"'";
}else return JSON.stringify(obj);
}
function son(value,notObject=false){
function son(value){
if(/^[A-Za-z\_][A-Za-z\d\_]*$/.test(value)/*is a qualified id*/){return '.'+value}
else return '['+(notObject?value:jsoToWxon(value))+']';
else return '['+value+']';
}
let op=ops[0];
if(typeof op!="object"){
Expand Down Expand Up @@ -131,17 +131,26 @@ function restoreSingle(ops,withScope=false,par=''){
break;
}
case 6://get value of an object
ans=restoreNext(ops[1],true)+son(restoreNext(ops[2],true),true);
{
let sonName=restoreNext(ops[2],true);
if(sonName._type==="var")
ans=restoreNext(ops[1],true)+'['+sonName+']';
else
ans=restoreNext(ops[1],true)+son(sonName);
break;
case 7://get value(may be value of one object)
}
case 7://get value of str
{
switch(ops[1][0]){
case 11:
ans=par;
ans="{__unTestedGetValue:["+jsoToWxon(ops)+"]}";
break;
case 3:
ans=par?(par+son(ops[1][1])):ops[1][1];
ans=new String(ops[1][1]);
ans._type="var";
break;
default:
throw "Unknown type to get value";
}
break;
}
Expand Down

0 comments on commit 5c7f1b7

Please # to comment.