mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-18 15:18:04 +00:00
29 lines
722 B
JavaScript
29 lines
722 B
JavaScript
'use strict';
|
|
|
|
var path = require('path');
|
|
var root = path.resolve(path.join(__dirname, '../../'));
|
|
var coffee = require(root + '/public/js/vendor/coffee-script').CoffeeScript;
|
|
|
|
module.exports = function (data) {
|
|
return new Promise(function (resolve) {
|
|
try {
|
|
var res = coffee.compile(data.source);
|
|
resolve({
|
|
errors: null,
|
|
result: res
|
|
});
|
|
} catch (e) {
|
|
// index starts at 0
|
|
var errors = {
|
|
line: parseInt(e.location.first_line, 10) || 0, // jshint ignore: line
|
|
ch: parseInt(e.location.first_column, 10) || 0, // jshint ignore: line
|
|
msg: e.message
|
|
};
|
|
resolve({
|
|
errors: [errors],
|
|
result: null
|
|
});
|
|
}
|
|
});
|
|
};
|