mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
caching the length property lookup for vanilla array comprehensions and rebuilding docs
This commit is contained in:
parent
5c7526a741
commit
d2d5f649d3
13 changed files with 154 additions and 149 deletions
|
@ -1,21 +1,21 @@
|
|||
(function(){
|
||||
var _a, _b, _c, _d, _e, _f, _g, food, lunch, roid, roid2;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2;
|
||||
// Eat lunch.
|
||||
lunch = (function() {
|
||||
_a = []; _b = ['toast', 'cheese', 'wine'];
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
food = _b[_c];
|
||||
_a.push(eat(food));
|
||||
}
|
||||
return _a;
|
||||
}).call(this);
|
||||
// Naive collision detection.
|
||||
_d = asteroids;
|
||||
for (_e = 0; _e < _d.length; _e++) {
|
||||
roid = _d[_e];
|
||||
_f = asteroids;
|
||||
for (_g = 0; _g < _f.length; _g++) {
|
||||
roid2 = _f[_g];
|
||||
_e = asteroids;
|
||||
for (_f = 0, _g = _e.length; _f < _g; _f++) {
|
||||
roid = _e[_f];
|
||||
_h = asteroids;
|
||||
for (_i = 0, _j = _h.length; _i < _j; _i++) {
|
||||
roid2 = _h[_i];
|
||||
if (roid !== roid2) {
|
||||
if (roid.overlaps(roid2)) {
|
||||
roid.explode();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
(function(){
|
||||
process.mixin(require('assert'));
|
||||
task('test', 'run each of the unit tests', function() {
|
||||
var _a, _b, _c, test;
|
||||
var _a, _b, _c, _d, test;
|
||||
_a = []; _b = test_files;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
test = _b[_c];
|
||||
_a.push(fs.readFile(test, function(err, code) {
|
||||
return eval(coffee.compile(code));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function(){
|
||||
var _a, _b, _c, cubed_list, list, math, num, number, opposite_day, race, square;
|
||||
var _a, _b, _c, _d, cubed_list, list, math, num, number, opposite_day, race, square;
|
||||
// Assignment:
|
||||
number = 42;
|
||||
opposite_day = true;
|
||||
|
@ -34,7 +34,7 @@
|
|||
// Array comprehensions:
|
||||
cubed_list = (function() {
|
||||
_a = []; _b = list;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
num = _b[_c];
|
||||
_a.push(math.cube(num));
|
||||
}
|
||||
|
|
28
index.html
28
index.html
|
@ -133,7 +133,7 @@ alert <span class="String"><span class="String">"</span>I knew it!<span cla
|
|||
|
||||
<span class="Comment"><span class="Comment">#</span> Array comprehensions:</span>
|
||||
<span class="FunctionName">cubed_list</span><span class="Keyword">:</span> math.cube num <span class="Keyword">for</span> num <span class="Keyword">in</span> list
|
||||
</pre><pre class="idle"><span class="Storage">var</span> _a, _b, _c, cubed_list, list, math, num, number, opposite_day, race, square;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> _a, _b, _c, _d, cubed_list, list, math, num, number, opposite_day, race, square;
|
||||
<span class="Comment"><span class="Comment">//</span> Assignment:</span>
|
||||
number <span class="Keyword">=</span> <span class="Number">42</span>;
|
||||
opposite_day <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
|
||||
|
@ -168,13 +168,13 @@ race <span class="Keyword">=</span> <span class="Storage">function</span> <span
|
|||
<span class="Comment"><span class="Comment">//</span> Array comprehensions:</span>
|
||||
cubed_list <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||
_a <span class="Keyword">=</span> []; _b <span class="Keyword">=</span> list;
|
||||
<span class="Keyword">for</span> (_c <span class="Keyword">=</span> <span class="Number">0</span>; _c <span class="Keyword"><</span> _b.<span class="LibraryConstant">length</span>; _c<span class="Keyword">++</span>) {
|
||||
<span class="Keyword">for</span> (_c <span class="Keyword">=</span> <span class="Number">0</span>, _d <span class="Keyword">=</span> _b.<span class="LibraryConstant">length</span>; _c <span class="Keyword"><</span> _d; _c<span class="Keyword">++</span>) {
|
||||
num <span class="Keyword">=</span> _b[_c];
|
||||
_a.<span class="LibraryFunction">push</span>(math.cube(num));
|
||||
}
|
||||
<span class="Keyword">return</span> _a;
|
||||
}).<span class="LibraryFunction">call</span>(<span class="Variable">this</span>);
|
||||
</pre><button onclick='javascript: var _a, _b, _c, cubed_list, list, math, num, number, opposite_day, race, square;
|
||||
</pre><button onclick='javascript: var _a, _b, _c, _d, cubed_list, list, math, num, number, opposite_day, race, square;
|
||||
// Assignment:
|
||||
number = 42;
|
||||
opposite_day = true;
|
||||
|
@ -209,7 +209,7 @@ if ((typeof elvis !== "undefined" && elvis !== null)) {
|
|||
// Array comprehensions:
|
||||
cubed_list = (function() {
|
||||
_a = []; _b = list;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
num = _b[_c];
|
||||
_a.push(math.cube(num));
|
||||
}
|
||||
|
@ -823,23 +823,23 @@ One fell out and bumped his head.");
|
|||
<span class="Keyword">for</span> roid <span class="Keyword">in</span> asteroids
|
||||
<span class="Keyword">for</span> roid2 <span class="Keyword">in</span> asteroids <span class="Keyword">when</span> roid <span class="Keyword">isnt</span> roid2
|
||||
roid.explode() <span class="Keyword">if</span> roid.overlaps roid2
|
||||
</pre><pre class="idle"><span class="Storage">var</span> _a, _b, _c, _d, _e, _f, _g, food, lunch, roid, roid2;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2;
|
||||
<span class="Comment"><span class="Comment">//</span> Eat lunch.</span>
|
||||
lunch <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||
_a <span class="Keyword">=</span> []; _b <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>];
|
||||
<span class="Keyword">for</span> (_c <span class="Keyword">=</span> <span class="Number">0</span>; _c <span class="Keyword"><</span> _b.<span class="LibraryConstant">length</span>; _c<span class="Keyword">++</span>) {
|
||||
<span class="Keyword">for</span> (_c <span class="Keyword">=</span> <span class="Number">0</span>, _d <span class="Keyword">=</span> _b.<span class="LibraryConstant">length</span>; _c <span class="Keyword"><</span> _d; _c<span class="Keyword">++</span>) {
|
||||
food <span class="Keyword">=</span> _b[_c];
|
||||
_a.<span class="LibraryFunction">push</span>(eat(food));
|
||||
}
|
||||
<span class="Keyword">return</span> _a;
|
||||
}).<span class="LibraryFunction">call</span>(<span class="Variable">this</span>);
|
||||
<span class="Comment"><span class="Comment">//</span> Naive collision detection.</span>
|
||||
_d <span class="Keyword">=</span> asteroids;
|
||||
<span class="Keyword">for</span> (_e <span class="Keyword">=</span> <span class="Number">0</span>; _e <span class="Keyword"><</span> _d.<span class="LibraryConstant">length</span>; _e<span class="Keyword">++</span>) {
|
||||
roid <span class="Keyword">=</span> _d[_e];
|
||||
_f <span class="Keyword">=</span> asteroids;
|
||||
<span class="Keyword">for</span> (_g <span class="Keyword">=</span> <span class="Number">0</span>; _g <span class="Keyword"><</span> _f.<span class="LibraryConstant">length</span>; _g<span class="Keyword">++</span>) {
|
||||
roid2 <span class="Keyword">=</span> _f[_g];
|
||||
_e <span class="Keyword">=</span> asteroids;
|
||||
<span class="Keyword">for</span> (_f <span class="Keyword">=</span> <span class="Number">0</span>, _g <span class="Keyword">=</span> _e.<span class="LibraryConstant">length</span>; _f <span class="Keyword"><</span> _g; _f<span class="Keyword">++</span>) {
|
||||
roid <span class="Keyword">=</span> _e[_f];
|
||||
_h <span class="Keyword">=</span> asteroids;
|
||||
<span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _j <span class="Keyword">=</span> _h.<span class="LibraryConstant">length</span>; _i <span class="Keyword"><</span> _j; _i<span class="Keyword">++</span>) {
|
||||
roid2 <span class="Keyword">=</span> _h[_i];
|
||||
<span class="Keyword">if</span> (roid <span class="Keyword">!</span><span class="Keyword">==</span> roid2) {
|
||||
<span class="Keyword">if</span> (roid.overlaps(roid2)) {
|
||||
roid.explode();
|
||||
|
@ -1594,9 +1594,9 @@ task <span class="String"><span class="String">'</span>test<span class="String">
|
|||
fs.readFile test, <span class="FunctionArgument">(</span><span class="FunctionArgument">err, code</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> eval coffee.compile code
|
||||
</pre><pre class="idle">process.mixin(require(<span class="String"><span class="String">'</span>assert<span class="String">'</span></span>));
|
||||
task(<span class="String"><span class="String">'</span>test<span class="String">'</span></span>, <span class="String"><span class="String">'</span>run each of the unit tests<span class="String">'</span></span>, <span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _a, _b, _c, test;
|
||||
<span class="Storage">var</span> _a, _b, _c, _d, test;
|
||||
_a <span class="Keyword">=</span> []; _b <span class="Keyword">=</span> test_files;
|
||||
<span class="Keyword">for</span> (_c <span class="Keyword">=</span> <span class="Number">0</span>; _c <span class="Keyword"><</span> _b.<span class="LibraryConstant">length</span>; _c<span class="Keyword">++</span>) {
|
||||
<span class="Keyword">for</span> (_c <span class="Keyword">=</span> <span class="Number">0</span>, _d <span class="Keyword">=</span> _b.<span class="LibraryConstant">length</span>; _c <span class="Keyword"><</span> _d; _c<span class="Keyword">++</span>) {
|
||||
test <span class="Keyword">=</span> _b[_c];
|
||||
_a.<span class="LibraryFunction">push</span>(fs.readFile(test, <span class="Storage">function</span>(err, code) {
|
||||
<span class="Keyword">return</span> <span class="LibraryFunction">eval</span>(coffee.<span class="LibraryFunction">compile</span>(code));
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
// prints them out, with no arguments.
|
||||
exports.run = function run() {
|
||||
return path.exists('Cakefile', function(exists) {
|
||||
var _a, _b, _c, arg, args;
|
||||
var _a, _b, _c, _d, arg, args;
|
||||
if (!(exists)) {
|
||||
throw new Error('Cakefile not found in ' + process.cwd());
|
||||
}
|
||||
|
@ -50,7 +50,7 @@
|
|||
}
|
||||
options = oparse.parse(args);
|
||||
_a = []; _b = options.arguments;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
arg = _b[_c];
|
||||
_a.push(invoke(arg));
|
||||
}
|
||||
|
|
|
@ -49,9 +49,9 @@
|
|||
// all script tags with a content-type of text/coffeescript.
|
||||
if ((typeof document !== "undefined" && document !== null) && document.getElementsByTagName) {
|
||||
process_scripts = function process_scripts() {
|
||||
var _a, _b, _c, tag;
|
||||
var _a, _b, _c, _d, tag;
|
||||
_a = []; _b = document.getElementsByTagName('script');
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
tag = _b[_c];
|
||||
if (tag.type === 'text/coffeescript') {
|
||||
_a.push(eval(exports.compile(tag.innerHTML)));
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
// Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
||||
// or JSLint results.
|
||||
compile_scripts = function compile_scripts() {
|
||||
var _a, _b, _c, compile, source;
|
||||
var _a, _b, _c, _d, compile, source;
|
||||
compile = function compile(source) {
|
||||
return path.exists(source, function(exists) {
|
||||
if (!(exists)) {
|
||||
|
@ -69,7 +69,7 @@
|
|||
});
|
||||
};
|
||||
_a = []; _b = sources;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
source = _b[_c];
|
||||
_a.push(compile(source));
|
||||
}
|
||||
|
@ -122,7 +122,7 @@
|
|||
// Watch a list of source CoffeeScript files, recompiling them every time the
|
||||
// files are updated.
|
||||
watch_scripts = function watch_scripts() {
|
||||
var _a, _b, _c, source, watch;
|
||||
var _a, _b, _c, _d, source, watch;
|
||||
watch = function watch(source) {
|
||||
return process.watchFile(source, {
|
||||
persistent: true,
|
||||
|
@ -137,7 +137,7 @@
|
|||
});
|
||||
};
|
||||
_a = []; _b = sources;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
source = _b[_c];
|
||||
_a.push(watch(source));
|
||||
}
|
||||
|
@ -170,10 +170,10 @@
|
|||
};
|
||||
// Pretty-print a token stream.
|
||||
print_tokens = function print_tokens(tokens) {
|
||||
var _a, _b, _c, strings, token;
|
||||
var _a, _b, _c, _d, strings, token;
|
||||
strings = (function() {
|
||||
_a = []; _b = tokens;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
token = _b[_c];
|
||||
_a.push('[' + token[0] + ' ' + token[1].toString().replace(/\n/, '\\n') + ']');
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function(){
|
||||
var Parser, _a, _b, _c, _d, _e, _f, bnf, grammar, name, non_terminal, o, operators, option, part, tokens, unwrap;
|
||||
var Parser, _a, _b, _c, _d, _e, _f, _g, _h, bnf, grammar, name, non_terminal, o, operators, option, part, tokens, unwrap;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
Parser = require('jison').Parser;
|
||||
// DSL ===================================================================
|
||||
|
@ -537,12 +537,12 @@
|
|||
non_terminal = _a[name];
|
||||
bnf[name] = (function() {
|
||||
_b = []; _c = non_terminal;
|
||||
for (_d = 0; _d < _c.length; _d++) {
|
||||
for (_d = 0, _e = _c.length; _d < _e; _d++) {
|
||||
option = _c[_d];
|
||||
_b.push((function() {
|
||||
_e = option[0].split(" ");
|
||||
for (_f = 0; _f < _e.length; _f++) {
|
||||
part = _e[_f];
|
||||
_f = option[0].split(" ");
|
||||
for (_g = 0, _h = _f.length; _g < _h; _g++) {
|
||||
part = _f[_g];
|
||||
!grammar[part] ? tokens.push(part) : null;
|
||||
}
|
||||
name === "Root" ? (option[1] = "return " + option[1]) : null;
|
||||
|
|
91
lib/nodes.js
91
lib/nodes.js
|
@ -28,9 +28,9 @@
|
|||
};
|
||||
// Trim out all falsy values from an array.
|
||||
compact = function compact(array) {
|
||||
var _a, _b, _c, item;
|
||||
var _a, _b, _c, _d, item;
|
||||
_a = []; _b = array;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
item = _b[_c];
|
||||
if (item) {
|
||||
_a.push(item);
|
||||
|
@ -40,10 +40,10 @@
|
|||
};
|
||||
// Return a completely flattened version of an array.
|
||||
flatten = function flatten(array) {
|
||||
var _a, _b, item, memo;
|
||||
var _a, _b, _c, item, memo;
|
||||
memo = [];
|
||||
_a = array;
|
||||
for (_b = 0; _b < _a.length; _b++) {
|
||||
for (_b = 0, _c = _a.length; _b < _c; _b++) {
|
||||
item = _a[_b];
|
||||
item instanceof Array ? (memo = memo.concat(item)) : memo.push(item);
|
||||
}
|
||||
|
@ -135,9 +135,9 @@
|
|||
};
|
||||
// Does this node, or any of its children, contain a node of a certain kind?
|
||||
BaseNode.prototype.contains = function contains(block) {
|
||||
var _a, _b, node;
|
||||
var _a, _b, _c, node;
|
||||
_a = this.children;
|
||||
for (_b = 0; _b < _a.length; _b++) {
|
||||
for (_b = 0, _c = _a.length; _b < _c; _b++) {
|
||||
node = _a[_b];
|
||||
if (block(node)) {
|
||||
return true;
|
||||
|
@ -150,11 +150,11 @@
|
|||
};
|
||||
// toString representation of the node, for inspecting the parse tree.
|
||||
BaseNode.prototype.toString = function toString(idt) {
|
||||
var _a, _b, _c, child;
|
||||
var _a, _b, _c, _d, child;
|
||||
idt = idt || '';
|
||||
return '\n' + idt + this.type + (function() {
|
||||
_a = []; _b = this.children;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
child = _b[_c];
|
||||
_a.push(child.toString(idt + TAB));
|
||||
}
|
||||
|
@ -216,10 +216,10 @@
|
|||
},
|
||||
// Compile each expression in the Expressions body.
|
||||
compile_node: function compile_node(o) {
|
||||
var _a, _b, _c, node;
|
||||
var _a, _b, _c, _d, node;
|
||||
return (function() {
|
||||
_a = []; _b = this.expressions;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
node = _b[_c];
|
||||
_a.push(this.compile_expression(node, merge(o)));
|
||||
}
|
||||
|
@ -365,7 +365,7 @@
|
|||
return this.base.is_statement && this.base.is_statement() && !this.has_properties();
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var _a, _b, baseline, complete, only, op, part, prop, props, soaked, temp;
|
||||
var _a, _b, _c, baseline, complete, only, op, part, prop, props, soaked, temp;
|
||||
soaked = false;
|
||||
only = del(o, 'only_first');
|
||||
op = del(o, 'operation');
|
||||
|
@ -376,7 +376,7 @@
|
|||
}
|
||||
complete = (this.last = baseline);
|
||||
_a = props;
|
||||
for (_b = 0; _b < _a.length; _b++) {
|
||||
for (_b = 0, _c = _a.length; _b < _c; _b++) {
|
||||
prop = _a[_b];
|
||||
this.source = baseline;
|
||||
if (prop.soak_node) {
|
||||
|
@ -430,13 +430,13 @@
|
|||
},
|
||||
// Compile a vanilla function call.
|
||||
compile_node: function compile_node(o) {
|
||||
var _a, _b, _c, arg, args;
|
||||
var _a, _b, _c, _d, arg, args;
|
||||
if (this.args[this.args.length - 1] instanceof SplatNode) {
|
||||
return this.compile_splat(o);
|
||||
}
|
||||
args = (function() {
|
||||
_a = []; _b = this.args;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
arg = _b[_c];
|
||||
_a.push(arg.compile(o));
|
||||
}
|
||||
|
@ -457,12 +457,12 @@
|
|||
},
|
||||
// Compile a function call being passed variable arguments.
|
||||
compile_splat: function compile_splat(o) {
|
||||
var _a, _b, arg, args, code, i, meth, obj;
|
||||
var _a, _b, _c, arg, args, code, i, meth, obj;
|
||||
meth = this.variable.compile(o);
|
||||
obj = this.variable.source || 'this';
|
||||
args = (function() {
|
||||
_a = []; _b = this.args;
|
||||
for (i = 0; i < _b.length; i++) {
|
||||
for (i = 0, _c = _b.length; i < _c; i++) {
|
||||
arg = _b[i];
|
||||
_a.push((function() {
|
||||
code = arg.compile(o);
|
||||
|
@ -602,11 +602,11 @@
|
|||
// AssignNodes get interleaved correctly, with no trailing commas or
|
||||
// commas affixed to comments. TODO: Extract this and add it to ArrayNode.
|
||||
compile_node: function compile_node(o) {
|
||||
var _a, _b, _c, _d, _e, i, indent, inner, join, last_noncom, non_comments, prop, props;
|
||||
var _a, _b, _c, _d, _e, _f, _g, i, indent, inner, join, last_noncom, non_comments, prop, props;
|
||||
o.indent = this.idt(1);
|
||||
non_comments = (function() {
|
||||
_a = []; _b = this.properties;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
prop = _b[_c];
|
||||
if (!(prop instanceof CommentNode)) {
|
||||
_a.push(prop);
|
||||
|
@ -616,10 +616,10 @@
|
|||
}).call(this);
|
||||
last_noncom = non_comments[non_comments.length - 1];
|
||||
props = (function() {
|
||||
_d = []; _e = this.properties;
|
||||
for (i = 0; i < _e.length; i++) {
|
||||
prop = _e[i];
|
||||
_d.push((function() {
|
||||
_e = []; _f = this.properties;
|
||||
for (i = 0, _g = _f.length; i < _g; i++) {
|
||||
prop = _f[i];
|
||||
_e.push((function() {
|
||||
join = ",\n";
|
||||
if ((prop === last_noncom) || (prop instanceof CommentNode)) {
|
||||
join = "\n";
|
||||
|
@ -631,7 +631,7 @@
|
|||
return indent + prop.compile(o) + join;
|
||||
}).call(this));
|
||||
}
|
||||
return _d;
|
||||
return _e;
|
||||
}).call(this);
|
||||
props = props.join('');
|
||||
inner = props ? '\n' + props + '\n' + this.idt() : '';
|
||||
|
@ -646,11 +646,11 @@
|
|||
return this;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var _a, _b, code, ending, i, obj, objects;
|
||||
var _a, _b, _c, code, ending, i, obj, objects;
|
||||
o.indent = this.idt(1);
|
||||
objects = (function() {
|
||||
_a = []; _b = this.objects;
|
||||
for (i = 0; i < _b.length; i++) {
|
||||
for (i = 0, _c = _b.length; i < _c; i++) {
|
||||
obj = _b[i];
|
||||
_a.push((function() {
|
||||
code = obj.compile(o);
|
||||
|
@ -756,20 +756,20 @@
|
|||
// object literals to a value. Peeks at their properties to assign inner names.
|
||||
// See: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
|
||||
compile_pattern_match: function compile_pattern_match(o) {
|
||||
var _a, _b, access_class, assigns, code, i, idx, obj, val, val_var, value;
|
||||
var _a, _b, _c, access_class, assigns, code, i, idx, obj, val, val_var, value;
|
||||
val_var = o.scope.free_variable();
|
||||
value = this.value.is_statement() ? ClosureNode.wrap(this.value) : this.value;
|
||||
assigns = [this.idt() + val_var + ' = ' + value.compile(o) + ';'];
|
||||
o.top = true;
|
||||
o.as_statement = true;
|
||||
_a = this.variable.base.objects;
|
||||
for (i = 0; i < _a.length; i++) {
|
||||
for (i = 0, _b = _a.length; i < _b; i++) {
|
||||
obj = _a[i];
|
||||
idx = i;
|
||||
if (this.variable.is_object()) {
|
||||
_b = [obj.value, obj.variable.base];
|
||||
obj = _b[0];
|
||||
idx = _b[1];
|
||||
_c = [obj.value, obj.variable.base];
|
||||
obj = _c[0];
|
||||
idx = _c[1];
|
||||
}
|
||||
access_class = this.variable.is_array() ? IndexNode : AccessorNode;
|
||||
if (obj instanceof SplatNode) {
|
||||
|
@ -812,7 +812,7 @@
|
|||
return this;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var _a, _b, _c, _d, _e, code, func, inner, name_part, param, params, shared_scope, splat, top;
|
||||
var _a, _b, _c, _d, _e, _f, _g, code, func, inner, name_part, param, params, shared_scope, splat, top;
|
||||
shared_scope = del(o, 'shared_scope');
|
||||
top = del(o, 'top');
|
||||
o.scope = shared_scope || new Scope(o.scope, this.body, this);
|
||||
|
@ -828,15 +828,15 @@
|
|||
}
|
||||
params = (function() {
|
||||
_a = []; _b = this.params;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
param = _b[_c];
|
||||
_a.push(param.compile(o));
|
||||
}
|
||||
return _a;
|
||||
}).call(this);
|
||||
_d = params;
|
||||
for (_e = 0; _e < _d.length; _e++) {
|
||||
param = _d[_e];
|
||||
_e = params;
|
||||
for (_f = 0, _g = _e.length; _f < _g; _f++) {
|
||||
param = _e[_f];
|
||||
(o.scope.parameter(param));
|
||||
}
|
||||
code = this.body.expressions.length ? '\n' + this.body.compile_with_declarations(o) + '\n' : '';
|
||||
|
@ -855,12 +855,12 @@
|
|||
return true;
|
||||
},
|
||||
toString: function toString(idt) {
|
||||
var _a, _b, _c, child, children;
|
||||
var _a, _b, _c, _d, child, children;
|
||||
idt = idt || '';
|
||||
children = flatten([this.params, this.body.expressions]);
|
||||
return '\n' + idt + this.type + (function() {
|
||||
_a = []; _b = children;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
child = _b[_c];
|
||||
_a.push(child.toString(idt + TAB));
|
||||
}
|
||||
|
@ -1129,7 +1129,7 @@
|
|||
return true;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var body, body_dent, close, for_part, index, index_found, index_var, ivar, name, name_found, range, return_result, rvar, scope, set_result, source, source_part, step_part, svar, top_level, var_part, vars;
|
||||
var body, body_dent, close, for_part, index, index_found, index_var, ivar, lvar, name, name_found, range, return_result, rvar, scope, set_result, source, source_part, step_part, svar, top_level, var_part, vars;
|
||||
top_level = del(o, 'top') && !o.returns;
|
||||
range = this.source instanceof ValueNode && this.source.base instanceof RangeNode && !this.source.properties.length;
|
||||
source = range ? this.source.base : this.source;
|
||||
|
@ -1156,11 +1156,14 @@
|
|||
} else {
|
||||
index_var = null;
|
||||
source_part = svar + ' = ' + this.source.compile(o) + ';\n' + this.idt();
|
||||
step_part = this.step ? ivar + ' += ' + this.step.compile(o) : ivar + '++';
|
||||
for_part = ivar + ' = 0; ' + ivar + ' < ' + svar + '.length; ' + step_part;
|
||||
if (name) {
|
||||
var_part = body_dent + name + ' = ' + svar + '[' + ivar + '];\n';
|
||||
}
|
||||
if (!this.object) {
|
||||
lvar = scope.free_variable();
|
||||
step_part = this.step ? ivar + ' += ' + this.step.compile(o) : ivar + '++';
|
||||
for_part = ivar + ' = 0, ' + lvar + ' = ' + svar + '.length; ' + ivar + ' < ' + lvar + '; ' + step_part;
|
||||
}
|
||||
}
|
||||
set_result = rvar ? this.idt() + rvar + ' = []; ' : this.idt();
|
||||
return_result = rvar || '';
|
||||
|
@ -1237,7 +1240,7 @@
|
|||
},
|
||||
// Rewrite a chain of IfNodes with their switch condition for equality.
|
||||
rewrite_switch: function rewrite_switch(o) {
|
||||
var _a, _b, assigner, cond, i, variable;
|
||||
var _a, _b, _c, assigner, cond, i, variable;
|
||||
assigner = this.switcher;
|
||||
if (!(this.switcher.unwrap() instanceof LiteralNode)) {
|
||||
variable = new LiteralNode(o.scope.free_variable());
|
||||
|
@ -1247,7 +1250,7 @@
|
|||
this.condition = (function() {
|
||||
if (this.multiple) {
|
||||
_a = []; _b = this.condition;
|
||||
for (i = 0; i < _b.length; i++) {
|
||||
for (i = 0, _c = _b.length; i < _c; i++) {
|
||||
cond = _b[i];
|
||||
_a.push(new OpNode('is', (i === 0 ? assigner : this.switcher), cond));
|
||||
}
|
||||
|
@ -1283,10 +1286,10 @@
|
|||
return this.statement = this.statement || !!(this.comment || this.tags.statement || this.body.is_statement() || (this.else_body && this.else_body.is_statement()));
|
||||
},
|
||||
compile_condition: function compile_condition(o) {
|
||||
var _a, _b, _c, cond;
|
||||
var _a, _b, _c, _d, cond;
|
||||
return (function() {
|
||||
_a = []; _b = flatten([this.condition]);
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
cond = _b[_c];
|
||||
_a.push(cond.compile(o));
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// specified options, and returning it. options.arguments will be an array
|
||||
// containing the remaning non-option arguments.
|
||||
op.prototype.parse = function parse(args) {
|
||||
var _a, _b, arg, is_option, matched_rule, options, rule;
|
||||
var _a, _b, _c, arg, is_option, matched_rule, options, rule;
|
||||
arguments = Array.prototype.slice.call(arguments, 0);
|
||||
options = {
|
||||
arguments: []
|
||||
|
@ -22,7 +22,7 @@
|
|||
is_option = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
||||
matched_rule = false;
|
||||
_a = this.rules;
|
||||
for (_b = 0; _b < _a.length; _b++) {
|
||||
for (_b = 0, _c = _a.length; _b < _c; _b++) {
|
||||
rule = _a[_b];
|
||||
if (rule.letter === arg || rule.flag === arg) {
|
||||
options[rule.name] = rule.has_argument ? args.shift() : true;
|
||||
|
@ -41,21 +41,21 @@
|
|||
};
|
||||
// Return the help text for this OptionParser, for --help and such.
|
||||
op.prototype.help = function help() {
|
||||
var _a, _b, _c, _d, _e, _f, _g, i, let_part, lines, rule, spaces;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, i, let_part, lines, rule, spaces;
|
||||
lines = ['Available options:'];
|
||||
if (this.banner) {
|
||||
lines.unshift(this.banner + '\n');
|
||||
}
|
||||
_a = this.rules;
|
||||
for (_b = 0; _b < _a.length; _b++) {
|
||||
for (_b = 0, _c = _a.length; _b < _c; _b++) {
|
||||
rule = _a[_b];
|
||||
spaces = 15 - rule.flag.length;
|
||||
spaces = spaces > 0 ? (function() {
|
||||
_c = []; _f = 0; _g = spaces;
|
||||
for (_e = 0, i=_f; (_f <= _g ? i <= _g : i >= _g); (_f <= _g ? i += 1 : i -= 1), _e++) {
|
||||
_c.push(' ');
|
||||
_d = []; _g = 0; _h = spaces;
|
||||
for (_f = 0, i = _g; (_g <= _h ? i <= _h : i >= _h); (_g <= _h ? i += 1 : i -= 1), _f++) {
|
||||
_d.push(' ');
|
||||
}
|
||||
return _c;
|
||||
return _d;
|
||||
}).call(this).join('') : '';
|
||||
let_part = rule.letter ? rule.letter + ', ' : ' ';
|
||||
lines.push(' ' + let_part + rule.flag + spaces + rule.description);
|
||||
|
@ -70,9 +70,9 @@
|
|||
// Build rules from a list of valid switch tuples in the form:
|
||||
// [letter-flag, long-flag, help], or [long-flag, help].
|
||||
build_rules = function build_rules(rules) {
|
||||
var _a, _b, _c, tuple;
|
||||
var _a, _b, _c, _d, tuple;
|
||||
_a = []; _b = rules;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
tuple = _b[_c];
|
||||
_a.push((function() {
|
||||
if (tuple.length < 3) {
|
||||
|
@ -98,16 +98,16 @@
|
|||
};
|
||||
// Normalize arguments by expanding merged flags into multiple flags.
|
||||
normalize_arguments = function normalize_arguments(args) {
|
||||
var _a, _b, _c, _d, arg, l, match, result;
|
||||
var _a, _b, _c, _d, _e, _f, arg, l, match, result;
|
||||
args = args.slice(0);
|
||||
result = [];
|
||||
_a = args;
|
||||
for (_b = 0; _b < _a.length; _b++) {
|
||||
for (_b = 0, _c = _a.length; _b < _c; _b++) {
|
||||
arg = _a[_b];
|
||||
if ((match = arg.match(MULTI_FLAG))) {
|
||||
_c = match[1].split('');
|
||||
for (_d = 0; _d < _c.length; _d++) {
|
||||
l = _c[_d];
|
||||
_d = match[1].split('');
|
||||
for (_e = 0, _f = _d.length; _e < _f; _e++) {
|
||||
l = _d[_e];
|
||||
result.push('-' + l);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function(){
|
||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_START, EXPRESSION_TAIL, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, pair, re;
|
||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_START, EXPRESSION_TAIL, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, pair, re;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
if (!((typeof process !== "undefined" && process !== null))) {
|
||||
this.exports = this;
|
||||
|
@ -13,7 +13,7 @@
|
|||
// Tokens that signal the start of a balanced pair.
|
||||
EXPRESSION_START = (function() {
|
||||
_a = []; _b = BALANCED_PAIRS;
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
pair = _b[_c];
|
||||
_a.push(pair[0]);
|
||||
}
|
||||
|
@ -21,12 +21,12 @@
|
|||
}).call(this);
|
||||
// Tokens that signal the end of a balanced pair.
|
||||
EXPRESSION_TAIL = (function() {
|
||||
_d = []; _e = BALANCED_PAIRS;
|
||||
for (_f = 0; _f < _e.length; _f++) {
|
||||
pair = _e[_f];
|
||||
_d.push(pair[1]);
|
||||
_e = []; _f = BALANCED_PAIRS;
|
||||
for (_g = 0, _h = _f.length; _g < _h; _g++) {
|
||||
pair = _f[_g];
|
||||
_e.push(pair[1]);
|
||||
}
|
||||
return _d;
|
||||
return _e;
|
||||
}).call(this);
|
||||
// Tokens that indicate the close of a clause of an expression.
|
||||
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_TAIL);
|
||||
|
@ -37,9 +37,9 @@
|
|||
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT', '@', '->', '=>', '[', '(', '{'];
|
||||
// The inverse mappings of token pairs we're trying to fix up.
|
||||
INVERSES = {};
|
||||
_g = BALANCED_PAIRS;
|
||||
for (_h = 0; _h < _g.length; _h++) {
|
||||
pair = _g[_h];
|
||||
_i = BALANCED_PAIRS;
|
||||
for (_j = 0, _k = _i.length; _j < _k; _j++) {
|
||||
pair = _i[_j];
|
||||
INVERSES[pair[0]] = pair[1];
|
||||
INVERSES[pair[1]] = pair[0];
|
||||
}
|
||||
|
@ -156,23 +156,23 @@
|
|||
brackets = [0];
|
||||
return this.scan_tokens((function(__this) {
|
||||
var __func = function(prev, token, post, i) {
|
||||
var _i;
|
||||
if ((_i = token[0]) === 'CALL_START') {
|
||||
var _l;
|
||||
if ((_l = token[0]) === 'CALL_START') {
|
||||
parens.push(0);
|
||||
} else if (_i === 'INDEX_START') {
|
||||
} else if (_l === 'INDEX_START') {
|
||||
brackets.push(0);
|
||||
} else if (_i === '(') {
|
||||
} else if (_l === '(') {
|
||||
parens[parens.length - 1] += 1;
|
||||
} else if (_i === '[') {
|
||||
} else if (_l === '[') {
|
||||
brackets[brackets.length - 1] += 1;
|
||||
} else if (_i === ')') {
|
||||
} else if (_l === ')') {
|
||||
if (parens[parens.length - 1] === 0) {
|
||||
parens.pop();
|
||||
token[0] = 'CALL_END';
|
||||
} else {
|
||||
parens[parens.length - 1] -= 1;
|
||||
}
|
||||
} else if (_i === ']') {
|
||||
} else if (_l === ']') {
|
||||
if (brackets[brackets.length - 1] === 0) {
|
||||
brackets.pop();
|
||||
token[0] = 'INDEX_END';
|
||||
|
@ -195,7 +195,7 @@
|
|||
stack = [0];
|
||||
return this.scan_tokens((function(__this) {
|
||||
var __func = function(prev, token, post, i) {
|
||||
var _i, _j, _k, _l, idx, last, size, stack_pointer, tag, tmp;
|
||||
var _l, _m, _n, _o, idx, last, size, stack_pointer, tag, tmp;
|
||||
tag = token[0];
|
||||
if (tag === 'INDENT') {
|
||||
stack.push(0);
|
||||
|
@ -211,8 +211,8 @@
|
|||
if (stack[stack.length - 1] > 0 || tag === 'INDENT') {
|
||||
idx = tag === 'OUTDENT' ? i + 1 : i;
|
||||
stack_pointer = tag === 'INDENT' ? 2 : 1;
|
||||
_k = 0; _l = stack[stack.length - stack_pointer];
|
||||
for (_j = 0, tmp=_k; (_k <= _l ? tmp < _l : tmp > _l); (_k <= _l ? tmp += 1 : tmp -= 1), _j++) {
|
||||
_n = 0; _o = stack[stack.length - stack_pointer];
|
||||
for (_m = 0, tmp = _n; (_n <= _o ? tmp < _o : tmp > _o); (_n <= _o ? tmp += 1 : tmp -= 1), _m++) {
|
||||
this.tokens.splice(idx, 0, ['CALL_END', ')', token[2]]);
|
||||
}
|
||||
size = stack[stack.length - stack_pointer] + 1;
|
||||
|
@ -276,17 +276,17 @@
|
|||
// Ensure that all listed pairs of tokens are correctly balanced throughout
|
||||
// the course of the token stream.
|
||||
re.prototype.ensure_balance = function ensure_balance(pairs) {
|
||||
var _i, _j, key, levels, unclosed, value;
|
||||
var _l, _m, key, levels, unclosed, value;
|
||||
levels = {};
|
||||
this.scan_tokens((function(__this) {
|
||||
var __func = function(prev, token, post, i) {
|
||||
var _i, _j, _k, close, open;
|
||||
_i = pairs;
|
||||
for (_j = 0; _j < _i.length; _j++) {
|
||||
pair = _i[_j];
|
||||
_k = pair;
|
||||
open = _k[0];
|
||||
close = _k[1];
|
||||
var _l, _m, _n, _o, close, open;
|
||||
_l = pairs;
|
||||
for (_m = 0, _n = _l.length; _m < _n; _m++) {
|
||||
pair = _l[_m];
|
||||
_o = pair;
|
||||
open = _o[0];
|
||||
close = _o[1];
|
||||
levels[open] = levels[open] || 0;
|
||||
if (token[0] === open) {
|
||||
levels[open] += 1;
|
||||
|
@ -305,14 +305,14 @@
|
|||
});
|
||||
})(this));
|
||||
unclosed = (function() {
|
||||
_i = []; _j = levels;
|
||||
for (key in _j) { if (__hasProp.call(_j, key)) {
|
||||
value = _j[key];
|
||||
_l = []; _m = levels;
|
||||
for (key in _m) { if (__hasProp.call(_m, key)) {
|
||||
value = _m[key];
|
||||
if (value > 0) {
|
||||
_i.push(key);
|
||||
_l.push(key);
|
||||
}
|
||||
}}
|
||||
return _i;
|
||||
return _l;
|
||||
}).call(this);
|
||||
if (unclosed.length) {
|
||||
throw new Error("unclosed " + unclosed[0]);
|
||||
|
@ -332,12 +332,12 @@
|
|||
// up balanced in the end.
|
||||
//
|
||||
re.prototype.rewrite_closing_parens = function rewrite_closing_parens() {
|
||||
var _i, debt, key, stack, val;
|
||||
var _l, debt, key, stack, val;
|
||||
stack = [];
|
||||
debt = {};
|
||||
_i = INVERSES;
|
||||
for (key in _i) { if (__hasProp.call(_i, key)) {
|
||||
val = _i[key];
|
||||
_l = INVERSES;
|
||||
for (key in _l) { if (__hasProp.call(_l, key)) {
|
||||
val = _l[key];
|
||||
((debt[key] = 0));
|
||||
}}
|
||||
return this.scan_tokens((function(__this) {
|
||||
|
|
|
@ -922,9 +922,11 @@ ForNode: exports.ForNode: inherit BaseNode, {
|
|||
else
|
||||
index_var: null
|
||||
source_part: svar + ' = ' + @source.compile(o) + ';\n' + @idt()
|
||||
step_part: if @step then ivar + ' += ' + @step.compile(o) else ivar + '++'
|
||||
for_part: ivar + ' = 0; ' + ivar + ' < ' + svar + '.length; ' + step_part
|
||||
var_part: body_dent + name + ' = ' + svar + '[' + ivar + '];\n' if name
|
||||
if not @object
|
||||
lvar: scope.free_variable()
|
||||
step_part: if @step then ivar + ' += ' + @step.compile(o) else ivar + '++'
|
||||
for_part: ivar + ' = 0, ' + lvar + ' = ' + svar + '.length; ' + ivar + ' < ' + lvar + '; ' + step_part
|
||||
set_result: if rvar then @idt() + rvar + ' = []; ' else @idt()
|
||||
return_result: rvar or ''
|
||||
body: ClosureNode.wrap(body, true) if top_level and @contains (n) -> n instanceof CodeNode
|
||||
|
|
Loading…
Reference in a new issue