Skip to content

Commit

Permalink
Reduce helper size for decorator 2023-11 (#16263)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicol貌 Ribaudo <hello@nicr.dev>
  • Loading branch information
liuxingbaoyu and nicolo-ribaudo committed Feb 7, 2024
1 parent c6407be commit dcfa8e4
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 219 deletions.
4 changes: 2 additions & 2 deletions packages/babel-helpers/src/helpers-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export default Object.freeze({
"7.21.0",
'import checkInRHS from"checkInRHS";import setFunctionName from"setFunctionName";import toPropertyKey from"toPropertyKey";export default function applyDecs2305(e,t,r,n,o,a){function i(e,t,r){return function(n,o){return r&&r(n),e[t].call(n,o)}}function c(e,t){for(var r=0;r<e.length;r++)e[r].call(t);return t}function s(e,t,r,n){if("function"!=typeof e&&(n||void 0!==e))throw new TypeError(t+" must "+(r||"be")+" a function"+(n?"":" or undefined"));return e}function applyDec(e,t,r,n,o,a,c,u,l,f,p,d,h){function m(e){if(!h(e))throw new TypeError("Attempted to access private element on non-instance")}var y,v=t[0],g=t[3],b=!u;if(!b){r||Array.isArray(v)||(v=[v]);var w={},S=[],A=3===o?"get":4===o||d?"set":"value";f?(p||d?w={get:setFunctionName((function(){return g(this)}),n,"get"),set:function(e){t[4](this,e)}}:w[A]=g,p||setFunctionName(w[A],n,2===o?"":A)):p||(w=Object.getOwnPropertyDescriptor(e,n))}for(var P=e,j=v.length-1;j>=0;j-=r?2:1){var D=v[j],E=r?v[j-1]:void 0,I={},O={kind:["field","accessor","method","getter","setter","class"][o],name:n,metadata:a,addInitializer:function(e,t){if(e.v)throw new Error("attempted to call addInitializer after decoration was finished");s(t,"An initializer","be",!0),c.push(t)}.bind(null,I)};try{if(b)(y=s(D.call(E,P,O),"class decorators","return"))&&(P=y);else{var k,F;O.static=l,O.private=f,f?2===o?k=function(e){return m(e),w.value}:(o<4&&(k=i(w,"get",m)),3!==o&&(F=i(w,"set",m))):(k=function(e){return e[n]},(o<2||4===o)&&(F=function(e,t){e[n]=t}));var N=O.access={has:f?h.bind():function(e){return n in e}};if(k&&(N.get=k),F&&(N.set=F),P=D.call(E,d?{get:w.get,set:w.set}:w[A],O),d){if("object"==typeof P&&P)(y=s(P.get,"accessor.get"))&&(w.get=y),(y=s(P.set,"accessor.set"))&&(w.set=y),(y=s(P.init,"accessor.init"))&&S.push(y);else if(void 0!==P)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else s(P,(p?"field":"method")+" decorators","return")&&(p?S.push(P):w[A]=P)}}finally{I.v=!0}}return(p||d)&&u.push((function(e,t){for(var r=S.length-1;r>=0;r--)t=S[r].call(e,t);return t})),p||b||(f?d?u.push(i(w,"get"),i(w,"set")):u.push(2===o?w[A]:i.call.bind(w[A])):Object.defineProperty(e,n,w)),P}function u(e,t){return Object.defineProperty(e,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:t})}if(arguments.length>=6)var l=a[Symbol.metadata||Symbol.for("Symbol.metadata")];var f=Object.create(null==l?null:l),p=function(e,t,r,n){var o,a,i=[],s=function(t){return checkInRHS(t)===e},u=new Map;function l(e){e&&i.push(c.bind(null,e))}for(var f=0;f<t.length;f++){var p=t[f];if(Array.isArray(p)){var d=p[1],h=p[2],m=p.length>3,y=16&d,v=!!(8&d),g=0==(d&=7),b=h+"/"+v;if(!g&&!m){var w=u.get(b);if(!0===w||3===w&&4!==d||4===w&&3!==d)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+h);u.set(b,!(d>2)||d)}applyDec(v?e:e.prototype,p,y,m?"#"+h:toPropertyKey(h),d,n,v?a=a||[]:o=o||[],i,v,m,g,1===d,v&&m?s:r)}}return l(o),l(a),i}(e,t,o,f);return r.length||u(e,f),{e:p,get c(){var t=[];return r.length&&[u(applyDec(e,[r],n,e.name,5,f,t),f),c.bind(null,t,e)]}}}',
),
// size: 3287, gzip size: 1636
// size: 2882, gzip size: 1463
applyDecs2311: helper(
"7.23.0",
'import checkInRHS from"checkInRHS";import setFunctionName from"setFunctionName";import toPropertyKey from"toPropertyKey";export default function applyDecs2311(e,t,r,n,o,a){function i(e,t,r){return function(n,o){return r&&r(n),e[t].call(n,o)}}function c(e,t){for(var r=0;r<e.length;r++)e[r].call(t);return t}function s(e,t,r,n){if("function"!=typeof e&&(n||void 0!==e))throw new TypeError(t+" must "+(r||"be")+" a function"+(n?"":" or undefined"));return e}function applyDec(e,t,r,n,o,a,u,l,f,p,d,m,h){function y(e){if(!h(e))throw new TypeError("Attempted to access private element on non-instance")}var v,g=t[0],b=t[3],w=!l;if(!w){r||Array.isArray(g)||(g=[g]);var S={},A=[],P=3===o?"get":4===o||m?"set":"value";p?(d||m?S={get:setFunctionName((function(){return b(this)}),n,"get"),set:function(e){t[4](this,e)}}:S[P]=b,d||setFunctionName(S[P],n,2===o?"":P)):d||(S=Object.getOwnPropertyDescriptor(e,n))}for(var j=e,D=g.length-1;D>=0;D-=r?2:1){var E=g[D],I=r?g[D-1]:void 0,O={},k={kind:["field","accessor","method","getter","setter","class"][o],name:n,metadata:a,addInitializer:function(e,t){if(e.v)throw new Error("attempted to call addInitializer after decoration was finished");s(t,"An initializer","be",!0),u.push(t)}.bind(null,O)};try{if(w)(v=s(E.call(I,j,k),"class decorators","return"))&&(j=v);else{var F,N;k.static=f,k.private=p,p?2===o?F=function(e){return y(e),S.value}:(o<4&&(F=i(S,"get",y)),3!==o&&(N=i(S,"set",y))):(F=function(e){return e[n]},(o<2||4===o)&&(N=function(e,t){e[n]=t}));var T=k.access={has:p?h.bind():function(e){return n in e}};if(F&&(T.get=F),N&&(T.set=N),j=E.call(I,m?{get:S.get,set:S.set}:S[P],k),m){if("object"==typeof j&&j)(v=s(j.get,"accessor.get"))&&(S.get=v),(v=s(j.set,"accessor.set"))&&(S.set=v),(v=s(j.init,"accessor.init"))&&A.push(v);else if(void 0!==j)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else s(j,(d?"field":"method")+" decorators","return")&&(d?A.push(j):S[P]=j)}}finally{O.v=!0}}return(d||m)&&l.push((function(e,t){for(var r=A.length-1;r>=0;r--)t=A[r].call(e,t);return t}),c.bind(null,u)),d||w||(p?m?l.splice(-1,0,i(S,"get"),i(S,"set")):l.push(2===o?S[P]:i.call.bind(S[P])):Object.defineProperty(e,n,S)),j}function u(e,t){return Object.defineProperty(e,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:t})}if(arguments.length>=6)var l=a[Symbol.metadata||Symbol.for("Symbol.metadata")];var f=Object.create(null==l?null:l),p=function(e,t,r,n){var o,a,i=[],s=function(t){return checkInRHS(t)===e},u=new Map;function l(e){e&&i.push(c.bind(null,e))}for(var f=0;f<t.length;f++){var p=t[f];if(Array.isArray(p)){var d=p[1],m=p[2],h=p.length>3,y=16&d,v=!!(8&d),g=0==(d&=7),b=1===d,w=m+"/"+v;if(!g&&!h){var S=u.get(w);if(!0===S||3===S&&4!==d||4===S&&3!==d)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+m);u.set(w,!(d>2)||d)}applyDec(v?e:e.prototype,p,y,h?"#"+m:toPropertyKey(m),d,n,g||b?[]:v?a=a||[]:o=o||[],i,v,h,g,b,v&&h?s:r)}}return l(o),l(a),i}(e,t,o,f);return r.length||u(e,f),{e:p,get c(){var t=[];return r.length&&[u(applyDec(e,[r],n,e.name,5,f,t),f),c.bind(null,t,e)]}}}',
'import checkInRHS from"checkInRHS";import setFunctionName from"setFunctionName";import toPropertyKey from"toPropertyKey";export default function applyDecs2311(e,t,n,r,o,i){var c,a,u=Symbol.metadata||Symbol.for("Symbol.metadata"),s=Object.defineProperty,l={},f=n.length;function p(e,t,n,r){for(var o=0;o<e.length;o++)r=e[o].apply(n,t?[r]:[]);return t?r:n}function d(e,t,n,r){if("function"!=typeof e&&(r||void 0!==e))throw new TypeError(t+" must "+(n||"be")+" a function"+(r?"":" or undefined"));return e}function applyDec(e,t,n,r,o,i,u,f,m,h,y,v){function g(e){if(!v(e))throw new TypeError("Attempted to access private element on non-instance")}var b=[].concat(t[0]),w=t[3],D=!u,S=r+"/"+f,j=3===o,E=4===o,I=2===o;function P(e){if(!H&&!h&&!m){if(l[S+e])throw new Error("Decorating two elements with the same name ("+r+") is not supported yet");l[S+e]=1}}function k(e,t){return function(n,r){return t&&t(n),F[e].call(n,r)}}if(!D){var F={},N=[],O=j?"get":E||y?"set":"value";m?(h||y?F={get:setFunctionName((function(){return w(this)}),r,"get"),set:function(e){t[4](this,e)}}:F[O]=w,h||setFunctionName(F[O],r,I?"":O)):h||(F=Object.getOwnPropertyDescriptor(e,r))}for(var z=e,H=b.length-1;H>=0;H-=n?2:1){var K=b[H],R=n?b[H-1]:void 0,T={},A={kind:["field","accessor","method","getter","setter","class"][o],name:r,metadata:c,addInitializer:function(e,t){if(e.v)throw new Error("attempted to call addInitializer after decoration was finished");d(t,"An initializer","be",!0),i.push(t)}.bind(null,T)};if(D)a=K.call(R,z,A),T.v=1,d(a,"class decorators","return")&&(z=a);else if(A.static=f,A.private=m,a=A.access={has:m?v.bind():function(e){return r in e}},E||(P(),a.get=m?I?function(e){return g(e),F.value}:k("get",g):function(e){return e[r]}),j||(P(1),a.set=m?k("set",g):function(e,t){e[r]=t}),z=K.call(R,y?{get:F.get,set:F.set}:F[O],A),T.v=1,y){if("object"==typeof z&&z)(a=d(z.get,"accessor.get"))&&(F.get=a),(a=d(z.set,"accessor.set"))&&(F.set=a),(a=d(z.init,"accessor.init"))&&N.unshift(a);else if(void 0!==z)throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined")}else d(z,(h?"field":"method")+" decorators","return")&&(h?N.unshift(z):F[O]=z)}return o<2&&u.push(p.bind(null,N,1),p.bind(null,i,0)),h||D||(m?y?u.splice(-1,0,k("get"),k("set")):u.push(I?F[O]:p.call.bind(F[O])):s(e,r,F)),z}function m(e){return s(e,u,{configurable:!0,enumerable:!0,value:c})}return void 0!==i&&(c=i[u]),c=Object.create(null==c?null:c),a=function(){var n,r,i=[];function c(e){e&&i.push(p.bind(null,e,0))}for(var a=0;a<t.length;a++){var u=t[a],s=u[1],l=u[2],f=!!u[3],d=16&s,m=!!(8&s),h=0==(s&=7),y=1===s;applyDec(m?e:e.prototype,u,d,f?"#"+l:toPropertyKey(l),s,h||y?[]:m?r=r||[]:n=n||[],i,m,f,h,y,m&&f?function(t){return checkInRHS(t)===e}:o)}return c(n),c(r),i}(),f||m(e),{e:a,get c(){var t=[];return f&&[m(applyDec(e,[n],r,e.name,5,t)),p.bind(null,t,0,e)]}}}',
),
// size: 544, gzip size: 300
asyncGeneratorDelegate: helper(
Expand Down

0 comments on commit dcfa8e4

Please sign in to comment.