Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50663 views
1
// Generated by CoffeeScript 1.12.6
2
(function() {
3
var Lexer, SourceMap, base64encode, compile, ext, fn1, formatSourcePosition, fs, getSourceMap, helpers, i, len, lexer, packageJson, parser, path, ref, sourceMaps, sources, vm, withPrettyErrors,
4
hasProp = {}.hasOwnProperty;
5
6
fs = require('fs');
7
8
vm = require('vm');
9
10
path = require('path');
11
12
Lexer = require('./lexer').Lexer;
13
14
parser = require('./parser').parser;
15
16
helpers = require('./helpers');
17
18
SourceMap = require('./sourcemap');
19
20
packageJson = require('../../package.json');
21
22
exports.VERSION = packageJson.version;
23
24
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
25
26
exports.helpers = helpers;
27
28
base64encode = function(src) {
29
switch (false) {
30
case typeof Buffer !== 'function':
31
return new Buffer(src).toString('base64');
32
case typeof btoa !== 'function':
33
return btoa(encodeURIComponent(src).replace(/%([0-9A-F]{2})/g, function(match, p1) {
34
return String.fromCharCode('0x' + p1);
35
}));
36
default:
37
throw new Error('Unable to base64 encode inline sourcemap.');
38
}
39
};
40
41
withPrettyErrors = function(fn) {
42
return function(code, options) {
43
var err;
44
if (options == null) {
45
options = {};
46
}
47
try {
48
return fn.call(this, code, options);
49
} catch (error) {
50
err = error;
51
if (typeof code !== 'string') {
52
throw err;
53
}
54
throw helpers.updateSyntaxError(err, code, options.filename);
55
}
56
};
57
};
58
59
sources = {};
60
61
sourceMaps = {};
62
63
exports.compile = compile = withPrettyErrors(function(code, options) {
64
var currentColumn, currentLine, encoded, extend, filename, fragment, fragments, generateSourceMap, header, i, j, js, len, len1, map, merge, newLines, ref, ref1, sourceMapDataURI, sourceURL, token, tokens, v3SourceMap;
65
merge = helpers.merge, extend = helpers.extend;
66
options = extend({}, options);
67
generateSourceMap = options.sourceMap || options.inlineMap || (options.filename == null);
68
filename = options.filename || '<anonymous>';
69
sources[filename] = code;
70
if (generateSourceMap) {
71
map = new SourceMap;
72
}
73
tokens = lexer.tokenize(code, options);
74
options.referencedVars = (function() {
75
var i, len, results;
76
results = [];
77
for (i = 0, len = tokens.length; i < len; i++) {
78
token = tokens[i];
79
if (token[0] === 'IDENTIFIER') {
80
results.push(token[1]);
81
}
82
}
83
return results;
84
})();
85
if (!((options.bare != null) && options.bare === true)) {
86
for (i = 0, len = tokens.length; i < len; i++) {
87
token = tokens[i];
88
if ((ref = token[0]) === 'IMPORT' || ref === 'EXPORT') {
89
options.bare = true;
90
break;
91
}
92
}
93
}
94
fragments = parser.parse(tokens).compileToFragments(options);
95
currentLine = 0;
96
if (options.header) {
97
currentLine += 1;
98
}
99
if (options.shiftLine) {
100
currentLine += 1;
101
}
102
currentColumn = 0;
103
js = "";
104
for (j = 0, len1 = fragments.length; j < len1; j++) {
105
fragment = fragments[j];
106
if (generateSourceMap) {
107
if (fragment.locationData && !/^[;\s]*$/.test(fragment.code)) {
108
map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
109
noReplace: true
110
});
111
}
112
newLines = helpers.count(fragment.code, "\n");
113
currentLine += newLines;
114
if (newLines) {
115
currentColumn = fragment.code.length - (fragment.code.lastIndexOf("\n") + 1);
116
} else {
117
currentColumn += fragment.code.length;
118
}
119
}
120
js += fragment.code;
121
}
122
if (options.header) {
123
header = "Generated by CoffeeScript " + this.VERSION;
124
js = "// " + header + "\n" + js;
125
}
126
if (generateSourceMap) {
127
v3SourceMap = map.generate(options, code);
128
sourceMaps[filename] = map;
129
}
130
if (options.inlineMap) {
131
encoded = base64encode(JSON.stringify(v3SourceMap));
132
sourceMapDataURI = "//# sourceMappingURL=data:application/json;base64," + encoded;
133
sourceURL = "//# sourceURL=" + ((ref1 = options.filename) != null ? ref1 : 'coffeescript');
134
js = js + "\n" + sourceMapDataURI + "\n" + sourceURL;
135
}
136
if (options.sourceMap) {
137
return {
138
js: js,
139
sourceMap: map,
140
v3SourceMap: JSON.stringify(v3SourceMap, null, 2)
141
};
142
} else {
143
return js;
144
}
145
});
146
147
exports.tokens = withPrettyErrors(function(code, options) {
148
return lexer.tokenize(code, options);
149
});
150
151
exports.nodes = withPrettyErrors(function(source, options) {
152
if (typeof source === 'string') {
153
return parser.parse(lexer.tokenize(source, options));
154
} else {
155
return parser.parse(source);
156
}
157
});
158
159
exports.run = function(code, options) {
160
var answer, dir, mainModule, ref;
161
if (options == null) {
162
options = {};
163
}
164
mainModule = require.main;
165
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '<anonymous>';
166
mainModule.moduleCache && (mainModule.moduleCache = {});
167
dir = options.filename != null ? path.dirname(fs.realpathSync(options.filename)) : fs.realpathSync('.');
168
mainModule.paths = require('module')._nodeModulePaths(dir);
169
if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
170
answer = compile(code, options);
171
code = (ref = answer.js) != null ? ref : answer;
172
}
173
return mainModule._compile(code, mainModule.filename);
174
};
175
176
exports["eval"] = function(code, options) {
177
var Module, _module, _require, createContext, i, isContext, js, k, len, o, r, ref, ref1, ref2, ref3, sandbox, v;
178
if (options == null) {
179
options = {};
180
}
181
if (!(code = code.trim())) {
182
return;
183
}
184
createContext = (ref = vm.Script.createContext) != null ? ref : vm.createContext;
185
isContext = (ref1 = vm.isContext) != null ? ref1 : function(ctx) {
186
return options.sandbox instanceof createContext().constructor;
187
};
188
if (createContext) {
189
if (options.sandbox != null) {
190
if (isContext(options.sandbox)) {
191
sandbox = options.sandbox;
192
} else {
193
sandbox = createContext();
194
ref2 = options.sandbox;
195
for (k in ref2) {
196
if (!hasProp.call(ref2, k)) continue;
197
v = ref2[k];
198
sandbox[k] = v;
199
}
200
}
201
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox;
202
} else {
203
sandbox = global;
204
}
205
sandbox.__filename = options.filename || 'eval';
206
sandbox.__dirname = path.dirname(sandbox.__filename);
207
if (!(sandbox !== global || sandbox.module || sandbox.require)) {
208
Module = require('module');
209
sandbox.module = _module = new Module(options.modulename || 'eval');
210
sandbox.require = _require = function(path) {
211
return Module._load(path, _module, true);
212
};
213
_module.filename = sandbox.__filename;
214
ref3 = Object.getOwnPropertyNames(require);
215
for (i = 0, len = ref3.length; i < len; i++) {
216
r = ref3[i];
217
if (r !== 'paths' && r !== 'arguments' && r !== 'caller') {
218
_require[r] = require[r];
219
}
220
}
221
_require.paths = _module.paths = Module._nodeModulePaths(process.cwd());
222
_require.resolve = function(request) {
223
return Module._resolveFilename(request, _module);
224
};
225
}
226
}
227
o = {};
228
for (k in options) {
229
if (!hasProp.call(options, k)) continue;
230
v = options[k];
231
o[k] = v;
232
}
233
o.bare = true;
234
js = compile(code, o);
235
if (sandbox === global) {
236
return vm.runInThisContext(js);
237
} else {
238
return vm.runInContext(js, sandbox);
239
}
240
};
241
242
exports.register = function() {
243
return require('./register');
244
};
245
246
if (require.extensions) {
247
ref = this.FILE_EXTENSIONS;
248
fn1 = function(ext) {
249
var base;
250
return (base = require.extensions)[ext] != null ? base[ext] : base[ext] = function() {
251
throw new Error("Use CoffeeScript.register() or require the coffee-script/register module to require " + ext + " files.");
252
};
253
};
254
for (i = 0, len = ref.length; i < len; i++) {
255
ext = ref[i];
256
fn1(ext);
257
}
258
}
259
260
exports._compileFile = function(filename, sourceMap, inlineMap) {
261
var answer, err, raw, stripped;
262
if (sourceMap == null) {
263
sourceMap = false;
264
}
265
if (inlineMap == null) {
266
inlineMap = false;
267
}
268
raw = fs.readFileSync(filename, 'utf8');
269
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
270
try {
271
answer = compile(stripped, {
272
filename: filename,
273
sourceMap: sourceMap,
274
inlineMap: inlineMap,
275
sourceFiles: [filename],
276
literate: helpers.isLiterate(filename)
277
});
278
} catch (error) {
279
err = error;
280
throw helpers.updateSyntaxError(err, stripped, filename);
281
}
282
return answer;
283
};
284
285
lexer = new Lexer;
286
287
parser.lexer = {
288
lex: function() {
289
var tag, token;
290
token = parser.tokens[this.pos++];
291
if (token) {
292
tag = token[0], this.yytext = token[1], this.yylloc = token[2];
293
parser.errorToken = token.origin || token;
294
this.yylineno = this.yylloc.first_line;
295
} else {
296
tag = '';
297
}
298
return tag;
299
},
300
setInput: function(tokens) {
301
parser.tokens = tokens;
302
return this.pos = 0;
303
},
304
upcomingInput: function() {
305
return "";
306
}
307
};
308
309
parser.yy = require('./nodes');
310
311
parser.yy.parseError = function(message, arg) {
312
var errorLoc, errorTag, errorText, errorToken, token, tokens;
313
token = arg.token;
314
errorToken = parser.errorToken, tokens = parser.tokens;
315
errorTag = errorToken[0], errorText = errorToken[1], errorLoc = errorToken[2];
316
errorText = (function() {
317
switch (false) {
318
case errorToken !== tokens[tokens.length - 1]:
319
return 'end of input';
320
case errorTag !== 'INDENT' && errorTag !== 'OUTDENT':
321
return 'indentation';
322
case errorTag !== 'IDENTIFIER' && errorTag !== 'NUMBER' && errorTag !== 'INFINITY' && errorTag !== 'STRING' && errorTag !== 'STRING_START' && errorTag !== 'REGEX' && errorTag !== 'REGEX_START':
323
return errorTag.replace(/_START$/, '').toLowerCase();
324
default:
325
return helpers.nameWhitespaceCharacter(errorText);
326
}
327
})();
328
return helpers.throwSyntaxError("unexpected " + errorText, errorLoc);
329
};
330
331
formatSourcePosition = function(frame, getSourceMapping) {
332
var as, column, fileLocation, filename, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
333
filename = void 0;
334
fileLocation = '';
335
if (frame.isNative()) {
336
fileLocation = "native";
337
} else {
338
if (frame.isEval()) {
339
filename = frame.getScriptNameOrSourceURL();
340
if (!filename) {
341
fileLocation = (frame.getEvalOrigin()) + ", ";
342
}
343
} else {
344
filename = frame.getFileName();
345
}
346
filename || (filename = "<anonymous>");
347
line = frame.getLineNumber();
348
column = frame.getColumnNumber();
349
source = getSourceMapping(filename, line, column);
350
fileLocation = source ? filename + ":" + source[0] + ":" + source[1] : filename + ":" + line + ":" + column;
351
}
352
functionName = frame.getFunctionName();
353
isConstructor = frame.isConstructor();
354
isMethodCall = !(frame.isToplevel() || isConstructor);
355
if (isMethodCall) {
356
methodName = frame.getMethodName();
357
typeName = frame.getTypeName();
358
if (functionName) {
359
tp = as = '';
360
if (typeName && functionName.indexOf(typeName)) {
361
tp = typeName + ".";
362
}
363
if (methodName && functionName.indexOf("." + methodName) !== functionName.length - methodName.length - 1) {
364
as = " [as " + methodName + "]";
365
}
366
return "" + tp + functionName + as + " (" + fileLocation + ")";
367
} else {
368
return typeName + "." + (methodName || '<anonymous>') + " (" + fileLocation + ")";
369
}
370
} else if (isConstructor) {
371
return "new " + (functionName || '<anonymous>') + " (" + fileLocation + ")";
372
} else if (functionName) {
373
return functionName + " (" + fileLocation + ")";
374
} else {
375
return fileLocation;
376
}
377
};
378
379
getSourceMap = function(filename) {
380
var answer;
381
if (sourceMaps[filename] != null) {
382
return sourceMaps[filename];
383
} else if (sourceMaps['<anonymous>'] != null) {
384
return sourceMaps['<anonymous>'];
385
} else if (sources[filename] != null) {
386
answer = compile(sources[filename], {
387
filename: filename,
388
sourceMap: true,
389
literate: helpers.isLiterate(filename)
390
});
391
return answer.sourceMap;
392
} else {
393
return null;
394
}
395
};
396
397
Error.prepareStackTrace = function(err, stack) {
398
var frame, frames, getSourceMapping;
399
getSourceMapping = function(filename, line, column) {
400
var answer, sourceMap;
401
sourceMap = getSourceMap(filename);
402
if (sourceMap != null) {
403
answer = sourceMap.sourceLocation([line - 1, column - 1]);
404
}
405
if (answer != null) {
406
return [answer[0] + 1, answer[1] + 1];
407
} else {
408
return null;
409
}
410
};
411
frames = (function() {
412
var j, len1, results;
413
results = [];
414
for (j = 0, len1 = stack.length; j < len1; j++) {
415
frame = stack[j];
416
if (frame.getFunction() === exports.run) {
417
break;
418
}
419
results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));
420
}
421
return results;
422
})();
423
return (err.toString()) + "\n" + (frames.join('\n')) + "\n";
424
};
425
426
}).call(this);
427
428