From f23532bcef17e8214dc77b576263a026f7055d98 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Sat, 9 Dec 2023 20:09:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0get#stringify=E5=AF=B9?= =?UTF-8?q?=E5=A4=9A=E7=A7=8D=E5=87=BD=E6=95=B0=E5=86=99=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index c40142075..3ec0ba9ea 100644 --- a/game/game.js +++ b/game/game.js @@ -59934,11 +59934,59 @@ new Promise(resolve=>{ if(get.objtype(obj)=='object'){ str='{\n'; for(var i in obj){ + var insertDefaultString; + var insertFunctionString=indent+' '+get.stringify(obj[i],level+1)+',\n'; + var parseFunction=i=>{ + var string=obj[i].toString(); + var execResult; + if(obj[i] instanceof GeneratorFunction){ + // *content(){} + execResult=new RegExp(`\\*\\s*${i}[\\s\\S]*?\\(`).exec(obj[i]); + if(execResult&&execResult.index===0){ + return insertFunctionString; + } + // content:function*(){} + else{ + return insertDefaultString; + } + } + else if(obj[i] instanceof AsyncFunction){ + execResult=new RegExp(`async\\s*${i}[\\s\\S]*?\\(`).exec(obj[i]); + // async content(){} + if(execResult&&execResult.index===0){ + return insertFunctionString; + } + // content:async function(){} + else{ + return insertDefaultString; + } + }else{ + execResult=new RegExp(`${i}[\\s\\S]*?\\(`).exec(obj[i]); + // content(){} + if(execResult&&execResult.index===0){ + return insertFunctionString; + } + // content:function(){} + else{ + return insertDefaultString; + } + } + }; if(/[^a-zA-Z]/.test(i)){ - str+=indent+' "'+i+'":'+get.stringify(obj[i],level+1)+',\n'; + insertDefaultString=indent+' "'+i+'":'+get.stringify(obj[i],level+1)+',\n'; + if(typeof obj[i]!=='function'){ + str+=insertDefaultString; + }else{ + str+=parseFunction(i); + } } else{ - str+=indent+' '+i+':'+get.stringify(obj[i],level+1)+',\n'; + insertDefaultString=indent+' '+i+':'+get.stringify(obj[i],level+1)+',\n'; + if(typeof obj[i]!=='function'){ + str+=insertDefaultString; + }else{ + str+=parseFunction(i); + } } } str+=indent+'}';