react / wstein / node_modules / jest-cli / node_modules / jasmine-only / node_modules / coffee-script / lib / coffee-script / helpers.js
81146 views// Generated by CoffeeScript 1.6.31(function() {2var buildLocationData, extend, flatten, last, repeat, _ref;34exports.starts = function(string, literal, start) {5return literal === string.substr(start, literal.length);6};78exports.ends = function(string, literal, back) {9var len;10len = literal.length;11return literal === string.substr(string.length - len - (back || 0), len);12};1314exports.repeat = repeat = function(str, n) {15var res;16res = '';17while (n > 0) {18if (n & 1) {19res += str;20}21n >>>= 1;22str += str;23}24return res;25};2627exports.compact = function(array) {28var item, _i, _len, _results;29_results = [];30for (_i = 0, _len = array.length; _i < _len; _i++) {31item = array[_i];32if (item) {33_results.push(item);34}35}36return _results;37};3839exports.count = function(string, substr) {40var num, pos;41num = pos = 0;42if (!substr.length) {43return 1 / 0;44}45while (pos = 1 + string.indexOf(substr, pos)) {46num++;47}48return num;49};5051exports.merge = function(options, overrides) {52return extend(extend({}, options), overrides);53};5455extend = exports.extend = function(object, properties) {56var key, val;57for (key in properties) {58val = properties[key];59object[key] = val;60}61return object;62};6364exports.flatten = flatten = function(array) {65var element, flattened, _i, _len;66flattened = [];67for (_i = 0, _len = array.length; _i < _len; _i++) {68element = array[_i];69if (element instanceof Array) {70flattened = flattened.concat(flatten(element));71} else {72flattened.push(element);73}74}75return flattened;76};7778exports.del = function(obj, key) {79var val;80val = obj[key];81delete obj[key];82return val;83};8485exports.last = last = function(array, back) {86return array[array.length - (back || 0) - 1];87};8889exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {90var e, _i, _len;91for (_i = 0, _len = this.length; _i < _len; _i++) {92e = this[_i];93if (fn(e)) {94return true;95}96}97return false;98};99100exports.invertLiterate = function(code) {101var line, lines, maybe_code;102maybe_code = true;103lines = (function() {104var _i, _len, _ref1, _results;105_ref1 = code.split('\n');106_results = [];107for (_i = 0, _len = _ref1.length; _i < _len; _i++) {108line = _ref1[_i];109if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {110_results.push(line);111} else if (maybe_code = /^\s*$/.test(line)) {112_results.push(line);113} else {114_results.push('# ' + line);115}116}117return _results;118})();119return lines.join('\n');120};121122buildLocationData = function(first, last) {123if (!last) {124return first;125} else {126return {127first_line: first.first_line,128first_column: first.first_column,129last_line: last.last_line,130last_column: last.last_column131};132}133};134135exports.addLocationDataFn = function(first, last) {136return function(obj) {137if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {138obj.updateLocationDataIfMissing(buildLocationData(first, last));139}140return obj;141};142};143144exports.locationDataToString = function(obj) {145var locationData;146if (("2" in obj) && ("first_line" in obj[2])) {147locationData = obj[2];148} else if ("first_line" in obj) {149locationData = obj;150}151if (locationData) {152return ("" + (locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ("" + (locationData.last_line + 1) + ":" + (locationData.last_column + 1));153} else {154return "No location data";155}156};157158exports.baseFileName = function(file, stripExt, useWinPathSep) {159var parts, pathSep;160if (stripExt == null) {161stripExt = false;162}163if (useWinPathSep == null) {164useWinPathSep = false;165}166pathSep = useWinPathSep ? /\\|\// : /\//;167parts = file.split(pathSep);168file = parts[parts.length - 1];169if (!stripExt) {170return file;171}172parts = file.split('.');173parts.pop();174if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {175parts.pop();176}177return parts.join('.');178};179180exports.isCoffee = function(file) {181return /\.((lit)?coffee|coffee\.md)$/.test(file);182};183184exports.isLiterate = function(file) {185return /\.(litcoffee|coffee\.md)$/.test(file);186};187188exports.throwSyntaxError = function(message, location) {189var error;190if (location.last_line == null) {191location.last_line = location.first_line;192}193if (location.last_column == null) {194location.last_column = location.first_column;195}196error = new SyntaxError(message);197error.location = location;198throw error;199};200201exports.prettyErrorMessage = function(error, fileName, code, useColors) {202var codeLine, colorize, end, first_column, first_line, last_column, last_line, marker, message, start, _ref1;203if (!error.location) {204return error.stack || ("" + error);205}206_ref1 = error.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;207codeLine = code.split('\n')[first_line];208start = first_column;209end = first_line === last_line ? last_column + 1 : codeLine.length;210marker = repeat(' ', start) + repeat('^', end - start);211if (useColors) {212colorize = function(str) {213return "\x1B[1;31m" + str + "\x1B[0m";214};215codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);216marker = colorize(marker);217}218message = "" + fileName + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + error.message + "\n" + codeLine + "\n" + marker;219return message;220};221222}).call(this);223224225