"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var guardKeys = ["window", "document"];
exports.evalWithScope = function (js, scope, options) {
    var e_1, _a;
    if (options === void 0) { options = {}; }
    var scopeString = Object.getOwnPropertyNames(scope).reduce(function (str, name) {
        str += "var " + name + " = scope[\"" + name + "\"];";
        return str;
    }, "");
    if (options.guard) {
        try {
            for (var guardKeys_1 = tslib_1.__values(guardKeys), guardKeys_1_1 = guardKeys_1.next(); !guardKeys_1_1.done; guardKeys_1_1 = guardKeys_1.next()) {
                var key = guardKeys_1_1.value;
                if (!scope[key]) {
                    scopeString += "var " + key + " = undefined;";
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (guardKeys_1_1 && !guardKeys_1_1.done && (_a = guardKeys_1.return)) _a.call(guardKeys_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
    }
    scopeString += "var evalWithScope = undefined;";
    return eval(scopeString + js);
};
