This uses the lovely acorn and magic-string libraries to find all of your long property accesses, like document.createDocumentFragment()
, create smaller variables with the property names hoisted to the top of the scope, and replaces them with something like document[a]()
. At the top of the scope, you'll end up with var a='createDocumentFragment';
, but anywhere in that scope, you'll have a much shorter reference.
I don't know if this is a good idea. It may have performance implications that I haven't run across. It may already be implemented in the closure compiler or something like it. All I know is that it can save ~15% on a big funky code base.
This uses acorn to get an AST of the source and tries to find all of the top-level scopes (functions). This works out very well for IIFE and UMD libraries. I have not tested it on anything else, but I can't really think of a good reason to apply this until everything is already bundled and uglified.
After the top-level scopes are gathered, this uses an acorn simple walker to find all of the identifiers, declarations, and member expressions to record what short names are already used and stats on which members are referenced the most. It then walks through the members and gets a savings estimate on each one by factoring in the size of the new access (.foozle
becomes [aa]
), the number of times it would apply, and the cost of the hoist (var aa='foozle';
). I used the doubled identifier because most minified code has a fair number of single char identifiers used already. This will try single char identifiers first. Anything with a savings of more than 3 chars is paired up with a new identifier, and the AST is traversed again replacing member accesses that have a new identifier with the bracketed form. Finally, all of the new hoisted names are added just inside the body of the scope, after 'use strict';
if it's there.
CLI:
# stdin and stdout
cat someSrc.min.js | hoist-props > someSrc.min.min.js
# in and out files - --input and --output also work
hoist-props -i someSrc.min.js -o someSrc.min.min.js
# in and out files and an out map - --map also works
hoist-props -i someSrc.min.js -o someSrc.min.min.js -m
# mix and match as desired
API:
const hoist = require('hoist-props');
const result = host(sourceString);
console.log(result.code); // the code
console.log(result.map); // the sourcemap
Here's the svelte TodoMVC minified bundle before:
!function(){"use strict";function e(e,t,n){("items"in t&&"object"==typeof e.items||e.items!==n.items)&&(e.numActive=t.numActive=l.computed.numActive(e.items)),("items"in t&&"object"==typeof e.items||e.items!==n.items)&&(e.numCompleted=t.numCompleted=l.computed.numCompleted(e.items))}function t(e,t,a){var r=document.createElement("header");r.className="header";var d=document.createElement("h1"),o=document.createTextNode("todos");d.appendChild(o),r.appendChild(d);var i=document.createTextNode("\n\t");r.appendChild(i);var c=document.createElement("input");t.refs.newTodo=c,c.className="new-todo";var m=l.events.enter.call(t,c,function(e){t.newTodo(this.value)});c.placeholder="What needs to be done?",c.autofocus=!0,r.appendChild(c),a.appendChild(r);var u=document.createTextNode("\n\n");a.appendChild(u);var s=document.createComment("#if items.length > 0");a.appendChild(s);var p=e.items.length>0?n(e,t,a,s):null;return{update:function(e,r){r.items.length>0?p?p.update(e,r):p=n(r,t,a,s):p&&(p.teardown(!0),p=null)},teardown:function(e){e&&r.parentNode.removeChild(r),o.parentNode.removeChild(o),i.parentNode.removeChild(i),t.refs.newTodo===c&&(t.refs.newTodo=null),m.teardown(),u.parentNode.removeChild(u),p&&p.teardown(e),e&&s.parentNode.removeChild(s)}}}function n(e,t,n,d){function o(e){t.toggleAll(this.checked)}var i=document.createElement("section");i.className="main";var l=document.createElement("input");l.className="toggle-all",l.type="checkbox",l.addEventListener("change",o,!1),l.checked=e.numCompleted===e.items.length,i.appendChild(l);var c=document.createTextNode("\n\t\t");i.appendChild(c);var m=document.createElement("label");m.htmlFor="toggle-all";var u=document.createTextNode("Mark all as complete");m.appendChild(u),i.appendChild(m);var s=document.createTextNode("\n\n\t\t");i.appendChild(s);var p=document.createElement("ul");p.className="todo-list";var v=document.createComment("#each items");p.appendChild(v);for(var h=e.items,f=document.createDocumentFragment(),C=[],N=0;N<h.length;N+=1)C[N]=r(e,h,h[N],N,t,f);v.parentNode.insertBefore(f,v),i.appendChild(p);var g=document.createTextNode("\n\n\t\t");i.appendChild(g);var _=document.createElement("footer");_.className="footer";var w=document.createElement("span");w.className="todo-count";var E=document.createElement("strong"),x=document.createTextNode(e.numActive);E.appendChild(x),w.appendChild(E);var T=document.createTextNode(" ");w.appendChild(T);var k=document.createTextNode(1===e.numActive?"item":"items");w.appendChild(k);var b=document.createTextNode(" left");w.appendChild(b),_.appendChild(w);var B=document.createTextNode("\n\n\t\t\t");_.appendChild(B);var L=document.createElement("ul");L.className="filters";var y=document.createElement("li"),F=document.createElement("a");F.className="all"===e.currentFilter?"selected":"",F.href="#/";var A=document.createTextNode("All");F.appendChild(A),y.appendChild(F),L.appendChild(y);var O=document.createTextNode("\n\t\t\t\t");L.appendChild(O);var j=document.createElement("li"),S=document.createElement("a");S.className="active"===e.currentFilter?"selected":"",S.href="#/active";var I=document.createTextNode("Active");S.appendChild(I),j.appendChild(S),L.appendChild(j);var J=document.createTextNode("\n\t\t\t\t");L.appendChild(J);var q=document.createElement("li"),D=document.createElement("a");D.className="completed"===e.currentFilter?"selected":"",D.href="#/completed";var H=document.createTextNode("Completed");D.appendChild(H),q.appendChild(D),L.appendChild(q),_.appendChild(L);var M=document.createTextNode("\n\n\t\t\t");_.appendChild(M);var W=document.createComment("#if numCompleted");_.appendChild(W);var z=e.numCompleted?a(e,t,_,W):null;return i.appendChild(_),d.parentNode.insertBefore(i,d),{update:function(e,n){l.checked=n.numCompleted===n.items.length;for(var d=n.items,o=0;o<d.length;o+=1)C[o]?C[o].update(e,n,d,d[o],o):C[o]=r(n,d,d[o],o,t,f);for(var o=d.length;o<C.length;o+=1)C[o].teardown(!0);v.parentNode.insertBefore(f,v),C.length=d.length,x.data=n.numActive,k.data=1===n.numActive?"item":"items",F.className="all"===n.currentFilter?"selected":"",S.className="active"===n.currentFilter?"selected":"",D.className="completed"===n.currentFilter?"selected":"",n.numCompleted?z?z.update(e,n):z=a(n,t,_,W):z&&(z.teardown(!0),z=null)},teardown:function(e){e&&i.parentNode.removeChild(i),l.removeEventListener("change",o,!1),c.parentNode.removeChild(c),u.parentNode.removeChild(u),s.parentNode.removeChild(s);for(var t=0;t<C.length;t+=1)C[t].teardown(e);e&&v.parentNode.removeChild(v),g.parentNode.removeChild(g),T.parentNode.removeChild(T),b.parentNode.removeChild(b),B.parentNode.removeChild(B),A.parentNode.removeChild(A),O.parentNode.removeChild(O),I.parentNode.removeChild(I),J.parentNode.removeChild(J),H.parentNode.removeChild(H),M.parentNode.removeChild(M),z&&z.teardown(e)}}}function a(e,t,n,a){function r(e){t.clearCompleted()}var d=document.createElement("button");d.className="clear-completed",d.addEventListener("click",r,!1);var o=document.createTextNode("Clear completed");return d.appendChild(o),a.parentNode.insertBefore(d,a),{update:function(e,t){},teardown:function(e){d.removeEventListener("click",r,!1),e&&d.parentNode.removeChild(d),o.parentNode.removeChild(o)}}}function r(e,t,n,a,r,o){var i=document.createComment("#if filter(item, currentFilter)");o.appendChild(i);var c=l.helpers.filter(n,e.currentFilter)?d(e,t,n,a,r,o,i):null;return{update:function(e,t,n,a,m){var a=n[m];l.helpers.filter(a,t.currentFilter)?c?c.update(e,t,n,a,m):c=d(t,n,a,m,r,o,i):c&&(c.teardown(!0),c=null)},teardown:function(e){c&&c.teardown(e),e&&i.parentNode.removeChild(i)}}}function d(e,t,n,a,r,d,i){function l(){v=!0;var e=this.__svelte.eachBlock_0_value,t=this.__svelte.index;e[t].completed=p.checked,r.set({items:r.get("items")}),v=!1}function c(e){var t=this.__svelte.eachBlock_0_value,n=this.__svelte.index;t[n];r.edit(n)}function m(e){var t=this.__svelte.eachBlock_0_value,n=this.__svelte.index;t[n];r.remove(n)}var u=document.createElement("li");u.className=""+(n.completed?"completed":"")+" "+(e.editing===a?"editing":"");var s=document.createElement("div");s.className="view";var p=document.createElement("input");p.className="toggle",p.type="checkbox";var v=!1;p.addEventListener("change",l,!1),p.checked=n.completed,p.__svelte={eachBlock_0_value:t,index:a},s.appendChild(p);var h=document.createTextNode("\n\t\t\t\t\t\t\t");s.appendChild(h);var f=document.createElement("label");f.addEventListener("dblclick",c,!1),f.__svelte={eachBlock_0_value:t,index:a};var C=document.createTextNode(n.description);f.appendChild(C),s.appendChild(f);var N=document.createTextNode("\n\t\t\t\t\t\t\t");s.appendChild(N);var g=document.createElement("button");g.addEventListener("click",m,!1),g.className="destroy",g.__svelte={eachBlock_0_value:t,index:a},s.appendChild(g),u.appendChild(s);var _=document.createTextNode("\n\n\t\t\t\t\t\t");u.appendChild(_);var w=document.createComment("#if editing === index");u.appendChild(w);var E=e.editing===a?o(e,t,n,a,r,u,w):null;return i.parentNode.insertBefore(u,i),{update:function(e,t,n,a,d){u.className=""+(a.completed?"completed":"")+" "+(t.editing===d?"editing":""),v||(p.checked=a.completed),p.__svelte.eachBlock_0_value=n,p.__svelte.index=d,f.__svelte.eachBlock_0_value=n,f.__svelte.index=d,C.data=a.description,g.__svelte.eachBlock_0_value=n,g.__svelte.index=d,t.editing===d?E?E.update(e,t,n,a,d):E=o(t,n,a,d,r,u,w):E&&(E.teardown(!0),E=null)},teardown:function(e){e&&u.parentNode.removeChild(u),p.removeEventListener("change",l,!1),h.parentNode.removeChild(h),f.removeEventListener("dblclick",c,!1),N.parentNode.removeChild(N),g.removeEventListener("click",m,!1),_.parentNode.removeChild(_),E&&E.teardown(e)}}}function o(e,t,n,a,r,d,o){function i(e){r.submit(this.value)}var c=document.createElement("input");c.value=n.description,c.id="edit",c.className="edit";var m=l.events.enter.call(r,c,function(e){r.blur(this)});c.addEventListener("blur",i,!1);var u=l.events.escape.call(r,c,function(e){r.cancel()});return c.autofocus=!0,o.parentNode.insertBefore(c,o),c.focus(),{update:function(e,t,n,a,r){c.value=a.description},teardown:function(e){m.teardown(),c.removeEventListener("blur",i,!1),u.teardown(),e&&c.parentNode.removeChild(c)}}}function i(n){function a(e,t,n){for(var a in e)if(a in t){var d=t[a],o=n[a];if(d!==o||"object"==typeof d){var i=e[a];if(i)for(var l=0;l<i.length;l+=1){var c=i[l];c.__calling||(c.__calling=!0,c.call(r,d,o),c.__calling=!1)}}}}var r=this;this.refs={};var d=Object.assign(l.data(),n.data);e(d,d,{});var o={immediate:Object.create(null),deferred:Object.create(null)},i=Object.create(null);this.fire=function(e,t){var n=this,a=e in i&&i[e].slice();if(a)for(var r=0;r<a.length;r+=1)a[r].call(n,t)},this.get=function(e){return d[e]},this.set=function(t){var n=d;d=Object.assign({},n,t),e(d,t,n),a(o.immediate,t,n),c&&c.update(t,d),a(o.deferred,t,n)},this.observe=function(e,t,n){void 0===n&&(n={});var a=n.defer?o.deferred:o.immediate;return(a[e]||(a[e]=[])).push(t),n.init!==!1&&(t.__calling=!0,t.call(r,d[e]),t.__calling=!1),{cancel:function(){var n=a[e].indexOf(t);~n&&a[e].splice(n,1)}}},this.on=function(e,t){var n=i[e]||(i[e]=[]);return n.push(t),{cancel:function(){var e=n.indexOf(t);~e&&n.splice(e,1)}}},this.teardown=function(e){this.fire("teardown"),c.teardown(e!==!1),c=null,d={}};var c=t(d,this,n.target);n.parent?n.parent.__renderHooks.push({fn:l.onrender,context:this}):l.onrender.call(this)}var l=function(){function e(e){return function(t,n){function a(t){t.which===e&&n.call(this,t)}return t.addEventListener("keydown",a,!1),{teardown:function(){t.removeEventListener("keydown",a,!1)}}}}var t,n=13,a=27;try{t=JSON.parse(localStorage.getItem("todos-svelte"))||[]}catch(e){t=[]}return{data:function(){return{currentFilter:"all",items:t}},computed:{numActive:function(e){return e.filter(function(e){return!e.completed}).length},numCompleted:function(e){return e.filter(function(e){return e.completed}).length}},helpers:{filter:function(e,t){return"all"===t||("completed"===t?e.completed:"active"===t?!e.completed:void 0)}},onrender:function(){var e=this,t=function(){var t="all";"#/active"===window.location.hash?t="active":"#/completed"===window.location.hash&&(t="completed"),e.set({currentFilter:t})};window.addEventListener("hashchange",t),t(),this.observe("items",function(e){try{localStorage.setItem("todos-svelte",JSON.stringify(e))}catch(e){}})},methods:{blur:function(e){e.blur()},cancel:function(){this.set({editing:null})},clearCompleted:function(){var e=this.get("items").filter(function(e){return!e.completed});this.set({items:e})},edit:function(e){this.set({editing:e})},newTodo:function(e){var t=this.get("items");t.push({description:e,completed:!1}),this.set({items:t}),this.refs.newTodo.value=""},remove:function(e){var t=this.get("items");t.splice(e,1),this.set({items:t})},submit:function(e){var t=this.get("items"),n=this.get("editing");t[n].description=e,this.set({items:t,editing:null})},toggleAll:function(e){var t=this.get("items");t.forEach(function(t){t.completed=e}),this.set({items:t})}},events:{enter:e(n),escape:e(a)}}}();i.prototype=l.methods,window.todomvc=new i({target:document.querySelector(".todoapp")})}();
//# sourceMappingURL=bundle.js.map
...and after:
!function(){"use strict";var G='appendChild';var K='createTextNode';var P='parentNode';var Q='createElement';var R='removeChild';var U='className';var V='removeEventListener';var X='addEventListener';var Y='currentFilter';var Z='__svelte';var $='eachBlock_0_value';var aa='teardown';var ab='completed';var ac='numCompleted';var ad='insertBefore';var ae='length';var af='createComment';var ag='numActive';var ah='description';var ai='items';var aj='__calling';var ak='checked';var al='newTodo';function e(e,t,n){("items"in t&&"object"==typeof e[ai]||e[ai]!==n[ai])&&(e[ag]=t[ag]=l.computed[ag](e[ai])),("items"in t&&"object"==typeof e[ai]||e[ai]!==n[ai])&&(e[ac]=t[ac]=l.computed[ac](e[ai]))}function t(e,t,a){var r=document[Q]("header");r[U]="header";var d=document[Q]("h1"),o=document[K]("todos");d[G](o),r[G](d);var i=document[K]("\n\t");r[G](i);var c=document[Q]("input");t.refs[al]=c,c[U]="new-todo";var m=l.events.enter.call(t,c,function(e){t[al](this.value)});c.placeholder="What needs to be done?",c.autofocus=!0,r[G](c),a[G](r);var u=document[K]("\n\n");a[G](u);var s=document[af]("#if items.length > 0");a[G](s);var p=e[ai][ae]>0?n(e,t,a,s):null;return{update:function(e,r){r[ai][ae]>0?p?p.update(e,r):p=n(r,t,a,s):p&&(p[aa](!0),p=null)},teardown:function(e){e&&r[P][R](r),o[P][R](o),i[P][R](i),t.refs[al]===c&&(t.refs[al]=null),m[aa](),u[P][R](u),p&&p[aa](e),e&&s[P][R](s)}}}function n(e,t,n,d){function o(e){t.toggleAll(this[ak])}var i=document[Q]("section");i[U]="main";var l=document[Q]("input");l[U]="toggle-all",l.type="checkbox",l[X]("change",o,!1),l[ak]=e[ac]===e[ai][ae],i[G](l);var c=document[K]("\n\t\t");i[G](c);var m=document[Q]("label");m.htmlFor="toggle-all";var u=document[K]("Mark all as complete");m[G](u),i[G](m);var s=document[K]("\n\n\t\t");i[G](s);var p=document[Q]("ul");p[U]="todo-list";var v=document[af]("#each items");p[G](v);for(var h=e[ai],f=document.createDocumentFragment(),C=[],N=0;N<h[ae];N+=1)C[N]=r(e,h,h[N],N,t,f);v[P][ad](f,v),i[G](p);var g=document[K]("\n\n\t\t");i[G](g);var _=document[Q]("footer");_[U]="footer";var w=document[Q]("span");w[U]="todo-count";var E=document[Q]("strong"),x=document[K](e[ag]);E[G](x),w[G](E);var T=document[K](" ");w[G](T);var k=document[K](1===e[ag]?"item":"items");w[G](k);var b=document[K](" left");w[G](b),_[G](w);var B=document[K]("\n\n\t\t\t");_[G](B);var L=document[Q]("ul");L[U]="filters";var y=document[Q]("li"),F=document[Q]("a");F[U]="all"===e[Y]?"selected":"",F.href="#/";var A=document[K]("All");F[G](A),y[G](F),L[G](y);var O=document[K]("\n\t\t\t\t");L[G](O);var j=document[Q]("li"),S=document[Q]("a");S[U]="active"===e[Y]?"selected":"",S.href="#/active";var I=document[K]("Active");S[G](I),j[G](S),L[G](j);var J=document[K]("\n\t\t\t\t");L[G](J);var q=document[Q]("li"),D=document[Q]("a");D[U]="completed"===e[Y]?"selected":"",D.href="#/completed";var H=document[K]("Completed");D[G](H),q[G](D),L[G](q),_[G](L);var M=document[K]("\n\n\t\t\t");_[G](M);var W=document[af]("#if numCompleted");_[G](W);var z=e[ac]?a(e,t,_,W):null;return i[G](_),d[P][ad](i,d),{update:function(e,n){l[ak]=n[ac]===n[ai][ae];for(var d=n[ai],o=0;o<d[ae];o+=1)C[o]?C[o].update(e,n,d,d[o],o):C[o]=r(n,d,d[o],o,t,f);for(var o=d[ae];o<C[ae];o+=1)C[o][aa](!0);v[P][ad](f,v),C[ae]=d[ae],x.data=n[ag],k.data=1===n[ag]?"item":"items",F[U]="all"===n[Y]?"selected":"",S[U]="active"===n[Y]?"selected":"",D[U]="completed"===n[Y]?"selected":"",n[ac]?z?z.update(e,n):z=a(n,t,_,W):z&&(z[aa](!0),z=null)},teardown:function(e){e&&i[P][R](i),l[V]("change",o,!1),c[P][R](c),u[P][R](u),s[P][R](s);for(var t=0;t<C[ae];t+=1)C[t][aa](e);e&&v[P][R](v),g[P][R](g),T[P][R](T),b[P][R](b),B[P][R](B),A[P][R](A),O[P][R](O),I[P][R](I),J[P][R](J),H[P][R](H),M[P][R](M),z&&z[aa](e)}}}function a(e,t,n,a){function r(e){t.clearCompleted()}var d=document[Q]("button");d[U]="clear-completed",d[X]("click",r,!1);var o=document[K]("Clear completed");return d[G](o),a[P][ad](d,a),{update:function(e,t){},teardown:function(e){d[V]("click",r,!1),e&&d[P][R](d),o[P][R](o)}}}function r(e,t,n,a,r,o){var i=document[af]("#if filter(item, currentFilter)");o[G](i);var c=l.helpers.filter(n,e[Y])?d(e,t,n,a,r,o,i):null;return{update:function(e,t,n,a,m){var a=n[m];l.helpers.filter(a,t[Y])?c?c.update(e,t,n,a,m):c=d(t,n,a,m,r,o,i):c&&(c[aa](!0),c=null)},teardown:function(e){c&&c[aa](e),e&&i[P][R](i)}}}function d(e,t,n,a,r,d,i){function l(){v=!0;var e=this[Z][$],t=this[Z].index;e[t][ab]=p[ak],r.set({items:r.get("items")}),v=!1}function c(e){var t=this[Z][$],n=this[Z].index;t[n];r.edit(n)}function m(e){var t=this[Z][$],n=this[Z].index;t[n];r.remove(n)}var u=document[Q]("li");u[U]=""+(n[ab]?"completed":"")+" "+(e.editing===a?"editing":"");var s=document[Q]("div");s[U]="view";var p=document[Q]("input");p[U]="toggle",p.type="checkbox";var v=!1;p[X]("change",l,!1),p[ak]=n[ab],p[Z]={eachBlock_0_value:t,index:a},s[G](p);var h=document[K]("\n\t\t\t\t\t\t\t");s[G](h);var f=document[Q]("label");f[X]("dblclick",c,!1),f[Z]={eachBlock_0_value:t,index:a};var C=document[K](n[ah]);f[G](C),s[G](f);var N=document[K]("\n\t\t\t\t\t\t\t");s[G](N);var g=document[Q]("button");g[X]("click",m,!1),g[U]="destroy",g[Z]={eachBlock_0_value:t,index:a},s[G](g),u[G](s);var _=document[K]("\n\n\t\t\t\t\t\t");u[G](_);var w=document[af]("#if editing === index");u[G](w);var E=e.editing===a?o(e,t,n,a,r,u,w):null;return i[P][ad](u,i),{update:function(e,t,n,a,d){u[U]=""+(a[ab]?"completed":"")+" "+(t.editing===d?"editing":""),v||(p[ak]=a[ab]),p[Z][$]=n,p[Z].index=d,f[Z][$]=n,f[Z].index=d,C.data=a[ah],g[Z][$]=n,g[Z].index=d,t.editing===d?E?E.update(e,t,n,a,d):E=o(t,n,a,d,r,u,w):E&&(E[aa](!0),E=null)},teardown:function(e){e&&u[P][R](u),p[V]("change",l,!1),h[P][R](h),f[V]("dblclick",c,!1),N[P][R](N),g[V]("click",m,!1),_[P][R](_),E&&E[aa](e)}}}function o(e,t,n,a,r,d,o){function i(e){r.submit(this.value)}var c=document[Q]("input");c.value=n[ah],c.id="edit",c[U]="edit";var m=l.events.enter.call(r,c,function(e){r.blur(this)});c[X]("blur",i,!1);var u=l.events.escape.call(r,c,function(e){r.cancel()});return c.autofocus=!0,o[P][ad](c,o),c.focus(),{update:function(e,t,n,a,r){c.value=a[ah]},teardown:function(e){m[aa](),c[V]("blur",i,!1),u[aa](),e&&c[P][R](c)}}}function i(n){function a(e,t,n){for(var a in e)if(a in t){var d=t[a],o=n[a];if(d!==o||"object"==typeof d){var i=e[a];if(i)for(var l=0;l<i[ae];l+=1){var c=i[l];c[aj]||(c[aj]=!0,c.call(r,d,o),c[aj]=!1)}}}}var r=this;this.refs={};var d=Object.assign(l.data(),n.data);e(d,d,{});var o={immediate:Object.create(null),deferred:Object.create(null)},i=Object.create(null);this.fire=function(e,t){var n=this,a=e in i&&i[e].slice();if(a)for(var r=0;r<a[ae];r+=1)a[r].call(n,t)},this.get=function(e){return d[e]},this.set=function(t){var n=d;d=Object.assign({},n,t),e(d,t,n),a(o.immediate,t,n),c&&c.update(t,d),a(o.deferred,t,n)},this.observe=function(e,t,n){void 0===n&&(n={});var a=n.defer?o.deferred:o.immediate;return(a[e]||(a[e]=[])).push(t),n.init!==!1&&(t[aj]=!0,t.call(r,d[e]),t[aj]=!1),{cancel:function(){var n=a[e].indexOf(t);~n&&a[e].splice(n,1)}}},this.on=function(e,t){var n=i[e]||(i[e]=[]);return n.push(t),{cancel:function(){var e=n.indexOf(t);~e&&n.splice(e,1)}}},this[aa]=function(e){this.fire("teardown"),c[aa](e!==!1),c=null,d={}};var c=t(d,this,n.target);n.parent?n.parent.__renderHooks.push({fn:l.onrender,context:this}):l.onrender.call(this)}var l=function(){function e(e){return function(t,n){function a(t){t.which===e&&n.call(this,t)}return t[X]("keydown",a,!1),{teardown:function(){t[V]("keydown",a,!1)}}}}var t,n=13,a=27;try{t=JSON.parse(localStorage.getItem("todos-svelte"))||[]}catch(e){t=[]}return{data:function(){return{currentFilter:"all",items:t}},computed:{numActive:function(e){return e.filter(function(e){return!e[ab]})[ae]},numCompleted:function(e){return e.filter(function(e){return e[ab]})[ae]}},helpers:{filter:function(e,t){return"all"===t||("completed"===t?e[ab]:"active"===t?!e[ab]:void 0)}},onrender:function(){var e=this,t=function(){var t="all";"#/active"===window.location.hash?t="active":"#/completed"===window.location.hash&&(t="completed"),e.set({currentFilter:t})};window[X]("hashchange",t),t(),this.observe("items",function(e){try{localStorage.setItem("todos-svelte",JSON.stringify(e))}catch(e){}})},methods:{blur:function(e){e.blur()},cancel:function(){this.set({editing:null})},clearCompleted:function(){var e=this.get("items").filter(function(e){return!e[ab]});this.set({items:e})},edit:function(e){this.set({editing:e})},newTodo:function(e){var t=this.get("items");t.push({description:e,completed:!1}),this.set({items:t}),this.refs[al].value=""},remove:function(e){var t=this.get("items");t.splice(e,1),this.set({items:t})},submit:function(e){var t=this.get("items"),n=this.get("editing");t[n][ah]=e,this.set({items:t,editing:null})},toggleAll:function(e){var t=this.get("items");t.forEach(function(t){t[ab]=e}),this.set({items:t})}},events:{enter:e(n),escape:e(a)}}}();i.prototype=l.methods,window.todomvc=new i({target:document.querySelector(".todoapp")})}();
//# sourceMappingURL=bundle.js.map
The original is 11214b and the adjusted is 9003b, which is a savings of 2211b or roughly 20%.
MIT, WTFPL - go nuts