forked from gkz/LiveScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.js
More file actions
101 lines (101 loc) · 2.87 KB
/
node.js
File metadata and controls
101 lines (101 loc) · 2.87 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Generated by LiveScript 1.5.0
module.exports = function(LiveScript){
var fs, path, events;
fs = require('fs');
path = require('path');
events = require('events');
LiveScript.run = function(code, options, arg$){
var filename, ref$, js, context, main, dirname, that, e;
if (options != null) {
filename = options.filename;
}
ref$ = arg$ != null
? arg$
: {}, js = ref$.js, context = ref$.context;
main = require.main;
dirname = filename
? path.dirname(fs.realpathSync(filename = path.resolve(filename)))
: filename = '.';
main.paths = main.constructor._nodeModulePaths(dirname);
main.filename = filename;
if (!js) {
code = LiveScript.compile(code, (ref$ = {}, import$(ref$, options), ref$.bare = true, ref$));
if (that = code.code) {
code = that;
}
}
if (context) {
global.__runContext = context;
code = "return (function() {\n" + code + "\n}).call(global.__runContext);";
}
filename += '(js)';
try {
return main._compile(code, filename);
} catch (e$) {
e = e$;
throw hackTrace(e, code, filename);
}
};
importAll$(LiveScript, events.EventEmitter.prototype);
require.extensions['.ls'] = function(module, filename){
var file, js, e;
file = fs.readFileSync(filename, 'utf8');
js = '.json.ls' === filename.substr(-8)
? 'module.exports = ' + LiveScript.compile(file, {
filename: filename,
json: true
})
: LiveScript.compile(file, {
filename: filename,
bare: true,
map: "embedded"
}).code;
try {
return module._compile(js, filename);
} catch (e$) {
e = e$;
throw hackTrace(e, js, filename);
}
};
};
function hackTrace(error, js, filename){
var stack, traces, i$, len$, i, trace, index, lno, end, length, lines, j$, ref$, n;
if (error != null) {
stack = error.stack;
}
if (!stack) {
return error;
}
traces = stack.split('\n');
if (!(traces.length > 1)) {
return error;
}
for (i$ = 0, len$ = traces.length; i$ < len$; ++i$) {
i = i$;
trace = traces[i$];
if (0 > (index = trace.indexOf("(" + filename + ":"))) {
continue;
}
lno = (/:(\d+):/.exec(trace.slice(index + filename.length)) || '')[1];
if (!(lno = +lno)) {
continue;
}
end = lno + 4;
length = ('' + end).length;
lines || (lines = js.split('\n'));
for (j$ = 1 > (ref$ = lno - 4) ? 1 : ref$; j$ <= end; ++j$) {
n = j$;
traces[i] += "\n" + (' ' + n).slice(-length) + "" + '|+'.charAt(n === lno) + " " + [lines[n - 1]];
}
}
return error.stack = traces.join('\n'), error;
}
function import$(obj, src){
var own = {}.hasOwnProperty;
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
return obj;
}
function importAll$(obj, src){
for (var key in src) obj[key] = src[key];
return obj;
}