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,66 @@
1
+ (function() {
2
+ var extend, flatten;
3
+ exports.starts = function(string, literal, start) {
4
+ return literal === string.substr(start, literal.length);
5
+ };
6
+ exports.ends = function(string, literal, back) {
7
+ var len;
8
+ len = literal.length;
9
+ return literal === string.substr(string.length - len - (back || 0), len);
10
+ };
11
+ exports.compact = function(array) {
12
+ var item, _i, _len, _results;
13
+ _results = [];
14
+ for (_i = 0, _len = array.length; _i < _len; _i++) {
15
+ item = array[_i];
16
+ if (item) {
17
+ _results.push(item);
18
+ }
19
+ }
20
+ return _results;
21
+ };
22
+ exports.count = function(string, substr) {
23
+ var num, pos;
24
+ num = pos = 0;
25
+ if (!substr.length) {
26
+ return 1 / 0;
27
+ }
28
+ while (pos = 1 + string.indexOf(substr, pos)) {
29
+ num++;
30
+ }
31
+ return num;
32
+ };
33
+ exports.merge = function(options, overrides) {
34
+ return extend(extend({}, options), overrides);
35
+ };
36
+ extend = exports.extend = function(object, properties) {
37
+ var key, val;
38
+ for (key in properties) {
39
+ val = properties[key];
40
+ object[key] = val;
41
+ }
42
+ return object;
43
+ };
44
+ exports.flatten = flatten = function(array) {
45
+ var element, flattened, _i, _len;
46
+ flattened = [];
47
+ for (_i = 0, _len = array.length; _i < _len; _i++) {
48
+ element = array[_i];
49
+ if (element instanceof Array) {
50
+ flattened = flattened.concat(flatten(element));
51
+ } else {
52
+ flattened.push(element);
53
+ }
54
+ }
55
+ return flattened;
56
+ };
57
+ exports.del = function(obj, key) {
58
+ var val;
59
+ val = obj[key];
60
+ delete obj[key];
61
+ return val;
62
+ };
63
+ exports.last = function(array, back) {
64
+ return array[array.length - (back || 0) - 1];
65
+ };
66
+ }).call(this);
@@ -0,0 +1,8 @@
1
+ (function() {
2
+ var key, val, _ref;
3
+ _ref = require('./coffee-script');
4
+ for (key in _ref) {
5
+ val = _ref[key];
6
+ exports[key] = val;
7
+ }
8
+ }).call(this);
@@ -0,0 +1,650 @@
1
+ (function() {
2
+ var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _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
+ };
9
+ Rewriter = require('./rewriter').Rewriter;
10
+ _ref = require('./helpers'), count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last;
11
+ exports.Lexer = Lexer = (function() {
12
+ function Lexer() {}
13
+ Lexer.prototype.tokenize = function(code, opts) {
14
+ var i;
15
+ if (opts == null) {
16
+ opts = {};
17
+ }
18
+ if (WHITESPACE.test(code)) {
19
+ code = "\n" + code;
20
+ }
21
+ code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
22
+ this.code = code;
23
+ this.line = opts.line || 0;
24
+ this.indent = 0;
25
+ this.indebt = 0;
26
+ this.outdebt = 0;
27
+ this.indents = [];
28
+ this.tokens = [];
29
+ i = 0;
30
+ while (this.chunk = code.slice(i)) {
31
+ i += this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
32
+ }
33
+ this.closeIndentation();
34
+ if (opts.rewrite === false) {
35
+ return this.tokens;
36
+ }
37
+ return (new Rewriter).rewrite(this.tokens);
38
+ };
39
+ Lexer.prototype.identifierToken = function() {
40
+ var colon, forcedIdentifier, id, input, match, prev, tag, _ref2, _ref3;
41
+ if (!(match = IDENTIFIER.exec(this.chunk))) {
42
+ return 0;
43
+ }
44
+ input = match[0], id = match[1], colon = match[2];
45
+ if (id === 'own' && this.tag() === 'FOR') {
46
+ this.token('OWN', id);
47
+ return id.length;
48
+ }
49
+ forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::') || !prev.spaced && prev[0] === '@');
50
+ tag = 'IDENTIFIER';
51
+ if (__indexOf.call(JS_KEYWORDS, id) >= 0 || !forcedIdentifier && __indexOf.call(COFFEE_KEYWORDS, id) >= 0) {
52
+ tag = id.toUpperCase();
53
+ if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
54
+ tag = 'LEADING_WHEN';
55
+ } else if (tag === 'FOR') {
56
+ this.seenFor = true;
57
+ } else if (tag === 'UNLESS') {
58
+ tag = 'IF';
59
+ } else if (__indexOf.call(UNARY, tag) >= 0) {
60
+ tag = 'UNARY';
61
+ } else if (__indexOf.call(RELATION, tag) >= 0) {
62
+ if (tag !== 'INSTANCEOF' && this.seenFor) {
63
+ tag = 'FOR' + tag;
64
+ this.seenFor = false;
65
+ } else {
66
+ tag = 'RELATION';
67
+ if (this.value() === '!') {
68
+ this.tokens.pop();
69
+ id = '!' + id;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {
75
+ if (forcedIdentifier) {
76
+ tag = 'IDENTIFIER';
77
+ id = new String(id);
78
+ id.reserved = true;
79
+ } else if (__indexOf.call(RESERVED, id) >= 0) {
80
+ this.identifierError(id);
81
+ }
82
+ }
83
+ if (!forcedIdentifier) {
84
+ if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {
85
+ id = COFFEE_ALIAS_MAP[id];
86
+ }
87
+ tag = (function() {
88
+ switch (id) {
89
+ case '!':
90
+ return 'UNARY';
91
+ case '==':
92
+ case '!=':
93
+ return 'COMPARE';
94
+ case '&&':
95
+ case '||':
96
+ return 'LOGIC';
97
+ case 'true':
98
+ case 'false':
99
+ case 'null':
100
+ case 'undefined':
101
+ return 'BOOL';
102
+ case 'break':
103
+ case 'continue':
104
+ case 'debugger':
105
+ return 'STATEMENT';
106
+ default:
107
+ return tag;
108
+ }
109
+ })();
110
+ }
111
+ this.token(tag, id);
112
+ if (colon) {
113
+ this.token(':', ':');
114
+ }
115
+ return input.length;
116
+ };
117
+ Lexer.prototype.numberToken = function() {
118
+ var match, number;
119
+ if (!(match = NUMBER.exec(this.chunk))) {
120
+ return 0;
121
+ }
122
+ number = match[0];
123
+ this.token('NUMBER', number);
124
+ return number.length;
125
+ };
126
+ Lexer.prototype.stringToken = function() {
127
+ var match, string;
128
+ switch (this.chunk.charAt(0)) {
129
+ case "'":
130
+ if (!(match = SIMPLESTR.exec(this.chunk))) {
131
+ return 0;
132
+ }
133
+ this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n'));
134
+ break;
135
+ case '"':
136
+ if (!(string = this.balancedString(this.chunk, '"'))) {
137
+ return 0;
138
+ }
139
+ if (0 < string.indexOf('#{', 1)) {
140
+ this.interpolateString(string.slice(1, -1));
141
+ } else {
142
+ this.token('STRING', this.escapeLines(string));
143
+ }
144
+ break;
145
+ default:
146
+ return 0;
147
+ }
148
+ this.line += count(string, '\n');
149
+ return string.length;
150
+ };
151
+ Lexer.prototype.heredocToken = function() {
152
+ var doc, heredoc, match, quote;
153
+ if (!(match = HEREDOC.exec(this.chunk))) {
154
+ return 0;
155
+ }
156
+ heredoc = match[0];
157
+ quote = heredoc.charAt(0);
158
+ doc = this.sanitizeHeredoc(match[2], {
159
+ quote: quote,
160
+ indent: null
161
+ });
162
+ if (quote === '"' && 0 <= doc.indexOf('#{')) {
163
+ this.interpolateString(doc, {
164
+ heredoc: true
165
+ });
166
+ } else {
167
+ this.token('STRING', this.makeString(doc, quote, true));
168
+ }
169
+ this.line += count(heredoc, '\n');
170
+ return heredoc.length;
171
+ };
172
+ Lexer.prototype.commentToken = function() {
173
+ var comment, here, match;
174
+ if (!(match = this.chunk.match(COMMENT))) {
175
+ return 0;
176
+ }
177
+ comment = match[0], here = match[1];
178
+ if (here) {
179
+ this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
180
+ herecomment: true,
181
+ indent: Array(this.indent + 1).join(' ')
182
+ }));
183
+ this.token('TERMINATOR', '\n');
184
+ }
185
+ this.line += count(comment, '\n');
186
+ return comment.length;
187
+ };
188
+ Lexer.prototype.jsToken = function() {
189
+ var match, script;
190
+ if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
191
+ return 0;
192
+ }
193
+ this.token('JS', (script = match[0]).slice(1, -1));
194
+ return script.length;
195
+ };
196
+ Lexer.prototype.regexToken = function() {
197
+ var match, prev, regex, _ref2;
198
+ if (this.chunk.charAt(0) !== '/') {
199
+ return 0;
200
+ }
201
+ if (match = HEREGEX.exec(this.chunk)) {
202
+ return this.heregexToken(match);
203
+ }
204
+ prev = last(this.tokens);
205
+ if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) {
206
+ return 0;
207
+ }
208
+ if (!(match = REGEX.exec(this.chunk))) {
209
+ return 0;
210
+ }
211
+ regex = match[0];
212
+ this.token('REGEX', regex === '//' ? '/(?:)/' : regex);
213
+ return regex.length;
214
+ };
215
+ Lexer.prototype.heregexToken = function(match) {
216
+ var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4, _ref5;
217
+ heregex = match[0], body = match[1], flags = match[2];
218
+ if (0 > body.indexOf('#{')) {
219
+ re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
220
+ this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
221
+ return heregex.length;
222
+ }
223
+ this.token('IDENTIFIER', 'RegExp');
224
+ this.tokens.push(['CALL_START', '(']);
225
+ tokens = [];
226
+ _ref2 = this.interpolateString(body, {
227
+ regex: true
228
+ });
229
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
230
+ _ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1];
231
+ if (tag === 'TOKENS') {
232
+ tokens.push.apply(tokens, value);
233
+ } else {
234
+ if (!(value = value.replace(HEREGEX_OMIT, ''))) {
235
+ continue;
236
+ }
237
+ value = value.replace(/\\/g, '\\\\');
238
+ tokens.push(['STRING', this.makeString(value, '"', true)]);
239
+ }
240
+ tokens.push(['+', '+']);
241
+ }
242
+ tokens.pop();
243
+ if (((_ref4 = tokens[0]) != null ? _ref4[0] : void 0) !== 'STRING') {
244
+ this.tokens.push(['STRING', '""'], ['+', '+']);
245
+ }
246
+ (_ref5 = this.tokens).push.apply(_ref5, tokens);
247
+ if (flags) {
248
+ this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
249
+ }
250
+ this.token(')', ')');
251
+ return heregex.length;
252
+ };
253
+ Lexer.prototype.lineToken = function() {
254
+ var diff, indent, match, noNewlines, prev, size;
255
+ if (!(match = MULTI_DENT.exec(this.chunk))) {
256
+ return 0;
257
+ }
258
+ indent = match[0];
259
+ this.line += count(indent, '\n');
260
+ prev = last(this.tokens, 1);
261
+ size = indent.length - 1 - indent.lastIndexOf('\n');
262
+ noNewlines = this.unfinished();
263
+ if (size - this.indebt === this.indent) {
264
+ if (noNewlines) {
265
+ this.suppressNewlines();
266
+ } else {
267
+ this.newlineToken();
268
+ }
269
+ return indent.length;
270
+ }
271
+ if (size > this.indent) {
272
+ if (noNewlines) {
273
+ this.indebt = size - this.indent;
274
+ this.suppressNewlines();
275
+ return indent.length;
276
+ }
277
+ diff = size - this.indent + this.outdebt;
278
+ this.token('INDENT', diff);
279
+ this.indents.push(diff);
280
+ this.outdebt = this.indebt = 0;
281
+ } else {
282
+ this.indebt = 0;
283
+ this.outdentToken(this.indent - size, noNewlines);
284
+ }
285
+ this.indent = size;
286
+ return indent.length;
287
+ };
288
+ Lexer.prototype.outdentToken = function(moveOut, noNewlines, close) {
289
+ var dent, len;
290
+ while (moveOut > 0) {
291
+ len = this.indents.length - 1;
292
+ if (this.indents[len] === void 0) {
293
+ moveOut = 0;
294
+ } else if (this.indents[len] === this.outdebt) {
295
+ moveOut -= this.outdebt;
296
+ this.outdebt = 0;
297
+ } else if (this.indents[len] < this.outdebt) {
298
+ this.outdebt -= this.indents[len];
299
+ moveOut -= this.indents[len];
300
+ } else {
301
+ dent = this.indents.pop() - this.outdebt;
302
+ moveOut -= dent;
303
+ this.outdebt = 0;
304
+ this.token('OUTDENT', dent);
305
+ }
306
+ }
307
+ if (dent) {
308
+ this.outdebt -= moveOut;
309
+ }
310
+ if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
311
+ this.token('TERMINATOR', '\n');
312
+ }
313
+ return this;
314
+ };
315
+ Lexer.prototype.whitespaceToken = function() {
316
+ var match, nline, prev;
317
+ if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
318
+ return 0;
319
+ }
320
+ prev = last(this.tokens);
321
+ if (prev) {
322
+ prev[match ? 'spaced' : 'newLine'] = true;
323
+ }
324
+ if (match) {
325
+ return match[0].length;
326
+ } else {
327
+ return 0;
328
+ }
329
+ };
330
+ Lexer.prototype.newlineToken = function() {
331
+ if (this.tag() !== 'TERMINATOR') {
332
+ this.token('TERMINATOR', '\n');
333
+ }
334
+ return this;
335
+ };
336
+ Lexer.prototype.suppressNewlines = function() {
337
+ if (this.value() === '\\') {
338
+ this.tokens.pop();
339
+ }
340
+ return this;
341
+ };
342
+ Lexer.prototype.literalToken = function() {
343
+ var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
344
+ if (match = OPERATOR.exec(this.chunk)) {
345
+ value = match[0];
346
+ if (CODE.test(value)) {
347
+ this.tagParameters();
348
+ }
349
+ } else {
350
+ value = this.chunk.charAt(0);
351
+ }
352
+ tag = value;
353
+ prev = last(this.tokens);
354
+ if (value === '=' && prev) {
355
+ if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
356
+ this.assignmentError();
357
+ }
358
+ if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
359
+ prev[0] = 'COMPOUND_ASSIGN';
360
+ prev[1] += '=';
361
+ return value.length;
362
+ }
363
+ }
364
+ if (value === ';') {
365
+ tag = 'TERMINATOR';
366
+ } else if (__indexOf.call(MATH, value) >= 0) {
367
+ tag = 'MATH';
368
+ } else if (__indexOf.call(COMPARE, value) >= 0) {
369
+ tag = 'COMPARE';
370
+ } else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
371
+ tag = 'COMPOUND_ASSIGN';
372
+ } else if (__indexOf.call(UNARY, value) >= 0) {
373
+ tag = 'UNARY';
374
+ } else if (__indexOf.call(SHIFT, value) >= 0) {
375
+ tag = 'SHIFT';
376
+ } else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
377
+ tag = 'LOGIC';
378
+ } else if (prev && !prev.spaced) {
379
+ if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {
380
+ if (prev[0] === '?') {
381
+ prev[0] = 'FUNC_EXIST';
382
+ }
383
+ tag = 'CALL_START';
384
+ } else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
385
+ tag = 'INDEX_START';
386
+ switch (prev[0]) {
387
+ case '?':
388
+ prev[0] = 'INDEX_SOAK';
389
+ break;
390
+ case '::':
391
+ prev[0] = 'INDEX_PROTO';
392
+ }
393
+ }
394
+ }
395
+ this.token(tag, value);
396
+ return value.length;
397
+ };
398
+ Lexer.prototype.sanitizeHeredoc = function(doc, options) {
399
+ var attempt, herecomment, indent, match, _ref2;
400
+ indent = options.indent, herecomment = options.herecomment;
401
+ if (herecomment) {
402
+ if (HEREDOC_ILLEGAL.test(doc)) {
403
+ throw new Error("block comment cannot contain \"*/\", starting on line " + (this.line + 1));
404
+ }
405
+ if (doc.indexOf('\n') <= 0) {
406
+ return doc;
407
+ }
408
+ } else {
409
+ while (match = HEREDOC_INDENT.exec(doc)) {
410
+ attempt = match[1];
411
+ if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) {
412
+ indent = attempt;
413
+ }
414
+ }
415
+ }
416
+ if (indent) {
417
+ doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
418
+ }
419
+ if (!herecomment) {
420
+ doc = doc.replace(/^\n/, '');
421
+ }
422
+ return doc;
423
+ };
424
+ Lexer.prototype.tagParameters = function() {
425
+ var i, stack, tok, tokens;
426
+ if (this.tag() !== ')') {
427
+ return this;
428
+ }
429
+ stack = [];
430
+ tokens = this.tokens;
431
+ i = tokens.length;
432
+ tokens[--i][0] = 'PARAM_END';
433
+ while (tok = tokens[--i]) {
434
+ switch (tok[0]) {
435
+ case ')':
436
+ stack.push(tok);
437
+ break;
438
+ case '(':
439
+ case 'CALL_START':
440
+ if (stack.length) {
441
+ stack.pop();
442
+ } else if (tok[0] === '(') {
443
+ tok[0] = 'PARAM_START';
444
+ return this;
445
+ }
446
+ }
447
+ }
448
+ return this;
449
+ };
450
+ Lexer.prototype.closeIndentation = function() {
451
+ return this.outdentToken(this.indent);
452
+ };
453
+ Lexer.prototype.identifierError = function(word) {
454
+ throw SyntaxError("Reserved word \"" + word + "\" on line " + (this.line + 1));
455
+ };
456
+ Lexer.prototype.assignmentError = function() {
457
+ throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
458
+ };
459
+ Lexer.prototype.balancedString = function(str, end) {
460
+ var i, letter, prev, stack, _ref2;
461
+ stack = [end];
462
+ for (i = 1, _ref2 = str.length; 1 <= _ref2 ? i < _ref2 : i > _ref2; 1 <= _ref2 ? i++ : i--) {
463
+ switch (letter = str.charAt(i)) {
464
+ case '\\':
465
+ i++;
466
+ continue;
467
+ case end:
468
+ stack.pop();
469
+ if (!stack.length) {
470
+ return str.slice(0, i + 1);
471
+ }
472
+ end = stack[stack.length - 1];
473
+ continue;
474
+ }
475
+ if (end === '}' && (letter === '"' || letter === "'")) {
476
+ stack.push(end = letter);
477
+ } else if (end === '}' && letter === '{') {
478
+ stack.push(end = '}');
479
+ } else if (end === '"' && prev === '#' && letter === '{') {
480
+ stack.push(end = '}');
481
+ }
482
+ prev = letter;
483
+ }
484
+ throw new Error("missing " + (stack.pop()) + ", starting on line " + (this.line + 1));
485
+ };
486
+ Lexer.prototype.interpolateString = function(str, options) {
487
+ var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref2, _ref3, _ref4;
488
+ if (options == null) {
489
+ options = {};
490
+ }
491
+ heredoc = options.heredoc, regex = options.regex;
492
+ tokens = [];
493
+ pi = 0;
494
+ i = -1;
495
+ while (letter = str.charAt(i += 1)) {
496
+ if (letter === '\\') {
497
+ i += 1;
498
+ continue;
499
+ }
500
+ if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) {
501
+ continue;
502
+ }
503
+ if (pi < i) {
504
+ tokens.push(['NEOSTRING', str.slice(pi, i)]);
505
+ }
506
+ inner = expr.slice(1, -1);
507
+ if (inner.length) {
508
+ nested = new Lexer().tokenize(inner, {
509
+ line: this.line,
510
+ rewrite: false
511
+ });
512
+ nested.pop();
513
+ if (((_ref2 = nested[0]) != null ? _ref2[0] : void 0) === 'TERMINATOR') {
514
+ nested.shift();
515
+ }
516
+ if (len = nested.length) {
517
+ if (len > 1) {
518
+ nested.unshift(['(', '(']);
519
+ nested.push([')', ')']);
520
+ }
521
+ tokens.push(['TOKENS', nested]);
522
+ }
523
+ }
524
+ i += expr.length;
525
+ pi = i + 1;
526
+ }
527
+ if ((i > pi && pi < str.length)) {
528
+ tokens.push(['NEOSTRING', str.slice(pi)]);
529
+ }
530
+ if (regex) {
531
+ return tokens;
532
+ }
533
+ if (!tokens.length) {
534
+ return this.token('STRING', '""');
535
+ }
536
+ if (tokens[0][0] !== 'NEOSTRING') {
537
+ tokens.unshift(['', '']);
538
+ }
539
+ if (interpolated = tokens.length > 1) {
540
+ this.token('(', '(');
541
+ }
542
+ for (i = 0, _len = tokens.length; i < _len; i++) {
543
+ _ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
544
+ if (i) {
545
+ this.token('+', '+');
546
+ }
547
+ if (tag === 'TOKENS') {
548
+ (_ref4 = this.tokens).push.apply(_ref4, value);
549
+ } else {
550
+ this.token('STRING', this.makeString(value, '"', heredoc));
551
+ }
552
+ }
553
+ if (interpolated) {
554
+ this.token(')', ')');
555
+ }
556
+ return tokens;
557
+ };
558
+ Lexer.prototype.token = function(tag, value) {
559
+ return this.tokens.push([tag, value, this.line]);
560
+ };
561
+ Lexer.prototype.tag = function(index, tag) {
562
+ var tok;
563
+ return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
564
+ };
565
+ Lexer.prototype.value = function(index, val) {
566
+ var tok;
567
+ return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
568
+ };
569
+ Lexer.prototype.unfinished = function() {
570
+ var prev, value;
571
+ return LINE_CONTINUER.test(this.chunk) || (prev = last(this.tokens, 1)) && prev[0] !== '.' && (value = this.value()) && !value.reserved && NO_NEWLINE.test(value) && !CODE.test(value) && !ASSIGNED.test(this.chunk);
572
+ };
573
+ Lexer.prototype.escapeLines = function(str, heredoc) {
574
+ return str.replace(MULTILINER, heredoc ? '\\n' : '');
575
+ };
576
+ Lexer.prototype.makeString = function(body, quote, heredoc) {
577
+ if (!body) {
578
+ return quote + quote;
579
+ }
580
+ body = body.replace(/\\([\s\S])/g, function(match, contents) {
581
+ if (contents === '\n' || contents === quote) {
582
+ return contents;
583
+ } else {
584
+ return match;
585
+ }
586
+ });
587
+ body = body.replace(RegExp("" + quote, "g"), '\\$&');
588
+ return quote + this.escapeLines(body, heredoc) + quote;
589
+ };
590
+ return Lexer;
591
+ })();
592
+ JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
593
+ COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
594
+ COFFEE_ALIAS_MAP = {
595
+ and: '&&',
596
+ or: '||',
597
+ is: '==',
598
+ isnt: '!=',
599
+ not: '!',
600
+ yes: 'true',
601
+ no: 'false',
602
+ on: 'true',
603
+ off: 'false'
604
+ };
605
+ COFFEE_ALIASES = (function() {
606
+ var _results;
607
+ _results = [];
608
+ for (key in COFFEE_ALIAS_MAP) {
609
+ _results.push(key);
610
+ }
611
+ return _results;
612
+ })();
613
+ COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
614
+ RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf'];
615
+ JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
616
+ exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS);
617
+ IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;
618
+ NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;
619
+ HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;
620
+ OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
621
+ WHITESPACE = /^[^\n\S]+/;
622
+ COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
623
+ CODE = /^[-=]>/;
624
+ MULTI_DENT = /^(?:\n[^\n\S]*)+/;
625
+ SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
626
+ JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
627
+ REGEX = /^\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4}(?!\w)/;
628
+ HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?!\w)/;
629
+ HEREGEX_OMIT = /\s+(?:#.*)?/g;
630
+ MULTILINER = /\n/g;
631
+ HEREDOC_INDENT = /\n+([^\n\S]*)/g;
632
+ HEREDOC_ILLEGAL = /\*\//;
633
+ ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/;
634
+ LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;
635
+ TRAILING_SPACES = /\s+$/;
636
+ NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;
637
+ COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
638
+ UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO'];
639
+ LOGIC = ['&&', '||', '&', '|', '^'];
640
+ SHIFT = ['<<', '>>', '>>>'];
641
+ COMPARE = ['==', '!=', '<', '>', '<=', '>='];
642
+ MATH = ['*', '/', '%'];
643
+ RELATION = ['IN', 'OF', 'INSTANCEOF'];
644
+ BOOL = ['TRUE', 'FALSE', 'NULL', 'UNDEFINED'];
645
+ NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']'];
646
+ NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING');
647
+ CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
648
+ INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL');
649
+ LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
650
+ }).call(this);