2012-01-10 12:55:41 -05:00
|
|
|
// Generated by CoffeeScript 1.2.1-pre
|
2010-07-24 11:31:43 -04:00
|
|
|
(function() {
|
2011-11-10 03:08:38 -05:00
|
|
|
var Lexer, RESERVED, compile, fs, lexer, parser, path, vm, _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
|
|
|
|
2010-09-21 05:19:49 -04:00
|
|
|
path = require('path');
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-12-03 18:07:36 -05:00
|
|
|
_ref = require('./lexer'), Lexer = _ref.Lexer, RESERVED = _ref.RESERVED;
|
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
|
|
|
|
2011-10-23 22:45:32 -04:00
|
|
|
vm = require('vm');
|
|
|
|
|
2010-09-21 05:19:49 -04:00
|
|
|
if (require.extensions) {
|
|
|
|
require.extensions['.coffee'] = function(module, filename) {
|
|
|
|
var content;
|
2011-04-26 20:35:30 -04:00
|
|
|
content = compile(fs.readFileSync(filename, 'utf8'), {
|
|
|
|
filename: filename
|
|
|
|
});
|
2010-09-22 19:55:05 -04:00
|
|
|
return module._compile(content, filename);
|
2010-09-21 05:19:49 -04:00
|
|
|
};
|
|
|
|
} else if (require.registerExtension) {
|
|
|
|
require.registerExtension('.coffee', function(content) {
|
|
|
|
return compile(content);
|
|
|
|
});
|
2010-02-13 15:25:04 -05:00
|
|
|
}
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-12-18 15:31:17 -05:00
|
|
|
exports.VERSION = '1.2.1-pre';
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-12-03 18:07:36 -05:00
|
|
|
exports.RESERVED = RESERVED;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-11 10:42:13 -04:00
|
|
|
exports.helpers = require('./helpers');
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-20 13:29:06 -04:00
|
|
|
exports.compile = compile = function(code, options) {
|
2012-01-10 12:55:41 -05:00
|
|
|
var header, js, merge;
|
2011-08-07 02:59:37 -04:00
|
|
|
if (options == null) options = {};
|
2011-12-10 21:00:28 -05:00
|
|
|
merge = exports.helpers.merge;
|
2010-03-07 22:08:24 -05:00
|
|
|
try {
|
2012-01-10 12:55:41 -05:00
|
|
|
js = (parser.parse(lexer.tokenize(code))).compile(options);
|
2012-01-10 14:00:29 -05:00
|
|
|
if (!options.header) return js;
|
2010-03-07 22:08:24 -05:00
|
|
|
} catch (err) {
|
2011-08-08 12:55:22 -04:00
|
|
|
if (options.filename) {
|
|
|
|
err.message = "In " + options.filename + ", " + err.message;
|
|
|
|
}
|
2010-03-07 22:08:24 -05:00
|
|
|
throw err;
|
|
|
|
}
|
2012-01-10 14:00:29 -05:00
|
|
|
header = "Generated by CoffeeScript " + this.VERSION;
|
|
|
|
return "// " + header + "\n" + js;
|
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) {
|
2011-11-08 15:58:48 -05:00
|
|
|
var mainModule;
|
2012-01-12 19:25:51 -05:00
|
|
|
if (options == null) options = {};
|
2011-05-03 15:53:10 -04:00
|
|
|
mainModule = require.main;
|
|
|
|
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
|
2011-05-03 16:10:30 -04:00
|
|
|
mainModule.moduleCache && (mainModule.moduleCache = {});
|
2011-11-08 15:58:48 -05:00
|
|
|
mainModule.paths = require('module')._nodeModulePaths(path.dirname(options.filename));
|
2011-05-03 15:53:10 -04:00
|
|
|
if (path.extname(mainModule.filename) !== '.coffee' || require.extensions) {
|
|
|
|
return mainModule._compile(compile(code, options), 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
|
|
|
|
2010-09-21 01:36:23 -04:00
|
|
|
exports.eval = function(code, options) {
|
2011-08-27 13:20:29 -04:00
|
|
|
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref2, _ref3, _require;
|
2011-08-07 02:59:37 -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();
|
2011-08-27 13:20:29 -04:00
|
|
|
_ref2 = options.sandbox;
|
|
|
|
for (k in _ref2) {
|
|
|
|
if (!__hasProp.call(_ref2, k)) continue;
|
|
|
|
v = _ref2[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;
|
2011-08-27 13:20:29 -04:00
|
|
|
_ref3 = Object.getOwnPropertyNames(require);
|
|
|
|
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
|
|
|
r = _ref3[_i];
|
2011-08-07 02:59:37 -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
|
|
|
|
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() {
|
2011-03-28 17:12:27 -04:00
|
|
|
var tag, _ref2;
|
|
|
|
_ref2 = this.tokens[this.pos++] || [''], tag = _ref2[0], this.yytext = _ref2[1], this.yylineno = _ref2[2];
|
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
|
|
|
|
2010-09-21 03:53:58 -04:00
|
|
|
}).call(this);
|