Skip to content

Commit

Permalink
Readability
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed May 27, 2018
1 parent a71d9d4 commit 766a41b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/commands/mapshaper-include.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* @requires mapshaper-cli-utils, mapshaper-expressions */

internal.include = function(opts) {
var ctx = internal.getIncludeContext();
var content, obj;
var content, obj, context;
// TODO: handle web context
if (!opts.file) {
stop("Missing name of a JS file to load");
Expand All @@ -18,7 +17,9 @@ internal.include = function(opts) {
// Try to isolate the imported JS code from the program scope and global environment
// TODO: consider whether this is desirable... it may be pointless anyway
// as long as we're passing through the 'require()' function
obj = Function('ctx', 'with(ctx) {return (' + content + ');}').call({}, ctx);
context = internal.getBaseContext();
context.require = require;
obj = Function('ctx', 'with(ctx) {return (' + content + ');}').call({}, context);
// obj = eval('(' + content + ')');
} catch(e) {
stop(e.name, 'in JS source:', e.message);
Expand All @@ -30,9 +31,3 @@ internal.include = function(opts) {

utils.extend(internal.getStateVar('defs'), obj);
};

internal.getIncludeContext = function() {
var ctx = internal.getBaseContext();
ctx.require = require;
return ctx;
};

0 comments on commit 766a41b

Please sign in to comment.