It appears that receiving the second argument is broken with 7.0.0-rc3.
const Babel = require('@babel/standalone');
const protect = require('loop-protect');
const userCode = 'while(true) { console.log("loop") }';
const timeout = 100; // defaults to 100ms
const x = (line) => {
throw new Error(`Bad loop on line ${line}`);
};
Babel.registerPlugin('loopProtection', protect(timeout, x));
const transform = source => Babel.transform(source, {
plugins: ['loopProtection'],
}).code;
// rewrite the user's JavaScript to protect loops
var processed = transform(userCode);
console.log(processed);
returns:
/Work/node_modules/@babel/standalone/babel.js:95063
throw e;
^
TypeError: [BABEL] unknown: Cannot read property 'program' of null (While processing: "base$0")
at /Work/node_modules/loop-protect/dist/index.js:69:44
at /Work/node_modules/@babel/standalone/babel.js:95096:14
It appears that receiving the second argument is broken with 7.0.0-rc3.
returns: