From 4a2c9fd83eaf8e05791c00bd0c9f4c163181e279 Mon Sep 17 00:00:00 2001 From: nickbrowne Date: Mon, 28 Oct 2024 14:01:03 +1100 Subject: [PATCH 1/2] Upgrade uglifier to 3.19.3 --- Cakefile | 21 ++++++++++++--------- package.json | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cakefile b/Cakefile index e875602..b3634cd 100644 --- a/Cakefile +++ b/Cakefile @@ -34,17 +34,20 @@ makeUgly = (infile, outfile) -> # Uglify compile the JS source = cat infile - {parser, uglify} = require 'uglify-js' + UglifyJS = require 'uglify-js' - opts = - defines: - WEB: ['name', 'true'] + unminifiedCode = fs.readFileSync(infile, "utf8") - ast = parser.parse source - ast = uglify.ast_lift_variables ast - ast = uglify.ast_mangle ast, opts - ast = uglify.ast_squeeze ast - code = uglify.gen_code ast + result = UglifyJS.minify(unminifiedCode, { + compress: { + global_defs: { + "WEB": true + }, + hoist_vars: true + } + }) + + code = result.code smaller = Math.round((1 - (code.length / source.length)) * 100) diff --git a/package.json b/package.json index 517f401..e0d95e5 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "optimist": ">= 0.2.4", "nodeunit": "0.9.0", "shelljs": "0.1.4", - "uglify-js": "1.3.5", + "uglify-js": "3.19.3", "websocket": "~1" }, "engine": "node >= 0.6", From 8ccdb5501bf2336fcdf2f67333814f26249dd138 Mon Sep 17 00:00:00 2001 From: nickbrowne Date: Mon, 28 Oct 2024 14:02:07 +1100 Subject: [PATCH 2/2] Recompile webclient after uglifier upgrade --- webclient/json.js | 2 +- webclient/share.js | 2 +- webclient/text-tp2.js | 2 +- webclient/text2.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webclient/json.js b/webclient/json.js index 785ad55..7e27e76 100644 --- a/webclient/json.js +++ b/webclient/json.js @@ -1 +1 @@ -(function(){var e,t,n,r,i,s,o,u,a,f=!0,l=[].slice,c=window.sharejs;typeof f!="undefined"&&f!==null?u=c.types.text:u=require("./text"),s={},s.name="json",s.create=function(){return null},s.invertComponent=function(e){var t={p:e.p};return e.si!==void 0&&(t.sd=e.si),e.sd!==void 0&&(t.si=e.sd),e.oi!==void 0&&(t.od=e.oi),e.od!==void 0&&(t.oi=e.od),e.li!==void 0&&(t.ld=e.li),e.ld!==void 0&&(t.li=e.ld),e.na!==void 0&&(t.na=-e.na),e.lm!==void 0&&(t.lm=e.p[e.p.length-1],t.p=e.p.slice(0,e.p.length-1).concat([e.lm])),t},s.invert=function(e){var t,n,r,i=e.slice().reverse(),o=[];for(n=0,r=i.length;n=t.length)return!1;if(r!==t[n])return!1}return!0},s.transformComponent=function(e,n,r,i){var o,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N;n=t(n),n.na!==void 0&&n.p.push(0),r.na!==void 0&&r.p.push(0),s.canOpAffectOp(r.p,n.p)&&(o=r.p.length-1),s.canOpAffectOp(n.p,r.p)&&(a=n.p.length-1),c=n.p.length,v=r.p.length,n.na!==void 0&&n.p.pop(),r.na!==void 0&&r.p.pop();if(r.na)return a!=null&&v>=c&&r.p[a]===n.p[a]&&(n.ld!==void 0?(d=t(r),d.p=d.p.slice(c),n.ld=s.apply(t(n.ld),[d])):n.od!==void 0&&(d=t(r),d.p=d.p.slice(c),n.od=s.apply(t(n.od),[d]))),s.append(e,n),e;a!=null&&v>c&&n.p[a]===r.p[a]&&(n.ld!==void 0?(d=t(r),d.p=d.p.slice(c),n.ld=s.apply(t(n.ld),[d])):n.od!==void 0&&(d=t(r),d.p=d.p.slice(c),n.od=s.apply(t(n.od),[d])));if(o!=null){f=c===v;if(r.na===void 0)if(r.si!==void 0||r.sd!==void 0){if(n.si!==void 0||n.sd!==void 0){if(!f)throw new Error("must be a string?");l=function(e){var t={p:e.p[e.p.length-1]};return e.si!=null?t.i=e.si:t.d=e.sd,t},E=l(n),S=l(r),b=[],u._tc(b,E,S,i);for(T=0,N=b.length;Tm&&n.p[o]--,h>g?n.p[o]++:h===g&&m>g&&(n.p[o]++,h===x&&n.lm++),x>m?n.lm--:x===m&&x>h&&n.lm--,x>g?n.lm++:x===g&&(g>m&&x>h||gh?n.lm++:x===m&&n.lm--)}else n.li!==void 0&&n.ld===void 0&&f?(h=r.p[o],x=r.lm,y=n.p[o],y>h&&n.p[o]--,y>x&&n.p[o]++):(h=r.p[o],x=r.lm,y=n.p[o],y===h?n.p[o]=x:(y>h&&n.p[o]--,y>x?n.p[o]++:y===x&&h>x&&n.p[o]++));else if(r.oi!==void 0&&r.od!==void 0){if(n.p[o]===r.p[o]){if(n.oi===void 0||!f)return e;if(i==="right")return e;n.od=r.oi}}else if(r.oi!==void 0){if(n.oi!==void 0&&n.p[o]===r.p[o]){if(i!=="left")return e;s.append(e,{p:n.p,od:r.oi})}}else if(r.od!==void 0&&n.p[o]===r.p[o]){if(!f)return e;if(n.oi===void 0)return e;delete n.od}}return s.append(e,n),e},typeof f!="undefined"&&f!==null?(c.types||(c.types={}),c._bt(s,s.transformComponent,s.checkValidOp,s.append),c.types.json=s):(module.exports=s,require("./helpers").bootstrapTransform(s,s.transformComponent,s.checkValidOp,s.append)),typeof f=="undefined"&&(s=require("./json")),typeof f!="undefined"&&f!==null&&(r=c.extendDoc,c.extendDoc=function(t,n){return e.prototype[t]=n,r(t,n)}),n=function(e){return e.length===1&&e[0].constructor===Array?e[0]:e},e=function(){function e(e,t){this.doc=e,this.path=t}return e.prototype.at=function(){var e=1<=arguments.length?l.call(arguments,0):[];return this.doc.at(this.path.concat(n(e)))},e.prototype.parent=function(){return this.path.length?this.doc.at(this.path.slice(0,this.path.length-1)):void 0},e.prototype.get=function(){return this.doc.getAt(this.path)},e.prototype.set=function(e,t){return this.doc.setAt(this.path,e,t)},e.prototype.insert=function(e,t,n){return this.doc.insertAt(this.path,e,t,n)},e.prototype.del=function(e,t,n){return this.doc.deleteTextAt(this.path,t,e,n)},e.prototype.remove=function(e){return this.doc.removeAt(this.path,e)},e.prototype.push=function(e,t){return this.insert(this.get().length,e,t)},e.prototype.move=function(e,t,n){return this.doc.moveAt(this.path,e,t,n)},e.prototype.add=function(e,t){return this.doc.addAt(this.path,e,t)},e.prototype.on=function(e,t){return this.doc.addListener(this.path,e,t)},e.prototype.removeListener=function(e){return this.doc.removeListener(e)},e.prototype.getLength=function(){return this.get().length},e.prototype.getText=function(){return this.get()},e}(),a=function(e,t){var n,r,i,s={data:e},o="data",u=s;for(r=0,i=t.length;r=e.length)return!1;if(n!==e[i])return!1}}return!0},transformComponent:function(t,e,i,n){var o,r,p,l,s,d,h,c,u,a,f,v,g,m;if(void 0!==(e=y(e)).na&&e.p.push(0),void 0!==i.na&&i.p.push(0),w.canOpAffectOp(i.p,e.p)&&(o=i.p.length-1),w.canOpAffectOp(e.p,i.p)&&(f=e.p.length-1),p=e.p.length,d=i.p.length,void 0!==e.na&&e.p.pop(),void 0!==i.na&&i.p.pop(),i.na)null!=f&&p<=d&&i.p[f]===e.p[f]&&(void 0!==e.ld?((a=y(i)).p=a.p.slice(p),e.ld=w.apply(y(e.ld),[a])):void 0!==e.od&&((a=y(i)).p=a.p.slice(p),e.od=w.apply(y(e.od),[a])));else if(null!=f&&p=0))throw new Error("position cannot be negative")},f=function(e){var t,n,r;for(n=0,r=e.length;n=n.p+n.d.length)o(e,{d:t.d,p:t.p-n.d.length});else if(t.p+t.d.length<=n.p)o(e,t);else{a={d:"",p:t.p},t.pn.p+n.d.length&&(a.d+=t.d.slice(n.p+n.d.length-t.p)),u=Math.max(t.p,n.p),s=Math.min(t.p+t.d.length,n.p+n.d.length),i=t.d.slice(u-t.p,s-t.p),l=n.d.slice(u-n.p,s-n.p);if(i!==l)throw new Error("Delete ops delete different text in the same region of the document");a.d!==""&&(a.p=b(a.p,n),o(e,a))}return e},p=function(e){return e.i!=null?{d:e.i,p:e.p}:{i:e.d,p:e.p}},g.invert=function(e){var t,n,r,i=e.slice().reverse(),s=[];for(n=0,r=i.length;n=t;w<=t?e++:e--)M.push(e);return M}.apply(this);if(a>=this.version)for(d=0,g=p.length;d=0)):i=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,r=e.error;if(r){this.type.invert?(l=this.type.invert(i),this.pendingOp&&(C=this._xf(this.pendingOp,l),this.pendingOp=C[0],l=C[1]),this._otApply(l,!0)):this.emit("error","Op apply failed ("+r+") and the op could not be reverted"),k=this.inflightCallbacks;for(v=0,y=k.length;v=n.p+n.d.length)r(t,{d:e.d,p:e.p-n.d.length});else if(e.p+e.d.length<=n.p)r(t,e);else{if(i={d:"",p:e.p},e.pn.p+n.d.length&&(i.d+=e.d.slice(n.p+n.d.length-e.p)),o=Math.max(e.p,n.p),s=Math.min(e.p+e.d.length,n.p+n.d.length),e.d.slice(o-e.p,s-e.p)!==n.d.slice(o-n.p,s-n.p))throw new Error("Delete ops delete different text in the same region of the document");""!==i.d&&(i.p=y(i.p,n),r(t,i))}return t},u=function(t){return null!=t.i?{d:t.i,p:t.p}:{i:t.d,p:t.p}},v.invert=function(t){for(var e,n=t.slice().reverse(),i=[],s=0,o=n.length;s=this.version)for(r=0,p=o.length;r0||typeof t.i=="number"&&t.i>0))throw new Error("Inserts must insert a string or a +ive number")}else{if(t.d===void 0)throw new Error("Operation component must define .i or .d");if(!(typeof t.d=="number"&&t.d>0))throw new Error("Deletes must be a +ive number")}else{if(typeof t!="number")throw new Error("Op components must be objects or numbers");if(!(t>0))throw new Error("Skip components must be a positive number");if(typeof n=="number")throw new Error("Adjacent skip components should be combined")}s.push(n=t)}return s};f._takeDoc=s=function(e,t,n,r){var i,s,o;if(t.index>=e.data.length)throw new Error("Operation goes past the end of the document");return i=e.data[t.index],s=typeof i=="string"?n!==void 0?i.slice(t.offset,t.offset+n):i.slice(t.offset):n===void 0||r?i-t.offset:Math.min(n,i-t.offset),o=s.length||s,(i.length||i)-t.offset>o?t.offset+=o:(t.index++,t.offset=0),s},f._appendDoc=t=function(e,t){var n;if(t===0||t==="")return;typeof t=="string"?(e.charLength+=t.length,e.totalLength+=t.length):e.totalLength+=t,n=e.data,n.length===0?n.push(t):typeof n[n.length-1]==typeof t?n[n.length-1]+=t:n.push(t)},f.apply=function(e,n){var r,i,o,u,a,c,h;if(e.totalLength===void 0||e.charLength===void 0||e.data.length===void 0)throw new Error("Snapshot is invalid");l(n),i=f.create(),u={index:0,offset:0};for(c=0,h=n.length;c0)o=s(e,u,a),t(i,o),a-=o.length||o}else if(r.i!==void 0)t(i,r.i);else if(r.d!==void 0){a=r.d;while(a>0)o=s(e,u,a),a-=o.length||o;t(i,r.d)}}return i},f._append=e=function(e,t){var n;if(t!==0&&t.i!==""&&t.i!==0&&t.d!==0)return e.length===0?e.push(t):(n=e[e.length-1],typeof t=="number"&&typeof n=="number"?e[e.length-1]+=t:t.i!==void 0&&n.i!=null&&typeof n.i==typeof t.i?n.i+=t.i:t.d!==void 0&&n.d!=null?n.d+=t.d:e.push(t))},i=function(e){var t=0,n=0,r=function(r,i){var s,o,u,a;return t===e.length?null:(u=e[t],typeof (o=u)=="number"||typeof (o=u.i)=="number"||(o=u.d)!==void 0?(r==null||o-n<=r||i&&u.i!==void 0?(s=o-n,++t,n=0):(n+=r,s=r),u.i!==void 0?{i:s}:u.d!==void 0?{d:s}:s):(r==null||u.i.length-n<=r||i?(a={i:u.i.slice(n)},++t,n=0):(a={i:u.i.slice(n,n+r)},n+=r),a))},i=function(){return e[t]};return[r,i]},r=function(e){return typeof e=="number"?e:typeof e.i=="string"?e.i.length:e.d||e.i},f.normalize=function(t){var n,r,i,s=[];for(r=0,i=t.length;r0){u=p(f,!0);if(u===null)throw new Error("The transformed op is invalid");if(u.d!==void 0)throw new Error("The transformed op deletes locally inserted characters - it cannot be purged of the insert.");typeof u=="number"?f-=u:e(c,u)}else while(f>0){u=p(f,!0);if(u===null)throw new Error("The op traverses more elements than the document has");e(c,u),u.i||(f-=r(u))}}while(a=p()){if(a.i===void 0)throw new Error("Remaining fragments in the op: "+a);e(c,a)}return c},f.transform=function(e,t,n){if(n!=="left"&&n!=="right")throw new Error("side ("+n+") should be 'left' or 'right'");return o(e,t,!0,n)},f.prune=function(e,t){return o(e,t,!1)},f.compose=function(t,n){var s,o,u,a,f,c,h,p,d,v;if(t===null||t===void 0)return n;l(t),l(n),f=[],v=i(t),c=v[0],h=v[1];for(p=0,d=n.length;p0){s=c(a);if(s===null)throw new Error("The op traverses more elements than the document has");e(f,s),a-=r(s)}}else if(u.i!==void 0)e(f,{i:u.i});else{a=u.d;while(a>0){s=c(a);if(s===null)throw new Error("The op traverses more elements than the document has");o=r(s),s.i!==void 0?e(f,{i:o}):e(f,{d:o}),a-=o}}}while(u=c()){if(u.i===void 0)throw new Error("Remaining fragments in op1: "+u);e(f,u)}return f},typeof u!="undefined"&&u!==null?a.types["text-tp2"]=f:module.exports=f,typeof u!="undefined"&&u!==null?f=a.types["text-tp2"]:f=require("./text-tp2"),s=f._takeDoc,e=f._append,n=function(t,n,r,i){var o,u=[];while((i===void 0||i>0)&&r.index0)o=s(this.snapshot,a,r,!0),typeof o=="string"?(e(u,{d:o.length}),r-=o.length):e(u,o);return n(u,this.snapshot,a),this.submitOp(u,i),u},_register:function(){return this.on("remoteop",function(e,t){var n,r,i,o,u,a=0,f={index:0,offset:0};for(o=0,u=e.length;o0)r=s(t,f,i),typeof r=="string"&&(a+=r.length),i-=r.length||r}else if(n.i!==void 0)typeof n.i=="string"&&(this.emit("insert",a,n.i),a+=n.i.length);else{i=n.d;while(i>0)r=s(t,f,i),typeof r=="string"&&this.emit("delete",a,r),i-=r.length||r}}})}}}).call(this) \ No newline at end of file +!function(){var p,a,f,g,c,l,r,e=window.sharejs,u={name:"text-tp2",tp2:!0,create:function(){return{charLength:0,totalLength:0,positionCache:[],data:[]}},serialize:function(e){if(e.data)return e.data;throw new Error("invalid doc snapshot")},deserialize:function(e){for(var t,n=u.create(),r=0,o=(n.data=e).length;r=e.data.length)throw new Error("Operation goes past the end of the document");return n=(r="string"==typeof(e=e.data[t.index])?void 0!==n?e.slice(t.offset,t.offset+n):e.slice(t.offset):void 0===n||r?e-t.offset:Math.min(n,e-t.offset)).length||r,(e.length||e)-t.offset>n?t.offset+=n:(t.index++,t.offset=0),r},u._appendDoc=a=function(e,t){0!==t&&""!==t&&("string"==typeof t?(e.charLength+=t.length,e.totalLength+=t.length):e.totalLength+=t,0!==(e=e.data).length&&typeof e[e.length-1]==typeof t?e[e.length-1]+=t:e.push(t))},u.apply=function(e,t){var n,r,o,i,f,s,h;if(void 0===e.totalLength||void 0===e.charLength||void 0===e.data.length)throw new Error("Snapshot is invalid");for(m(t),r=u.create(),i={index:0,offset:0},s=0,h=t.length;s0))throw new Error("Object components must be deletes of size > 0");break;case"string":if(!(t.length>0))throw new Error("Inserts cannot be empty");break;case"number":if(!(t>0))throw new Error("Skip components must be >0");if(typeof n=="number")throw new Error("Adjacent skip components should be combined")}n=t}if(typeof n=="number")throw new Error("Op has a trailing skip")},n=function(e){return function(t){if(!!t&&t.d!==0)return e.length===0?e.push(t):typeof t==typeof e[e.length-1]?typeof t=="object"?e[e.length-1].d+=t.d:e[e.length-1]+=t:e.push(t)}},r=function(e){var t=0,n=0,r=function(r,i){var s,o;return t===e.length?r===-1?null:r:(s=e[t],typeof s=="number"?r===-1||s-n<=r?(o=s-n,++t,n=0,o):(n+=r,r):typeof s=="string"?r===-1||i==="i"||s.length-n<=r?(o=s.slice(n),++t,n=0,o):(o=s.slice(n,n+r),n+=r,o):r===-1||i==="d"||s.d-n<=r?(o={d:s.d-n},++t,n=0,o):(n+=r,{d:r}))},i=function(){return e[t]};return[r,i]},t=function(e){return typeof e=="number"?e:e.length||e.d},s=function(e){return e.length>0&&typeof e[e.length-1]=="number"&&e.pop(),e},f.normalize=function(e){var t,r,i,o=[],u=n(o);for(r=0,i=e.length;rt.length)throw new Error("The op is too long for this document");i.push(t.slice(0,r)),t=t.slice(r);break;case"string":i.push(r);break;case"object":t=t.slice(r.d)}}return i.join("")+t},f.transform=function(i,o,u){var a,f,l,c,h,p,d,v,m,g,y;if(u!=="left"&&u!=="right")throw new Error("side ("+u+") must be 'left' or 'right'");e(i),e(o),h=[],a=n(h),y=r(i),v=y[0],d=y[1];for(m=0,g=o.length;m0)f=v(c,"i"),a(f),typeof f!="string"&&(c-=t(f));break;case"string":u==="left"&&(p=d(),typeof p=="string"&&a(v(-1))),a(l.length);break;case"object":c=l.d;while(c>0){f=v(c,"i");switch(typeof f){case"number":c-=f;break;case"string":a(f);break;case"object":c-=f.d}}}}while(l=v(-1))a(l);return s(h)},f.compose=function(i,o){var u,a,f,l,c,h,p,d,v,m;e(i),e(o),c=[],u=n(c),m=r(i),h=m[0],p=m[1];for(d=0,v=o.length;d0)a=h(l,"d"),u(a),typeof a!="object"&&(l-=t(a));break;case"string":u(f);break;case"object":l=f.d;while(l>0){a=h(l,"d");switch(typeof a){case"number":u({d:a}),l-=a;break;case"string":l-=a.length;break;case"object":u(a)}}}}while(f=h(-1))u(f);return s(c)},i=function(e,t){var n,r,i,s=0;for(r=0,i=t.length;r 0");case"string":if(00");if("number"==typeof r)throw new Error("Adjacent skip components should be combined")}r=t}if("number"==typeof r)throw new Error("Op has a trailing skip")},b=function(t){return function(e){if(e&&0!==e.d)return 0!==t.length&&typeof e==typeof t[t.length-1]?"object"==typeof e?t[t.length-1].d+=e.d:t[t.length-1]+=e:t.push(e)}},l=function(o){var s=0,i=0;return[function(e,t){var r,n;return s===o.length?-1===e?null:e:"number"==typeof(r=o[s])?-1===e||r-i<=e?(n=r-i,++s,i=0,n):(i+=e,e):"string"==typeof r?(-1===e||"i"===t||r.length-i<=e?(n=r.slice(i),++s,i=0):(n=r.slice(i,i+e),i+=e),n):-1===e||"d"===t||r.d-i<=e?(n={d:r.d-i},++s,i=0,n):(i+=e,{d:e})},function(){return o[s]}]},g=function(e){return"number"==typeof e?e:e.length||e.d},m=function(e){return 0e.length)throw new Error("The op is too long for this document");n.push(e.slice(0,r)),e=e.slice(r);break;case"string":n.push(r);break;case"object":e=e.slice(r.d)}return n.join("")+e},t.transform=function(e,t,r){var n,o,s,i,c,a,f,u,h;if("left"!==r&&"right"!==r)throw new Error("side ("+r+") must be 'left' or 'right'");for(p(e),p(t),n=b(c=[]),f=(e=l(e))[0],a=e[1],u=0,h=t.length;u