2013-03-18 01:06:33 -04:00
|
|
|
// Generated by CoffeeScript 1.6.2
|
2010-07-24 11:31:43 -04:00
|
|
|
(function() {
|
2013-03-18 07:23:05 -04:00
|
|
|
var Lexer, SourceMap, child_process, compile, ext, fork, formatSourcePosition, fs, helpers, lexer, loadFile, parser, patchStackTrace, patched, path, vm, _i, _len, _ref,
|
2012-01-10 17:00:06 -05:00
|
|
|
__hasProp = {}.hasOwnProperty;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-24 14:19:47 -04:00
|
|
|
fs = require('fs');
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-17 23:46:54 -04:00
|
|
|
vm = require('vm');
|
|
|
|
|
2010-09-21 05:19:49 -04:00
|
|
|
path = require('path');
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-02-28 20:51:55 -05:00
|
|
|
child_process = require('child_process');
|
|
|
|
|
2012-09-25 19:01:16 -04:00
|
|
|
Lexer = require('./lexer').Lexer;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-09-28 16:47:12 -04:00
|
|
|
parser = require('./parser').parser;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-02-27 21:54:17 -05:00
|
|
|
helpers = require('./helpers');
|
2013-02-28 15:51:29 -05:00
|
|
|
|
2013-03-18 07:23:05 -04:00
|
|
|
SourceMap = require('./sourcemap');
|
2012-09-25 19:01:16 -04:00
|
|
|
|
2013-03-18 01:06:33 -04:00
|
|
|
exports.VERSION = '1.6.2';
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-04 16:40:39 -05:00
|
|
|
exports.helpers = helpers;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-20 13:29:06 -04:00
|
|
|
exports.compile = compile = function(code, options) {
|
2013-03-18 07:23:05 -04:00
|
|
|
var answer, currentColumn, currentLine, fragment, fragments, header, js, map, merge, newLines, _i, _len;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
2013-04-27 18:56:44 -04:00
|
|
|
merge = helpers.merge;
|
2013-03-04 21:37:36 -05:00
|
|
|
if (options.sourceMap) {
|
2013-03-18 07:23:05 -04:00
|
|
|
map = new SourceMap;
|
2013-03-04 21:37:36 -05:00
|
|
|
}
|
2013-04-27 18:56:44 -04:00
|
|
|
fragments = parser.parse(lexer.tokenize(code, options)).compileToFragments(options);
|
2013-03-04 21:37:36 -05:00
|
|
|
currentLine = 0;
|
2013-03-25 13:56:24 -04:00
|
|
|
if (options.header) {
|
|
|
|
currentLine += 1;
|
|
|
|
}
|
|
|
|
if (options.shiftLine) {
|
2013-03-04 21:37:36 -05:00
|
|
|
currentLine += 1;
|
|
|
|
}
|
|
|
|
currentColumn = 0;
|
|
|
|
js = "";
|
2013-03-17 23:46:54 -04:00
|
|
|
for (_i = 0, _len = fragments.length; _i < _len; _i++) {
|
|
|
|
fragment = fragments[_i];
|
2013-03-18 07:23:05 -04:00
|
|
|
if (options.sourceMap) {
|
2013-03-04 21:37:36 -05:00
|
|
|
if (fragment.locationData) {
|
2013-03-18 07:23:05 -04:00
|
|
|
map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
|
2013-03-04 21:37:36 -05:00
|
|
|
noReplace: true
|
|
|
|
});
|
2013-02-28 15:51:29 -05:00
|
|
|
}
|
2013-03-04 21:37:36 -05:00
|
|
|
newLines = helpers.count(fragment.code, "\n");
|
|
|
|
currentLine += newLines;
|
|
|
|
currentColumn = fragment.code.length - (newLines ? fragment.code.lastIndexOf("\n") : 0);
|
2013-02-28 15:51:29 -05:00
|
|
|
}
|
2013-03-04 21:37:36 -05:00
|
|
|
js += fragment.code;
|
2010-03-07 22:08:24 -05:00
|
|
|
}
|
2013-02-25 17:20:37 -05:00
|
|
|
if (options.header) {
|
|
|
|
header = "Generated by CoffeeScript " + this.VERSION;
|
|
|
|
js = "// " + header + "\n" + js;
|
2010-03-07 22:08:24 -05:00
|
|
|
}
|
2013-03-04 16:19:21 -05:00
|
|
|
if (options.sourceMap) {
|
2013-03-04 09:45:25 -05:00
|
|
|
answer = {
|
|
|
|
js: js
|
2013-03-01 11:34:39 -05:00
|
|
|
};
|
2013-03-18 07:23:05 -04:00
|
|
|
answer.sourceMap = map;
|
|
|
|
answer.v3SourceMap = map.generate(options, code);
|
2013-03-04 09:45:25 -05:00
|
|
|
return answer;
|
|
|
|
} else {
|
|
|
|
return js;
|
2013-02-28 15:51:29 -05:00
|
|
|
}
|
2010-10-20 13:29:06 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-08 15:27:05 -04:00
|
|
|
exports.tokens = function(code, options) {
|
|
|
|
return lexer.tokenize(code, options);
|
2010-03-06 20:30:40 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-11-17 11:34:23 -05:00
|
|
|
exports.nodes = function(source, options) {
|
|
|
|
if (typeof source === 'string') {
|
2010-11-20 16:25:22 -05:00
|
|
|
return parser.parse(lexer.tokenize(source, options));
|
2010-11-17 11:34:23 -05:00
|
|
|
} else {
|
|
|
|
return parser.parse(source);
|
|
|
|
}
|
2010-03-06 20:30:40 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-09-04 06:39:01 -04:00
|
|
|
exports.run = function(code, options) {
|
2013-04-22 14:38:17 -04:00
|
|
|
var answer, mainModule;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
2011-05-03 15:53:10 -04:00
|
|
|
mainModule = require.main;
|
2013-04-22 14:38:17 -04:00
|
|
|
if (options.sourceMap == null) {
|
2013-03-12 02:33:55 -04:00
|
|
|
options.sourceMap = true;
|
|
|
|
}
|
2011-05-03 15:53:10 -04:00
|
|
|
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
|
2011-05-03 16:10:30 -04:00
|
|
|
mainModule.moduleCache && (mainModule.moduleCache = {});
|
2013-03-13 04:00:57 -04:00
|
|
|
mainModule.paths = require('module')._nodeModulePaths(path.dirname(fs.realpathSync(options.filename || '.')));
|
2013-02-27 21:54:17 -05:00
|
|
|
if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
|
2013-03-12 02:26:51 -04:00
|
|
|
answer = compile(code, options);
|
|
|
|
patchStackTrace();
|
|
|
|
mainModule._sourceMaps[mainModule.filename] = answer.sourceMap;
|
|
|
|
return mainModule._compile(answer.js, mainModule.filename);
|
2010-11-08 23:07:51 -05:00
|
|
|
} else {
|
2011-05-03 15:53:10 -04:00
|
|
|
return mainModule._compile(code, mainModule.filename);
|
2010-11-08 23:07:51 -05:00
|
|
|
}
|
2010-09-04 06:39:01 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-01-11 18:04:14 -05:00
|
|
|
exports["eval"] = function(code, options) {
|
2013-03-17 23:46:54 -04:00
|
|
|
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _require;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
if (!(code = code.trim())) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-23 22:45:32 -04:00
|
|
|
Script = vm.Script;
|
2011-08-27 13:20:29 -04:00
|
|
|
if (Script) {
|
2011-08-04 23:17:23 -04:00
|
|
|
if (options.sandbox != null) {
|
2011-10-23 22:45:32 -04:00
|
|
|
if (options.sandbox instanceof Script.createContext().constructor) {
|
2011-08-04 23:17:23 -04:00
|
|
|
sandbox = options.sandbox;
|
|
|
|
} else {
|
2011-10-23 22:45:32 -04:00
|
|
|
sandbox = Script.createContext();
|
2013-03-17 23:46:54 -04:00
|
|
|
_ref = options.sandbox;
|
|
|
|
for (k in _ref) {
|
|
|
|
if (!__hasProp.call(_ref, k)) continue;
|
|
|
|
v = _ref[k];
|
2011-08-04 23:17:23 -04:00
|
|
|
sandbox[k] = v;
|
|
|
|
}
|
2011-05-01 01:45:14 -04:00
|
|
|
}
|
2011-10-23 22:45:32 -04:00
|
|
|
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox;
|
|
|
|
} else {
|
|
|
|
sandbox = global;
|
2011-04-29 13:59:59 -04:00
|
|
|
}
|
2011-08-04 23:17:23 -04:00
|
|
|
sandbox.__filename = options.filename || 'eval';
|
|
|
|
sandbox.__dirname = path.dirname(sandbox.__filename);
|
2011-10-23 22:45:32 -04:00
|
|
|
if (!(sandbox !== global || sandbox.module || sandbox.require)) {
|
2011-08-04 23:17:23 -04:00
|
|
|
Module = require('module');
|
|
|
|
sandbox.module = _module = new Module(options.modulename || 'eval');
|
|
|
|
sandbox.require = _require = function(path) {
|
2011-10-23 22:45:32 -04:00
|
|
|
return Module._load(path, _module, true);
|
2011-08-04 23:17:23 -04:00
|
|
|
};
|
|
|
|
_module.filename = sandbox.__filename;
|
2013-03-17 23:46:54 -04:00
|
|
|
_ref1 = Object.getOwnPropertyNames(require);
|
|
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
|
|
r = _ref1[_i];
|
2012-04-10 14:57:45 -04:00
|
|
|
if (r !== 'paths') {
|
|
|
|
_require[r] = require[r];
|
|
|
|
}
|
2011-08-04 23:17:23 -04:00
|
|
|
}
|
|
|
|
_require.paths = _module.paths = Module._nodeModulePaths(process.cwd());
|
|
|
|
_require.resolve = function(request) {
|
|
|
|
return Module._resolveFilename(request, _module);
|
|
|
|
};
|
2011-07-06 03:54:36 -04:00
|
|
|
}
|
|
|
|
}
|
2011-05-25 03:53:51 -04:00
|
|
|
o = {};
|
|
|
|
for (k in options) {
|
2011-07-06 03:54:36 -04:00
|
|
|
if (!__hasProp.call(options, k)) continue;
|
2011-05-25 03:53:51 -04:00
|
|
|
v = options[k];
|
|
|
|
o[k] = v;
|
|
|
|
}
|
|
|
|
o.bare = true;
|
2011-07-06 16:31:48 -04:00
|
|
|
js = compile(code, o);
|
2011-10-23 22:45:32 -04:00
|
|
|
if (sandbox === global) {
|
|
|
|
return vm.runInThisContext(js);
|
2011-08-04 23:17:23 -04:00
|
|
|
} else {
|
2011-10-23 22:45:32 -04:00
|
|
|
return vm.runInContext(js, sandbox);
|
2011-08-04 23:17:23 -04:00
|
|
|
}
|
2010-09-21 01:36:23 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-17 23:46:54 -04:00
|
|
|
loadFile = function(module, filename) {
|
|
|
|
var raw, stripped;
|
|
|
|
raw = fs.readFileSync(filename, 'utf8');
|
|
|
|
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
|
|
|
|
return module._compile(compile(stripped, {
|
|
|
|
filename: filename,
|
|
|
|
literate: helpers.isLiterate(filename)
|
|
|
|
}), filename);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (require.extensions) {
|
|
|
|
_ref = ['.coffee', '.litcoffee', '.coffee.md'];
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
|
ext = _ref[_i];
|
|
|
|
require.extensions[ext] = loadFile;
|
|
|
|
}
|
2013-05-26 01:59:49 -04:00
|
|
|
(function(Module) {
|
2013-05-25 09:01:41 -04:00
|
|
|
var NATIVELOAD, findExtension;
|
|
|
|
NATIVELOAD = "function(filename){debug('load'+JSON.stringify(filename)+'formodule'+JSON.stringify(this.id));assert(!this.loaded);this.filename=filename;this.paths=Module._nodeModulePaths(path.dirname(filename));varextension=path.extname(filename)||'.js';if(!Module._extensions[extension])extension='.js';Module._extensions[extension](this,filename);this.loaded=true;}";
|
2013-05-26 01:59:49 -04:00
|
|
|
if (Module.prototype.load.toString().replace(/\s+/g, '') !== NATIVELOAD) {
|
2013-05-25 12:17:24 -04:00
|
|
|
return;
|
2013-05-25 09:01:41 -04:00
|
|
|
}
|
2013-05-25 12:17:24 -04:00
|
|
|
findExtension = function(filename) {
|
|
|
|
var curExtension, extensions;
|
|
|
|
extensions = path.basename(filename).split('.');
|
|
|
|
if (extensions[0] === '') {
|
|
|
|
extensions.shift();
|
|
|
|
}
|
|
|
|
while (extensions.shift()) {
|
|
|
|
curExtension = '.' + extensions.join('.');
|
2013-05-26 01:59:49 -04:00
|
|
|
if (Module._extensions[curExtension]) {
|
2013-05-25 12:17:24 -04:00
|
|
|
return curExtension;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '.js';
|
|
|
|
};
|
2013-05-26 01:59:49 -04:00
|
|
|
return Module.prototype.load = function(filename) {
|
2013-05-25 12:17:24 -04:00
|
|
|
var extension;
|
|
|
|
this.filename = filename;
|
2013-05-26 01:59:49 -04:00
|
|
|
this.paths = Module._nodeModulePaths(path.dirname(filename));
|
2013-05-25 12:17:24 -04:00
|
|
|
extension = findExtension(filename);
|
2013-05-26 01:59:49 -04:00
|
|
|
Module._extensions[extension](this, filename);
|
2013-05-25 12:17:24 -04:00
|
|
|
return this.loaded = true;
|
|
|
|
};
|
2013-05-25 09:01:41 -04:00
|
|
|
})(require('module'));
|
2013-03-17 23:46:54 -04:00
|
|
|
}
|
|
|
|
|
2013-03-18 01:06:33 -04:00
|
|
|
if (child_process) {
|
|
|
|
fork = child_process.fork;
|
|
|
|
child_process.fork = function(path, args, options) {
|
|
|
|
var execPath;
|
|
|
|
if (args == null) {
|
|
|
|
args = [];
|
|
|
|
}
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
execPath = helpers.isCoffee(path) ? 'coffee' : null;
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
args = [];
|
|
|
|
options = args || {};
|
|
|
|
}
|
|
|
|
options.execPath || (options.execPath = execPath);
|
|
|
|
return fork(path, args, options);
|
|
|
|
};
|
|
|
|
}
|
2013-03-17 23:46:54 -04:00
|
|
|
|
2010-09-25 04:39:19 -04:00
|
|
|
lexer = new Lexer;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-02-11 01:57:33 -05:00
|
|
|
parser.lexer = {
|
2010-05-14 23:40:04 -04:00
|
|
|
lex: function() {
|
2012-11-21 16:57:30 -05:00
|
|
|
var tag, token;
|
2013-01-14 15:20:35 -05:00
|
|
|
token = this.tokens[this.pos++];
|
|
|
|
if (token) {
|
|
|
|
tag = token[0], this.yytext = token[1], this.yylloc = token[2];
|
|
|
|
this.yylineno = this.yylloc.first_line;
|
|
|
|
} else {
|
|
|
|
tag = '';
|
|
|
|
}
|
2010-11-02 00:05:06 -04:00
|
|
|
return tag;
|
2010-02-11 01:57:33 -05:00
|
|
|
},
|
2010-11-20 20:39:35 -05:00
|
|
|
setInput: function(tokens) {
|
|
|
|
this.tokens = tokens;
|
2010-10-20 18:19:08 -04:00
|
|
|
return this.pos = 0;
|
2010-02-11 01:57:33 -05:00
|
|
|
},
|
2010-05-14 23:40:04 -04:00
|
|
|
upcomingInput: function() {
|
2010-02-11 01:57:33 -05:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-09-21 03:50:32 -04:00
|
|
|
parser.yy = require('./nodes');
|
2011-12-14 10:39:20 -05:00
|
|
|
|
2013-02-25 13:09:42 -05:00
|
|
|
parser.yy.parseError = function(message, _arg) {
|
2013-02-26 21:03:33 -05:00
|
|
|
var token;
|
2013-02-26 03:55:09 -05:00
|
|
|
token = _arg.token;
|
2013-03-09 22:30:27 -05:00
|
|
|
message = "unexpected " + (token === 1 ? 'end of input' : token);
|
2013-03-04 23:13:46 -05:00
|
|
|
return helpers.throwSyntaxError(message, parser.lexer.yylloc);
|
2013-02-25 13:09:42 -05:00
|
|
|
};
|
|
|
|
|
2013-03-12 02:26:51 -04:00
|
|
|
patched = false;
|
|
|
|
|
|
|
|
patchStackTrace = function() {
|
|
|
|
var mainModule;
|
|
|
|
if (patched) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
patched = true;
|
|
|
|
mainModule = require.main;
|
|
|
|
mainModule._sourceMaps = {};
|
|
|
|
return Error.prepareStackTrace = function(err, stack) {
|
|
|
|
var frame, frames, getSourceMapping, sourceFiles, _ref1;
|
|
|
|
sourceFiles = {};
|
|
|
|
getSourceMapping = function(filename, line, column) {
|
|
|
|
var answer, sourceMap;
|
|
|
|
sourceMap = mainModule._sourceMaps[filename];
|
|
|
|
if (sourceMap) {
|
2013-03-18 07:23:05 -04:00
|
|
|
answer = sourceMap.sourceLocation([line - 1, column - 1]);
|
2013-03-13 09:43:29 -04:00
|
|
|
}
|
|
|
|
if (answer) {
|
2013-03-13 20:23:27 -04:00
|
|
|
return [answer[0] + 1, answer[1] + 1];
|
|
|
|
} else {
|
|
|
|
return null;
|
2013-03-12 02:26:51 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
frames = (function() {
|
|
|
|
var _j, _len1, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_j = 0, _len1 = stack.length; _j < _len1; _j++) {
|
|
|
|
frame = stack[_j];
|
|
|
|
if (frame.getFunction() === exports.run) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
|
|
|
return "" + err.name + ": " + ((_ref1 = err.message) != null ? _ref1 : '') + "\n" + (frames.join('\n')) + "\n";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
formatSourcePosition = function(frame, getSourceMapping) {
|
|
|
|
var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
|
|
|
|
fileName = void 0;
|
|
|
|
fileLocation = '';
|
|
|
|
if (frame.isNative()) {
|
|
|
|
fileLocation = "native";
|
|
|
|
} else {
|
|
|
|
if (frame.isEval()) {
|
|
|
|
fileName = frame.getScriptNameOrSourceURL();
|
|
|
|
if (!fileName) {
|
|
|
|
fileLocation = "" + (frame.getEvalOrigin()) + ", ";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fileName = frame.getFileName();
|
|
|
|
}
|
|
|
|
fileName || (fileName = "<anonymous>");
|
|
|
|
line = frame.getLineNumber();
|
|
|
|
column = frame.getColumnNumber();
|
|
|
|
source = getSourceMapping(fileName, line, column);
|
|
|
|
fileLocation = source ? "" + fileName + ":" + source[0] + ":" + source[1] + ", <js>:" + line + ":" + column : "" + fileName + ":" + line + ":" + column;
|
|
|
|
}
|
|
|
|
functionName = frame.getFunctionName();
|
|
|
|
isConstructor = frame.isConstructor();
|
|
|
|
isMethodCall = !(frame.isToplevel() || isConstructor);
|
|
|
|
if (isMethodCall) {
|
|
|
|
methodName = frame.getMethodName();
|
|
|
|
typeName = frame.getTypeName();
|
|
|
|
if (functionName) {
|
|
|
|
tp = as = '';
|
|
|
|
if (typeName && functionName.indexOf(typeName)) {
|
|
|
|
tp = "" + typeName + ".";
|
|
|
|
}
|
|
|
|
if (methodName && functionName.indexOf("." + methodName) !== functionName.length - methodName.length - 1) {
|
|
|
|
as = " [as " + methodName + "]";
|
|
|
|
}
|
|
|
|
return "" + tp + functionName + as + " (" + fileLocation + ")";
|
|
|
|
} else {
|
|
|
|
return "" + typeName + "." + (methodName || '<anonymous>') + " (" + fileLocation + ")";
|
|
|
|
}
|
|
|
|
} else if (isConstructor) {
|
|
|
|
return "new " + (functionName || '<anonymous>') + " (" + fileLocation + ")";
|
|
|
|
} else if (functionName) {
|
|
|
|
return "" + functionName + " (" + fileLocation + ")";
|
|
|
|
} else {
|
|
|
|
return fileLocation;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-21 03:53:58 -04:00
|
|
|
}).call(this);
|