1 // Generated by CoffeeScript 1.10.0
3 var buildLocationData, extend, flatten, ref, repeat, syntaxErrorToString;
5 exports.starts = function(string, literal, start) {
6 return literal === string.substr(start, literal.length);
9 exports.ends = function(string, literal, back) {
12 return literal === string.substr(string.length - len - (back || 0), len);
15 exports.repeat = repeat = function(str, n) {
28 exports.compact = function(array) {
29 var i, item, len1, results;
31 for (i = 0, len1 = array.length; i < len1; i++) {
40 exports.count = function(string, substr) {
46 while (pos = 1 + string.indexOf(substr, pos)) {
52 exports.merge = function(options, overrides) {
53 return extend(extend({}, options), overrides);
56 extend = exports.extend = function(object, properties) {
58 for (key in properties) {
59 val = properties[key];
65 exports.flatten = flatten = function(array) {
66 var element, flattened, i, len1;
68 for (i = 0, len1 = array.length; i < len1; i++) {
70 if ('[object Array]' === Object.prototype.toString.call(element)) {
71 flattened = flattened.concat(flatten(element));
73 flattened.push(element);
79 exports.del = function(obj, key) {
86 exports.some = (ref = Array.prototype.some) != null ? ref : function(fn) {
88 for (i = 0, len1 = this.length; i < len1; i++) {
97 exports.invertLiterate = function(code) {
98 var line, lines, maybe_code;
100 lines = (function() {
101 var i, len1, ref1, results;
102 ref1 = code.split('\n');
104 for (i = 0, len1 = ref1.length; i < len1; i++) {
106 if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
108 } else if (maybe_code = /^\s*$/.test(line)) {
111 results.push('# ' + line);
116 return lines.join('\n');
119 buildLocationData = function(first, last) {
124 first_line: first.first_line,
125 first_column: first.first_column,
126 last_line: last.last_line,
127 last_column: last.last_column
132 exports.addLocationDataFn = function(first, last) {
133 return function(obj) {
134 if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {
135 obj.updateLocationDataIfMissing(buildLocationData(first, last));
141 exports.locationDataToString = function(obj) {
143 if (("2" in obj) && ("first_line" in obj[2])) {
144 locationData = obj[2];
145 } else if ("first_line" in obj) {
149 return ((locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ((locationData.last_line + 1) + ":" + (locationData.last_column + 1));
151 return "No location data";
155 exports.baseFileName = function(file, stripExt, useWinPathSep) {
157 if (stripExt == null) {
160 if (useWinPathSep == null) {
161 useWinPathSep = false;
163 pathSep = useWinPathSep ? /\\|\// : /\//;
164 parts = file.split(pathSep);
165 file = parts[parts.length - 1];
166 if (!(stripExt && file.indexOf('.') >= 0)) {
169 parts = file.split('.');
171 if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {
174 return parts.join('.');
177 exports.isCoffee = function(file) {
178 return /\.((lit)?coffee|coffee\.md)$/.test(file);
181 exports.isLiterate = function(file) {
182 return /\.(litcoffee|coffee\.md)$/.test(file);
185 exports.throwSyntaxError = function(message, location) {
187 error = new SyntaxError(message);
188 error.location = location;
189 error.toString = syntaxErrorToString;
190 error.stack = error.toString();
194 exports.updateSyntaxError = function(error, code, filename) {
195 if (error.toString === syntaxErrorToString) {
196 error.code || (error.code = code);
197 error.filename || (error.filename = filename);
198 error.stack = error.toString();
203 syntaxErrorToString = function() {
204 var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, ref1, ref2, ref3, ref4, start;
205 if (!(this.code && this.location)) {
206 return Error.prototype.toString.call(this);
208 ref1 = this.location, first_line = ref1.first_line, first_column = ref1.first_column, last_line = ref1.last_line, last_column = ref1.last_column;
209 if (last_line == null) {
210 last_line = first_line;
212 if (last_column == null) {
213 last_column = first_column;
215 filename = this.filename || '[stdin]';
216 codeLine = this.code.split('\n')[first_line];
217 start = first_column;
218 end = first_line === last_line ? last_column + 1 : codeLine.length;
219 marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start);
220 if (typeof process !== "undefined" && process !== null) {
221 colorsEnabled = ((ref2 = process.stdout) != null ? ref2.isTTY : void 0) && !((ref3 = process.env) != null ? ref3.NODE_DISABLE_COLORS : void 0);
223 if ((ref4 = this.colorful) != null ? ref4 : colorsEnabled) {
224 colorize = function(str) {
225 return "\x1B[1;31m" + str + "\x1B[0m";
227 codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
228 marker = colorize(marker);
230 return filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
233 exports.nameWhitespaceCharacter = function(string) {
240 return 'carriage return';