overlookmotel / livepack

Serialize live running code to Javascript
MIT License
30 stars 0 forks source link

Tests for strict mode `eval()` not capturing vars which are illegal to use in strict mode code #548

Closed overlookmotel closed 7 months ago

overlookmotel commented 7 months ago

Certain keywords are not allowed to be used as var names according to ECMA spec in strict mode code. One such keyword is package.

Livepack correctly handles this. In this function, eval() will execute in strict mode, so the var package is not accessible to it. Therefore Livepack does not capture package as an external var of the function.

// Sloppy mode
const package = 123;
module.exports = function() {
  'use strict';
  return eval('1');
};

So this works fine, but there's currently no test for it.

overlookmotel commented 7 months ago

There are tests!

https://github.com/overlookmotel/livepack/blob/5e3f35b60fa7ce09fd20476464704f8d33dbd68f/test/strict.test.js#L736-L785