Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function compile(content, mod, filename, dirname) {
var Script = process.binding('evals').NodeScript;
var runInThisContext = Script.runInThisContext;
// create wrapper function
//
var wrapper = Module.wrap(content);
var compiledWrapper = runInThisContext(wrapper, filename, true);
var args = [mod.exports, requireSubst(mod), mod, filename, dirname];
return compiledWrapper.apply(mod.exports, args);
}
function getCompiledScript (filename) {
if (compiledScripts[filename]) {
return compiledScripts[filename]
}
const code = files[filename]
const wrapper = NativeModule.wrap(code)
const script = new vm.Script(wrapper, {
filename,
displayErrors: true
})
compiledScripts[filename] = script
return script
}
function getCompiledScript (filename) {
if (compiledScripts[filename]) {
return compiledScripts[filename]
}
const code = files[filename]
const wrapper = NativeModule.wrap(code)
const script = new vm.Script(wrapper, {
filename,
displayErrors: true
})
compiledScripts[filename] = script
return script
}
app.react.render = function* (name, locals, options) {
const filePath = path.isAbsolute(name) ? name : path.join(app.config.view.root[0], name);
const code = yield app.webpack.fileSystem.readWebpackMemoryFile(filePath, name);
if (!code) {
throw new Error(`read webpack memory file[${filePath}] content is empty, please check if the file exists`);
}
const wrapper = NativeModule.wrap(code);
vm.runInThisContext(wrapper)(exports, require, module, __filename, __dirname);
const reactClass = module.exports;
if (options && options.markup) {
return app.react.renderToStaticMarkup(reactClass, locals);
}
return app.react.renderToString(reactClass, locals);
};
}