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

merging fix for #1124

This commit is contained in:
Jeremy Ashkenas 2011-04-18 20:44:27 -04:00
commit 2f39102026
8 changed files with 226 additions and 221 deletions

View file

@ -70,8 +70,8 @@
lexer = new Lexer; lexer = new Lexer;
parser.lexer = { parser.lexer = {
lex: function() { lex: function() {
var tag, _ref; var tag, _ref2;
_ref = this.tokens[this.pos++] || [''], tag = _ref[0], this.yytext = _ref[1], this.yylineno = _ref[2]; _ref2 = this.tokens[this.pos++] || [''], tag = _ref2[0], this.yytext = _ref2[1], this.yylineno = _ref2[2];
return tag; return tag;
}, },
setInput: function(tokens) { setInput: function(tokens) {

View file

@ -66,13 +66,13 @@
return fs.stat(source, function(err, stats) { return fs.stat(source, function(err, stats) {
if (stats.isDirectory()) { if (stats.isDirectory()) {
return fs.readdir(source, function(err, files) { return fs.readdir(source, function(err, files) {
var file, _i, _len, _results; var file, _j, _len2, _results2;
_results = []; _results2 = [];
for (_i = 0, _len = files.length; _i < _len; _i++) { for (_j = 0, _len2 = files.length; _j < _len2; _j++) {
file = files[_i]; file = files[_j];
_results.push(compile(path.join(source, file))); _results2.push(compile(path.join(source, file)));
} }
return _results; return _results2;
}); });
} else if (topLevel || path.extname(source) === '.coffee') { } else if (topLevel || path.extname(source) === '.coffee') {
fs.readFile(source, function(err, code) { fs.readFile(source, function(err, code) {
@ -155,12 +155,12 @@
return compileScript("concatenation", code, "concatenation"); return compileScript("concatenation", code, "concatenation");
}; };
loadRequires = function() { loadRequires = function() {
var realFilename, req, _i, _len, _ref; var realFilename, req, _i, _len, _ref2;
realFilename = module.filename; realFilename = module.filename;
module.filename = '.'; module.filename = '.';
_ref = opts.require; _ref2 = opts.require;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
req = _ref[_i]; req = _ref2[_i];
require(req); require(req);
} }
return module.filename = realFilename; return module.filename = realFilename;
@ -223,11 +223,11 @@
printTokens = function(tokens) { printTokens = function(tokens) {
var strings, tag, token, value; var strings, tag, token, value;
strings = (function() { strings = (function() {
var _i, _len, _ref, _results; var _i, _len, _ref2, _results;
_results = []; _results = [];
for (_i = 0, _len = tokens.length; _i < _len; _i++) { for (_i = 0, _len = tokens.length; _i < _len; _i++) {
token = tokens[_i]; token = tokens[_i];
_ref = [token[0], token[1].toString().replace(/\n/, '\\n')], tag = _ref[0], value = _ref[1]; _ref2 = [token[0], token[1].toString().replace(/\n/, '\\n')], tag = _ref2[0], value = _ref2[1];
_results.push("[" + tag + " " + value + "]"); _results.push("[" + tag + " " + value + "]");
} }
return _results; return _results;

View file

@ -37,7 +37,7 @@
return (new Rewriter).rewrite(this.tokens); return (new Rewriter).rewrite(this.tokens);
}; };
Lexer.prototype.identifierToken = function() { Lexer.prototype.identifierToken = function() {
var colon, forcedIdentifier, id, input, match, prev, tag, _ref, _ref2; var colon, forcedIdentifier, id, input, match, prev, tag, _ref2, _ref3;
if (!(match = IDENTIFIER.exec(this.chunk))) { if (!(match = IDENTIFIER.exec(this.chunk))) {
return 0; return 0;
} }
@ -46,11 +46,11 @@
this.token('OWN', id); this.token('OWN', id);
return id.length; return id.length;
} }
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref = prev[0]) === '.' || _ref === '?.' || _ref === '::') || !prev.spaced && prev[0] === '@'); forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::') || !prev.spaced && prev[0] === '@');
tag = 'IDENTIFIER'; tag = 'IDENTIFIER';
if (__indexOf.call(JS_KEYWORDS, id) >= 0 || !forcedIdentifier && __indexOf.call(COFFEE_KEYWORDS, id) >= 0) { if (__indexOf.call(JS_KEYWORDS, id) >= 0 || !forcedIdentifier && __indexOf.call(COFFEE_KEYWORDS, id) >= 0) {
tag = id.toUpperCase(); tag = id.toUpperCase();
if (tag === 'WHEN' && (_ref2 = this.tag(), __indexOf.call(LINE_BREAK, _ref2) >= 0)) { if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
tag = 'LEADING_WHEN'; tag = 'LEADING_WHEN';
} else if (tag === 'FOR') { } else if (tag === 'FOR') {
this.seenFor = true; this.seenFor = true;
@ -194,7 +194,7 @@
return script.length; return script.length;
}; };
Lexer.prototype.regexToken = function() { Lexer.prototype.regexToken = function() {
var match, prev, regex, _ref; var match, prev, regex, _ref2;
if (this.chunk.charAt(0) !== '/') { if (this.chunk.charAt(0) !== '/') {
return 0; return 0;
} }
@ -202,7 +202,7 @@
return this.heregexToken(match); return this.heregexToken(match);
} }
prev = last(this.tokens); prev = last(this.tokens);
if (prev && (_ref = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref) >= 0)) { if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) {
return 0; return 0;
} }
if (!(match = REGEX.exec(this.chunk))) { if (!(match = REGEX.exec(this.chunk))) {
@ -213,7 +213,7 @@
return regex.length; return regex.length;
}; };
Lexer.prototype.heregexToken = function(match) { Lexer.prototype.heregexToken = function(match) {
var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref, _ref2, _ref3, _ref4; var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4, _ref5;
heregex = match[0], body = match[1], flags = match[2]; heregex = match[0], body = match[1], flags = match[2];
if (0 > body.indexOf('#{')) { if (0 > body.indexOf('#{')) {
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/'); re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
@ -223,11 +223,11 @@
this.token('IDENTIFIER', 'RegExp'); this.token('IDENTIFIER', 'RegExp');
this.tokens.push(['CALL_START', '(']); this.tokens.push(['CALL_START', '(']);
tokens = []; tokens = [];
_ref = this.interpolateString(body, { _ref2 = this.interpolateString(body, {
regex: true regex: true
}); });
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_ref2 = _ref[_i], tag = _ref2[0], value = _ref2[1]; _ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1];
if (tag === 'TOKENS') { if (tag === 'TOKENS') {
tokens.push.apply(tokens, value); tokens.push.apply(tokens, value);
} else { } else {
@ -240,10 +240,10 @@
tokens.push(['+', '+']); tokens.push(['+', '+']);
} }
tokens.pop(); tokens.pop();
if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') { if (((_ref4 = tokens[0]) != null ? _ref4[0] : void 0) !== 'STRING') {
this.tokens.push(['STRING', '""'], ['+', '+']); this.tokens.push(['STRING', '""'], ['+', '+']);
} }
(_ref4 = this.tokens).push.apply(_ref4, tokens); (_ref5 = this.tokens).push.apply(_ref5, tokens);
if (flags) { if (flags) {
this.tokens.push([',', ','], ['STRING', '"' + flags + '"']); this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
} }
@ -340,7 +340,7 @@
return this; return this;
}; };
Lexer.prototype.literalToken = function() { Lexer.prototype.literalToken = function() {
var match, prev, tag, value, _ref, _ref2, _ref3, _ref4; var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
if (match = OPERATOR.exec(this.chunk)) { if (match = OPERATOR.exec(this.chunk)) {
value = match[0]; value = match[0];
if (CODE.test(value)) { if (CODE.test(value)) {
@ -352,10 +352,10 @@
tag = value; tag = value;
prev = last(this.tokens); prev = last(this.tokens);
if (value === '=' && prev) { if (value === '=' && prev) {
if (!prev[1].reserved && (_ref = prev[1], __indexOf.call(JS_FORBIDDEN, _ref) >= 0)) { if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
this.assignmentError(); this.assignmentError();
} }
if ((_ref2 = prev[1]) === '||' || _ref2 === '&&') { if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
prev[0] = 'COMPOUND_ASSIGN'; prev[0] = 'COMPOUND_ASSIGN';
prev[1] += '='; prev[1] += '=';
return value.length; return value.length;
@ -376,12 +376,12 @@
} else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) { } else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
tag = 'LOGIC'; tag = 'LOGIC';
} else if (prev && !prev.spaced) { } else if (prev && !prev.spaced) {
if (value === '(' && (_ref3 = prev[0], __indexOf.call(CALLABLE, _ref3) >= 0)) { if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {
if (prev[0] === '?') { if (prev[0] === '?') {
prev[0] = 'FUNC_EXIST'; prev[0] = 'FUNC_EXIST';
} }
tag = 'CALL_START'; tag = 'CALL_START';
} else if (value === '[' && (_ref4 = prev[0], __indexOf.call(INDEXABLE, _ref4) >= 0)) { } else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
tag = 'INDEX_START'; tag = 'INDEX_START';
switch (prev[0]) { switch (prev[0]) {
case '?': case '?':
@ -396,7 +396,7 @@
return value.length; return value.length;
}; };
Lexer.prototype.sanitizeHeredoc = function(doc, options) { Lexer.prototype.sanitizeHeredoc = function(doc, options) {
var attempt, herecomment, indent, match, _ref; var attempt, herecomment, indent, match, _ref2;
indent = options.indent, herecomment = options.herecomment; indent = options.indent, herecomment = options.herecomment;
if (herecomment) { if (herecomment) {
if (HEREDOC_ILLEGAL.test(doc)) { if (HEREDOC_ILLEGAL.test(doc)) {
@ -408,7 +408,7 @@
} else { } else {
while (match = HEREDOC_INDENT.exec(doc)) { while (match = HEREDOC_INDENT.exec(doc)) {
attempt = match[1]; attempt = match[1];
if (indent === null || (0 < (_ref = attempt.length) && _ref < indent.length)) { if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) {
indent = attempt; indent = attempt;
} }
} }
@ -457,9 +457,9 @@
throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned"); throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
}; };
Lexer.prototype.balancedString = function(str, end) { Lexer.prototype.balancedString = function(str, end) {
var i, letter, prev, stack, _ref; var i, letter, prev, stack, _ref2;
stack = [end]; stack = [end];
for (i = 1, _ref = str.length; 1 <= _ref ? i < _ref : i > _ref; 1 <= _ref ? i++ : i--) { for (i = 1, _ref2 = str.length; 1 <= _ref2 ? i < _ref2 : i > _ref2; 1 <= _ref2 ? i++ : i--) {
switch (letter = str.charAt(i)) { switch (letter = str.charAt(i)) {
case '\\': case '\\':
i++; i++;
@ -484,7 +484,7 @@
throw new Error("missing " + (stack.pop()) + ", starting on line " + (this.line + 1)); throw new Error("missing " + (stack.pop()) + ", starting on line " + (this.line + 1));
}; };
Lexer.prototype.interpolateString = function(str, options) { Lexer.prototype.interpolateString = function(str, options) {
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2, _ref3; var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref2, _ref3, _ref4;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -510,7 +510,7 @@
rewrite: false rewrite: false
}); });
nested.pop(); nested.pop();
if (((_ref = nested[0]) != null ? _ref[0] : void 0) === 'TERMINATOR') { if (((_ref2 = nested[0]) != null ? _ref2[0] : void 0) === 'TERMINATOR') {
nested.shift(); nested.shift();
} }
if (len = nested.length) { if (len = nested.length) {
@ -540,12 +540,12 @@
this.token('(', '('); this.token('(', '(');
} }
for (i = 0, _len = tokens.length; i < _len; i++) { for (i = 0, _len = tokens.length; i < _len; i++) {
_ref2 = tokens[i], tag = _ref2[0], value = _ref2[1]; _ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
if (i) { if (i) {
this.token('+', '+'); this.token('+', '+');
} }
if (tag === 'TOKENS') { if (tag === 'TOKENS') {
(_ref3 = this.tokens).push.apply(_ref3, value); (_ref4 = this.tokens).push.apply(_ref4, value);
} else { } else {
this.token('STRING', this.makeString(value, '"', heredoc)); this.token('STRING', this.makeString(value, '"', heredoc));
} }

View file

@ -63,9 +63,9 @@
} }
}; };
Base.prototype.compileLoopReference = function(o, name) { Base.prototype.compileLoopReference = function(o, name) {
var src, tmp, _ref; var src, tmp, _ref2;
src = tmp = this.compile(o, LEVEL_LIST); src = tmp = this.compile(o, LEVEL_LIST);
if (!((-Infinity < (_ref = +src) && _ref < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) { if (!((-Infinity < (_ref2 = +src) && _ref2 < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) {
src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src; src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
} }
return [src, tmp]; return [src, tmp];
@ -117,17 +117,17 @@
return tree; return tree;
}; };
Base.prototype.eachChild = function(func) { Base.prototype.eachChild = function(func) {
var attr, child, _i, _j, _len, _len2, _ref, _ref2; var attr, child, _i, _j, _len, _len2, _ref2, _ref3;
if (!this.children) { if (!this.children) {
return this; return this;
} }
_ref = this.children; _ref2 = this.children;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
attr = _ref[_i]; attr = _ref2[_i];
if (this[attr]) { if (this[attr]) {
_ref2 = flatten([this[attr]]); _ref3 = flatten([this[attr]]);
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
child = _ref2[_j]; child = _ref3[_j];
if (func(child) === false) { if (func(child) === false) {
return this; return this;
} }
@ -194,10 +194,10 @@
return !this.expressions.length; return !this.expressions.length;
}; };
Block.prototype.isStatement = function(o) { Block.prototype.isStatement = function(o) {
var exp, _i, _len, _ref; var exp, _i, _len, _ref2;
_ref = this.expressions; _ref2 = this.expressions;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
exp = _ref[_i]; exp = _ref2[_i];
if (exp.isStatement(o)) { if (exp.isStatement(o)) {
return true; return true;
} }
@ -205,10 +205,10 @@
return false; return false;
}; };
Block.prototype.jumps = function(o) { Block.prototype.jumps = function(o) {
var exp, _i, _len, _ref; var exp, _i, _len, _ref2;
_ref = this.expressions; _ref2 = this.expressions;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
exp = _ref[_i]; exp = _ref2[_i];
if (exp.jumps(o)) { if (exp.jumps(o)) {
return exp; return exp;
} }
@ -240,13 +240,13 @@
} }
}; };
Block.prototype.compileNode = function(o) { Block.prototype.compileNode = function(o) {
var code, codes, node, top, _i, _len, _ref; var code, codes, node, top, _i, _len, _ref2;
this.tab = o.indent; this.tab = o.indent;
top = o.level === LEVEL_TOP; top = o.level === LEVEL_TOP;
codes = []; codes = [];
_ref = this.expressions; _ref2 = this.expressions;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
node = _ref[_i]; node = _ref2[_i];
node = node.unwrapAll(); node = node.unwrapAll();
node = node.unfoldSoak(o) || node; node = node.unfoldSoak(o) || node;
if (top) { if (top) {
@ -280,11 +280,11 @@
} }
}; };
Block.prototype.compileWithDeclarations = function(o) { Block.prototype.compileWithDeclarations = function(o) {
var code, exp, i, post, rest, scope, _len, _ref; var code, exp, i, post, rest, scope, _len, _ref2;
code = post = ''; code = post = '';
_ref = this.expressions; _ref2 = this.expressions;
for (i = 0, _len = _ref.length; i < _len; i++) { for (i = 0, _len = _ref2.length; i < _len; i++) {
exp = _ref[i]; exp = _ref2[i];
exp = exp.unwrap(); exp = exp.unwrap();
if (!(exp instanceof Comment || exp instanceof Literal)) { if (!(exp instanceof Comment || exp instanceof Literal)) {
break; break;
@ -334,8 +334,8 @@
return IDENTIFIER.test(this.value); return IDENTIFIER.test(this.value);
}; };
Literal.prototype.isStatement = function() { Literal.prototype.isStatement = function() {
var _ref; var _ref2;
return (_ref = this.value) === 'break' || _ref === 'continue' || _ref === 'debugger'; return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
}; };
Literal.prototype.isComplex = NO; Literal.prototype.isComplex = NO;
Literal.prototype.assigns = function(name) { Literal.prototype.assigns = function(name) {
@ -377,8 +377,8 @@
Return.prototype.makeReturn = THIS; Return.prototype.makeReturn = THIS;
Return.prototype.jumps = THIS; Return.prototype.jumps = THIS;
Return.prototype.compile = function(o, level) { Return.prototype.compile = function(o, level) {
var expr, _ref; var expr, _ref2;
expr = (_ref = this.expression) != null ? _ref.makeReturn() : void 0; expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0;
if (expr && !(expr instanceof Return)) { if (expr && !(expr instanceof Return)) {
return expr.compile(o, level); return expr.compile(o, level);
} else { } else {
@ -424,10 +424,10 @@
return this.base instanceof Literal && SIMPLENUM.test(this.base.value); return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
}; };
Value.prototype.isAtomic = function() { Value.prototype.isAtomic = function() {
var node, _i, _len, _ref; var node, _i, _len, _ref2;
_ref = this.properties.concat(this.base); _ref2 = this.properties.concat(this.base);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
node = _ref[_i]; node = _ref2[_i];
if (node.soak || node instanceof Call) { if (node.soak || node instanceof Call) {
return false; return false;
} }
@ -502,14 +502,14 @@
return code; return code;
}; };
Value.prototype.unfoldSoak = function(o) { Value.prototype.unfoldSoak = function(o) {
var fst, i, ifn, prop, ref, snd, _len, _ref; var fst, i, ifn, prop, ref, snd, _len, _ref2;
if (ifn = this.base.unfoldSoak(o)) { if (ifn = this.base.unfoldSoak(o)) {
Array.prototype.push.apply(ifn.body.properties, this.properties); Array.prototype.push.apply(ifn.body.properties, this.properties);
return ifn; return ifn;
} }
_ref = this.properties; _ref2 = this.properties;
for (i = 0, _len = _ref.length; i < _len; i++) { for (i = 0, _len = _ref2.length; i < _len; i++) {
prop = _ref[i]; prop = _ref2[i];
if (prop.soak) { if (prop.soak) {
prop.soak = false; prop.soak = false;
fst = new Value(this.base, this.properties.slice(0, i)); fst = new Value(this.base, this.properties.slice(0, i));
@ -582,13 +582,13 @@
} }
}; };
Call.prototype.unfoldSoak = function(o) { Call.prototype.unfoldSoak = function(o) {
var call, ifn, left, list, rite, _i, _len, _ref, _ref2; var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
if (this.soak) { if (this.soak) {
if (this.variable) { if (this.variable) {
if (ifn = unfoldSoak(o, this, 'variable')) { if (ifn = unfoldSoak(o, this, 'variable')) {
return ifn; return ifn;
} }
_ref = new Value(this.variable).cacheReference(o), left = _ref[0], rite = _ref[1]; _ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1];
} else { } else {
left = new Literal(this.superReference(o)); left = new Literal(this.superReference(o));
rite = new Value(left); rite = new Value(left);
@ -616,9 +616,9 @@
break; break;
} }
} }
_ref2 = list.reverse(); _ref3 = list.reverse();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
call = _ref2[_i]; call = _ref3[_i];
if (ifn) { if (ifn) {
if (call.variable instanceof Call) { if (call.variable instanceof Call) {
call.variable = ifn; call.variable = ifn;
@ -631,7 +631,7 @@
return ifn; return ifn;
}; };
Call.prototype.filterImplicitObjects = function(list) { Call.prototype.filterImplicitObjects = function(list) {
var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref; var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref2;
nodes = []; nodes = [];
for (_i = 0, _len = list.length; _i < _len; _i++) { for (_i = 0, _len = list.length; _i < _len; _i++) {
node = list[_i]; node = list[_i];
@ -640,9 +640,9 @@
continue; continue;
} }
obj = null; obj = null;
_ref = node.base.properties; _ref2 = node.base.properties;
for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
prop = _ref[_j]; prop = _ref2[_j];
if (prop instanceof Assign) { if (prop instanceof Assign) {
if (!obj) { if (!obj) {
nodes.push(obj = new Obj(properties = [], true)); nodes.push(obj = new Obj(properties = [], true));
@ -657,9 +657,9 @@
return nodes; return nodes;
}; };
Call.prototype.compileNode = function(o) { Call.prototype.compileNode = function(o) {
var arg, args, code, _ref; var arg, args, code, _ref2;
if ((_ref = this.variable) != null) { if ((_ref2 = this.variable) != null) {
_ref.front = this.front; _ref2.front = this.front;
} }
if (code = Splat.compileSplattedArray(o, this.args, true)) { if (code = Splat.compileSplattedArray(o, this.args, true)) {
return this.compileSplat(o, code); return this.compileSplat(o, code);
@ -766,13 +766,13 @@
this.equals = this.exclusive ? '' : '='; this.equals = this.exclusive ? '' : '=';
} }
Range.prototype.compileVariables = function(o) { Range.prototype.compileVariables = function(o) {
var parts, _ref, _ref2, _ref3; var parts, _ref2, _ref3, _ref4;
o = merge(o, { o = merge(o, {
top: true top: true
}); });
_ref = this.from.cache(o, LEVEL_LIST), this.from = _ref[0], this.fromVar = _ref[1]; _ref2 = this.from.cache(o, LEVEL_LIST), this.from = _ref2[0], this.fromVar = _ref2[1];
_ref2 = this.to.cache(o, LEVEL_LIST), this.to = _ref2[0], this.toVar = _ref2[1]; _ref3 = this.to.cache(o, LEVEL_LIST), this.to = _ref3[0], this.toVar = _ref3[1];
_ref3 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref3[0], this.toNum = _ref3[1]; _ref4 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref4[0], this.toNum = _ref4[1];
parts = []; parts = [];
if (this.from !== this.fromVar) { if (this.from !== this.fromVar) {
parts.push(this.from); parts.push(this.from);
@ -799,8 +799,8 @@
return "" + vars + "; " + compare + "; " + incr; return "" + vars + "; " + compare + "; " + incr;
}; };
Range.prototype.compileSimple = function(o) { Range.prototype.compileSimple = function(o) {
var from, idx, step, to, _ref; var from, idx, step, to, _ref2;
_ref = [+this.fromNum, +this.toNum], from = _ref[0], to = _ref[1]; _ref2 = [+this.fromNum, +this.toNum], from = _ref2[0], to = _ref2[1];
idx = del(o, 'index'); idx = del(o, 'index');
step = del(o, 'step'); step = del(o, 'step');
step && (step = "" + idx + " += " + (step.compile(o))); step && (step = "" + idx + " += " + (step.compile(o)));
@ -811,11 +811,11 @@
} }
}; };
Range.prototype.compileArray = function(o) { Range.prototype.compileArray = function(o) {
var body, cond, i, idt, post, pre, range, result, vars, _i, _ref, _ref2, _results; var body, cond, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results;
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) { if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
range = (function() { range = (function() {
_results = []; _results = [];
for (var _i = _ref = +this.fromNum, _ref2 = +this.toNum; _ref <= _ref2 ? _i <= _ref2 : _i >= _ref2; _ref <= _ref2 ? _i++ : _i--){ _results.push(_i); } for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); }
return _results; return _results;
}).apply(this, arguments); }).apply(this, arguments);
if (this.exclusive) { if (this.exclusive) {
@ -848,8 +848,8 @@
Slice.__super__.constructor.call(this); Slice.__super__.constructor.call(this);
} }
Slice.prototype.compileNode = function(o) { Slice.prototype.compileNode = function(o) {
var compiled, from, fromStr, to, toStr, _ref; var compiled, from, fromStr, to, toStr, _ref2;
_ref = this.range, to = _ref.to, from = _ref.from; _ref2 = this.range, to = _ref2.to, from = _ref2.from;
fromStr = from && from.compile(o, LEVEL_PAREN) || '0'; fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
compiled = to && to.compile(o, LEVEL_PAREN); compiled = to && to.compile(o, LEVEL_PAREN);
if (to && !(!this.range.exclusive && +compiled === -1)) { if (to && !(!this.range.exclusive && +compiled === -1)) {
@ -887,9 +887,9 @@
idt = o.indent += TAB; idt = o.indent += TAB;
lastNoncom = this.lastNonComment(this.properties); lastNoncom = this.lastNonComment(this.properties);
props = (function() { props = (function() {
var _len, _results; var _len2, _results;
_results = []; _results = [];
for (i = 0, _len = props.length; i < _len; i++) { for (i = 0, _len2 = props.length; i < _len2; i++) {
prop = props[i]; prop = props[i];
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n'; join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
indent = prop instanceof Comment ? '' : idt; indent = prop instanceof Comment ? '' : idt;
@ -915,10 +915,10 @@
} }
}; };
Obj.prototype.assigns = function(name) { Obj.prototype.assigns = function(name) {
var prop, _i, _len, _ref; var prop, _i, _len, _ref2;
_ref = this.properties; _ref2 = this.properties;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
prop = _ref[_i]; prop = _ref2[_i];
if (prop.assigns(name)) { if (prop.assigns(name)) {
return true; return true;
} }
@ -960,10 +960,10 @@
} }
}; };
Arr.prototype.assigns = function(name) { Arr.prototype.assigns = function(name) {
var obj, _i, _len, _ref; var obj, _i, _len, _ref2;
_ref = this.objects; _ref2 = this.objects;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
obj = _ref[_i]; obj = _ref2[_i];
if (obj.assigns(name)) { if (obj.assigns(name)) {
return true; return true;
} }
@ -1006,12 +1006,12 @@
}); });
}; };
Class.prototype.addBoundFunctions = function(o) { Class.prototype.addBoundFunctions = function(o) {
var bname, bvar, _i, _len, _ref, _results; var bname, bvar, _i, _len, _ref2, _results;
if (this.boundFuncs.length) { if (this.boundFuncs.length) {
_ref = this.boundFuncs; _ref2 = this.boundFuncs;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
bvar = _ref[_i]; bvar = _ref2[_i];
bname = bvar.compile(o); bname = bvar.compile(o);
_results.push(this.ctor.body.unshift(new Literal("this." + bname + " = " + (utility('bind')) + "(this." + bname + ", this);"))); _results.push(this.ctor.body.unshift(new Literal("this." + bname + " = " + (utility('bind')) + "(this." + bname + ", this);")));
} }
@ -1055,14 +1055,14 @@
}; };
Class.prototype.walkBody = function(name) { Class.prototype.walkBody = function(name) {
return this.traverseChildren(false, __bind(function(child) { return this.traverseChildren(false, __bind(function(child) {
var exps, i, node, _len, _ref; var exps, i, node, _len, _ref2;
if (child instanceof Class) { if (child instanceof Class) {
return false; return false;
} }
if (child instanceof Block) { if (child instanceof Block) {
_ref = exps = child.expressions; _ref2 = exps = child.expressions;
for (i = 0, _len = _ref.length; i < _len; i++) { for (i = 0, _len = _ref2.length; i < _len; i++) {
node = _ref[i]; node = _ref2[i];
if (node instanceof Value && node.isObject(true)) { if (node instanceof Value && node.isObject(true)) {
exps[i] = this.addProperties(node, name); exps[i] = this.addProperties(node, name);
} }
@ -1121,7 +1121,7 @@
return unfoldSoak(o, this, 'variable'); return unfoldSoak(o, this, 'variable');
}; };
Assign.prototype.compileNode = function(o) { Assign.prototype.compileNode = function(o) {
var isValue, match, name, val, _ref; var isValue, match, name, val, _ref2;
if (isValue = this.variable instanceof Value) { if (isValue = this.variable instanceof Value) {
if (this.variable.isArray() || this.variable.isObject()) { if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o); return this.compilePatternMatch(o);
@ -1129,7 +1129,7 @@
if (this.variable.isSplice()) { if (this.variable.isSplice()) {
return this.compileSplice(o); return this.compileSplice(o);
} }
if ((_ref = this.context) === '||=' || _ref === '&&=' || _ref === '?=') { if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') {
return this.compileConditional(o); return this.compileConditional(o);
} }
} }
@ -1162,7 +1162,7 @@
} }
}; };
Assign.prototype.compilePatternMatch = function(o) { Assign.prototype.compilePatternMatch = function(o) {
var acc, assigns, code, i, idx, isObject, ivar, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref, _ref2, _ref3, _ref4; var acc, assigns, code, i, idx, isObject, ivar, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref2, _ref3, _ref4, _ref5;
top = o.level === LEVEL_TOP; top = o.level === LEVEL_TOP;
value = this.value; value = this.value;
objects = this.variable.base.objects; objects = this.variable.base.objects;
@ -1177,10 +1177,10 @@
isObject = this.variable.isObject(); isObject = this.variable.isObject();
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) { if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
if (obj instanceof Assign) { if (obj instanceof Assign) {
_ref = obj, idx = _ref.variable.base, obj = _ref.value; _ref2 = obj, idx = _ref2.variable.base, obj = _ref2.value;
} else { } else {
if (obj.base instanceof Parens) { if (obj.base instanceof Parens) {
_ref2 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref2[0], idx = _ref2[1]; _ref3 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref3[0], idx = _ref3[1];
} else { } else {
idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0); idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
} }
@ -1202,10 +1202,10 @@
idx = i; idx = i;
if (isObject) { if (isObject) {
if (obj instanceof Assign) { if (obj instanceof Assign) {
_ref3 = obj, idx = _ref3.variable.base, obj = _ref3.value; _ref4 = obj, idx = _ref4.variable.base, obj = _ref4.value;
} else { } else {
if (obj.base instanceof Parens) { if (obj.base instanceof Parens) {
_ref4 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref4[0], idx = _ref4[1]; _ref5 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref5[0], idx = _ref5[1];
} else { } else {
idx = obj["this"] ? obj.properties[0].name : obj; idx = obj["this"] ? obj.properties[0].name : obj;
} }
@ -1249,15 +1249,15 @@
} }
}; };
Assign.prototype.compileConditional = function(o) { Assign.prototype.compileConditional = function(o) {
var left, rite, _ref; var left, rite, _ref2;
_ref = this.variable.cacheReference(o), left = _ref[0], rite = _ref[1]; _ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1];
return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o); return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o);
}; };
Assign.prototype.compileSplice = function(o) { Assign.prototype.compileSplice = function(o) {
var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref, _ref2, _ref3; var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
_ref = this.variable.properties.pop().range, from = _ref.from, to = _ref.to, exclusive = _ref.exclusive; _ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive;
name = this.variable.compile(o); name = this.variable.compile(o);
_ref2 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref2[0], fromRef = _ref2[1]; _ref3 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref3[0], fromRef = _ref3[1];
if (to) { if (to) {
if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) { if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
to = +to.compile(o) - +fromRef; to = +to.compile(o) - +fromRef;
@ -1273,7 +1273,7 @@
} else { } else {
to = "9e9"; to = "9e9";
} }
_ref3 = this.value.cache(o, LEVEL_LIST), valDef = _ref3[0], valRef = _ref3[1]; _ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1];
code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef; code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef;
if (o.level > LEVEL_TOP) { if (o.level > LEVEL_TOP) {
return "(" + code + ")"; return "(" + code + ")";
@ -1299,7 +1299,7 @@
}; };
Code.prototype.jumps = NO; Code.prototype.jumps = NO;
Code.prototype.compileNode = function(o) { Code.prototype.compileNode = function(o) {
var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _len, _len2, _len3, _ref, _ref2, _ref3; var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _len, _len2, _len3, _ref2, _ref3, _ref4;
o.scope = new Scope(o.scope, this.body, this); o.scope = new Scope(o.scope, this.body, this);
o.scope.shared = del(o, 'sharedScope'); o.scope.shared = del(o, 'sharedScope');
o.indent += TAB; o.indent += TAB;
@ -1307,19 +1307,19 @@
delete o.globals; delete o.globals;
vars = []; vars = [];
exprs = []; exprs = [];
_ref = this.params; _ref2 = this.params;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
param = _ref[_i]; param = _ref2[_i];
if (param.splat) { if (param.splat) {
if (param.name.value) { if (param.name.value) {
o.scope.add(param.name.value, 'var'); o.scope.add(param.name.value, 'var');
} }
splats = new Assign(new Value(new Arr((function() { splats = new Assign(new Value(new Arr((function() {
var _i, _len, _ref, _results; var _j, _len2, _ref3, _results;
_ref = this.params; _ref3 = this.params;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
p = _ref[_i]; p = _ref3[_j];
_results.push(p.asReference(o)); _results.push(p.asReference(o));
} }
return _results; return _results;
@ -1327,9 +1327,9 @@
break; break;
} }
} }
_ref2 = this.params; _ref3 = this.params;
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
param = _ref2[_j]; param = _ref3[_j];
if (param.isComplex()) { if (param.isComplex()) {
val = ref = param.asReference(o); val = ref = param.asReference(o);
if (param.value) { if (param.value) {
@ -1355,7 +1355,7 @@
exprs.unshift(splats); exprs.unshift(splats);
} }
if (exprs.length) { if (exprs.length) {
(_ref3 = this.body.expressions).unshift.apply(_ref3, exprs); (_ref4 = this.body.expressions).unshift.apply(_ref4, exprs);
} }
if (!splats) { if (!splats) {
for (i = 0, _len3 = vars.length; i < _len3; i++) { for (i = 0, _len3 = vars.length; i < _len3; i++) {
@ -1474,11 +1474,11 @@
return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")"); return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
} }
base = (function() { base = (function() {
var _i, _len, _ref, _results; var _i, _len2, _ref2, _results;
_ref = list.slice(0, index); _ref2 = list.slice(0, index);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) {
node = _ref[_i]; node = _ref2[_i];
_results.push(node.compile(o, LEVEL_LIST)); _results.push(node.compile(o, LEVEL_LIST));
} }
return _results; return _results;
@ -1589,11 +1589,11 @@
return !this.second; return !this.second;
}; };
Op.prototype.isChainable = function() { Op.prototype.isChainable = function() {
var _ref; var _ref2;
return (_ref = this.operator) === '<' || _ref === '>' || _ref === '>=' || _ref === '<=' || _ref === '===' || _ref === '!=='; return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!==';
}; };
Op.prototype.invert = function() { Op.prototype.invert = function() {
var allInvertable, curr, fst, op, _ref; var allInvertable, curr, fst, op, _ref2;
if (this.isChainable() && this.first.isChainable()) { if (this.isChainable() && this.first.isChainable()) {
allInvertable = true; allInvertable = true;
curr = this; curr = this;
@ -1619,15 +1619,15 @@
return this; return this;
} else if (this.second) { } else if (this.second) {
return new Parens(this).invert(); return new Parens(this).invert();
} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref = fst.operator) === '!' || _ref === 'in' || _ref === 'instanceof')) { } else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) {
return fst; return fst;
} else { } else {
return new Op('!', this); return new Op('!', this);
} }
}; };
Op.prototype.unfoldSoak = function(o) { Op.prototype.unfoldSoak = function(o) {
var _ref; var _ref2;
return ((_ref = this.operator) === '++' || _ref === '--' || _ref === 'delete') && unfoldSoak(o, this, 'first'); return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
}; };
Op.prototype.compileNode = function(o) { Op.prototype.compileNode = function(o) {
var code; var code;
@ -1649,8 +1649,8 @@
} }
}; };
Op.prototype.compileChain = function(o) { Op.prototype.compileChain = function(o) {
var code, fst, shared, _ref; var code, fst, shared, _ref2;
_ref = this.first.second.cache(o), this.first.second = _ref[0], shared = _ref[1]; _ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
fst = this.first.compile(o, LEVEL_OP); fst = this.first.compile(o, LEVEL_OP);
code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP)); code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
return "(" + code + ")"; return "(" + code + ")";
@ -1704,15 +1704,15 @@
} }
}; };
In.prototype.compileOrTest = function(o) { In.prototype.compileOrTest = function(o) {
var cmp, cnj, i, item, ref, sub, tests, _ref, _ref2; var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;
_ref = this.object.cache(o, LEVEL_OP), sub = _ref[0], ref = _ref[1]; _ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
_ref2 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref2[0], cnj = _ref2[1]; _ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
tests = (function() { tests = (function() {
var _len, _ref, _results; var _len, _ref4, _results;
_ref = this.array.base.objects; _ref4 = this.array.base.objects;
_results = []; _results = [];
for (i = 0, _len = _ref.length; i < _len; i++) { for (i = 0, _len = _ref4.length; i < _len; i++) {
item = _ref[i]; item = _ref4[i];
_results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_OP)); _results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_OP));
} }
return _results; return _results;
@ -1728,8 +1728,8 @@
} }
}; };
In.prototype.compileLoopTest = function(o) { In.prototype.compileLoopTest = function(o) {
var code, ref, sub, _ref; var code, ref, sub, _ref2;
_ref = this.object.cache(o, LEVEL_LIST), sub = _ref[0], ref = _ref[1]; _ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0'); code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
if (sub === ref) { if (sub === ref) {
return code; return code;
@ -1757,8 +1757,8 @@
Try.prototype.children = ['attempt', 'recovery', 'ensure']; Try.prototype.children = ['attempt', 'recovery', 'ensure'];
Try.prototype.isStatement = YES; Try.prototype.isStatement = YES;
Try.prototype.jumps = function(o) { Try.prototype.jumps = function(o) {
var _ref; var _ref2;
return this.attempt.jumps(o) || ((_ref = this.recovery) != null ? _ref.jumps(o) : void 0); return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0);
}; };
Try.prototype.makeReturn = function() { Try.prototype.makeReturn = function() {
if (this.attempt) { if (this.attempt) {
@ -1846,13 +1846,13 @@
exports.For = For = (function() { exports.For = For = (function() {
__extends(For, Base); __extends(For, Base);
function For(body, source) { function For(body, source) {
var _ref; var _ref2;
this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index; this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
this.body = Block.wrap([body]); this.body = Block.wrap([body]);
this.own = !!source.own; this.own = !!source.own;
this.object = !!source.object; this.object = !!source.object;
if (this.object) { if (this.object) {
_ref = [this.index, this.name], this.name = _ref[0], this.index = _ref[1]; _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
} }
if (this.index instanceof Value) { if (this.index instanceof Value) {
throw SyntaxError('index cannot be a pattern matching expression'); throw SyntaxError('index cannot be a pattern matching expression');
@ -1875,9 +1875,9 @@
return this; return this;
}; };
For.prototype.compileNode = function(o) { For.prototype.compileNode = function(o) {
var body, defPart, forPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, svar, varPart, _ref; var body, defPart, forPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, svar, varPart, _ref2;
body = Block.wrap([this.body]); body = Block.wrap([this.body]);
lastJumps = (_ref = last(body.expressions)) != null ? _ref.jumps() : void 0; lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
if (lastJumps && lastJumps instanceof Return) { if (lastJumps && lastJumps instanceof Return) {
this.returns = false; this.returns = false;
} }
@ -1956,24 +1956,24 @@
return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || ''); return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || '');
}; };
For.prototype.pluckDirectCall = function(o, body) { For.prototype.pluckDirectCall = function(o, body) {
var base, defs, expr, fn, idx, ref, val, _len, _ref, _ref2, _ref3, _ref4, _ref5, _ref6; var base, defs, expr, fn, idx, ref, val, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
defs = ''; defs = '';
_ref = body.expressions; _ref2 = body.expressions;
for (idx = 0, _len = _ref.length; idx < _len; idx++) { for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
expr = _ref[idx]; expr = _ref2[idx];
expr = expr.unwrapAll(); expr = expr.unwrapAll();
if (!(expr instanceof Call)) { if (!(expr instanceof Call)) {
continue; continue;
} }
val = expr.variable.unwrapAll(); val = expr.variable.unwrapAll();
if (!((val instanceof Code) || (val instanceof Value && ((_ref2 = val.base) != null ? _ref2.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref3 = (_ref4 = val.properties[0].name) != null ? _ref4.value : void 0) === 'call' || _ref3 === 'apply')))) { if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) {
continue; continue;
} }
fn = ((_ref5 = val.base) != null ? _ref5.unwrapAll() : void 0) || val; fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val;
ref = new Literal(o.scope.freeVariable('fn')); ref = new Literal(o.scope.freeVariable('fn'));
base = new Value(ref); base = new Value(ref);
if (val.base) { if (val.base) {
_ref6 = [base, val], val.base = _ref6[0], base = _ref6[1]; _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
args.unshift(new Literal('this')); args.unshift(new Literal('this'));
} }
body.expressions[idx] = new Call(base, expr.args); body.expressions[idx] = new Call(base, expr.args);
@ -1993,44 +1993,44 @@
Switch.prototype.children = ['subject', 'cases', 'otherwise']; Switch.prototype.children = ['subject', 'cases', 'otherwise'];
Switch.prototype.isStatement = YES; Switch.prototype.isStatement = YES;
Switch.prototype.jumps = function(o) { Switch.prototype.jumps = function(o) {
var block, conds, _i, _len, _ref, _ref2, _ref3; var block, conds, _i, _len, _ref2, _ref3, _ref4;
if (o == null) { if (o == null) {
o = { o = {
block: true block: true
}; };
} }
_ref = this.cases; _ref2 = this.cases;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_ref2 = _ref[_i], conds = _ref2[0], block = _ref2[1]; _ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
if (block.jumps(o)) { if (block.jumps(o)) {
return block; return block;
} }
} }
return (_ref3 = this.otherwise) != null ? _ref3.jumps(o) : void 0; return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0;
}; };
Switch.prototype.makeReturn = function() { Switch.prototype.makeReturn = function() {
var pair, _i, _len, _ref, _ref2; var pair, _i, _len, _ref2, _ref3;
_ref = this.cases; _ref2 = this.cases;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
pair = _ref[_i]; pair = _ref2[_i];
pair[1].makeReturn(); pair[1].makeReturn();
} }
if ((_ref2 = this.otherwise) != null) { if ((_ref3 = this.otherwise) != null) {
_ref2.makeReturn(); _ref3.makeReturn();
} }
return this; return this;
}; };
Switch.prototype.compileNode = function(o) { Switch.prototype.compileNode = function(o) {
var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _len, _len2, _ref, _ref2, _ref3, _ref4; var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _len, _len2, _ref2, _ref3, _ref4, _ref5;
idt1 = o.indent + TAB; idt1 = o.indent + TAB;
idt2 = o.indent = idt1 + TAB; idt2 = o.indent = idt1 + TAB;
code = this.tab + ("switch (" + (((_ref = this.subject) != null ? _ref.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n"); code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
_ref2 = this.cases; _ref3 = this.cases;
for (i = 0, _len = _ref2.length; i < _len; i++) { for (i = 0, _len = _ref3.length; i < _len; i++) {
_ref3 = _ref2[i], conditions = _ref3[0], block = _ref3[1]; _ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1];
_ref4 = flatten([conditions]); _ref5 = flatten([conditions]);
for (_i = 0, _len2 = _ref4.length; _i < _len2; _i++) { for (_i = 0, _len2 = _ref5.length; _i < _len2; _i++) {
cond = _ref4[_i]; cond = _ref5[_i];
if (!this.subject) { if (!this.subject) {
cond = cond.invert(); cond = cond.invert();
} }
@ -2069,12 +2069,12 @@
} }
If.prototype.children = ['condition', 'body', 'elseBody']; If.prototype.children = ['condition', 'body', 'elseBody'];
If.prototype.bodyNode = function() { If.prototype.bodyNode = function() {
var _ref; var _ref2;
return (_ref = this.body) != null ? _ref.unwrap() : void 0; return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0;
}; };
If.prototype.elseBodyNode = function() { If.prototype.elseBodyNode = function() {
var _ref; var _ref2;
return (_ref = this.elseBody) != null ? _ref.unwrap() : void 0; return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0;
}; };
If.prototype.addElse = function(elseBody) { If.prototype.addElse = function(elseBody) {
if (this.isChain) { if (this.isChain) {
@ -2086,12 +2086,12 @@
return this; return this;
}; };
If.prototype.isStatement = function(o) { If.prototype.isStatement = function(o) {
var _ref; var _ref2;
return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref = this.elseBodyNode()) != null ? _ref.isStatement(o) : void 0); return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0);
}; };
If.prototype.jumps = function(o) { If.prototype.jumps = function(o) {
var _ref; var _ref2;
return this.body.jumps(o) || ((_ref = this.elseBody) != null ? _ref.jumps(o) : void 0); return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0);
}; };
If.prototype.compileNode = function(o) { If.prototype.compileNode = function(o) {
if (this.isStatement(o)) { if (this.isStatement(o)) {

View file

@ -178,7 +178,7 @@
} }
tokens.splice(i, 0, ['CALL_START', '(', token[2]]); tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
this.detectEnd(i + 1, function(token, i) { this.detectEnd(i + 1, function(token, i) {
var post, _ref; var post, _ref4;
tag = token[0]; tag = token[0];
if (!seenSingle && token.fromThen) { if (!seenSingle && token.fromThen) {
return true; return true;
@ -189,7 +189,7 @@
if ((tag === '.' || tag === '?.' || tag === '::') && this.tag(i - 1) === 'OUTDENT') { if ((tag === '.' || tag === '?.' || tag === '::') && this.tag(i - 1) === 'OUTDENT') {
return true; return true;
} }
return !token.generated && this.tag(i - 1) !== ',' && __indexOf.call(IMPLICIT_END, tag) >= 0 && (tag !== 'INDENT' || (this.tag(i - 2) !== 'CLASS' && (_ref = this.tag(i - 1), __indexOf.call(IMPLICIT_BLOCK, _ref) < 0) && !((post = this.tokens[i + 1]) && post.generated && post[0] === '{'))); 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] === '{')));
}, action); }, action);
if (prev[0] === '?') { if (prev[0] === '?') {
prev[0] = 'FUNC_EXIST'; prev[0] = 'FUNC_EXIST';
@ -222,8 +222,8 @@
indent.generated = outdent.generated = true; indent.generated = outdent.generated = true;
tokens.splice(i + 1, 0, indent); tokens.splice(i + 1, 0, indent);
condition = function(token, i) { condition = function(token, i) {
var _ref; var _ref3;
return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN')); return token[1] !== ';' && (_ref3 = token[0], __indexOf.call(SINGLE_CLOSERS, _ref3) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN'));
}; };
action = function(token, i) { action = function(token, i) {
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent); return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);

View file

@ -46,12 +46,12 @@
return this.add(name, 'param'); return this.add(name, 'param');
}; };
Scope.prototype.check = function(name, immediate) { Scope.prototype.check = function(name, immediate) {
var found, _ref; var found, _ref2;
found = !!this.type(name); found = !!this.type(name);
if (found || immediate) { if (found || immediate) {
return found; return found;
} }
return !!((_ref = this.parent) != null ? _ref.check(name) : void 0); return !!((_ref2 = this.parent) != null ? _ref2.check(name) : void 0);
}; };
Scope.prototype.temporary = function(name, index) { Scope.prototype.temporary = function(name, index) {
if (name.length > 1) { if (name.length > 1) {
@ -61,10 +61,10 @@
} }
}; };
Scope.prototype.type = function(name) { Scope.prototype.type = function(name) {
var v, _i, _len, _ref; var v, _i, _len, _ref2;
_ref = this.variables; _ref2 = this.variables;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
v = _ref[_i]; v = _ref2[_i];
if (v.name === name) { if (v.name === name) {
return v.type; return v.type;
} }
@ -74,7 +74,7 @@
Scope.prototype.freeVariable = function(type) { Scope.prototype.freeVariable = function(type) {
var index, temp; var index, temp;
index = 0; index = 0;
while (this.check((temp = this.temporary(type, index)), true)) { while (this.check((temp = this.temporary(type, index)))) {
index++; index++;
} }
this.add(temp, 'var', true); this.add(temp, 'var', true);
@ -91,12 +91,12 @@
return !!this.declaredVariables().length; return !!this.declaredVariables().length;
}; };
Scope.prototype.declaredVariables = function() { Scope.prototype.declaredVariables = function() {
var realVars, tempVars, v, _i, _len, _ref; var realVars, tempVars, v, _i, _len, _ref2;
realVars = []; realVars = [];
tempVars = []; tempVars = [];
_ref = this.variables; _ref2 = this.variables;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
v = _ref[_i]; v = _ref2[_i];
if (v.type === 'var') { if (v.type === 'var') {
(v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name); (v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name);
} }
@ -104,11 +104,11 @@
return realVars.sort().concat(tempVars.sort()); return realVars.sort().concat(tempVars.sort());
}; };
Scope.prototype.assignedVariables = function() { Scope.prototype.assignedVariables = function() {
var v, _i, _len, _ref, _results; var v, _i, _len, _ref2, _results;
_ref = this.variables; _ref2 = this.variables;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
v = _ref[_i]; v = _ref2[_i];
if (v.type.assigned) { if (v.type.assigned) {
_results.push("" + v.name + " = " + v.type.value); _results.push("" + v.name + " = " + v.type.value);
} }

View file

@ -66,7 +66,7 @@ exports.Scope = class Scope
# compiler-generated variable. `_var`, `_var2`, and so on... # compiler-generated variable. `_var`, `_var2`, and so on...
freeVariable: (type) -> freeVariable: (type) ->
index = 0 index = 0
index++ while @check((temp = @temporary type, index), true) index++ while @check((temp = @temporary type, index))
@add temp, 'var', yes @add temp, 'var', yes
temp temp

View file

@ -402,3 +402,8 @@ test "implicit destructuring assignment in array of arrays", ->
arr = [[a, [b]], [c, [d]], [e, [f]]] arr = [[a, [b]], [c, [d]], [e, [f]]]
result = ([y,z] for [y, [z]] in arr) result = ([y,z] for [y, [z]] in arr)
arrayEq [[a,b],[c,d],[e,f]], result arrayEq [[a,b],[c,d],[e,f]], result
test "issue #1124: don't assign a variable in two scopes", ->
lista = [1, 2, 3, 4, 5]
listb = (_i + 1 for _i in lista)
arrayEq [2, 3, 4, 5, 6], listb