-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
compile.js
43 lines (34 loc) · 1.12 KB
/
compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
var Compiler = require('traceur').NodeCompiler
, xtend = require('xtend')
;
var traceurOptions = {
modules : 'commonjs',
sourceMaps : 'inline'
};
function buildTraceurOptions(overrides) {
var options = xtend(traceurOptions, overrides);
if (typeof options.sourceMap !== 'undefined') {
console.warn('es6ify: DEPRECATED traceurOverrides.sourceMap has changed to traceurOverrides.sourceMaps (plural)');
options.sourceMaps = options.sourceMap;
delete options.sourceMap;
}
if (options.sourceMaps === true) {
console.warn('es6ify: DEPRECATED "traceurOverrides.sourceMaps = true" is not a valid option, traceur sourceMaps options are [false|inline|file]');
options.sourceMaps = 'inline';
}
return options;
}
exports = module.exports = function compileFile(file, contents, traceurOverrides) {
var options = buildTraceurOptions(traceurOverrides);
try{
var compiler = new Compiler(options);
var result = compiler.compile(contents, file, file);
}catch(errors){
return { source: null, error: errors[0] };
}
return {
source: result,
error: null
};
};