Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50640 views
1
/*
2
MIT License http://www.opensource.org/licenses/mit-license.php
3
Author Tobias Koppers @sokra
4
*/
5
var coffee = require("coffee-script");
6
var loaderUtils = require("loader-utils");
7
module.exports = function(source) {
8
this.cacheable && this.cacheable();
9
var coffeeRequest = loaderUtils.getRemainingRequest(this);
10
var jsRequest = loaderUtils.getCurrentRequest(this);
11
var query = loaderUtils.getOptions(this) || {};
12
var result;
13
try {
14
result = coffee.compile(source, {
15
literate: query.literate,
16
filename: coffeeRequest,
17
debug: this.debug,
18
bare: true,
19
sourceMap: true,
20
sourceRoot: "",
21
sourceFiles: [coffeeRequest],
22
generatedFile: jsRequest
23
});
24
} catch (e) {
25
var err = "";
26
if (e.location == null || e.location.first_column == null || e.location.first_line == null) {
27
err += "Got an unexpected exception from the coffee-script compiler. The original exception was: " + e + "\n";
28
err += "(The coffee-script compiler should not raise *unexpected* exceptions. You can file this error as an issue of the coffee-script compiler: https://github.com/jashkenas/coffee-script/issues)\n";
29
} else {
30
var codeLine = source.split("\n")[e.location.first_line];
31
var offendingCharacter = (e.location.first_column < codeLine.length) ? codeLine[e.location.first_column] : "";
32
err += e + "\n";
33
// log erroneous line and highlight offending character
34
err += " L" + e.location.first_line + ": " + codeLine.substring(0, e.location.first_column) + offendingCharacter + codeLine.substring(e.location.first_column + 1) + "\n";
35
err += " " + (new Array(e.location.first_column + 1).join(" ")) + "^\n";
36
}
37
throw new Error(err);
38
}
39
var map = JSON.parse(result.v3SourceMap);
40
map.sourcesContent = [source];
41
this.callback(null, result.js, map);
42
}
43
44