forked from sindresorhus/gulp-traceur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (37 loc) · 1.07 KB
/
index.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
44
45
46
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var applySourceMap = require('vinyl-sourcemaps-apply');
var objectAssign = require('object-assign');
var traceur = require('traceur');
module.exports = function (opts) {
var compiler = new traceur.NodeCompiler(objectAssign({modules: 'commonjs'}, opts));
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-traceur', 'Streaming not supported'));
return;
}
try {
var ret = compiler.compile(file.contents.toString(), file.relative, file.relative, file.base);
var sourceMap = file.sourceMap && compiler.getSourceMap();
if (ret) {
file.contents = new Buffer(ret);
}
if (sourceMap) {
applySourceMap(file, sourceMap);
}
this.push(file);
} catch (errs) {
this.emit('error', new gutil.PluginError('gulp-traceur', errs.join('\n'), {
fileName: file.path,
showStack: false
}));
}
cb();
});
};
module.exports.RUNTIME_PATH = traceur.RUNTIME_PATH;