From 0dea35c53257241aa016493cc23568b6842a3dad Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Sun, 10 Dec 2023 14:31:41 +0000 Subject: [PATCH] More tests for internal vars in instrumentation --- test/with.test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/with.test.js b/test/with.test.js index 975c1932..aba3a50c 100644 --- a/test/with.test.js +++ b/test/with.test.js @@ -409,6 +409,40 @@ describe('with statements', () => { } }); + itSerializes('`livepack_scopeId`', { + in: ` + const x = 123; + with ({livepack_scopeId_2: 1}) { + module.exports = () => x; + } + `, + out: '(x=>a=>{with(a)return()=>x})(123)({livepack_scopeId_2:1})', + validate(fn, {transpiled}) { + expect(fn).toBeFunction(); + expect(fn()).toBe(123); + + // Check internal var matches the one being tested for + expect(transpiled.split('\n')[0]) + .toInclude(';const livepack_scopeId_2 = livepack_getScopeId();'); + } + }); + + itSerializes('`livepack_temp` for `with` object', { + in: ` + with ({livepack_temp_6: 1, x: 2}) { + module.exports = () => x; + } + `, + out: '(a=>{with(a)return()=>x})({livepack_temp_6:1,x:2})', + validate(fn, {transpiled}) { + expect(fn).toBeFunction(); + expect(fn()).toBe(2); + + // Check internal var match the one being tested for + expect(transpiled.split('\n')[0]).toInclude(';let livepack_temp_6;'); + } + }); + itSerializes('`livepack_temp` for class `super`', { in: ` class S {