From c744b834802a975d9a6953997d483dffeb0b522f Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 29 Oct 2024 17:16:22 +0100 Subject: [PATCH] Put knockout bind context Proxy outside bindingFunction --- .../build/output/knockout-latest.debug.js | 18 ++--- .../knockout/build/output/knockout-latest.js | 69 +++++++++---------- .../knockout/src/binding/bindingProvider.js | 18 ++--- 3 files changed, 52 insertions(+), 53 deletions(-) diff --git a/vendors/knockout/build/output/knockout-latest.debug.js b/vendors/knockout/build/output/knockout-latest.debug.js index 0a8a199e3..c568dbbcd 100644 --- a/vendors/knockout/build/output/knockout-latest.debug.js +++ b/vendors/knockout/build/output/knockout-latest.debug.js @@ -1636,17 +1636,17 @@ ko.bindingProvider = new class // Build the source for a function that evaluates "expression" // Use one "with" that has one secure scope handling Proxy // Deprecated: with is no longer recommended - var rewrittenBindings = ko.expressionRewriting.preProcessBindings(bindingsString), - functionBody = "$context = new Proxy(\ - $context,\ - {\ - has: () => true,\ - get: (target, key) => target[key] || target['$data'][key]\ - }\ - );with($context){return{" + rewrittenBindings + "}}"; - bindingFunction = new Function("$context", functionBody); + bindingFunction = new Function("$context", + "with($context){return{" + ko.expressionRewriting.preProcessBindings(bindingsString) + "}}"); bindingCache.set(cacheKey, bindingFunction); } + bindingContext = new Proxy( + bindingContext, + { + has: () => true, + get: (target, key) => target[key] || target['$data'][key] + } + ); return bindingFunction(bindingContext); } catch (ex) { ex.message = "Unable to parse bindings.\nBindings value: " + bindingsString diff --git a/vendors/knockout/build/output/knockout-latest.js b/vendors/knockout/build/output/knockout-latest.js index cec856c34..4d55a6ba7 100644 --- a/vendors/knockout/build/output/knockout-latest.js +++ b/vendors/knockout/build/output/knockout-latest.js @@ -31,38 +31,37 @@ a.value=b):(c.g.l.set(a,c.i.options.Wa,b),a.__ko__hasDomDataOptionValue__=!0,a.v l[k-1].match(b))&&!d[p[0]]&&(e=e.slice(e.indexOf(m)+1),l=e.match(a),k=-1,m="/"):40===p||123===p||91===p?++h:41===p||125===p||93===p?--h:n||f.length||34!==p&&39!==p||(m=m.slice(1,-1));f.push(m)}if(0$data");return g.join(",")},cc:(e,g)=>-1l.key==g),Ga:(e,g,l,f,h,k)=>{g&&c.W(g)?!c.vb(g)||k&&g.L()===h||g(h):(console.log(`"${f}" should contain observable in ${e.outerHTML.replace(/>.+/,">")}`),l.get("$data")[f]= h)}}})();(()=>{function a(f){return 8==f.nodeType&&e.test(f.nodeValue)}function b(f){return 8==f.nodeType&&g.test(f.nodeValue)}function d(f,h){for(var k=f,m=1,p=[];k=k.nextSibling;){if(b(k)&&(c.g.l.set(k,l,!0),!--m))return p;p.push(k);a(k)&&++m}if(!h)throw Error("Cannot find closing comment tag to match: "+f.nodeValue);return null}var e=/^\s*ko(?:\s+([\s\S]+))?\s*$/,g=/^\s*\/ko\s*$/,l="__ko_matchedEndComment__";c.m={aa:{},childNodes:f=>a(f)?d(f):f.childNodes,ja:f=>{a(f)?(f=d(f))&&[...f].forEach(h=> c.removeNode(h)):c.g.Qa(f)},pa:(f,h)=>{a(f)?(c.m.ja(f),f.after(...h)):c.g.pa(f,h)},prepend:(f,h)=>{a(f)?f.nextSibling.before(h):f.prepend(h)},Ub:(f,h,k)=>{k?k.after(h):c.m.prepend(f,h)},firstChild:f=>{if(a(f))return f=f.nextSibling,!f||b(f)?null:f;let h=f.firstChild;if(h&&b(h))throw Error("Found invalid end comment, as the first child of "+f);return h},nextSibling:f=>{if(a(f)){var h=d(f,void 0);f=h?(h.length?h[h.length-1]:f).nextSibling:null}if((h=f.nextSibling)&&b(h)){if(b(h)&&!c.g.l.get(h,l))throw Error("Found end comment without a matching opening comment, as child of "+ -f);return null}return h},Qb:a,ac:f=>(f=f.nodeValue.match(e))?f[1]:null}})();const S=new Map;c.ob=new class{Xb(a){switch(a.nodeType){case 1:return null!=a.getAttribute("data-bind");case 8:return c.m.Qb(a)}return!1}Ob(a,b){a:{switch(a.nodeType){case 1:a=a.getAttribute("data-bind");break a;case 8:a=c.m.ac(a);break a}a=null}if(a)try{let e=S.get(a);if(!e){var d="$context = new Proxy( $context, { has: () => true, get: (target, key) => target[key] || target['$data'][key] } );with($context){return{"+ -c.la.Yb(a)+"}}";e=new Function("$context",d);S.set(a,e)}return e(b)}catch(e){throw e.message="Unable to parse bindings.\nBindings value: "+a+"\nMessage: "+e.message,e;}return null}};const G=Symbol("_subscribable"),H=Symbol("_ancestorBindingInfo"),T=Symbol("_dataDependency"),U={},I=c.g.l.Z();c.i={};c.ba=class{constructor(a,b,d,e){var g=this,l=a===U,f=l?void 0:a,h="function"==typeof f&&!c.W(f),k=e?.dataDependency;a=()=>{var p=h?f():f;p=c.g.h(p);b?(c.g.extend(g,b),H in b&&(g[H]=b[H])):g.$root=p;g[G]= -m;l?p=g.$data:g.$data=p;d?.(g,b,p);if(b?.[G]&&!c.u.o().Sa(b[G]))b[G]();k&&(g[T]=k);return g.$data};if(e?.exportDependencies)a();else{var m=c.xb(a);m.L();m.isActive()?m.ka=null:g[G]=void 0}}createChildContext(a,b){return new c.ba(a,this,(d,e)=>{d.$parent=e.$data;b.extend?.(d)},b)}extend(a,b){return new c.ba(U,this,d=>c.g.extend(d,"function"==typeof a?a(d):a),b)}};const V=a=>{a=c.g.l.get(a,I);var b=a?.D;b&&(a.D=null,b.wb())};class la{constructor(a,b,d){this.H=a;this.da=b;this.ta=new Set;this.F=!1;b.D|| -c.g.N.addDisposeCallback(a,V);d?.D&&(d.D.ta.add(a),this.za=d)}wb(){this.za?.D?.Mb(this.H)}Mb(a){this.ta.delete(a);this.ta.size||this.rb?.()}rb(){this.F=!0;this.da.D&&!this.ta.size&&(this.da.D=null,c.g.N.Ya(this.H,V),c.j.notify(this.H,c.j.ca),this.wb())}}c.j={F:"childrenComplete",ca:"descendantsComplete",subscribe:(a,b,d,e,g)=>{var l=c.g.l.Ra(a,I,{});l.wa||(l.wa=new c.P);g?.notifyImmediately&&l.Va[b]&&c.u.I(d,e,[a]);return l.wa.subscribe(d,e,b)},notify:(a,b)=>{var d=c.g.l.get(a,I);if(d&&(d.Va[b]=!0, -d.wa?.B(a,b),b==c.j.F))if(d.D)d.D.rb();else if(void 0===d.D&&d.wa?.na(c.j.ca))throw Error("descendantsComplete event not supported for bindings on this node");},$a:(a,b)=>{var d=c.g.l.Ra(a,I,{});d.D||(d.D=new la(a,d,b[H]));return b[H]==d?b:b.extend(e=>{e[H]=d})}};const X=(a,b)=>{for(var d,e=c.m.firstChild(b);d=e;)e=c.m.nextSibling(d),W(a,d);c.j.notify(b,c.j.F)},W=(a,b)=>{var d=a;if(1===b.nodeType||c.ob.Xb(b))d=Y(b,null,a);d&&!b.matches?.("SCRIPT,TEXTAREA,TEMPLATE")&&X(d,b)},ma=a=>{var b=[],d={},e= -[],g=l=>{if(!d[l]){var f=c.i[l];f&&(f.after&&(e.push(l),f.after.forEach(h=>{if(a[h]){if(e.includes(h))throw Error("Cannot combine the following bindings, because they have a cyclic dependency: "+e.join(", "));g(h)}}),e.length--),b.push({key:l,ub:f}));d[l]=!0}};c.g.K(a,g);return b},Y=(a,b,d)=>{var e=c.g.l.Ra(a,I,{}),g=e.Hb;if(!b){if(g)throw Error("You cannot apply bindings multiple times to the same element.");e.Hb=!0}g||(e.context=d);e.Va||(e.Va={});if(b&&"function"!==typeof b)var l=b;else{var f= -c.o(()=>{if(l=b?b(d,a):c.ob.Ob(a,d))d[G]?.(),d[T]?.();return l},{s:a});l&&f.isActive()||(f=null)}var h=d,k;if(l){var m=f?n=>()=>f()[n]():n=>l[n],p={get:n=>l[n]&&m(n)(),has:n=>n in l};c.j.F in l&&c.j.subscribe(a,c.j.F,()=>{var n=l[c.j.F]();if(n){var q=c.m.childNodes(a);q.length&&n(q,c.dataFor(q[0]))}});c.j.ca in l&&(h=c.j.$a(a,d),c.j.subscribe(a,c.j.ca,()=>{var n=l[c.j.ca]();n&&c.m.firstChild(a)&&n(a)}));ma(l).forEach(n=>{var q=n.ub.init,r=n.ub.update,u=n.key;if(8===a.nodeType&&!c.m.aa[u])throw Error("The binding '"+ -u+"' cannot be used with comment nodes");try{"function"==typeof q&&c.u.I(()=>{var t=q(a,m(u),p,h.$data,h);if(t&&t.controlsDescendantBindings){if(void 0!==k)throw Error("Multiple bindings ("+k+" and "+u+") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");k=u}}),"function"==typeof r&&c.o(()=>r(a,m(u),p,h.$data,h),{s:a})}catch(t){throw t.message='Unable to process binding "'+u+": "+l[u]+'"\nMessage: '+t.message,t;}})}return void 0=== -k&&h};c.$b=a=>c.g.l.get(a,I)?.context;const O=a=>a&&a instanceof c.ba?a:new c.ba(a);c.applyBindingAccessorsToNode=(a,b,d)=>Y(a,b,O(d));c.mb=(a,b)=>{1!==b.nodeType&&8!==b.nodeType||X(O(a),b)};c.Ib=(a,b)=>W(O(a),b);c.dataFor=a=>([1,8].includes(a?.nodeType)&&c.$b(a))?.$data;c.U("bindingHandlers",c.i);(()=>{var a=Object.create(null),b=new Map;c.components={get:(l,f)=>{if(b.has(l))f(b.get(l));else{var h=a[l];h?h.subscribe(f):(h=a[l]=new c.P,h.subscribe(f),g(l,k=>{b.set(l,k);delete a[l];h.B(k)}))}},register:(l, -f)=>{if(!f)throw Error("Invalid configuration for "+l);if(d[l])throw Error("Component "+l+" is already registered");d[l]=f}};var d=Object.create(null),e=(l,f)=>{throw Error(`Component '${l}': ${f}`);},g=(l,f)=>{var h={},k=d[l]||{},m=k.template;k=k.viewModel;if(m){m.element||e(l,"Unknown template value: "+m);m=m.element;var p=J.getElementById(m);p||e(l,"Cannot find element with ID "+m);p.matches("TEMPLATE")||e(l,"Template Source Element not a