1 // Generated by CoffeeScript 1.8.0
3 var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
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 item, _i, _len, _results;
31 for (_i = 0, _len = array.length; _i < _len; _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, _len;
68 for (_i = 0, _len = array.length; _i < _len; _i++) {
70 if (element instanceof Array) {
71 flattened = flattened.concat(flatten(element));
73 flattened.push(element);
79 exports.del = function(obj, key) {
86 exports.last = last = function(array, back) {
87 return array[array.length - (back || 0) - 1];
90 exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
92 for (_i = 0, _len = this.length; _i < _len; _i++) {
101 exports.invertLiterate = function(code) {
102 var line, lines, maybe_code;
104 lines = (function() {
105 var _i, _len, _ref1, _results;
106 _ref1 = code.split('\n');
108 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
110 if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
112 } else if (maybe_code = /^\s*$/.test(line)) {
115 _results.push('# ' + line);
120 return lines.join('\n');
123 buildLocationData = function(first, last) {
128 first_line: first.first_line,
129 first_column: first.first_column,
130 last_line: last.last_line,
131 last_column: last.last_column
136 exports.addLocationDataFn = function(first, last) {
137 return function(obj) {
138 if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {
139 obj.updateLocationDataIfMissing(buildLocationData(first, last));
145 exports.locationDataToString = function(obj) {
147 if (("2" in obj) && ("first_line" in obj[2])) {
148 locationData = obj[2];
149 } else if ("first_line" in obj) {
153 return ("" + (locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ("" + (locationData.last_line + 1) + ":" + (locationData.last_column + 1));
155 return "No location data";
159 exports.baseFileName = function(file, stripExt, useWinPathSep) {
161 if (stripExt == null) {
164 if (useWinPathSep == null) {
165 useWinPathSep = false;
167 pathSep = useWinPathSep ? /\\|\// : /\//;
168 parts = file.split(pathSep);
169 file = parts[parts.length - 1];
170 if (!(stripExt && file.indexOf('.') >= 0)) {
173 parts = file.split('.');
175 if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {
178 return parts.join('.');
181 exports.isCoffee = function(file) {
182 return /\.((lit)?coffee|coffee\.md)$/.test(file);
185 exports.isLiterate = function(file) {
186 return /\.(litcoffee|coffee\.md)$/.test(file);
189 exports.throwSyntaxError = function(message, location) {
191 error = new SyntaxError(message);
192 error.location = location;
193 error.toString = syntaxErrorToString;
194 error.stack = error.toString();
198 exports.updateSyntaxError = function(error, code, filename) {
199 if (error.toString === syntaxErrorToString) {
200 error.code || (error.code = code);
201 error.filename || (error.filename = filename);
202 error.stack = error.toString();
207 syntaxErrorToString = function() {
208 var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
209 if (!(this.code && this.location)) {
210 return Error.prototype.toString.call(this);
212 _ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
213 if (last_line == null) {
214 last_line = first_line;
216 if (last_column == null) {
217 last_column = first_column;
219 filename = this.filename || '[stdin]';
220 codeLine = this.code.split('\n')[first_line];
221 start = first_column;
222 end = first_line === last_line ? last_column + 1 : codeLine.length;
223 marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start);
224 if (typeof process !== "undefined" && process !== null) {
225 colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
227 if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
228 colorize = function(str) {
229 return "\x1B[1;31m" + str + "\x1B[0m";
231 codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
232 marker = colorize(marker);
234 return "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
237 exports.nameWhitespaceCharacter = function(string) {
244 return 'carriage return';