diff --git a/test/arrays.test.js b/test/arrays.test.js index d7276464..c08627a0 100644 --- a/test/arrays.test.js +++ b/test/arrays.test.js @@ -340,13 +340,9 @@ describe('Arrays', () => { out: `(()=>{ const a=Object.setPrototypeOf, b=Array, - c=(b=>b=class A{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - a(c,b); - a(d,b.prototype); - return a([],d) + c=a(class A extends class{}{},b).prototype; + a(c,b.prototype); + return a([],c) })()`, validate(arr) { expect(arr).toBeArrayOfSize(0); @@ -367,13 +363,9 @@ describe('Arrays', () => { out: `(()=>{ const a=Object.setPrototypeOf, b=Array, - c=(b=>b=class A{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - a(c,b); - a(d,b.prototype); - return a([1,2,3],d) + c=a(class A extends class{}{},b).prototype; + a(c,b.prototype); + return a([1,2,3],c) })()`, validate(arr) { expect(arr).toBeArrayOfSize(3); @@ -399,16 +391,12 @@ describe('Arrays', () => { out: `(()=>{ const a=Object.setPrototypeOf, b=Array, - c=(b=>b=class A{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype, - e=a([,2],d); - a(c,b); - a(d,b.prototype); - e[0]=e; - e[2]=e; - return e + c=a(class A extends class{}{},b).prototype, + d=a([,2],c); + a(c,b.prototype); + d[0]=d; + d[2]=d; + return d })()`, validate(arr) { expect(arr).toBeArrayOfSize(3); diff --git a/test/boxed.test.js b/test/boxed.test.js index 75dd384a..aaab057f 100644 --- a/test/boxed.test.js +++ b/test/boxed.test.js @@ -79,13 +79,9 @@ describe('Boxed Strings', () => { out: `(()=>{ const a=String, b=Object.setPrototypeOf, - c=(b=>b=class S{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a("abc"),d) + c=b(class S extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a("abc"),c) })()`, validate(str) { expect(typeof str).toBe('object'); @@ -146,13 +142,9 @@ describe('Boxed Booleans', () => { out: `(()=>{ const a=Boolean, b=Object.setPrototypeOf, - c=(b=>b=class B{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a(1),d) + c=b(class B extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a(1),c) })()`, validate(bool) { expect(typeof bool).toBe('object'); @@ -282,13 +274,9 @@ describe('Boxed Numbers', () => { out: `(()=>{ const a=Number, b=Object.setPrototypeOf, - c=(b=>b=class N{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a(1),d) + c=b(class N extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a(1),c) })()`, validate(num) { expect(typeof num).toBe('object'); @@ -368,13 +356,9 @@ describe('Boxed BigInts', () => { const a=Object, b=a.setPrototypeOf, c=BigInt, - d=(b=>b=class B{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - e=d.prototype; - b(d,c); - b(e,c.prototype); - return b(a(100n),e) + d=b(class B extends class{}{},c).prototype; + b(d,c.prototype); + return b(a(100n),d) })()`, validate(bigInt) { expect(typeof bigInt).toBe('object'); diff --git a/test/buffers.test.js b/test/buffers.test.js index 80ca2171..aaea78ce 100644 --- a/test/buffers.test.js +++ b/test/buffers.test.js @@ -45,13 +45,9 @@ describe('Buffers', () => { out: `(()=>{ const a=Buffer, b=Object.setPrototypeOf, - c=(b=>b=class B{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(a.from("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=","base64"),d) + c=b(class B extends class{}{},a).prototype; + b(c,a.prototype); + return b(a.from("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=","base64"),c) })()`, validate(buf) { expect(buf).toBeInstanceOf(Buffer); @@ -377,18 +373,9 @@ describe('Buffers', () => { out: `(()=>{ const a=Uint8Array, b=Object.setPrototypeOf, - c=(b=>b=class B{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b( - new a([100,200]), - d - ) + c=b(class B extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a([100,200]),c) })()`, validate(buf) { expect(buf).toBeInstanceOf(Uint8Array); diff --git a/test/eval.test.js b/test/eval.test.js index 49a13ae7..b630f7f8 100644 --- a/test/eval.test.js +++ b/test/eval.test.js @@ -1376,26 +1376,19 @@ describe('eval', () => { delete C.prototype.meth; `, out: `(()=>{ - const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, - a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a) - ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=class S{}, - f=e.prototype, - g=b.prototype; - c.defineProperties(f,{ + const a=Object, + b=a.setPrototypeOf, + c=class S{}, + d=c.prototype, + e=b(class C extends class{}{},c), + f=e.prototype; + a.defineProperties(d,{ meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true} }); - d(b,e); - d(g,f); - return a[1](c.create(g)) + b(f,d); + return( + b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a) + )(e)(a.create(f)) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -1418,26 +1411,19 @@ describe('eval', () => { delete C.prototype.meth; `, out: `(()=>{ - const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, - a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a) - ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=class S{}, - f=e.prototype, - g=b.prototype; - c.defineProperties(f,{ + const a=Object, + b=a.setPrototypeOf, + c=class S{}, + d=c.prototype, + e=b(class C extends class{}{},c), + f=e.prototype; + a.defineProperties(d,{ meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true} }); - d(b,e); - d(g,f); - return a[1](c.create(g)) + b(f,d); + return( + b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a) + )(e)(a.create(f)) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -1461,24 +1447,17 @@ describe('eval', () => { delete C.meth; `, out: `(()=>{ - const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, - a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a) - ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=c.defineProperties( + const a=Object, + b=a.setPrototypeOf, + c=a.defineProperties( class S{}, {meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}} - ); - d(b,e); - d(b.prototype,e.prototype); - return a[1](b) + ), + d=b(class C extends class{}{},c); + b(d.prototype,c.prototype); + return( + b=>a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a) + )(d)(d) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -1500,24 +1479,17 @@ describe('eval', () => { delete C.meth; `, out: `(()=>{ - const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, - a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a) - ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=c.defineProperties( + const a=Object, + b=a.setPrototypeOf, + c=a.defineProperties( class S{}, {meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}} - ); - d(b,e); - d(b.prototype,e.prototype); - return a[1](b) + ), + d=b(class C extends class{}{},c); + b(d.prototype,c.prototype); + return( + b=>a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a) + )(d)(d) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -1533,7 +1505,7 @@ describe('eval', () => { meth() { return 123; } } class C extends S { - constructor(module, exports, obj) { + constructor(module, exports, S, obj) { super(); this.f = eval('() => super.meth()'); } @@ -1544,19 +1516,22 @@ describe('eval', () => { delete obj.f; `, out: `(()=>{ - const a=class S{}, - b=a.prototype, - c=Object, - d=(0,eval)("\\"use strict\\";S=>_b=>[_b=class C{constructor(module,exports,obj){const _a=Reflect.construct(Object.getPrototypeOf(_b),[],_b);_a.f=eval(\\"() => super.meth()\\");return _a}},a=>()=>Reflect.get(Object.getPrototypeOf(_b.prototype),\\"meth\\",a).call(a)]")(a)(), - e=d[0], - f=c.setPrototypeOf, - g=e.prototype; - c.defineProperties(b,{ + const a=Object, + b=a.setPrototypeOf, + c=class S{}, + d=c.prototype, + e=b( + (0,eval)("(class C extends class{}{constructor(module,exports,S,obj){super();this.f=eval(\\"() => super.meth()\\")}})"), + c + ), + f=e.prototype; + a.defineProperties(d,{ meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true} }); - f(e,a); - f(g,b); - return d[1](c.create(g)) + b(f,d); + return( + b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a) + )(e)(a.create(f)) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -1570,7 +1545,7 @@ describe('eval', () => { meth() { return 123; } } class C extends S { - constructor(module, exports, obj) { + constructor(module, exports, S, obj) { super(); this.f = eval('let livepack_tracker; () => super.meth()'); } @@ -1581,19 +1556,22 @@ describe('eval', () => { delete obj.f; `, out: `(()=>{ - const a=class S{}, - b=a.prototype, - c=Object, - d=(0,eval)("\\"use strict\\";S=>_b=>[_b=class C{constructor(module,exports,obj){const _a=Reflect.construct(Object.getPrototypeOf(_b),[],_b);_a.f=eval(\\"let livepack_tracker; () => super.meth()\\");return _a}},a=>()=>Reflect.get(Object.getPrototypeOf(_b.prototype),\\"meth\\",a).call(a)]")(a)(), - e=d[0], - f=c.setPrototypeOf, - g=e.prototype; - c.defineProperties(b,{ + const a=Object, + b=a.setPrototypeOf, + c=class S{}, + d=c.prototype, + e=b( + (0,eval)("(class C extends class{}{constructor(module,exports,S,obj){super();this.f=eval(\\"let livepack_tracker; () => super.meth()\\")}})"), + c + ), + f=e.prototype; + a.defineProperties(d,{ meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true} }); - f(e,a); - f(g,b); - return d[1](c.create(g)) + b(f,d); + return( + b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a) + )(e)(a.create(f)) })()`, validate(fn) { expect(fn).toBeFunction(); diff --git a/test/functions.test.js b/test/functions.test.js index 70641bf3..8b055793 100644 --- a/test/functions.test.js +++ b/test/functions.test.js @@ -3407,11 +3407,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { getFoo(){ return()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",this).call(this) @@ -3419,15 +3415,15 @@ describe('Functions', () => { }.getFoo, a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",a).call(a) ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=class S{}, - f=e.prototype, - g=c.defineProperties, - h=b.prototype; - g( - f, + b=Object, + c=b.setPrototypeOf, + d=class S{}, + e=d.prototype, + f=b.defineProperties, + g=c(class C extends class{}{},d), + h=g.prototype; + f( + e, { foo:{ value:{foo(){return 1}}.foo, @@ -3436,17 +3432,17 @@ describe('Functions', () => { } } ); - d(b,e); - d( - g( + c( + f( h, { getFoo:{value:a[1],writable:true,configurable:true} } ), - f + e ); - return a[2](c.create(h)) + a[0](g); + return a[2](b.create(h)) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -3470,11 +3466,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { getFoo(){ return()=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",this).call(this) @@ -3482,15 +3474,15 @@ describe('Functions', () => { }.getFoo, a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",a).call(a) ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=class S{}, - f=e.prototype, - g=c.defineProperties, - h=b.prototype; - g( - f, + b=Object, + c=b.setPrototypeOf, + d=class S{}, + e=d.prototype, + f=b.defineProperties, + g=c(class C extends class{}{},d), + h=g.prototype; + f( + e, { foo:{ value:{foo(){return 1}}.foo, @@ -3499,17 +3491,17 @@ describe('Functions', () => { } } ); - d(b,e); - d( - g( + c( + f( h, { getFoo:{value:a[1],writable:true,configurable:true} } ), - f + e ); - return a[2](c.create(h)) + a[0](g); + return a[2](b.create(h)) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -3532,28 +3524,24 @@ describe('Functions', () => { return [C, new C().getFoo()]; }, out: `(()=>{ - const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + const a=Object, + b=a.setPrototypeOf, + c=class S{}, + d=c.prototype, + e=a.defineProperties, + f=b(class C extends class{}{},c), + g=f.prototype, + h=(b=>[ + a=>b=a, { getFoo(){ return()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",this).call(this) } }.getFoo, a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",a).call(a) - ])(), - b=Object, - c=b.setPrototypeOf, - d=class S{}, - e=d.prototype, - f=b.defineProperties, - g=a[0], - h=g.prototype; - f( - e, + ])(); + e( + d, { foo:{ value:{foo(){return 1}}.foo, @@ -3562,17 +3550,17 @@ describe('Functions', () => { } } ); - c(g,d); - c( - f( - h, + h[0](f); + b( + e( + g, { - getFoo:{value:a[1],writable:true,configurable:true} + getFoo:{value:h[1],writable:true,configurable:true} } ), - e + d ); - return[g,a[2](b.create(h))] + return[f,h[2](a.create(g))] })()`, validate([C, fn]) { expect(fn).toBeFunction(); @@ -3604,11 +3592,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { getFoo(){ return()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",this) @@ -3616,31 +3600,31 @@ describe('Functions', () => { }.getFoo, a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"foo",a) ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=class S{}, - f=e.prototype, - g=c.defineProperties, - h=b.prototype; - g( - f, + b=Object, + c=b.setPrototypeOf, + d=class S{}, + e=d.prototype, + f=b.defineProperties, + g=c(class C extends class{}{},d), + h=g.prototype; + f( + e, { foo:{get:{"get foo"(){return this.x*2}}["get foo"],configurable:true} } ); - d(b,e); - d( - g( + c( + f( h, { foo:{get:{"get foo"(){return this.x*3}}["get foo"],configurable:true}, getFoo:{value:a[1],writable:true,configurable:true} } ), - f + e ); - return a[2](c.assign(c.create(h),{x:5})) + a[0](g); + return a[2](b.assign(b.create(h),{x:5})) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -3671,11 +3655,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { setFoo(){ return()=>{ @@ -3687,31 +3667,31 @@ describe('Functions', () => { Reflect.set(Object.getPrototypeOf(b.prototype),"foo",5,a) } ])(), - b=a[0], - c=Object, - d=c.setPrototypeOf, - e=class S{}, - f=e.prototype, - g=c.defineProperties, - h=b.prototype, - i=c.create(h); - g( - f, + b=Object, + c=b.setPrototypeOf, + d=class S{}, + e=d.prototype, + f=b.defineProperties, + g=c(class C extends class{}{},d), + h=g.prototype, + i=b.create(h); + f( + e, { foo:{set:{"set foo"(a){this.x=a*2}}["set foo"],configurable:true} } ); - d(b,e); - d( - g( + c( + f( h, { foo:{set:{"set foo"(a){this.x=a*3}}["set foo"],configurable:true}, setFoo:{value:a[1],writable:true,configurable:true} } ), - f + e ); + a[0](g); return{fn:a[2](i),c:i} })()`, validate({fn, c}) { @@ -3741,11 +3721,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { getFoo(){ return()=>Reflect.get(Object.getPrototypeOf(b),"foo",this).call(this) @@ -3753,11 +3729,10 @@ describe('Functions', () => { }.getFoo, a=>()=>Reflect.get(Object.getPrototypeOf(b),"foo",a).call(a) ])(), - b=a[0], - c=Object, - d=c.defineProperties, - e=c.setPrototypeOf, - f=d( + b=Object, + c=b.defineProperties, + d=b.setPrototypeOf, + e=c( class S{}, { foo:{ @@ -3766,18 +3741,19 @@ describe('Functions', () => { configurable:true } } - ); - e( - d( - b, - { - getFoo:{value:a[1],writable:true,configurable:true} - } ), - f - ); - e(b.prototype,f.prototype); - return a[2](b) + f=d( + c( + class C extends class{}{}, + { + getFoo:{value:a[1],writable:true,configurable:true} + } + ), + e + ); + d(f.prototype,e.prototype); + a[0](f); + return a[2](f) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -3801,11 +3777,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { getFoo(){ return()=>()=>Reflect.get(Object.getPrototypeOf(b),"foo",this).call(this) @@ -3813,11 +3785,10 @@ describe('Functions', () => { }.getFoo, a=>()=>Reflect.get(Object.getPrototypeOf(b),"foo",a).call(a) ])(), - b=a[0], - c=Object, - d=c.defineProperties, - e=c.setPrototypeOf, - f=d( + b=Object, + c=b.defineProperties, + d=b.setPrototypeOf, + e=c( class S{}, { foo:{ @@ -3826,18 +3797,19 @@ describe('Functions', () => { configurable:true } } - ); - e( - d( - b, - { - getFoo:{value:a[1],writable:true,configurable:true} - } ), - f - ); - e(b.prototype,f.prototype); - return a[2](b) + f=d( + c( + class C extends class{}{}, + { + getFoo:{value:a[1],writable:true,configurable:true} + } + ), + e + ); + d(f.prototype,e.prototype); + a[0](f); + return a[2](f) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -3861,11 +3833,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { getFoo(){ return()=>Reflect.get(Object.getPrototypeOf(b),"foo",this).call(this) @@ -3886,16 +3854,16 @@ describe('Functions', () => { } } ), - f=a[0]; - d( - c( - f, - { - getFoo:{value:a[1],writable:true,configurable:true} - } - ), - e - ); + f=d( + c( + class C extends class{}{}, + { + getFoo:{value:a[1],writable:true,configurable:true} + } + ), + e + ); + a[0](f); d(f.prototype,e.prototype); return[f,a[2](f)] })()`, @@ -3928,11 +3896,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { getFoo(){ return()=>Reflect.get(Object.getPrototypeOf(b),"foo",this) @@ -3940,29 +3904,29 @@ describe('Functions', () => { }.getFoo, a=>()=>Reflect.get(Object.getPrototypeOf(b),"foo",a) ])(), - b=a[0], - c=Object, - d=c.defineProperties, - e=c.setPrototypeOf, - f=d( + b=Object, + c=b.defineProperties, + d=b.setPrototypeOf, + e=c( class S{}, { foo:{get:{"get foo"(){return this.x*2}}["get foo"],configurable:true} } - ); - e( - d( - b, - { - foo:{get:{"get foo"(){return this.x*3}}["get foo"],configurable:true}, - getFoo:{value:a[1],writable:true,configurable:true}, - x:{value:5,writable:true,enumerable:true,configurable:true} - } ), - f - ); - e(b.prototype,f.prototype); - return a[2](b) + f=d( + c( + class C extends class{}{}, + { + foo:{get:{"get foo"(){return this.x*3}}["get foo"],configurable:true}, + getFoo:{value:a[1],writable:true,configurable:true}, + x:{value:5,writable:true,enumerable:true,configurable:true} + } + ), + e + ); + d(f.prototype,e.prototype); + a[0](f); + return a[2](f) })()`, validate(fn) { expect(fn).toBeFunction(); @@ -3992,11 +3956,7 @@ describe('Functions', () => { }, out: `(()=>{ const a=(b=>[ - b=class C{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - }, + a=>b=a, { setFoo(){ return()=>{ @@ -4008,28 +3968,28 @@ describe('Functions', () => { Reflect.set(Object.getPrototypeOf(b),"foo",5,a) } ])(), - b=a[0], - c=Object, - d=c.defineProperties, - e=c.setPrototypeOf, - f=d( + b=Object, + c=b.defineProperties, + d=b.setPrototypeOf, + e=c( class S{}, { foo:{set:{"set foo"(a){this.x=a*2}}["set foo"],configurable:true} } - ); - e( - d( - b, - { - foo:{set:{"set foo"(a){this.x=a*3}}["set foo"],configurable:true}, - setFoo:{value:a[1],writable:true,configurable:true} - } ), - f - ); - e(b.prototype,f.prototype); - return{fn:a[2](b),C:b} + f=d( + c( + class C extends class{}{}, + { + foo:{set:{"set foo"(a){this.x=a*3}}["set foo"],configurable:true}, + setFoo:{value:a[1],writable:true,configurable:true} + } + ), + e + ); + d(f.prototype,e.prototype); + a[0](f); + return{fn:a[2](f),C:f} })()`, validate({fn, C}) { expect(fn).toBeFunction(); @@ -10395,44 +10355,52 @@ describe('Functions', () => { extB = 2; } } + + let setExtA; + class Klass extends SuperKlass { + constructor() { // eslint-disable-line constructor-super + // eslint-disable-next-line no-const-assign, no-return-assign + setExtA = (0, () => extA = super()); + } + } + try { + new Klass(); // eslint-disable-line no-new + } catch {} // eslint-disable-line no-empty + return [ - class extends SuperKlass { - constructor() { - extA = super(); // eslint-disable-line no-const-assign - } - }, + setExtA, () => extA, () => extB ]; }, out: `(()=>{ const a=Object.setPrototypeOf, - b=((a,b)=>[ - class SuperKlass{ + b=((b,c,d)=>[ + class Klass extends class{}{ constructor(){ - b=2 + c=(0,()=>(super(),(()=>{const a=0;a=0})())) } }, - ()=>a, - ()=>b + class SuperKlass{ + constructor(){d=2} + }, + ()=>b, + ()=>d ])(1), - c=b[0], - d=( - c=>c=(0,class{ - constructor(){ - let a; - a=Reflect.construct(Object.getPrototypeOf(c),[],c),(()=>{const b=0;b=0})(); - return a - } - }) - )(); - a(d,c); + c=b[1], + d=a(b[0],c); a(d.prototype,c.prototype); - return[d,b[1],b[2]] + return[ + (b=>()=>( + Reflect.construct(Object.getPrototypeOf(b),[],b), + (()=>{const a=0;a=0})()) + )(d), + b[2], + b[3] + ] })()`, - validate([Klass, getExtA, getExtB]) { - expect(Klass).toBeFunction(); - expect(() => new Klass()).toThrowWithMessage(TypeError, 'Assignment to constant variable.'); + validate([setExtA, getExtA, getExtB]) { + expect(setExtA).toThrowWithMessage(TypeError, 'Assignment to constant variable.'); expect(getExtA()).toBe(1); // `ext` not set expect(getExtB()).toBe(2); // `SuperKlass` constructor called } @@ -10447,42 +10415,57 @@ describe('Functions', () => { extB = 2; } } + + let setExtA; + class Klass extends SuperKlass { + constructor() { // eslint-disable-line constructor-super + // eslint-disable-next-line no-const-assign, no-return-assign + setExtA = (0, () => super(extA = 3)); + } + } + try { + new Klass(); // eslint-disable-line no-new + } catch {} // eslint-disable-line no-empty + return [ - class extends SuperKlass { - constructor() { - super(extA = 3); // eslint-disable-line no-const-assign - } - }, + setExtA, () => extA, () => extB ]; }, out: `(()=>{ const a=Object.setPrototypeOf, - b=((a,b)=>[ - class SuperKlass{ + b=((b,c,d)=>[ + class Klass extends class{}{ constructor(){ - b=2 + c=(0,()=>super((3,(()=>{const a=0;a=0})()))) } }, - ()=>a, - ()=>b - ])(1), - c=b[0], - d=( - b=>b=(0,class{ + class SuperKlass{ constructor(){ - return Reflect.construct(Object.getPrototypeOf(b),[(3,(()=>{const a=0;a=0})())],b) + d=2 } - }) - )(); - a(d,c); + }, + ()=>b, + ()=>d + ])(1), + c=b[1], + d=a(b[0],c); a(d.prototype,c.prototype); - return[d,b[1],b[2]] + return[ + ( + b=>()=>Reflect.construct( + Object.getPrototypeOf(b), + [(3,(()=>{const a=0;a=0})())], + b + ) + )(d), + b[2], + b[3] + ] })()`, - validate([Klass, getExtA, getExtB]) { - expect(Klass).toBeFunction(); - expect(() => new Klass()).toThrowWithMessage(TypeError, 'Assignment to constant variable.'); + validate([setExtA, getExtA, getExtB]) { + expect(setExtA).toThrowWithMessage(TypeError, 'Assignment to constant variable.'); expect(getExtA()).toBe(1); // `ext` not set expect(getExtB()).toBeUndefined(); // `SuperKlass` constructor not called } diff --git a/test/maps.test.js b/test/maps.test.js index 20cd15ae..dc66f33b 100644 --- a/test/maps.test.js +++ b/test/maps.test.js @@ -102,15 +102,9 @@ describe('Maps', () => { out: `(()=>{ const a=Map, b=Object.setPrototypeOf, - c=(b=>b=class M{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a,d) + c=b(class M extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a,c) })()`, validate(map) { expect(map).toBeInstanceOf(Map); @@ -130,15 +124,9 @@ describe('Maps', () => { out: `(()=>{ const a=Map, b=Object.setPrototypeOf, - c=(b=>b=class M{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a([[1,2],[3,4],[5,6]]),d) + c=b(class M extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a([[1,2],[3,4],[5,6]]),c) })()`, validate(map) { expect(map).toBeInstanceOf(Map); @@ -163,19 +151,13 @@ describe('Maps', () => { out: `(()=>{ const a=Map, b=Object.setPrototypeOf, - c=(b=>b=class M{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - })(), - d=c.prototype, - e=b(new a([[1,2]]),d); - b(c,a); - b(d,a.prototype); - e.set(e,3); - e.set(4,e); - e.set(5,6); - return e + c=b(class M extends class{}{},a).prototype, + d=b(new a([[1,2]]),c); + b(c,a.prototype); + d.set(d,3); + d.set(4,d); + d.set(5,6); + return d })()`, validate(map) { expect(map).toBeInstanceOf(Map); diff --git a/test/other.test.js b/test/other.test.js index 25a15357..78fde16e 100644 --- a/test/other.test.js +++ b/test/other.test.js @@ -57,13 +57,9 @@ describe('RegExps', () => { out: `(()=>{ const a=Object.setPrototypeOf, b=RegExp, - c=(b=>b=class R{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - a(c,b); - a(d,b.prototype); - return a(/^foo$/gu,d) + c=a(class R extends class{}{},b).prototype; + a(c,b.prototype); + return a(/^foo$/gu,c) })()`, validate(regex) { expect(regex).toBeInstanceOf(RegExp); @@ -139,13 +135,9 @@ describe('Dates', () => { out: `(()=>{ const a=Date, b=Object.setPrototypeOf, - c=(b=>b=class D{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a(1577880000000),d) + c=b(class D extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a(1577880000000),c) })()`, validate(date) { expect(date.toISOString()).toBe('2020-01-01T12:00:00.000Z'); @@ -175,13 +167,9 @@ describe('URLs', () => { out: `(()=>{ const a=URL, b=Object.setPrototypeOf, - c=(b=>b=class U{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a("http://foo.com/path/to/file.html?a=1&b=2"),d) + c=b(class U extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a("http://foo.com/path/to/file.html?a=1&b=2"),c) })()`, validate(url) { expect(url).toBeInstanceOf(URL); @@ -231,13 +219,9 @@ describe('URLSearchParams', () => { out: `(()=>{ const a=URLSearchParams, b=Object.setPrototypeOf, - c=(b=>b=class U{ - constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)} - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a("a=1&b=2"),d) + c=b(class U extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a("a=1&b=2"),c) })()`, validate(params) { expect(params).toBeInstanceOf(URLSearchParams); diff --git a/test/sets.test.js b/test/sets.test.js index 0dc3df4f..ca420922 100644 --- a/test/sets.test.js +++ b/test/sets.test.js @@ -98,15 +98,9 @@ describe('Sets', () => { out: `(()=>{ const a=Set, b=Object.setPrototypeOf, - c=(b=>b=class S{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a,d) + c=b(class S extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a,c) })()`, validate(set) { expect(set).toBeInstanceOf(Set); @@ -126,15 +120,9 @@ describe('Sets', () => { out: `(()=>{ const a=Set, b=Object.setPrototypeOf, - c=(b=>b=class S{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - })(), - d=c.prototype; - b(c,a); - b(d,a.prototype); - return b(new a([1,2,3]),d) + c=b(class S extends class{}{},a).prototype; + b(c,a.prototype); + return b(new a([1,2,3]),c) })()`, validate(set) { expect(set).toBeInstanceOf(Set); @@ -158,18 +146,12 @@ describe('Sets', () => { out: `(()=>{ const a=Set, b=Object.setPrototypeOf, - c=(b=>b=class S{ - constructor(...a){ - return Reflect.construct(Object.getPrototypeOf(b),a,b) - } - })(), - d=c.prototype, - e=b(new a([1]),d); - b(c,a); - b(d,a.prototype); - e.add(e); - e.add(2); - return e + c=b(class S extends class{}{},a).prototype, + d=b(new a([1]),c); + b(c,a.prototype); + d.add(d); + d.add(2); + return d })()`, validate(set) { expect(set).toBeInstanceOf(Set);