react / wstein / node_modules / jest-cli / node_modules / coffee-script / lib / coffee-script / helpers.js
80677 views// Generated by CoffeeScript 1.9.31(function() {2var buildLocationData, extend, flatten, ref, repeat, syntaxErrorToString;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 i, item, len1, results;29results = [];30for (i = 0, len1 = array.length; i < len1; i++) {31item = array[i];32if (item) {33results.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, len1;66flattened = [];67for (i = 0, len1 = array.length; i < len1; 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.some = (ref = Array.prototype.some) != null ? ref : function(fn) {86var e, i, len1;87for (i = 0, len1 = this.length; i < len1; i++) {88e = this[i];89if (fn(e)) {90return true;91}92}93return false;94};9596exports.invertLiterate = function(code) {97var line, lines, maybe_code;98maybe_code = true;99lines = (function() {100var i, len1, ref1, results;101ref1 = code.split('\n');102results = [];103for (i = 0, len1 = ref1.length; i < len1; i++) {104line = ref1[i];105if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {106results.push(line);107} else if (maybe_code = /^\s*$/.test(line)) {108results.push(line);109} else {110results.push('# ' + line);111}112}113return results;114})();115return lines.join('\n');116};117118buildLocationData = function(first, last) {119if (!last) {120return first;121} else {122return {123first_line: first.first_line,124first_column: first.first_column,125last_line: last.last_line,126last_column: last.last_column127};128}129};130131exports.addLocationDataFn = function(first, last) {132return function(obj) {133if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {134obj.updateLocationDataIfMissing(buildLocationData(first, last));135}136return obj;137};138};139140exports.locationDataToString = function(obj) {141var locationData;142if (("2" in obj) && ("first_line" in obj[2])) {143locationData = obj[2];144} else if ("first_line" in obj) {145locationData = obj;146}147if (locationData) {148return ((locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ((locationData.last_line + 1) + ":" + (locationData.last_column + 1));149} else {150return "No location data";151}152};153154exports.baseFileName = function(file, stripExt, useWinPathSep) {155var parts, pathSep;156if (stripExt == null) {157stripExt = false;158}159if (useWinPathSep == null) {160useWinPathSep = false;161}162pathSep = useWinPathSep ? /\\|\// : /\//;163parts = file.split(pathSep);164file = parts[parts.length - 1];165if (!(stripExt && file.indexOf('.') >= 0)) {166return file;167}168parts = file.split('.');169parts.pop();170if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {171parts.pop();172}173return parts.join('.');174};175176exports.isCoffee = function(file) {177return /\.((lit)?coffee|coffee\.md)$/.test(file);178};179180exports.isLiterate = function(file) {181return /\.(litcoffee|coffee\.md)$/.test(file);182};183184exports.throwSyntaxError = function(message, location) {185var error;186error = new SyntaxError(message);187error.location = location;188error.toString = syntaxErrorToString;189error.stack = error.toString();190throw error;191};192193exports.updateSyntaxError = function(error, code, filename) {194if (error.toString === syntaxErrorToString) {195error.code || (error.code = code);196error.filename || (error.filename = filename);197error.stack = error.toString();198}199return error;200};201202syntaxErrorToString = function() {203var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, ref1, ref2, ref3, ref4, start;204if (!(this.code && this.location)) {205return Error.prototype.toString.call(this);206}207ref1 = this.location, first_line = ref1.first_line, first_column = ref1.first_column, last_line = ref1.last_line, last_column = ref1.last_column;208if (last_line == null) {209last_line = first_line;210}211if (last_column == null) {212last_column = first_column;213}214filename = this.filename || '[stdin]';215codeLine = this.code.split('\n')[first_line];216start = first_column;217end = first_line === last_line ? last_column + 1 : codeLine.length;218marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start);219if (typeof process !== "undefined" && process !== null) {220colorsEnabled = ((ref2 = process.stdout) != null ? ref2.isTTY : void 0) && !((ref3 = process.env) != null ? ref3.NODE_DISABLE_COLORS : void 0);221}222if ((ref4 = this.colorful) != null ? ref4 : colorsEnabled) {223colorize = function(str) {224return "\x1B[1;31m" + str + "\x1B[0m";225};226codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);227marker = colorize(marker);228}229return filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;230};231232exports.nameWhitespaceCharacter = function(string) {233switch (string) {234case ' ':235return 'space';236case '\n':237return 'newline';238case '\r':239return 'carriage return';240case '\t':241return 'tab';242default:243return string;244}245};246247}).call(this);248249250