jsbin/lib/processors/coffeescript.js
Remy Sharp bfac12e53d chore: es6 upgrade check in
Complete package upgrades for node 7 compat
2017-04-22 15:28:56 +01:00

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
});
}
});
};