Closed overlookmotel closed 9 months ago
To avoid a problem if Object
is a local var too (!), add a method to livepack_getScopeId
for this purpose and call it rather than using Object.defineProperty
directly in instrumented code:
livepack_getScopeId.nameRequire = require => {
return Object.defineProperty(require, 'name', {value: 'require'});
};
Should only rename function declarations at top level, and not inside nested blocks.
A function declaration in a nested block will not be hoisted up, because it's blocked from doing that by the parameter called require
in the CommonJS wrapper function.
{
function require() {}
require.x = 1;
}
assert(require.x === undefined);
Implemented on require-funcs branch. Just needs tests.
Weird but legal CommonJS input:
When instrumented code is run, this throws
ReferenceError: Cannot access 'livepack_tracker' before initialization
.Instumented code:
require("/path/to/livepack/lib/init/index.js")
calls the locally-definedrequire
function instead of CommonJSrequire
.Fix would be if instrumentation renamed the local
require
function, and then assigned it to avar
: