From 93fa12deff1541034d5311a22a35580e862787f0 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 16 Nov 2023 11:52:53 +0000 Subject: [PATCH] Tests WIP 1 --- test/eval.test.js | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) diff --git a/test/eval.test.js b/test/eval.test.js index 6f2be3fa..9cdf3f83 100644 --- a/test/eval.test.js +++ b/test/eval.test.js @@ -175,6 +175,228 @@ describe('eval', () => { } }); }); + + describe('`super`', () => { + describe('in object literal method', () => { + describe('with no prefix num change', () => { + itSerializesEqual('at top level of eval', { + in() { + const obj = { + meth() { + return eval('super.meth()'); + }, + __proto__: { + meth() { return 123; } + } + }; + return obj.meth(); + }, + out: '123' + }); + + itSerializesEqual('within arrow function', { + in() { + const obj = { + meth() { + return eval('() => super.meth()'); + }, + __proto__: { + meth() { return 123; } + } + }; + return obj.meth()(); + }, + out: '123' + }); + }); + + describe('with prefix num change', () => { + itSerializesEqual('at top level of eval', { + in() { + const obj = { + meth() { + return eval('let livepack_tracker; super.meth()'); + }, + __proto__: { + meth() { return 123; } + } + }; + return obj.meth(); + }, + out: '123' + }); + + itSerializesEqual('within arrow function', { + in() { + const obj = { + meth() { + return eval('let livepack_tracker; () => super.meth()'); + }, + __proto__: { + meth() { return 123; } + } + }; + return obj.meth()(); + }, + out: '123' + }); + }); + }); + + describe('in class method', () => { + /* eslint-disable class-methods-use-this */ + describe('with no prefix num change', () => { + itSerializesEqual('at top level of eval', { + in() { + class S { + meth() { return 123; } + } + class C extends S { + meth() { + return eval('super.meth()'); + } + } + const obj = new C(); + return obj.meth(); + }, + out: '123' + }); + + itSerializesEqual('within arrow function', { + in() { + class S { + meth() { return 123; } + } + class C extends S { + meth() { + return eval('() => super.meth()'); + } + } + const obj = new C(); + return obj.meth()(); + }, + out: '123' + }); + }); + + describe('with prefix num change', () => { + itSerializesEqual('at top level of eval', { + in() { + class S { + meth() { return 123; } + } + class C extends S { + meth() { + return eval('let livepack_tracker; super.meth()'); + } + } + const obj = new C(); + return obj.meth(); + }, + out: '123' + }); + + itSerializesEqual('within arrow function', { + in() { + class S { + meth() { return 123; } + } + class C extends S { + meth() { + return eval('let livepack_tracker; () => super.meth()'); + } + } + const obj = new C(); + return obj.meth()(); + }, + out: '123' + }); + }); + /* eslint-enable class-methods-use-this */ + }); + + describe('in class constructor', () => { + /* eslint-disable class-methods-use-this, constructor-super, no-this-before-super */ + describe('with no prefix num change', () => { + itSerializesEqual('at top level of eval', { + in() { + class S { + constructor() { this.x = 456; } + meth() { return 123; } + } + class C extends S { + constructor() { + eval('super()'); + eval('this.n = super.meth();'); + } + } + const obj = new C(); + return [obj.n, obj.x]; + }, + out: '[123,456]' + }); + + itSerializesEqual('within arrow function', { + in() { + class S { + constructor() { this.x = 456; } + meth() { return 123; } + } + class C extends S { + constructor() { + const callSuper = eval('() => super()'); + callSuper(); + this.f = eval('() => super.meth()'); + } + } + const obj = new C(); + return [obj.f(), obj.x]; + }, + out: '[123,456]' + }); + }); + + describe('with prefix num change', () => { + itSerializesEqual('at top level of eval', { + in() { + class S { + constructor() { this.x = 456; } + meth() { return 123; } + } + class C extends S { + constructor() { + eval('let livepack_tracker; super()'); + eval('let livepack1_tracker; this.n = super.meth()'); + } + } + const obj = new C(); + return [obj.n, obj.x]; + }, + out: '[123,456]' + }); + + itSerializesEqual('within arrow function', { + in() { + class S { + constructor() { this.x = 456; } + meth() { return 123; } + } + class C extends S { + constructor() { + const callSuper = eval('let livepack_tracker; () => super()'); + callSuper(); + this.f = eval('let livepack1_tracker; () => super.meth()'); + } + } + const obj = new C(); + return [obj.f(), obj.x]; + }, + out: '[123,456]' + }); + }); + /* eslint-enable class-methods-use-this, constructor-super, no-this-before-super */ + }); + }); }); describe('functions', () => {