forked from postcss/autoprefixer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enable-es6.js
30 lines (25 loc) · 989 Bytes
/
enable-es6.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
var es6tr = require('es6-transpiler');
var fs = require('fs');
var origin = require.extensions['.js'];
require.extensions['.js'] = function(module, file) {
var isLib = file.indexOf(__dirname + '/binary.js') != -1;
var isTest = file.indexOf(__dirname + '/test') != -1;
var isBench = file.indexOf(__dirname + '/benchmark') != -1;
if ( isLib || isTest || isBench ) {
var opts = { filename: file, includePolyfills: true };
if ( isTest ) {
opts.disallowUnknownReferences = false;
}
var result = es6tr.run(opts);
if ( result.errors.length ) {
process.stderr.write("Can't compile " + file + ": \n\n");
for ( var i = 0; i < result.errors.length; i++ ) {
process.stderr.write(result.errors[i] + "\n");
}
process.exit(-1);
}
return module._compile(result.src, file);
} else {
return origin.apply(this, arguments);
}
};