Merge branch 'syntax-errors' of https://github.com/boazsender/p5.js-web-editor into boazsender-syntax-errors

This commit is contained in:
Cassie Tarakajian 2017-10-30 17:48:40 -04:00
commit a043dc16fe

View file

@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
import srcDoc from 'srcdoc-polyfill';
import loopProtect from 'loop-protect';
import { JSHINT } from 'jshint';
import { getBlobUrl } from '../actions/files';
import { resolvePathToFile } from '../../../../server/utils/filePath';
@ -161,6 +162,22 @@ class PreviewFrame extends React.Component {
});
}
jsPreprocess(sketchDoc) {
let newContent = sketchDoc;
// check the code for js errors before sending it to strip comments
// or loops.
JSHINT(newContent);
if (!JSHINT.errors) {
newContent = decomment(newContent, {
ignore: /noprotect/g,
space: true
});
newContent = loopProtect(newContent);
}
return newContent;
}
injectLocalFiles() {
const htmlFile = this.props.htmlFile.content;
let scriptOffs = [];
@ -289,12 +306,8 @@ class PreviewFrame extends React.Component {
}
}
});
newContent = decomment(newContent, {
ignore: /noprotect/g,
space: true
});
newContent = loopProtect(newContent);
return newContent;
return this.jsPreprocess(newContent);
}
resolveCSSLinksInString(content, files) {