From a5fb25629cd93d85233fea6d2e9f4f358b2dd0f6 Mon Sep 17 00:00:00 2001 From: Stefano Balocco Date: Sat, 29 Jan 2022 23:33:57 +0100 Subject: [PATCH] null is an object, but is a primitive type. So, every time I typeof == 'object', I should also check != null --- README.md | 4 +++- jTDAL.js | 32 ++++++++++++++------------------ jTDAL.min.js | 2 +- jTDAL.ts | 27 ++++++++++++--------------- package.json | 2 +- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index a6275b5..2a95fd3 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,9 @@ The first that exists and is not false, is the used as result of the path expres If the path expression supports booleans, you can prepend [!] to a path. -If the path expression supports strings, you can append, as last path, STRING:this is a string {and/you/can/have/paths/too}! {?this/path/is/true} showed only if the condition is true{?this/path/is/true}{?!this/is/false} visible only unless is true{?!this/is/false} +If the path expression supports strings, you can append, as last path + + STRING:this is a string {and/you/can/have/paths/too}! {?this/path/is/true} showed only if the condition is true{?this/path/is/true}{?!this/is/false} visible only unless is true{?!this/is/false} In a boolean check, empty lists or empty string will be considered "false". diff --git a/jTDAL.js b/jTDAL.js index ddcef78..5ad2c3b 100644 --- a/jTDAL.js +++ b/jTDAL.js @@ -97,36 +97,36 @@ var jTDAL; case 'GLOBAL': { if (1 < path.length) { const countSecondLevel = path.length; - returnValue += (boolPath ? (not ? '!(' : '(') : '') + '"object"===typeof (t[i]=d)'; + returnValue += (boolPath ? (not ? '!(' : '(') : '') + '"object"===typeof(t[i]=d)&&null!==t[i]'; for (let indexSecondLevel = 1; indexSecondLevel < countSecondLevel; ++indexSecondLevel) { returnValue += '&&'; let lastPath = 't[i]["' + path[indexSecondLevel] + '"]'; - returnValue += '"undefined"!==typeof '; + returnValue += '"undefined"!==typeof'; returnValue += '(t[i]=("function"===typeof ' + lastPath + '?' + lastPath + '(r,d)):' + lastPath + ')'; } - returnValue += (boolPath ? '?"object"===typeof t[i]?0]+?)??\\s+data-tdal-(?:"+["condition","repeat","content","replace","attributes","omittag"].join("|")+")=(['\"])(.*?)\\3(\\s+[^<>]+?)??\\s*(/)?>","i"),tagWithAttribute:new RegExp("<((?:w+:)?w+)(s+[^<>]+?)??s+%s=(['\"])(.*?)\\3(s+[^<>]+?)??s*(/)?>","i"),tagAttributes:new RegExp("(?<=\\s)((?:[\\w-]+:)?[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi"),pathString:new RegExp("(?:{("+e+")}|{\\?("+i+")}(.*?){\\?\\2})"),pathInString:new RegExp("{("+e+")}","g"),conditionInString:new RegExp("{\\?("+i+")}(.*?){\\?\\1}","g"),condition:new RegExp("^[\\s]*("+r+")[\\s]*$"),repeat:new RegExp("^[\\s]*([\\w-]+?)[\\s]+("+e+")[\\s]*$"),content:new RegExp("^[\\s]*(?:(text|structure)[\\s]+)?("+r+")[\\s]*$"),attributes:new RegExp("[\\s]*(?:(?:([\\w-]+?)[\\s]+("+r+")[\\s]*)(?:;[\\s]*|$))","g"),attributesTDAL:new RegExp("\\s*(data-tdal-[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi")},s=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"];function l(t){let e='""',i=null;for(;null!=(i=n.pathString.exec(t));)if(0]*(?","gi");let s=1;for(;void 0===e[0]&&null!==(r=n.exec(t));)r[1]?s--:s++,0==s&&(e=[r.index,r[0].length]);void 0===e[0]?u=!0:(a[4]+=o(t.substr(0,e[0])),a[6]+=t.substr(e[0],e[1]),t=t.substr(e[0]+e[1]))}t:{if(l["data-tdal-condition"]&&n.condition.exec(l["data-tdal-condition"][3])){let t=f(l["data-tdal-condition"][3],!0);if("false"===t)break t;"true"!==t&&(a[0]+="+(true==="+t+'?""',a[7]=':"")'+a[7])}let t;if(l["data-tdal-repeat"]&&(t=n.repeat.exec(l["data-tdal-repeat"][3]))){let e=f(t[2]);if("false"==e||'""'==e||"true"==e)break t;a[0]+="+(",a[0]+="false!==(t[i++]="+e+")&&",a[0]+="(!Array.isArray(t[--i])||(t[i]=Object.assign({},t[i])))&&",a[0]+='("object"===typeof t[i]&&0$/,""),!u||""==a[4]&&""==a[3]&&""==a[5]||(a[6]="",u=!1),e+=a[0]+"+"+JSON.stringify(String(a[1]))+a[2]+(""!=a[1]?'+"'+(u?"/":"")+'>"':"")+a[3]+a[4]+a[5]+"+"+JSON.stringify(String(a[6]))+a[7]}return e+="+"+JSON.stringify(String(t)),e}function a(t,e=!0,i=!0){return('let r={"REPEAT":{}},i=0,t=[];return '+(e?"(":"")+'""'+o(i?t.replace(//gs,""):t)).replace(/(?]+?)??\\s+data-tdal-(?:"+["condition","repeat","content","replace","attributes","omittag"].join("|")+")=(['\"])(.*?)\\3(\\s+[^<>]+?)??\\s*(/)?>","i"),tagWithAttribute:new RegExp("<((?:w+:)?w+)(s+[^<>]+?)??s+%s=(['\"])(.*?)\\3(s+[^<>]+?)??s*(/)?>","i"),tagAttributes:new RegExp("(?<=\\s)((?:[\\w-]+:)?[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi"),pathString:new RegExp("(?:{("+e+")}|{\\?("+i+")}(.*?){\\?\\2})"),pathInString:new RegExp("{("+e+")}","g"),conditionInString:new RegExp("{\\?("+i+")}(.*?){\\?\\1}","g"),condition:new RegExp("^[\\s]*("+r+")[\\s]*$"),repeat:new RegExp("^[\\s]*([\\w-]+?)[\\s]+("+e+")[\\s]*$"),content:new RegExp("^[\\s]*(?:(text|structure)[\\s]+)?("+r+")[\\s]*$"),attributes:new RegExp("[\\s]*(?:(?:([\\w-]+?)[\\s]+("+r+")[\\s]*)(?:;[\\s]*|$))","g"),attributesTDAL:new RegExp("\\s*(data-tdal-[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi")},l=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"];function s(t){let e='""',i=null;for(;null!=(i=n.pathString.exec(t));)if(0]*(?","gi");let l=1;for(;void 0===e[0]&&null!==(r=n.exec(t));)r[1]?l--:l++,0==l&&(e=[r.index,r[0].length]);void 0===e[0]?a=!0:(u[4]+=o(t.substr(0,e[0])),u[6]+=t.substr(e[0],e[1]),t=t.substr(e[0]+e[1]))}t:{if(s["data-tdal-condition"]&&n.condition.exec(s["data-tdal-condition"][3])){let t=f(s["data-tdal-condition"][3],!0);if("false"===t)break t;"true"!==t&&(u[0]+="+(true==="+t+'?""',u[7]=':"")'+u[7])}let t;if(s["data-tdal-repeat"]&&(t=n.repeat.exec(s["data-tdal-repeat"][3]))){let e=f(t[2]);if("false"==e||'""'==e||"true"==e)break t;u[0]+="+(",u[0]+="false!==(t[i++]="+e+")&&",u[0]+="(!Array.isArray(t[--i])||(t[i]=Object.assign({},t[i])))&&",u[0]+='("object"===typeof t[i]&&null!==t[i]&&0$/,""),!a||""==u[4]&&""==u[3]&&""==u[5]||(u[6]="",a=!1),e+=u[0]+"+"+JSON.stringify(String(u[1]))+u[2]+(""!=u[1]?'+"'+(a?"/":"")+'>"':"")+u[3]+u[4]+u[5]+"+"+JSON.stringify(String(u[6]))+u[7]}return e+="+"+JSON.stringify(String(t)),e}function u(t,e=!0,i=!0){return('let r={"REPEAT":{}},i=0,t=[];return '+(e?"(":"")+'""'+o(i?t.replace(//gs,""):t)).replace(/(?