From 402e9bc95e1d15f0075afa7e0cdd83cc7a475464 Mon Sep 17 00:00:00 2001 From: Lauren McCarthy Date: Sat, 27 Aug 2016 13:54:20 -0400 Subject: [PATCH] fixes line numbers closes #36 --- client/modules/IDE/components/PreviewFrame.js | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/client/modules/IDE/components/PreviewFrame.js b/client/modules/IDE/components/PreviewFrame.js index 9d505e51..228c5f8d 100644 --- a/client/modules/IDE/components/PreviewFrame.js +++ b/client/modules/IDE/components/PreviewFrame.js @@ -3,28 +3,44 @@ import ReactDOM from 'react-dom'; import escapeStringRegexp from 'escape-string-regexp'; import srcDoc from 'srcdoc-polyfill'; - -/** - * Stringify all of the console objects from an array for proxying - */ -function stringifyArgs(args) { - var newArgs = []; - // TODO this was forEach but when the array is [undefined] it wouldn't - // iterate over them - var i = 0, length = args.length, arg; - for(; i < length; i++) { - arg = args[i]; - if (typeof arg === 'undefined') { - newArgs.push('undefined'); +function getAllScriptOffsets(htmlFile) { + var offs = []; + var found = true; + var lastInd = 0; + var startTag = 'filestart-'; + while (found) { + var ind = htmlFile.indexOf(startTag, lastInd); + if (ind == -1) { + found = false; } else { - newArgs.push(stringify(arg)); + var endFilenameInd = htmlFile.indexOf('.js', ind+startTag.length); + var filename = htmlFile.substring(ind+startTag.length, endFilenameInd); + var lineOffset = htmlFile.substring(0, ind).split('\n').length; + offs.push([lineOffset, filename+'.js']); + lastInd = ind + 1; } } - return newArgs; -}; + return offs; +} -function hijackConsoleScript(lineOffset) { +function hijackConsoleScript(offs) { return ``); + htmlFile = htmlFile.replace(fileRegex, ``); }); this.props.cssFiles.forEach(cssFile => { @@ -165,10 +185,8 @@ class PreviewFrame extends React.Component { htmlFile = htmlFile.replace(/(?:)([\s\S]*?)(?:<\/head>)/gmi, `\n${htmlHeadContents}\n`); } - var lineOffset = htmlFile.substring(0, htmlFile.indexOf('