fixing linting errors

This commit is contained in:
Lauren McCarthy 2016-08-28 09:52:57 -04:00
parent 402e9bc95e
commit f936d98f76
2 changed files with 27 additions and 17 deletions

View file

@ -65,7 +65,8 @@ function Nav(props) {
</p> </p>
</li> </li>
); );
} else { }
if (!props.user.authenticated) {
return ( return (
<li className="nav__item"> <li className="nav__item">
<p className="nav__open"> <p className="nav__open">

View file

@ -3,20 +3,26 @@ import ReactDOM from 'react-dom';
import escapeStringRegexp from 'escape-string-regexp'; import escapeStringRegexp from 'escape-string-regexp';
import srcDoc from 'srcdoc-polyfill'; import srcDoc from 'srcdoc-polyfill';
const startTag = 'filestart-';
function getAllScriptOffsets(htmlFile) { function getAllScriptOffsets(htmlFile) {
var offs = []; const offs = [];
var found = true; let found = true;
var lastInd = 0; let lastInd = 0;
var startTag = 'filestart-'; let ind = 0;
let endFilenameInd = 0;
let filename = '';
let lineOffset = 0;
while (found) { while (found) {
var ind = htmlFile.indexOf(startTag, lastInd); ind = htmlFile.indexOf(startTag, lastInd);
if (ind == -1) { if (ind === -1) {
found = false; found = false;
} else { } else {
var endFilenameInd = htmlFile.indexOf('.js', ind+startTag.length); endFilenameInd = htmlFile.indexOf('.js', ind + startTag.length + 3);
var filename = htmlFile.substring(ind+startTag.length, endFilenameInd); filename = htmlFile.substring(ind + startTag.length, endFilenameInd);
var lineOffset = htmlFile.substring(0, ind).split('\n').length; lineOffset = htmlFile.substring(0, ind).split('\n').length;
offs.push([lineOffset, filename+'.js']); offs.push([lineOffset, filename]);
lastInd = ind + 1; lastInd = ind + 1;
} }
} }
@ -24,10 +30,9 @@ function getAllScriptOffsets(htmlFile) {
} }
function hijackConsoleScript(offs) { function hijackConsoleScript(offs) {
return `<script> const s = `<script>
function getScriptOff(line) { function getScriptOff(line) {
var offs = `+offs+`; var offs = ${offs};
var l = 0; var l = 0;
var file = ''; var file = '';
for (var i=0; i<offs.length; i++) { for (var i=0; i<offs.length; i++) {
@ -90,6 +95,7 @@ function hijackConsoleScript(offs) {
}; };
}); });
</script>`; </script>`;
return s;
} }
class PreviewFrame extends React.Component { class PreviewFrame extends React.Component {
@ -134,6 +140,7 @@ class PreviewFrame extends React.Component {
injectLocalFiles() { injectLocalFiles() {
let htmlFile = this.props.htmlFile.content; let htmlFile = this.props.htmlFile.content;
let scriptOffs = [];
// have to build the array manually because the spread operator is only // have to build the array manually because the spread operator is only
// one level down... // one level down...
@ -141,9 +148,10 @@ class PreviewFrame extends React.Component {
this.props.jsFiles.forEach(jsFile => { this.props.jsFiles.forEach(jsFile => {
const newJSFile = { ...jsFile }; const newJSFile = { ...jsFile };
let jsFileStrings = newJSFile.content.match(/(['"])((\\\1|.)*?)\1/gm); let jsFileStrings = newJSFile.content.match(/(['"])((\\\1|.)*?)\1/gm);
const jsFileRegex = /^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json)('|")$/i;
jsFileStrings = jsFileStrings || []; jsFileStrings = jsFileStrings || [];
jsFileStrings.forEach(jsFileString => { jsFileStrings.forEach(jsFileString => {
if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json)('|")$/i)) { if (jsFileString.match(jsFileRegex)) {
const filePath = jsFileString.substr(1, jsFileString.length - 2); const filePath = jsFileString.substr(1, jsFileString.length - 2);
let fileName = filePath; let fileName = filePath;
if (fileName.match(/^\.\//)) { if (fileName.match(/^\.\//)) {
@ -164,7 +172,8 @@ class PreviewFrame extends React.Component {
jsFiles.forEach(jsFile => { jsFiles.forEach(jsFile => {
const fileName = escapeStringRegexp(jsFile.name); const fileName = escapeStringRegexp(jsFile.name);
const fileRegex = new RegExp(`<script.*?src=('|")((\.\/)|\/)?${fileName}('|").*?>([\s\S]*?)<\/script>`, 'gmi'); const fileRegex = new RegExp(`<script.*?src=('|")((\.\/)|\/)?${fileName}('|").*?>([\s\S]*?)<\/script>`, 'gmi');
htmlFile = htmlFile.replace(fileRegex, `<script data-tag="filestart-`+jsFile.name+`">\n${jsFile.content}\n</script>`); const replacementString = `<script data-tag="${startTag}${jsFile.name}">\n${jsFile.content}\n</script>`;
htmlFile = htmlFile.replace(fileRegex, replacementString);
}); });
this.props.cssFiles.forEach(cssFile => { this.props.cssFiles.forEach(cssFile => {
@ -185,7 +194,7 @@ class PreviewFrame extends React.Component {
htmlFile = htmlFile.replace(/(?:<head.*?>)([\s\S]*?)(?:<\/head>)/gmi, `<head>\n${htmlHeadContents}\n</head>`); htmlFile = htmlFile.replace(/(?:<head.*?>)([\s\S]*?)(?:<\/head>)/gmi, `<head>\n${htmlHeadContents}\n</head>`);
} }
var scriptOffs = getAllScriptOffsets(htmlFile); scriptOffs = getAllScriptOffsets(htmlFile);
htmlFile += hijackConsoleScript(JSON.stringify(scriptOffs)); htmlFile += hijackConsoleScript(JSON.stringify(scriptOffs));
return htmlFile; return htmlFile;