Skip to content

Commit

Permalink
Better support for Traceur. Nearly there ref #266
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Jul 27, 2012
1 parent f2b116d commit 9d162a8
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions public/js/processors/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,67 @@ var processors = jsbin.processors = {
return css;
});
},
traceur: function () {
jsbin.panels.panels.javascript.type = 'traceur';
traceur: function (ready) {
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var doc = iframe.contentDocument,
win = iframe.contentWindow,
callback = function (source) { console.log("Traceur not ready yet"); return source; },
log = function () {
if (jsbin.panels.panels.console.visible) {
window._console.log.apply(window._console, arguments);
} else {
window.console.log.apply(window.console, arguments);
}
};

iframe.onload = function () {
console.log('iframe load event');
// return;
iframe.parentNode.removeChild(iframe);
var traceur = win.traceur;
var ProjectWriter = traceur.outputgeneration.ProjectWriter;
var ErrorReporter = traceur.util.ErrorReporter;

var reporter = new ErrorReporter();
reporter.reportMessageInternal = function(location, kind, format, args) {
log(ErrorReporter.format(location, format, args));
};

callback = function (contents) {
var project = new traceur.semantics.symbols.Project(jsbin.getURL());
var name = 'jsbin';
var sourceFile = new traceur.syntax.SourceFile(name, contents);
project.addFile(sourceFile);
var res = traceur.codegeneration.Compiler.compile(reporter, project, false);

if (reporter.hadError()) {
// do nothing?
console.log('errors')
return '';
} else {
var options;
// console.log('it is ok', ProjectWriter.write(res, options))
return ProjectWriter.write(res, options);
}
};
ready && ready();
};

iframe.style.display = 'none';

doc.open();
doc.write('<' + 'body><' + 'script src="http://traceur-compiler.googlecode.com/git/src/traceur.js"><' + '/script><' + 'script src="http://traceur-compiler.googlecode.com/git/src/bootstrap.js"><' + '/script>');
doc.close();

// jsbin.panels.panels.javascript.type = 'traceur';

// force select the traceur in the client HTML
$('#library').val( $('#library').find(':contains("Traceur")').val() ).trigger('change');
ready();
return function (source) { return source; };

return function () {
return callback.apply(this, arguments);
};
}
};

Expand Down

0 comments on commit 9d162a8

Please sign in to comment.