react / wstein / node_modules / jest-cli / node_modules / jasmine-only / node_modules / coffee-script / lib / coffee-script / coffee-script.js
81146 views// Generated by CoffeeScript 1.6.31(function() {2var Lexer, Module, SourceMap, child_process, compile, ext, findExtension, fork, formatSourcePosition, fs, helpers, lexer, loadFile, parser, patchStackTrace, patched, path, sourceMaps, vm, _i, _len, _ref,3__hasProp = {}.hasOwnProperty;45fs = require('fs');67vm = require('vm');89path = require('path');1011child_process = require('child_process');1213Lexer = require('./lexer').Lexer;1415parser = require('./parser').parser;1617helpers = require('./helpers');1819SourceMap = require('./sourcemap');2021exports.VERSION = '1.6.3';2223exports.helpers = helpers;2425exports.compile = compile = function(code, options) {26var answer, currentColumn, currentLine, fragment, fragments, header, js, map, merge, newLines, _i, _len;27if (options == null) {28options = {};29}30merge = helpers.merge;31if (options.sourceMap) {32map = new SourceMap;33}34fragments = parser.parse(lexer.tokenize(code, options)).compileToFragments(options);35currentLine = 0;36if (options.header) {37currentLine += 1;38}39if (options.shiftLine) {40currentLine += 1;41}42currentColumn = 0;43js = "";44for (_i = 0, _len = fragments.length; _i < _len; _i++) {45fragment = fragments[_i];46if (options.sourceMap) {47if (fragment.locationData) {48map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {49noReplace: true50});51}52newLines = helpers.count(fragment.code, "\n");53currentLine += newLines;54currentColumn = fragment.code.length - (newLines ? fragment.code.lastIndexOf("\n") : 0);55}56js += fragment.code;57}58if (options.header) {59header = "Generated by CoffeeScript " + this.VERSION;60js = "// " + header + "\n" + js;61}62if (options.sourceMap) {63answer = {64js: js65};66answer.sourceMap = map;67answer.v3SourceMap = map.generate(options, code);68return answer;69} else {70return js;71}72};7374exports.tokens = function(code, options) {75return lexer.tokenize(code, options);76};7778exports.nodes = function(source, options) {79if (typeof source === 'string') {80return parser.parse(lexer.tokenize(source, options));81} else {82return parser.parse(source);83}84};8586exports.run = function(code, options) {87var answer, mainModule;88if (options == null) {89options = {};90}91mainModule = require.main;92if (options.sourceMap == null) {93options.sourceMap = true;94}95mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';96mainModule.moduleCache && (mainModule.moduleCache = {});97mainModule.paths = require('module')._nodeModulePaths(path.dirname(fs.realpathSync(options.filename || '.')));98if (!helpers.isCoffee(mainModule.filename) || require.extensions) {99answer = compile(code, options);100patchStackTrace();101sourceMaps[mainModule.filename] = answer.sourceMap;102return mainModule._compile(answer.js, mainModule.filename);103} else {104return mainModule._compile(code, mainModule.filename);105}106};107108exports["eval"] = function(code, options) {109var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _require;110if (options == null) {111options = {};112}113if (!(code = code.trim())) {114return;115}116Script = vm.Script;117if (Script) {118if (options.sandbox != null) {119if (options.sandbox instanceof Script.createContext().constructor) {120sandbox = options.sandbox;121} else {122sandbox = Script.createContext();123_ref = options.sandbox;124for (k in _ref) {125if (!__hasProp.call(_ref, k)) continue;126v = _ref[k];127sandbox[k] = v;128}129}130sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox;131} else {132sandbox = global;133}134sandbox.__filename = options.filename || 'eval';135sandbox.__dirname = path.dirname(sandbox.__filename);136if (!(sandbox !== global || sandbox.module || sandbox.require)) {137Module = require('module');138sandbox.module = _module = new Module(options.modulename || 'eval');139sandbox.require = _require = function(path) {140return Module._load(path, _module, true);141};142_module.filename = sandbox.__filename;143_ref1 = Object.getOwnPropertyNames(require);144for (_i = 0, _len = _ref1.length; _i < _len; _i++) {145r = _ref1[_i];146if (r !== 'paths') {147_require[r] = require[r];148}149}150_require.paths = _module.paths = Module._nodeModulePaths(process.cwd());151_require.resolve = function(request) {152return Module._resolveFilename(request, _module);153};154}155}156o = {};157for (k in options) {158if (!__hasProp.call(options, k)) continue;159v = options[k];160o[k] = v;161}162o.bare = true;163js = compile(code, o);164if (sandbox === global) {165return vm.runInThisContext(js);166} else {167return vm.runInContext(js, sandbox);168}169};170171loadFile = function(module, filename) {172var answer, raw, stripped;173raw = fs.readFileSync(filename, 'utf8');174stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;175answer = compile(stripped, {176filename: filename,177sourceMap: true,178literate: helpers.isLiterate(filename)179});180sourceMaps[filename] = answer.sourceMap;181return module._compile(answer.js, filename);182};183184if (require.extensions) {185_ref = ['.coffee', '.litcoffee', '.coffee.md'];186for (_i = 0, _len = _ref.length; _i < _len; _i++) {187ext = _ref[_i];188require.extensions[ext] = loadFile;189}190Module = require('module');191findExtension = function(filename) {192var curExtension, extensions;193extensions = path.basename(filename).split('.');194if (extensions[0] === '') {195extensions.shift();196}197while (extensions.shift()) {198curExtension = '.' + extensions.join('.');199if (Module._extensions[curExtension]) {200return curExtension;201}202}203return '.js';204};205Module.prototype.load = function(filename) {206var extension;207this.filename = filename;208this.paths = Module._nodeModulePaths(path.dirname(filename));209extension = findExtension(filename);210Module._extensions[extension](this, filename);211return this.loaded = true;212};213}214215if (child_process) {216fork = child_process.fork;217child_process.fork = function(path, args, options) {218var execPath;219if (args == null) {220args = [];221}222if (options == null) {223options = {};224}225execPath = helpers.isCoffee(path) ? 'coffee' : null;226if (!Array.isArray(args)) {227args = [];228options = args || {};229}230options.execPath || (options.execPath = execPath);231return fork(path, args, options);232};233}234235lexer = new Lexer;236237parser.lexer = {238lex: function() {239var tag, token;240token = this.tokens[this.pos++];241if (token) {242tag = token[0], this.yytext = token[1], this.yylloc = token[2];243this.yylineno = this.yylloc.first_line;244} else {245tag = '';246}247return tag;248},249setInput: function(tokens) {250this.tokens = tokens;251return this.pos = 0;252},253upcomingInput: function() {254return "";255}256};257258parser.yy = require('./nodes');259260parser.yy.parseError = function(message, _arg) {261var token;262token = _arg.token;263message = "unexpected " + (token === 1 ? 'end of input' : token);264return helpers.throwSyntaxError(message, parser.lexer.yylloc);265};266267patched = false;268269sourceMaps = {};270271patchStackTrace = function() {272var mainModule;273if (patched) {274return;275}276patched = true;277mainModule = require.main;278return Error.prepareStackTrace = function(err, stack) {279var frame, frames, getSourceMapping, sourceFiles, _ref1;280sourceFiles = {};281getSourceMapping = function(filename, line, column) {282var answer, sourceMap;283sourceMap = sourceMaps[filename];284if (sourceMap) {285answer = sourceMap.sourceLocation([line - 1, column - 1]);286}287if (answer) {288return [answer[0] + 1, answer[1] + 1];289} else {290return null;291}292};293frames = (function() {294var _j, _len1, _results;295_results = [];296for (_j = 0, _len1 = stack.length; _j < _len1; _j++) {297frame = stack[_j];298if (frame.getFunction() === exports.run) {299break;300}301_results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));302}303return _results;304})();305return "" + err.name + ": " + ((_ref1 = err.message) != null ? _ref1 : '') + "\n" + (frames.join('\n')) + "\n";306};307};308309formatSourcePosition = function(frame, getSourceMapping) {310var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;311fileName = void 0;312fileLocation = '';313if (frame.isNative()) {314fileLocation = "native";315} else {316if (frame.isEval()) {317fileName = frame.getScriptNameOrSourceURL();318if (!fileName) {319fileLocation = "" + (frame.getEvalOrigin()) + ", ";320}321} else {322fileName = frame.getFileName();323}324fileName || (fileName = "<anonymous>");325line = frame.getLineNumber();326column = frame.getColumnNumber();327source = getSourceMapping(fileName, line, column);328fileLocation = source ? "" + fileName + ":" + source[0] + ":" + source[1] + ", <js>:" + line + ":" + column : "" + fileName + ":" + line + ":" + column;329}330functionName = frame.getFunctionName();331isConstructor = frame.isConstructor();332isMethodCall = !(frame.isToplevel() || isConstructor);333if (isMethodCall) {334methodName = frame.getMethodName();335typeName = frame.getTypeName();336if (functionName) {337tp = as = '';338if (typeName && functionName.indexOf(typeName)) {339tp = "" + typeName + ".";340}341if (methodName && functionName.indexOf("." + methodName) !== functionName.length - methodName.length - 1) {342as = " [as " + methodName + "]";343}344return "" + tp + functionName + as + " (" + fileLocation + ")";345} else {346return "" + typeName + "." + (methodName || '<anonymous>') + " (" + fileLocation + ")";347}348} else if (isConstructor) {349return "new " + (functionName || '<anonymous>') + " (" + fileLocation + ")";350} else if (functionName) {351return "" + functionName + " (" + fileLocation + ")";352} else {353return fileLocation;354}355};356357}).call(this);358359360