Merge branch 'boazsender-syntax-errors'

This commit is contained in:
Cassie Tarakajian 2017-11-01 16:48:58 -04:00
commit 3aafc0651d

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';
@ -157,10 +158,26 @@ class PreviewFrame extends React.Component {
const scriptsInHTML = sketchDoc.getElementsByTagName('script');
const scriptsInHTMLArray = Array.prototype.slice.call(scriptsInHTML);
scriptsInHTMLArray.forEach((script) => {
script.innerHTML = loopProtect(script.innerHTML); // eslint-disable-line
script.innerHTML = this.jsPreprocess(script.innerHTML); // eslint-disable-line
});
}
jsPreprocess(jsText) {
let newContent = jsText;
// 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) {