overlookmotel / livepack

Serialize live running code to Javascript
MIT License
42 stars 1 forks source link

Multiple `eval()`s can produce code which can't be serialized #538

Closed overlookmotel closed 10 months ago

overlookmotel commented 11 months ago

Attempting to serialize this:

eval('let livepack_x');
export default eval('() => 123');

fails with error "Failed to extract scope vars from function".

Reason is that livepack_x in 1st eval causes the internal vars prefix num to be incremented, and this affects both inside the eval() and outside. So when the 2nd eval() is entered, the that code is instrumented as:

() => { livepack1_tracker(livepack1_getFnInfo_9,()=>[]); return 123; };

This should be livepack_tracker() not livepack1_tracker() - because the prefix num in the external code is 0 not 1.

Prefix num needs to be tracked inside each eval() separately not globally. NB nextBlockId, in contrast, needs to be tracked globally.

overlookmotel commented 10 months ago

Fixed in issue-538 branch. Just needs tests.