coffeescript-router 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.gitignore +3 -0
  2. data/Cakefile +122 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/LICENSE.txt +19 -0
  6. data/README.md +18 -0
  7. data/Rakefile +2 -0
  8. data/SpecRunner.html +25 -0
  9. data/coffeescript-router.gemspec +19 -0
  10. data/lib/CoffeeScript.png +0 -0
  11. data/lib/coffeescript-router/version.rb +5 -0
  12. data/lib/jasmine-1.0.2/MIT.LICENSE +20 -0
  13. data/lib/jasmine-1.0.2/jasmine-html.js +188 -0
  14. data/lib/jasmine-1.0.2/jasmine.css +166 -0
  15. data/lib/jasmine-1.0.2/jasmine.js +2421 -0
  16. data/node_modules/.bin/cake +7 -0
  17. data/node_modules/.bin/coffee +7 -0
  18. data/node_modules/.bin/uglifyjs +212 -0
  19. data/node_modules/coffee-script/.npmignore +11 -0
  20. data/node_modules/coffee-script/LICENSE +22 -0
  21. data/node_modules/coffee-script/README +48 -0
  22. data/node_modules/coffee-script/Rakefile +78 -0
  23. data/node_modules/coffee-script/bin/cake +7 -0
  24. data/node_modules/coffee-script/bin/coffee +7 -0
  25. data/node_modules/coffee-script/lib/browser.js +75 -0
  26. data/node_modules/coffee-script/lib/cake.js +76 -0
  27. data/node_modules/coffee-script/lib/coffee-script.js +107 -0
  28. data/node_modules/coffee-script/lib/command.js +274 -0
  29. data/node_modules/coffee-script/lib/grammar.js +591 -0
  30. data/node_modules/coffee-script/lib/helpers.js +66 -0
  31. data/node_modules/coffee-script/lib/index.js +8 -0
  32. data/node_modules/coffee-script/lib/lexer.js +650 -0
  33. data/node_modules/coffee-script/lib/nodes.js +2230 -0
  34. data/node_modules/coffee-script/lib/optparse.js +111 -0
  35. data/node_modules/coffee-script/lib/parser.js +676 -0
  36. data/node_modules/coffee-script/lib/repl.js +114 -0
  37. data/node_modules/coffee-script/lib/rewriter.js +359 -0
  38. data/node_modules/coffee-script/lib/scope.js +120 -0
  39. data/node_modules/coffee-script/package.json +27 -0
  40. data/node_modules/growl/History.md +16 -0
  41. data/node_modules/growl/Readme.md +74 -0
  42. data/node_modules/growl/lib/growl.js +82 -0
  43. data/node_modules/growl/package.json +6 -0
  44. data/node_modules/growl/test.js +17 -0
  45. data/node_modules/uglify-js/.gitignore +4 -0
  46. data/node_modules/uglify-js/README.html +825 -0
  47. data/node_modules/uglify-js/README.org +431 -0
  48. data/node_modules/uglify-js/bin/uglifyjs +212 -0
  49. data/node_modules/uglify-js/docstyle.css +75 -0
  50. data/node_modules/uglify-js/lib/parse-js.js +1319 -0
  51. data/node_modules/uglify-js/lib/process.js +1614 -0
  52. data/node_modules/uglify-js/lib/squeeze-more.js +22 -0
  53. data/node_modules/uglify-js/package.json +22 -0
  54. data/node_modules/uglify-js/test/beautify.js +28 -0
  55. data/node_modules/uglify-js/test/testparser.js +402 -0
  56. data/node_modules/uglify-js/test/unit/compress/expected/array1.js +1 -0
  57. data/node_modules/uglify-js/test/unit/compress/expected/array2.js +1 -0
  58. data/node_modules/uglify-js/test/unit/compress/expected/array3.js +1 -0
  59. data/node_modules/uglify-js/test/unit/compress/expected/array4.js +1 -0
  60. data/node_modules/uglify-js/test/unit/compress/expected/assignment.js +1 -0
  61. data/node_modules/uglify-js/test/unit/compress/expected/concatstring.js +1 -0
  62. data/node_modules/uglify-js/test/unit/compress/expected/const.js +1 -0
  63. data/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js +1 -0
  64. data/node_modules/uglify-js/test/unit/compress/expected/forstatement.js +1 -0
  65. data/node_modules/uglify-js/test/unit/compress/expected/if.js +1 -0
  66. data/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js +1 -0
  67. data/node_modules/uglify-js/test/unit/compress/expected/issue10.js +1 -0
  68. data/node_modules/uglify-js/test/unit/compress/expected/issue11.js +1 -0
  69. data/node_modules/uglify-js/test/unit/compress/expected/issue13.js +1 -0
  70. data/node_modules/uglify-js/test/unit/compress/expected/issue14.js +1 -0
  71. data/node_modules/uglify-js/test/unit/compress/expected/issue16.js +1 -0
  72. data/node_modules/uglify-js/test/unit/compress/expected/issue17.js +1 -0
  73. data/node_modules/uglify-js/test/unit/compress/expected/issue20.js +1 -0
  74. data/node_modules/uglify-js/test/unit/compress/expected/issue21.js +1 -0
  75. data/node_modules/uglify-js/test/unit/compress/expected/issue25.js +1 -0
  76. data/node_modules/uglify-js/test/unit/compress/expected/issue27.js +1 -0
  77. data/node_modules/uglify-js/test/unit/compress/expected/issue28.js +1 -0
  78. data/node_modules/uglify-js/test/unit/compress/expected/issue29.js +1 -0
  79. data/node_modules/uglify-js/test/unit/compress/expected/issue30.js +1 -0
  80. data/node_modules/uglify-js/test/unit/compress/expected/issue34.js +1 -0
  81. data/node_modules/uglify-js/test/unit/compress/expected/issue4.js +1 -0
  82. data/node_modules/uglify-js/test/unit/compress/expected/issue48.js +1 -0
  83. data/node_modules/uglify-js/test/unit/compress/expected/issue50.js +1 -0
  84. data/node_modules/uglify-js/test/unit/compress/expected/issue53.js +1 -0
  85. data/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js +1 -0
  86. data/node_modules/uglify-js/test/unit/compress/expected/issue68.js +1 -0
  87. data/node_modules/uglify-js/test/unit/compress/expected/issue69.js +1 -0
  88. data/node_modules/uglify-js/test/unit/compress/expected/issue9.js +1 -0
  89. data/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js +1 -0
  90. data/node_modules/uglify-js/test/unit/compress/expected/var.js +1 -0
  91. data/node_modules/uglify-js/test/unit/compress/test/array1.js +3 -0
  92. data/node_modules/uglify-js/test/unit/compress/test/array2.js +4 -0
  93. data/node_modules/uglify-js/test/unit/compress/test/array3.js +4 -0
  94. data/node_modules/uglify-js/test/unit/compress/test/array4.js +6 -0
  95. data/node_modules/uglify-js/test/unit/compress/test/assignment.js +20 -0
  96. data/node_modules/uglify-js/test/unit/compress/test/concatstring.js +3 -0
  97. data/node_modules/uglify-js/test/unit/compress/test/const.js +5 -0
  98. data/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js +4 -0
  99. data/node_modules/uglify-js/test/unit/compress/test/forstatement.js +10 -0
  100. data/node_modules/uglify-js/test/unit/compress/test/if.js +6 -0
  101. data/node_modules/uglify-js/test/unit/compress/test/ifreturn.js +9 -0
  102. data/node_modules/uglify-js/test/unit/compress/test/issue10.js +1 -0
  103. data/node_modules/uglify-js/test/unit/compress/test/issue11.js +3 -0
  104. data/node_modules/uglify-js/test/unit/compress/test/issue13.js +1 -0
  105. data/node_modules/uglify-js/test/unit/compress/test/issue14.js +1 -0
  106. data/node_modules/uglify-js/test/unit/compress/test/issue16.js +1 -0
  107. data/node_modules/uglify-js/test/unit/compress/test/issue17.js +4 -0
  108. data/node_modules/uglify-js/test/unit/compress/test/issue20.js +1 -0
  109. data/node_modules/uglify-js/test/unit/compress/test/issue21.js +6 -0
  110. data/node_modules/uglify-js/test/unit/compress/test/issue25.js +7 -0
  111. data/node_modules/uglify-js/test/unit/compress/test/issue27.js +1 -0
  112. data/node_modules/uglify-js/test/unit/compress/test/issue28.js +3 -0
  113. data/node_modules/uglify-js/test/unit/compress/test/issue29.js +1 -0
  114. data/node_modules/uglify-js/test/unit/compress/test/issue30.js +3 -0
  115. data/node_modules/uglify-js/test/unit/compress/test/issue34.js +3 -0
  116. data/node_modules/uglify-js/test/unit/compress/test/issue4.js +3 -0
  117. data/node_modules/uglify-js/test/unit/compress/test/issue48.js +1 -0
  118. data/node_modules/uglify-js/test/unit/compress/test/issue50.js +9 -0
  119. data/node_modules/uglify-js/test/unit/compress/test/issue53.js +1 -0
  120. data/node_modules/uglify-js/test/unit/compress/test/issue54.1.js +3 -0
  121. data/node_modules/uglify-js/test/unit/compress/test/issue68.js +5 -0
  122. data/node_modules/uglify-js/test/unit/compress/test/issue69.js +1 -0
  123. data/node_modules/uglify-js/test/unit/compress/test/issue9.js +4 -0
  124. data/node_modules/uglify-js/test/unit/compress/test/strict-equals.js +3 -0
  125. data/node_modules/uglify-js/test/unit/compress/test/var.js +3 -0
  126. data/node_modules/uglify-js/test/unit/scripts.js +46 -0
  127. data/node_modules/uglify-js/uglify-js.js +2 -0
  128. data/src/coffeescript/coffeescript-router.js.coffee +31 -0
  129. data/test/coffeescript/routerSpec.coffee +47 -0
  130. data/vendor/assets/javascripts/coffeescript-router.min.js +1 -0
  131. metadata +187 -0
