Parse source into json for event.

pull/1/head
chriseth 8 years ago
parent cb05660b23
commit 6b10fccd04
  1. 8
      src/app/compiler.js

@ -52,7 +52,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
files[utils.fileNameFromKey(editor.getCacheFile())] = input; files[utils.fileNameFromKey(editor.getCacheFile())] = input;
gatherImports(files, missingInputs, function (input, error) { gatherImports(files, missingInputs, function (input, error) {
if (input === null) { if (input === null) {
self.event.trigger('compilationFinished', [false, [error], editor.getValue()]); self.event.trigger('compilationFinished', [false, [error], files]);
} else { } else {
var optimize = queryParams.get().optimize; var optimize = queryParams.get().optimize;
compileJSON(input, optimize ? 1 : 0); compileJSON(input, optimize ? 1 : 0);
@ -144,7 +144,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
function loadInternal (url) { function loadInternal (url) {
delete window.Module; delete window.Module;
// Set a safe fallback until the new one is loaded // Set a safe fallback until the new one is loaded
setCompileJSON(function (source, optimize) { compilationFinished('{}'); }); setCompileJSON(function (source, optimize) { compilationFinished({}); });
var newScript = document.createElement('script'); var newScript = document.createElement('script');
newScript.type = 'text/javascript'; newScript.type = 'text/javascript';
@ -173,12 +173,14 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
break; break;
case 'compiled': case 'compiled':
var result; var result;
var source;
try { try {
result = JSON.parse(data.data); result = JSON.parse(data.data);
source = JSON.parse(data.source);
} catch (exception) { } catch (exception) {
result = { 'error': 'Invalid JSON output from the compiler: ' + exception }; result = { 'error': 'Invalid JSON output from the compiler: ' + exception };
} }
compilationFinished(result, data.missingInputs, data.source); compilationFinished(result, data.missingInputs, source);
break; break;
} }
}); });

Loading…
Cancel
Save