PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/platforms/blackberry10/cordova/node_modules/jasmine-node/node_modules/coffee-script/lib/coffee-script/coffee-script.js

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