"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/coffee-script/lib/coffee-script/coffee-script.js" (8 Mar 2017, 11664 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Generated by CoffeeScript 1.9.0
    2 (function() {
    3   var Lexer, SourceMap, compile, ext, formatSourcePosition, fs, getSourceMap, helpers, lexer, parser, path, sourceMaps, vm, withPrettyErrors, _base, _i, _len, _ref,
    4     __hasProp = {}.hasOwnProperty,
    5     __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
    6 
    7   fs = require('fs');
    8 
    9   vm = require('vm');
   10 
   11   path = require('path');
   12 
   13   Lexer = require('./lexer').Lexer;
   14 
   15   parser = require('./parser').parser;
   16 
   17   helpers = require('./helpers');
   18 
   19   SourceMap = require('./sourcemap');
   20 
   21   exports.VERSION = '1.9.0';
   22 
   23   exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
   24 
   25   exports.helpers = helpers;
   26 
   27   withPrettyErrors = function(fn) {
   28     return function(code, options) {
   29       var err;
   30       if (options == null) {
   31         options = {};
   32       }
   33       try {
   34         return fn.call(this, code, options);
   35       } catch (_error) {
   36         err = _error;
   37         throw helpers.updateSyntaxError(err, code, options.filename);
   38       }
   39     };
   40   };
   41 
   42   exports.compile = compile = withPrettyErrors(function(code, options) {
   43     var answer, currentColumn, currentLine, extend, fragment, fragments, header, js, map, merge, newLines, token, tokens, _i, _len;
   44     merge = helpers.merge, extend = helpers.extend;
   45     options = extend({}, options);
   46     if (options.sourceMap) {
   47       map = new SourceMap;
   48     }
   49     tokens = lexer.tokenize(code, options);
   50     options.referencedVars = (function() {
   51       var _i, _len, _results;
   52       _results = [];
   53       for (_i = 0, _len = tokens.length; _i < _len; _i++) {
   54         token = tokens[_i];
   55         if (token.variable && token[1].charAt(0) === '_') {
   56           _results.push(token[1]);
   57         }
   58       }
   59       return _results;
   60     })();
   61     fragments = parser.parse(tokens).compileToFragments(options);
   62     currentLine = 0;
   63     if (options.header) {
   64       currentLine += 1;
   65     }
   66     if (options.shiftLine) {
   67       currentLine += 1;
   68     }
   69     currentColumn = 0;
   70     js = "";
   71     for (_i = 0, _len = fragments.length; _i < _len; _i++) {
   72       fragment = fragments[_i];
   73       if (options.sourceMap) {
   74         if (fragment.locationData) {
   75           map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
   76             noReplace: true
   77           });
   78         }
   79         newLines = helpers.count(fragment.code, "\n");
   80         currentLine += newLines;
   81         if (newLines) {
   82           currentColumn = fragment.code.length - (fragment.code.lastIndexOf("\n") + 1);
   83         } else {
   84           currentColumn += fragment.code.length;
   85         }
   86       }
   87       js += fragment.code;
   88     }
   89     if (options.header) {
   90       header = "Generated by CoffeeScript " + this.VERSION;
   91       js = "// " + header + "\n" + js;
   92     }
   93     if (options.sourceMap) {
   94       answer = {
   95         js: js
   96       };
   97       answer.sourceMap = map;
   98       answer.v3SourceMap = map.generate(options, code);
   99       return answer;
  100     } else {
  101       return js;
  102     }
  103   });
  104 
  105   exports.tokens = withPrettyErrors(function(code, options) {
  106     return lexer.tokenize(code, options);
  107   });
  108 
  109   exports.nodes = withPrettyErrors(function(source, options) {
  110     if (typeof source === 'string') {
  111       return parser.parse(lexer.tokenize(source, options));
  112     } else {
  113       return parser.parse(source);
  114     }
  115   });
  116 
  117   exports.run = function(code, options) {
  118     var answer, dir, mainModule, _ref;
  119     if (options == null) {
  120       options = {};
  121     }
  122     mainModule = require.main;
  123     mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
  124     mainModule.moduleCache && (mainModule.moduleCache = {});
  125     dir = options.filename ? path.dirname(fs.realpathSync(options.filename)) : fs.realpathSync('.');
  126     mainModule.paths = require('module')._nodeModulePaths(dir);
  127     if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
  128       answer = compile(code, options);
  129       code = (_ref = answer.js) != null ? _ref : answer;
  130     }
  131     return mainModule._compile(code, mainModule.filename);
  132   };
  133 
  134   exports["eval"] = function(code, options) {
  135     var Module, createContext, isContext, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _ref2, _ref3, _require;
  136     if (options == null) {
  137       options = {};
  138     }
  139     if (!(code = code.trim())) {
  140       return;
  141     }
  142     createContext = (_ref = vm.Script.createContext) != null ? _ref : vm.createContext;
  143     isContext = (_ref1 = vm.isContext) != null ? _ref1 : function(ctx) {
  144       return options.sandbox instanceof createContext().constructor;
  145     };
  146     if (createContext) {
  147       if (options.sandbox != null) {
  148         if (isContext(options.sandbox)) {
  149           sandbox = options.sandbox;
  150         } else {
  151           sandbox = createContext();
  152           _ref2 = options.sandbox;
  153           for (k in _ref2) {
  154             if (!__hasProp.call(_ref2, k)) continue;
  155             v = _ref2[k];
  156             sandbox[k] = v;
  157           }
  158         }
  159         sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox;
  160       } else {
  161         sandbox = global;
  162       }
  163       sandbox.__filename = options.filename || 'eval';
  164       sandbox.__dirname = path.dirname(sandbox.__filename);
  165       if (!(sandbox !== global || sandbox.module || sandbox.require)) {
  166         Module = require('module');
  167         sandbox.module = _module = new Module(options.modulename || 'eval');
  168         sandbox.require = _require = function(path) {
  169           return Module._load(path, _module, true);
  170         };
  171         _module.filename = sandbox.__filename;
  172         _ref3 = Object.getOwnPropertyNames(require);
  173         for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
  174           r = _ref3[_i];
  175           if (r !== 'paths') {
  176             _require[r] = require[r];
  177           }
  178         }
  179         _require.paths = _module.paths = Module._nodeModulePaths(process.cwd());
  180         _require.resolve = function(request) {
  181           return Module._resolveFilename(request, _module);
  182         };
  183       }
  184     }
  185     o = {};
  186     for (k in options) {
  187       if (!__hasProp.call(options, k)) continue;
  188       v = options[k];
  189       o[k] = v;
  190     }
  191     o.bare = true;
  192     js = compile(code, o);
  193     if (sandbox === global) {
  194       return vm.runInThisContext(js);
  195     } else {
  196       return vm.runInContext(js, sandbox);
  197     }
  198   };
  199 
  200   exports.register = function() {
  201     return require('./register');
  202   };
  203 
  204   if (require.extensions) {
  205     _ref = this.FILE_EXTENSIONS;
  206     for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  207       ext = _ref[_i];
  208       if ((_base = require.extensions)[ext] == null) {
  209         _base[ext] = function() {
  210           throw new Error("Use CoffeeScript.register() or require the coffee-script/register module to require " + ext + " files.");
  211         };
  212       }
  213     }
  214   }
  215 
  216   exports._compileFile = function(filename, sourceMap) {
  217     var answer, err, raw, stripped;
  218     if (sourceMap == null) {
  219       sourceMap = false;
  220     }
  221     raw = fs.readFileSync(filename, 'utf8');
  222     stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
  223     try {
  224       answer = compile(stripped, {
  225         filename: filename,
  226         sourceMap: sourceMap,
  227         literate: helpers.isLiterate(filename)
  228       });
  229     } catch (_error) {
  230       err = _error;
  231       throw helpers.updateSyntaxError(err, stripped, filename);
  232     }
  233     return answer;
  234   };
  235 
  236   lexer = new Lexer;
  237 
  238   parser.lexer = {
  239     lex: function() {
  240       var tag, token;
  241       token = parser.tokens[this.pos++];
  242       if (token) {
  243         tag = token[0], this.yytext = token[1], this.yylloc = token[2];
  244         parser.errorToken = token.origin || token;
  245         this.yylineno = this.yylloc.first_line;
  246       } else {
  247         tag = '';
  248       }
  249       return tag;
  250     },
  251     setInput: function(tokens) {
  252       parser.tokens = tokens;
  253       return this.pos = 0;
  254     },
  255     upcomingInput: function() {
  256       return "";
  257     }
  258   };
  259 
  260   parser.yy = require('./nodes');
  261 
  262   parser.yy.parseError = function(message, _arg) {
  263     var errorLoc, errorTag, errorText, errorToken, token, tokens;
  264     token = _arg.token;
  265     errorToken = parser.errorToken, tokens = parser.tokens;
  266     errorTag = errorToken[0], errorText = errorToken[1], errorLoc = errorToken[2];
  267     errorText = errorToken === tokens[tokens.length - 1] ? 'end of input' : errorTag === 'INDENT' || errorTag === 'OUTDENT' ? 'indentation' : helpers.nameWhitespaceCharacter(errorText);
  268     return helpers.throwSyntaxError("unexpected " + errorText, errorLoc);
  269   };
  270 
  271   formatSourcePosition = function(frame, getSourceMapping) {
  272     var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
  273     fileName = void 0;
  274     fileLocation = '';
  275     if (frame.isNative()) {
  276       fileLocation = "native";
  277     } else {
  278       if (frame.isEval()) {
  279         fileName = frame.getScriptNameOrSourceURL();
  280         if (!fileName) {
  281           fileLocation = (frame.getEvalOrigin()) + ", ";
  282         }
  283       } else {
  284         fileName = frame.getFileName();
  285       }
  286       fileName || (fileName = "<anonymous>");
  287       line = frame.getLineNumber();
  288       column = frame.getColumnNumber();
  289       source = getSourceMapping(fileName, line, column);
  290       fileLocation = source ? fileName + ":" + source[0] + ":" + source[1] : fileName + ":" + line + ":" + column;
  291     }
  292     functionName = frame.getFunctionName();
  293     isConstructor = frame.isConstructor();
  294     isMethodCall = !(frame.isToplevel() || isConstructor);
  295     if (isMethodCall) {
  296       methodName = frame.getMethodName();
  297       typeName = frame.getTypeName();
  298       if (functionName) {
  299         tp = as = '';
  300         if (typeName && functionName.indexOf(typeName)) {
  301           tp = typeName + ".";
  302         }
  303         if (methodName && functionName.indexOf("." + methodName) !== functionName.length - methodName.length - 1) {
  304           as = " [as " + methodName + "]";
  305         }
  306         return "" + tp + functionName + as + " (" + fileLocation + ")";
  307       } else {
  308         return typeName + "." + (methodName || '<anonymous>') + " (" + fileLocation + ")";
  309       }
  310     } else if (isConstructor) {
  311       return "new " + (functionName || '<anonymous>') + " (" + fileLocation + ")";
  312     } else if (functionName) {
  313       return functionName + " (" + fileLocation + ")";
  314     } else {
  315       return fileLocation;
  316     }
  317   };
  318 
  319   sourceMaps = {};
  320 
  321   getSourceMap = function(filename) {
  322     var answer, _ref1;
  323     if (sourceMaps[filename]) {
  324       return sourceMaps[filename];
  325     }
  326     if (_ref1 = path != null ? path.extname(filename) : void 0, __indexOf.call(exports.FILE_EXTENSIONS, _ref1) < 0) {
  327       return;
  328     }
  329     answer = exports._compileFile(filename, true);
  330     return sourceMaps[filename] = answer.sourceMap;
  331   };
  332 
  333   Error.prepareStackTrace = function(err, stack) {
  334     var frame, frames, getSourceMapping;
  335     getSourceMapping = function(filename, line, column) {
  336       var answer, sourceMap;
  337       sourceMap = getSourceMap(filename);
  338       if (sourceMap) {
  339         answer = sourceMap.sourceLocation([line - 1, column - 1]);
  340       }
  341       if (answer) {
  342         return [answer[0] + 1, answer[1] + 1];
  343       } else {
  344         return null;
  345       }
  346     };
  347     frames = (function() {
  348       var _j, _len1, _results;
  349       _results = [];
  350       for (_j = 0, _len1 = stack.length; _j < _len1; _j++) {
  351         frame = stack[_j];
  352         if (frame.getFunction() === exports.run) {
  353           break;
  354         }
  355         _results.push("  at " + (formatSourcePosition(frame, getSourceMapping)));
  356       }
  357       return _results;
  358     })();
  359     return (err.toString()) + "\n" + (frames.join('\n')) + "\n";
  360   };
  361 
  362 }).call(this);