disallow let and modules in babel-node REPL

This commit is contained in:
Sebastian McKenzie 2015-08-09 20:37:18 +01:00
parent d3a73b87e9
commit 34bc8b0aea

View File

@ -38,6 +38,22 @@ babel.register({
// //
var replPlugin = new babel.Plugin("repl", {
visitor: {
ModuleDeclaration() {
throw this.errorWithNode("Modules aren't supported in the REPL");
},
VariableDeclaration(node) {
if (node.kind !== "var") {
throw this.errorWithNode("Only `var` variables are supported in the REPL");
}
}
}
});
//
var _eval = function (code, filename) { var _eval = function (code, filename) {
code = code.trim(); code = code.trim();
if (!code) return undefined; if (!code) return undefined;
@ -47,7 +63,8 @@ var _eval = function (code, filename) {
blacklist: program.blacklist, blacklist: program.blacklist,
whitelist: program.whitelist, whitelist: program.whitelist,
optional: program.optional, optional: program.optional,
stage: program.stage stage: program.stage,
plugins: [replPlugin]
}).code; }).code;
return vm.runInThisContext(code, { return vm.runInThisContext(code, {