Skip to content

Commit fc8451a

Browse files
committed
Converted eval to new Function to enhance readability
1 parent 3700a8c commit fc8451a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

loadmodule/loadmodule.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
/*jshint globalstrict: true*/
1+
/*jshint globalstrict: true */
22
/*jshint node: true */
33
/*jshint latedef: false */
4-
/*jshint unused:false*/
4+
/*jshint unused:false */
5+
/*jshint evil:true */
56
"use strict";
67

78
const fs = require('fs');
89
//save the original require
910
let originalRequire = require;
1011

11-
function loadModule(filename, module, require) {
12+
/**function loadModule(filename, module, require) {
1213
const wrappedSrc =
1314
`(function(module, exports, require) {
1415
${fs.readFileSync(filename, 'utf8')}
1516
})(module, module.exports, require);`;
1617
eval(wrappedSrc); // jshint ignore:line
18+
}**/
19+
20+
function loadModule(filename, module, require) {
21+
const load = new Function('module', 'exports', 'require',`${fs.readFileSync(filename, 'utf8')}`);
22+
load(module, module.exports, require);
1723
}
1824

1925
// We intentionally use var in the next line to avoid "SyntaxError: Identifier 'require' has already been declared"

0 commit comments

Comments
 (0)