untitled notebook

node v8.9.4
version: 1.0.0
endpointsharetweet
const babel = require("babel-core");
const File = require("babel-core/lib/transformation/file").File; const pedanticSecurityCheck = source => { const matches = source.match(/BAD/g); const children = matches && matches.map(match => new SecuritySyntaxError({ message: match })); if (children) return new SecuritySyntaxError({ children }); return null; } function SecuritySyntaxError({ children, message }) { this.message = message; this.children = children; this.toString = function () { if (this.children) return "Multiple Security Errors: " + this.children; return "Security Error:" + message; } } function secureParse(self, insecureParse, args) { var source = args[0]; var pedanticSecurityError = pedanticSecurityCheck(source); try { const result = insecureParse.apply(this, arguments); result.program.pedanticSecurityError = pedanticSecurityError; return result; } catch (e) { if (pedanticSecurityError) throw pedanticSecurityError; throw e; } } babel.transform("BAD BAD BAD", { plugins:[ function ({ File }) { if (File.__RunKitModified) return; const FileParse = File.prototype.parse; File.__RunKitModified = true; File.prototype.parse = function () { return secureParse(this, FileParse, arguments); } return { visitor: { Program: { enter: function (path, state) { state.metadata = { }; }, exit: function (path, state) { if (state.metadata.errors) throw new Error("NORMAL"); if (path.node.pedanticSecurityError) throw pedanticSecurityError; } } } } } ] }),0; /*{ manipulateOptions(opts, parserOpts) { console.log("MANIPULATE PROPERTIES"); //console.log("IN HERE") //console.log(parserOpts); opts.parser = () => { console.log("YES!") }; parserOpts.parser = () => { console.log("YES!") } console.log(new Error().stack+"") //console.log(opts); return parserOpts; } }*/
Loading…

no comments

    sign in to comment