1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/extras/coffee-script.js

1 line
263 KiB
JavaScript
Raw Normal View History

2010-03-23 00:18:50 -04:00
(function(){var balanced_string,compact,count,del,extend,flatten,helpers,include,merge,starts;var __hasProp=Object.prototype.hasOwnProperty;if(!((typeof process!=="undefined"&&process!==null))){this.exports=this}helpers=(exports.helpers={});helpers.include=(include=function include(list,value){return list.indexOf(value)>=0});helpers.starts=(starts=function starts(string,literal,start){return string.substring(start,(start||0)+literal.length)===literal});helpers.compact=(compact=function compact(array){var _a,_b,_c,_d,item;_a=[];_b=array;for(_c=0,_d=_b.length;_c<_d;_c++){item=_b[_c];item?_a.push(item):null}return _a});helpers.count=(count=function count(string,letter){var num,pos;num=0;pos=string.indexOf(letter);while(pos!==-1){num+=1;pos=string.indexOf(letter,pos+1)}return num});helpers.merge=(merge=function merge(options,overrides){var _a,_b,fresh,key,val;fresh={};_a=options;for(key in _a){if(__hasProp.call(_a,key)){val=_a[key];(fresh[key]=val)}}if(overrides){_b=overrides;for(key in _b){if(__hasProp.call(_b,key)){val=_b[key];(fresh[key]=val)}}}return fresh});helpers.extend=(extend=function extend(object,properties){var _a,_b,key,val;_a=[];_b=properties;for(key in _b){if(__hasProp.call(_b,key)){val=_b[key];_a.push((object[key]=val))}}return _a});helpers.flatten=(flatten=function flatten(array){var _a,_b,_c,item,memo;memo=[];_a=array;for(_b=0,_c=_a.length;_b<_c;_b++){item=_a[_b];item instanceof Array?(memo=memo.concat(item)):memo.push(item)}return memo});helpers.del=(del=function del(obj,key){var val;val=obj[key];delete obj[key];return val});helpers.balanced_string=(balanced_string=function balanced_string(str,delimited,options){var _a,_b,_c,_d,close,i,levels,open,pair,slash;options=options||{};slash=delimited[0][0]==="/";levels=[];i=0;while(i<str.length){if(levels.length&&starts(str,"\\",i)){i+=1}else{_a=delimited;for(_b=0,_c=_a.length;_b<_c;_b++){pair=_a[_b];_d=pair;open=_d[0];close=_d[1];if(levels.length&&starts(str,close,i)&&levels[levels.length-1]===pair){levels.pop();i+=close.length-1;if(!(levels.length)){i+=1}break}else{if(starts(str,open,i)){levels.push(pair);i+=open.length-1;break}}}}if(!levels.length||slash&&starts(str,"\n",i)){break}i+=1}if(levels.length){if(slash){return false}throw new Error("SyntaxError: Unterminated "+(levels.pop()[0])+" starting on line "+(this.line+1))}if(!i){return false}else{return str.substring(0,i)}})})();(function(){var BALANCED_PAIRS,EXPRESSION_CLOSE,EXPRESSION_END,EXPRESSION_START,IMPLICIT_BLOCK,IMPLICIT_CALL,IMPLICIT_END,IMPLICIT_FUNC,INVERSES,Rewriter,SINGLE_CLOSERS,SINGLE_LINERS,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,helpers,include,pair;var __hasProp=Object.prototype.hasOwnProperty;if((typeof process!=="undefined"&&process!==null)){helpers=require("./helpers").helpers}else{this.exports=this;helpers=this.helpers}include=helpers.include;exports.Rewriter=(function(){Rewriter=function Rewriter(){};Rewriter.prototype.rewrite=function rewrite(tokens){this.tokens=tokens;this.adjust_comments();this.remove_leading_newlines();this.remove_mid_expression_newlines();this.close_open_calls_and_indexes();this.add_implicit_indentation();this.add_implicit_parentheses();this.ensure_balance(BALANCED_PAIRS);this.rewrite_closing_parens();return this.tokens};Rewriter.prototype.scan_tokens=function scan_tokens(block){var i,move;i=0;while(true){if(!(this.tokens[i])){break}move=block(this.tokens[i-1],this.tokens[i],this.tokens[i+1],i);i+=move}return true};Rewriter.prototype.adjust_comments=function adjust_comments(){return this.scan_tokens((function(__this){var __func=function(prev,token,post,i){var after;if(!(token[0]==="COMMENT")){return 1}after=this.tokens[i+2];if(after&&after[0]==="INDENT"){this.tokens.splice(i+2,1);this.tokens.splice(i,0,after);return 1}else{if(prev&&prev[0]!=="TERMINATOR"&&prev[0]!=="INDENT"&&prev[0]!=="OUTDENT"){this.tokens.splice(i,0,["TERMINATOR","\n",prev[2]]);return 2}else{return 1}}};return(function(){return __func.apply(__this,arguments)})})(this))};Rewriter.prototype.remove_leading_newlines=function remove_leading_newlines(){var _a;_a=[];while(this.tokens[0]&&this.tokens[0][0]==