Remy Sharp bfac12e53d chore: es6 upgrade check in
Complete package upgrades for node 7 compat
2017-04-22 15:28:56 +01:00

37 lines
790 B
JavaScript

'use strict';
var path = require('path');
var root = path.resolve(path.join(__dirname, '../../'));
var jsx = require(root + '/public/js/vendor/JSXTransformer');
module.exports = function(data) {
return new Promise(function (resolve) {
try {
var res = jsx.transform(data.source).code;
resolve({
errors: null,
result: res
});
} catch (e) {
// index starts at 1
var line = parseInt(e.lineNumber, 10) || 0;
var ch = parseInt(e.column, 10) || 0;
if (line > 0) {
line = line - 1;
}
if (ch > 0) {
ch = ch - 1;
}
var errors = {
line: line,
ch: ch,
msg: e.description
};
resolve({
errors: [errors],
result: null
});
}
});
};