-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (37 loc) · 1.15 KB
/
Copy pathindex.js
File metadata and controls
45 lines (37 loc) · 1.15 KB
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
/**
* index.js
* Version 0.3.0
* December 29th, 2016
*
* Copyright (c) 2016 Baptiste Augrain
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
**/
var _ = require('kaoscript')();
var fs = require('./fs.js');
var util = require('loader-utils');
var Compiler = _.Compiler;
var defaultTarget = parseInt(/^v(\d+)\./.exec(process.version)[1]) >= 6 ? 'ecma-v6' : 'ecma-v5';
module.exports = function(source) {
this.cacheable && this.cacheable();
var filename = util.getRemainingRequest(this);
var params = util.parseQuery(this.query);
if(params.register) {
var modules = params.register.split('+');
for(var i = 0; i < modules.length; i++) {
require(modules[i])(Compiler);
}
}
var target = params.target || defaultTarget;
if(fs.isFile(_.getBinaryPath(filename, target)) && fs.isFile(_.getHashPath(filename, target)) && _.isUpToDate(filename, target, source)) {
this.callback(null, fs.readFile(_.getBinaryPath(filename, target)));
}
else {
var compiler = new Compiler(filename, {
register: false,
target: target
});
compiler.compile(source);
this.callback(null, compiler.toSource());
}
};