@@ -0,0 +1,114 @@
1
+ (function() {
2
+ var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, getPropertyNames, inspect, readline, repl, run, stdin, stdout;
3
+ var __hasProp = Object.prototype.hasOwnProperty;
4
+ CoffeeScript = require('./coffee-script');
5
+ readline = require('readline');
6
+ inspect = require('util').inspect;
7
+ Script = require('vm').Script;
8
+ enableColours = false;
9
+ if (process.platform !== 'win32') {
10
+ enableColours = !process.env.NODE_DISABLE_COLORS;
11
+ }
12
+ stdin = process.openStdin();
13
+ stdout = process.stdout;
14
+ error = function(err) {
15
+ return stdout.write((err.stack || err.toString()) + '\n\n');
16
+ };
17
+ backlog = '';
18
+ run = (function() {
19
+ var g, sandbox;
20
+ sandbox = {
21
+ require: require,
22
+ module: {
23
+ exports: {}
24
+ }
25
+ };
26
+ for (g in global) {
27
+ sandbox[g] = global[g];
28
+ }
29
+ sandbox.global = sandbox;
30
+ sandbox.global.global = sandbox.global.root = sandbox.global.GLOBAL = sandbox;
31
+ return function(buffer) {
32
+ var code, val;
33
+ code = backlog += '\n' + buffer.toString();
34
+ if (code[code.length - 1] === '\\') {
35
+ return backlog = backlog.slice(0, backlog.length - 1);
36
+ }
37
+ backlog = '';
38
+ try {
39
+ val = CoffeeScript.eval(code, {
40
+ sandbox: sandbox,
41
+ bare: true,
42
+ filename: 'repl'
43
+ });
44
+ if (val !== void 0) {
45
+ process.stdout.write(inspect(val, false, 2, enableColours) + '\n');
46
+ }
47
+ } catch (err) {
48
+ error(err);
49
+ }
50
+ return repl.prompt();
51
+ };
52
+ })();
53
+ ACCESSOR = /\s*([\w\.]+)(?:\.(\w*))$/;
54
+ SIMPLEVAR = /\s*(\w*)$/i;
55
+ autocomplete = function(text) {
56
+ return completeAttribute(text) || completeVariable(text) || [[], text];
57
+ };
58
+ completeAttribute = function(text) {
59
+ var all, completions, match, obj, prefix, val;
60
+ if (match = text.match(ACCESSOR)) {
61
+ all = match[0], obj = match[1], prefix = match[2];
62
+ try {
63
+ val = Script.runInThisContext(obj);
64
+ } catch (error) {
65
+ return [[], text];
66
+ }
67
+ completions = getCompletions(prefix, getPropertyNames(val));
68
+ return [completions, prefix];
69
+ }
70
+ };
71
+ completeVariable = function(text) {
72
+ var completions, free, scope, _ref;
73
+ if (free = (_ref = text.match(SIMPLEVAR)) != null ? _ref[1] : void 0) {
74
+ scope = Script.runInThisContext('this');
75
+ completions = getCompletions(free, CoffeeScript.RESERVED.concat(getPropertyNames(scope)));
76
+ return [completions, free];
77
+ }
78
+ };
79
+ getCompletions = function(prefix, candidates) {
80
+ var el, _i, _len, _results;
81
+ _results = [];
82
+ for (_i = 0, _len = candidates.length; _i < _len; _i++) {
83
+ el = candidates[_i];
84
+ if (el.indexOf(prefix) === 0) {
85
+ _results.push(el);
86
+ }
87
+ }
88
+ return _results;
89
+ };
90
+ getPropertyNames = function(obj) {
91
+ var name, _results;
92
+ _results = [];
93
+ for (name in obj) {
94
+ if (!__hasProp.call(obj, name)) continue;
95
+ _results.push(name);
96
+ }
97
+ return _results;
98
+ };
99
+ process.on('uncaughtException', error);
100
+ if (readline.createInterface.length < 3) {
101
+ repl = readline.createInterface(stdin, autocomplete);
102
+ stdin.on('data', function(buffer) {
103
+ return repl.write(buffer);
104
+ });
105
+ } else {
106
+ repl = readline.createInterface(stdin, stdout, autocomplete);
107
+ }
108
+ repl.setPrompt('coffee> ');
109
+ repl.on('close', function() {
110
+ return stdin.destroy();
111
+ });
112
+ repl.on('line', run);
113
+ repl.prompt();
114
+ }).call(this);
@@ -0,0 +1,359 @@
1
+ (function() {
2
+ var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref;
3
+ var __indexOf = Array.prototype.indexOf || function(item) {
4
+ for (var i = 0, l = this.length; i < l; i++) {
5
+ if (this[i] === item) return i;
6
+ }
7
+ return -1;
8
+ }, __slice = Array.prototype.slice;
9
+ exports.Rewriter = (function() {
10
+ function Rewriter() {}
11
+ Rewriter.prototype.rewrite = function(tokens) {
12
+ this.tokens = tokens;
13
+ this.removeLeadingNewlines();
14
+ this.removeMidExpressionNewlines();
15
+ this.closeOpenCalls();
16
+ this.closeOpenIndexes();
17
+ this.addImplicitIndentation();
18
+ this.tagPostfixConditionals();
19
+ this.addImplicitBraces();
20
+ this.addImplicitParentheses();
21
+ this.ensureBalance(BALANCED_PAIRS);
22
+ this.rewriteClosingParens();
23
+ return this.tokens;
24
+ };
25
+ Rewriter.prototype.scanTokens = function(block) {
26
+ var i, token, tokens;
27
+ tokens = this.tokens;
28
+ i = 0;
29
+ while (token = tokens[i]) {
30
+ i += block.call(this, token, i, tokens);
31
+ }
32
+ return true;
33
+ };
34
+ Rewriter.prototype.detectEnd = function(i, condition, action) {
35
+ var levels, token, tokens, _ref, _ref2;
36
+ tokens = this.tokens;
37
+ levels = 0;
38
+ while (token = tokens[i]) {
39
+ if (levels === 0 && condition.call(this, token, i)) {
40
+ return action.call(this, token, i);
41
+ }
42
+ if (!token || levels < 0) {
43
+ return action.call(this, token, i - 1);
44
+ }
45
+ if (_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) {
46
+ levels += 1;
47
+ } else if (_ref2 = token[0], __indexOf.call(EXPRESSION_END, _ref2) >= 0) {
48
+ levels -= 1;
49
+ }
50
+ i += 1;
51
+ }
52
+ return i - 1;
53
+ };
54
+ Rewriter.prototype.removeLeadingNewlines = function() {
55
+ var i, tag, _len, _ref;
56
+ _ref = this.tokens;
57
+ for (i = 0, _len = _ref.length; i < _len; i++) {
58
+ tag = _ref[i][0];
59
+ if (tag !== 'TERMINATOR') {
60
+ break;
61
+ }
62
+ }
63
+ if (i) {
64
+ return this.tokens.splice(0, i);
65
+ }
66
+ };
67
+ Rewriter.prototype.removeMidExpressionNewlines = function() {
68
+ return this.scanTokens(function(token, i, tokens) {
69
+ var _ref;
70
+ if (!(token[0] === 'TERMINATOR' && (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0))) {
71
+ return 1;
72
+ }
73
+ tokens.splice(i, 1);
74
+ return 0;
75
+ });
76
+ };
77
+ Rewriter.prototype.closeOpenCalls = function() {
78
+ var action, condition;
79
+ condition = function(token, i) {
80
+ var _ref;
81
+ return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
82
+ };
83
+ action = function(token, i) {
84
+ return this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END';
85
+ };
86
+ return this.scanTokens(function(token, i) {
87
+ if (token[0] === 'CALL_START') {
88
+ this.detectEnd(i + 1, condition, action);
89
+ }
90
+ return 1;
91
+ });
92
+ };
93
+ Rewriter.prototype.closeOpenIndexes = function() {
94
+ var action, condition;
95
+ condition = function(token, i) {
96
+ var _ref;
97
+ return (_ref = token[0]) === ']' || _ref === 'INDEX_END';
98
+ };
99
+ action = function(token, i) {
100
+ return token[0] = 'INDEX_END';
101
+ };
102
+ return this.scanTokens(function(token, i) {
103
+ if (token[0] === 'INDEX_START') {
104
+ this.detectEnd(i + 1, condition, action);
105
+ }
106
+ return 1;
107
+ });
108
+ };
109
+ Rewriter.prototype.addImplicitBraces = function() {
110
+ var action, condition, stack, start, startIndent;
111
+ stack = [];
112
+ start = null;
113
+ startIndent = 0;
114
+ condition = function(token, i) {
115
+ var one, tag, three, two, _ref, _ref2;
116
+ _ref = this.tokens.slice(i + 1, (i + 3 + 1) || 9e9), one = _ref[0], two = _ref[1], three = _ref[2];
117
+ if ('HERECOMMENT' === (one != null ? one[0] : void 0)) {
118
+ return false;
119
+ }
120
+ tag = token[0];
121
+ return ((tag === 'TERMINATOR' || tag === 'OUTDENT') && !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':')) || (tag === ',' && one && ((_ref2 = one[0]) !== 'IDENTIFIER' && _ref2 !== 'NUMBER' && _ref2 !== 'STRING' && _ref2 !== '@' && _ref2 !== 'TERMINATOR' && _ref2 !== 'OUTDENT'));
122
+ };
123
+ action = function(token, i) {
124
+ var tok;
125
+ tok = ['}', '}', token[2]];
126
+ tok.generated = true;
127
+ return this.tokens.splice(i, 0, tok);
128
+ };
129
+ return this.scanTokens(function(token, i, tokens) {
130
+ var ago, idx, tag, tok, value, _ref, _ref2;
131
+ if (_ref = (tag = token[0]), __indexOf.call(EXPRESSION_START, _ref) >= 0) {
132
+ stack.push([(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag), i]);
133
+ return 1;
134
+ }
135
+ if (__indexOf.call(EXPRESSION_END, tag) >= 0) {
136
+ start = stack.pop();
137
+ return 1;
138
+ }
139
+ if (!(tag === ':' && ((ago = this.tag(i - 2)) === ':' || ((_ref2 = stack[stack.length - 1]) != null ? _ref2[0] : void 0) !== '{'))) {
140
+ return 1;
141
+ }
142
+ stack.push(['{']);
143
+ idx = ago === '@' ? i - 2 : i - 1;
144
+ while (this.tag(idx - 2) === 'HERECOMMENT') {
145
+ idx -= 2;
146
+ }
147
+ value = new String('{');
148
+ value.generated = true;
149
+ tok = ['{', value, token[2]];
150
+ tok.generated = true;
151
+ tokens.splice(idx, 0, tok);
152
+ this.detectEnd(i + 2, condition, action);
153
+ return 2;
154
+ });
155
+ };
156
+ Rewriter.prototype.addImplicitParentheses = function() {
157
+ var action, noCall;
158
+ noCall = false;
159
+ action = function(token, i) {
160
+ var idx;
161
+ idx = token[0] === 'OUTDENT' ? i + 1 : i;
162
+ return this.tokens.splice(idx, 0, ['CALL_END', ')', token[2]]);
163
+ };
164
+ return this.scanTokens(function(token, i, tokens) {
165
+ var callObject, current, next, prev, seenSingle, tag, _ref, _ref2, _ref3;
166
+ tag = token[0];
167
+ if (tag === 'CLASS' || tag === 'IF') {
168
+ noCall = true;
169
+ }
170
+ _ref = tokens.slice(i - 1, (i + 1 + 1) || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2];
171
+ callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0);
172
+ seenSingle = false;
173
+ if (__indexOf.call(LINEBREAKS, tag) >= 0) {
174
+ noCall = false;
175
+ }
176
+ if (prev && !prev.spaced && tag === '?') {
177
+ token.call = true;
178
+ }
179
+ if (token.fromThen) {
180
+ return 1;
181
+ }
182
+ if (!(callObject || (prev != null ? prev.spaced : void 0) && (prev.call || (_ref3 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref3) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) {
183
+ return 1;
184
+ }
185
+ tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
186
+ this.detectEnd(i + 1, function(token, i) {
187
+ var post, _ref4;
188
+ tag = token[0];
189
+ if (!seenSingle && token.fromThen) {
190
+ return true;
191
+ }
192
+ if (tag === 'IF' || tag === 'ELSE' || tag === '->' || tag === '=>') {
193
+ seenSingle = true;
194
+ }
195
+ if ((tag === '.' || tag === '?.' || tag === '::') && this.tag(i - 1) === 'OUTDENT') {
196
+ return true;
197
+ }
198
+ return !token.generated && this.tag(i - 1) !== ',' && __indexOf.call(IMPLICIT_END, tag) >= 0 && (tag !== 'INDENT' || (this.tag(i - 2) !== 'CLASS' && (_ref4 = this.tag(i - 1), __indexOf.call(IMPLICIT_BLOCK, _ref4) < 0) && !((post = this.tokens[i + 1]) && post.generated && post[0] === '{')));
199
+ }, action);
200
+ if (prev[0] === '?') {
201
+ prev[0] = 'FUNC_EXIST';
202
+ }
203
+ return 2;
204
+ });
205
+ };
206
+ Rewriter.prototype.addImplicitIndentation = function() {
207
+ return this.scanTokens(function(token, i, tokens) {
208
+ var action, condition, indent, outdent, starter, tag, _ref, _ref2;
209
+ tag = token[0];
210
+ if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') {
211
+ tokens.splice(i, 1);
212
+ return 0;
213
+ }
214
+ if (tag === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
215
+ tokens.splice.apply(tokens, [i, 0].concat(__slice.call(this.indentation(token))));
216
+ return 2;
217
+ }
218
+ if (tag === 'CATCH' && ((_ref = this.tag(i + 2)) === 'OUTDENT' || _ref === 'TERMINATOR' || _ref === 'FINALLY')) {
219
+ tokens.splice.apply(tokens, [i + 2, 0].concat(__slice.call(this.indentation(token))));
220
+ return 4;
221
+ }
222
+ if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
223
+ starter = tag;
224
+ _ref2 = this.indentation(token), indent = _ref2[0], outdent = _ref2[1];
225
+ if (starter === 'THEN') {
226
+ indent.fromThen = true;
227
+ }
228
+ indent.generated = outdent.generated = true;
229
+ tokens.splice(i + 1, 0, indent);
230
+ condition = function(token, i) {
231
+ var _ref3;
232
+ return token[1] !== ';' && (_ref3 = token[0], __indexOf.call(SINGLE_CLOSERS, _ref3) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN'));
233
+ };
234
+ action = function(token, i) {
235
+ return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
236
+ };
237
+ this.detectEnd(i + 2, condition, action);
238
+ if (tag === 'THEN') {
239
+ tokens.splice(i, 1);
240
+ }
241
+ return 1;
242
+ }
243
+ return 1;
244
+ });
245
+ };
246
+ Rewriter.prototype.tagPostfixConditionals = function() {
247
+ var condition;
248
+ condition = function(token, i) {
249
+ var _ref;
250
+ return (_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT';
251
+ };
252
+ return this.scanTokens(function(token, i) {
253
+ var original;
254
+ if (token[0] !== 'IF') {
255
+ return 1;
256
+ }
257
+ original = token;
258
+ this.detectEnd(i + 1, condition, function(token, i) {
259
+ if (token[0] !== 'INDENT') {
260
+ return original[0] = 'POST_' + original[0];
261
+ }
262
+ });
263
+ return 1;
264
+ });
265
+ };
266
+ Rewriter.prototype.ensureBalance = function(pairs) {
267
+ var close, level, levels, open, openLine, tag, token, _i, _j, _len, _len2, _ref, _ref2;
268
+ levels = {};
269
+ openLine = {};
270
+ _ref = this.tokens;
271
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
272
+ token = _ref[_i];
273
+ tag = token[0];
274
+ for (_j = 0, _len2 = pairs.length; _j < _len2; _j++) {
275
+ _ref2 = pairs[_j], open = _ref2[0], close = _ref2[1];
276
+ levels[open] |= 0;
277
+ if (tag === open) {
278
+ if (levels[open]++ === 0) {
279
+ openLine[open] = token[2];
280
+ }
281
+ } else if (tag === close && --levels[open] < 0) {
282
+ throw Error("too many " + token[1] + " on line " + (token[2] + 1));
283
+ }
284
+ }
285
+ }
286
+ for (open in levels) {
287
+ level = levels[open];
288
+ if (level > 0) {
289
+ throw Error("unclosed " + open + " on line " + (openLine[open] + 1));
290
+ }
291
+ }
292
+ return this;
293
+ };
294
+ Rewriter.prototype.rewriteClosingParens = function() {
295
+ var debt, key, stack;
296
+ stack = [];
297
+ debt = {};
298
+ for (key in INVERSES) {
299
+ debt[key] = 0;
300
+ }
301
+ return this.scanTokens(function(token, i, tokens) {
302
+ var inv, match, mtag, oppos, tag, val, _ref;
303
+ if (_ref = (tag = token[0]), __indexOf.call(EXPRESSION_START, _ref) >= 0) {
304
+ stack.push(token);
305
+ return 1;
306
+ }
307
+ if (__indexOf.call(EXPRESSION_END, tag) < 0) {
308
+ return 1;
309
+ }
310
+ if (debt[inv = INVERSES[tag]] > 0) {
311
+ debt[inv] -= 1;
312
+ tokens.splice(i, 1);
313
+ return 0;
314
+ }
315
+ match = stack.pop();
316
+ mtag = match[0];
317
+ oppos = INVERSES[mtag];
318
+ if (tag === oppos) {
319
+ return 1;
320
+ }
321
+ debt[mtag] += 1;
322
+ val = [oppos, mtag === 'INDENT' ? match[1] : oppos];
323
+ if (this.tag(i + 2) === mtag) {
324
+ tokens.splice(i + 3, 0, val);
325
+ stack.push(match);
326
+ } else {
327
+ tokens.splice(i, 0, val);
328
+ }
329
+ return 1;
330
+ });
331
+ };
332
+ Rewriter.prototype.indentation = function(token) {
333
+ return [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]];
334
+ };
335
+ Rewriter.prototype.tag = function(i) {
336
+ var _ref;
337
+ return (_ref = this.tokens[i]) != null ? _ref[0] : void 0;
338
+ };
339
+ return Rewriter;
340
+ })();
341
+ BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['CALL_START', 'CALL_END'], ['PARAM_START', 'PARAM_END'], ['INDEX_START', 'INDEX_END']];
342
+ INVERSES = {};
343
+ EXPRESSION_START = [];
344
+ EXPRESSION_END = [];
345
+ for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; _i++) {
346
+ _ref = BALANCED_PAIRS[_i], left = _ref[0], rite = _ref[1];
347
+ EXPRESSION_START.push(INVERSES[rite] = left);
348
+ EXPRESSION_END.push(INVERSES[left] = rite);
349
+ }
350
+ EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
351
+ IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
352
+ IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', 'SUPER', '@', '->', '=>', '[', '(', '{', '--', '++'];
353
+ IMPLICIT_UNSPACED_CALL = ['+', '-'];
354
+ IMPLICIT_BLOCK = ['->', '=>', '{', '[', ','];
355
+ IMPLICIT_END = ['POST_IF', 'FOR', 'WHILE', 'UNTIL', 'WHEN', 'BY', 'LOOP', 'TERMINATOR', 'INDENT'];
356
+ SINGLE_LINERS = ['ELSE', '->', '=>', 'TRY', 'FINALLY', 'THEN'];
357
+ SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN'];
358
+ LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT'];
359
+ }).call(this);