From 8e63b3204db1b5e86ab6be0107f58368c5330691 Mon Sep 17 00:00:00 2001 From: Boaz Sender Date: Sat, 21 Oct 2017 17:22:16 -0400 Subject: [PATCH 1/2] resolves behavior in #428 where syntax errors in auto refresh mode are unrecoverable --- client/modules/IDE/components/PreviewFrame.jsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/modules/IDE/components/PreviewFrame.jsx b/client/modules/IDE/components/PreviewFrame.jsx index 5627a7a9..2dc3904a 100644 --- a/client/modules/IDE/components/PreviewFrame.jsx +++ b/client/modules/IDE/components/PreviewFrame.jsx @@ -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'; @@ -289,11 +290,18 @@ class PreviewFrame extends React.Component { } } }); - newContent = decomment(newContent, { - ignore: /noprotect/g, - space: true - }); - newContent = loopProtect(newContent); + + // 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; } From a69cf8b916a6a711f061802325ba3681a72735b6 Mon Sep 17 00:00:00 2001 From: Boaz Sender Date: Thu, 26 Oct 2017 13:48:01 -0400 Subject: [PATCH 2/2] make syntax error checking more reusable per feedback from @catarak --- .../modules/IDE/components/PreviewFrame.jsx | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/client/modules/IDE/components/PreviewFrame.jsx b/client/modules/IDE/components/PreviewFrame.jsx index 2dc3904a..594e5bfd 100644 --- a/client/modules/IDE/components/PreviewFrame.jsx +++ b/client/modules/IDE/components/PreviewFrame.jsx @@ -162,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 = []; @@ -291,18 +307,7 @@ class PreviewFrame extends React.Component { } }); - // 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; + return this.jsPreprocess(newContent); } resolveCSSLinksInString(content, files) {