Merge branch 'boazsender-syntax-errors'
This commit is contained in:
commit
3aafc0651d
1 changed files with 20 additions and 7 deletions
|
@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
|
||||||
import srcDoc from 'srcdoc-polyfill';
|
import srcDoc from 'srcdoc-polyfill';
|
||||||
|
|
||||||
import loopProtect from 'loop-protect';
|
import loopProtect from 'loop-protect';
|
||||||
|
import { JSHINT } from 'jshint';
|
||||||
import { getBlobUrl } from '../actions/files';
|
import { getBlobUrl } from '../actions/files';
|
||||||
import { resolvePathToFile } from '../../../../server/utils/filePath';
|
import { resolvePathToFile } from '../../../../server/utils/filePath';
|
||||||
|
|
||||||
|
@ -157,10 +158,26 @@ class PreviewFrame extends React.Component {
|
||||||
const scriptsInHTML = sketchDoc.getElementsByTagName('script');
|
const scriptsInHTML = sketchDoc.getElementsByTagName('script');
|
||||||
const scriptsInHTMLArray = Array.prototype.slice.call(scriptsInHTML);
|
const scriptsInHTMLArray = Array.prototype.slice.call(scriptsInHTML);
|
||||||
scriptsInHTMLArray.forEach((script) => {
|
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() {
|
injectLocalFiles() {
|
||||||
const htmlFile = this.props.htmlFile.content;
|
const htmlFile = this.props.htmlFile.content;
|
||||||
let scriptOffs = [];
|
let scriptOffs = [];
|
||||||
|
@ -289,12 +306,8 @@ class PreviewFrame extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
newContent = decomment(newContent, {
|
|
||||||
ignore: /noprotect/g,
|
return this.jsPreprocess(newContent);
|
||||||
space: true
|
|
||||||
});
|
|
||||||
newContent = loopProtect(newContent);
|
|
||||||
return newContent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveCSSLinksInString(content, files) {
|
resolveCSSLinksInString(content, files) {
|
||||||
|
|
Loading…
Reference in a new issue