baset-vm
Version:
VM package for BaseT project.
34 lines • 981 B
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const vm_1 = __importDefault(require("vm"));
class VMScript {
constructor(code, filename = 'vm.js') {
this.code = code;
this.filename = filename;
this.wrapped = false;
}
wrap(prefix, postfix) {
if (this.wrapped) {
return this;
}
this.code = prefix + this.code + postfix;
this.wrapped = true;
return this;
}
compile() {
if (this.compiled) {
return this.compiled;
}
const compiled = new vm_1.default.Script(this.code, {
filename: this.filename,
displayErrors: false,
});
this.compiled = compiled;
return compiled;
}
}
exports.VMScript = VMScript;
//# sourceMappingURL=VMScript.js.map