From 766a41b41fe22e3874ae618e6a50fce4ce9a6385 Mon Sep 17 00:00:00 2001 From: Matthew Bloch Date: Sun, 27 May 2018 14:49:59 -0400 Subject: [PATCH] Readability --- src/commands/mapshaper-include.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/commands/mapshaper-include.js b/src/commands/mapshaper-include.js index dffeba430..d3b338f30 100644 --- a/src/commands/mapshaper-include.js +++ b/src/commands/mapshaper-include.js @@ -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"); @@ -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); @@ -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; -};