Files
freeCodeCamp/client/new-framework/add-loop-protect.js

22 lines
670 B
JavaScript
Raw Normal View History

2016-05-06 13:20:18 -07:00
import loopProtect from 'loopProtect';
loopProtect.hit = function hit(line) {
var err = 'Error: Exiting potential infinite loop at line ' +
line +
'. To disable loop protection, write: \n\\/\\/ noprotect\nas the first' +
'line. Beware that if you do have an infinite loop in your code' +
'this will crash your browser.';
console.error(err);
};
// Observable[Observable[File]]::addLoopProtect() => Observable[String]
export default function addLoopProtect() {
const source = this;
return source.map(files$ => files$.map(file => {
if (file.extname === 'js') {
file.contents = loopProtect(file.contents);
}
return file;
}));
}