fixing #768, preserving execution order of `in` arguments when compiled

to an `or`.
This commit is contained in:
Michael Ficarra 2010-10-13 12:10:36 -04:00
parent 1d4d7e96fa
commit 1ea38d2f93
5 changed files with 20 additions and 20 deletions

View File

@ -245,7 +245,7 @@
prev = last(this.tokens, 1);
size = indent.length - 1 - indent.lastIndexOf('\n');
nextCharacter = NEXT_CHARACTER.exec(this.chunk)[1];
noNewlines = (('.' === nextCharacter || ',' === nextCharacter) && !NEXT_ELLIPSIS.test(this.chunk)) || this.unfinished();
noNewlines = ((nextCharacter === '.' || nextCharacter === ',') && !NEXT_ELLIPSIS.test(this.chunk)) || this.unfinished();
if (size - this.indebt === this.indent) {
if (noNewlines) {
return this.suppressNewlines();
@ -335,7 +335,7 @@
if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
this.assignmentError();
}
if (('||' === (_ref2 = prev[1]) || '&&' === _ref2)) {
if (((_ref2 = prev[1]) === '||' || _ref2 === '&&')) {
prev[0] = 'COMPOUND_ASSIGN';
prev[1] += '=';
return true;
@ -575,7 +575,7 @@
return quote + quote;
}
body = body.replace(/\\([\s\S])/g, function(match, contents) {
return ('\n' === contents || quote === contents) ? contents : match;
return (contents === '\n' || contents === quote) ? contents : match;
});
body = body.replace(RegExp("" + quote, "g"), '\\$&');
return quote + this.escapeLines(body, heredoc) + quote;

View File

@ -259,7 +259,7 @@
};
Literal.prototype.isStatement = function() {
var _ref2;
return ('break' === (_ref2 = this.value) || 'continue' === _ref2 || 'debugger' === _ref2);
return ((_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger');
};
Literal.prototype.isPureStatement = Literal.prototype.isStatement;
Literal.prototype.isComplex = NO;
@ -1398,14 +1398,14 @@
};
Op.prototype.isMutator = function() {
var _ref2;
return ends(this.operator, '=') && !('===' === (_ref2 = this.operator) || '!==' === _ref2);
return ends(this.operator, '=') && !((_ref2 = this.operator) === '===' || _ref2 === '!==');
};
Op.prototype.isChainable = function() {
return include(this.CHAINABLE, this.operator);
};
Op.prototype.invert = function() {
var _ref2;
if (('===' === (_ref2 = this.operator) || '!==' === _ref2)) {
if (((_ref2 = this.operator) === '===' || _ref2 === '!==')) {
this.operator = this.INVERSIONS[this.operator];
return this;
} else return this.second ? new Parens(this).invert() : Op.__super__.invert.call(this);
@ -1497,7 +1497,7 @@
_result = [];
for (i = 0, _len = (_ref2 = this.array.base.objects).length; i < _len; i++) {
item = _ref2[i];
_result.push("" + (item.compile(o)) + " === " + (i ? this.obj2 : this.obj1));
_result.push("" + (i ? this.obj2 : this.obj1) + " === " + (item.compile(o)));
}
return _result;
}).call(this);

View File

@ -66,7 +66,7 @@
} else {
tokens.splice(i, 0, after);
}
} else if (prev && !('TERMINATOR' === (_ref = prev[0]) || 'INDENT' === _ref || 'OUTDENT' === _ref)) {
} else if (prev && !((_ref = prev[0]) === 'TERMINATOR' || _ref === 'INDENT' || _ref === 'OUTDENT')) {
if (((post != null) ? post[0] : undefined) === 'TERMINATOR' && ((after != null) ? after[0] : undefined) === 'OUTDENT') {
tokens.splice.apply(tokens, [i + 2, 0].concat(tokens.splice(i, 2)));
if (tokens[i + 2][0] !== 'TERMINATOR') {
@ -103,7 +103,7 @@
var action, condition;
condition = function(token, i) {
var _ref;
return (')' === (_ref = token[0]) || 'CALL_END' === _ref) || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
};
action = function(token, i) {
return (this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END');
@ -119,7 +119,7 @@
var action, condition;
condition = function(token, i) {
var _ref;
return (']' === (_ref = token[0]) || 'INDEX_END' === _ref);
return ((_ref = token[0]) === ']' || _ref === 'INDEX_END');
};
action = function(token, i) {
return (token[0] = 'INDEX_END');
@ -136,12 +136,12 @@
stack = [];
condition = function(token, i) {
var _ref, _ref2, one, tag, three, two;
if ((this.tag(i + 1) === 'HERECOMMENT' || this.tag(i - 1) === 'HERECOMMENT')) {
if (('HERECOMMENT' === this.tag(i + 1) || 'HERECOMMENT' === this.tag(i - 1))) {
return false;
}
_ref = this.tokens.slice(i + 1, i + 4), one = _ref[0], two = _ref[1], three = _ref[2];
tag = token[0];
return ('TERMINATOR' === tag || 'OUTDENT' === tag) && !(((two != null) ? two[0] : undefined) === ':' || ((one != null) ? one[0] : undefined) === '@' && ((three != null) ? three[0] : undefined) === ':') || tag === ',' && !('IDENTIFIER' === (_ref2 = ((one != null) ? one[0] : undefined)) || 'NUMBER' === _ref2 || 'STRING' === _ref2 || '@' === _ref2 || 'TERMINATOR' === _ref2 || 'OUTDENT' === _ref2);
return (tag === 'TERMINATOR' || tag === 'OUTDENT') && !(((two != null) ? two[0] : undefined) === ':' || ((one != null) ? one[0] : undefined) === '@' && ((three != null) ? three[0] : undefined) === ':') || tag === ',' && !((_ref2 = ((one != null) ? one[0] : undefined)) === 'IDENTIFIER' || _ref2 === 'NUMBER' || _ref2 === 'STRING' || _ref2 === '@' || _ref2 === 'TERMINATOR' || _ref2 === 'OUTDENT');
};
action = function(token, i) {
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
@ -205,7 +205,7 @@
return true;
}
tag = token[0];
if (('IF' === tag || 'ELSE' === tag || 'UNLESS' === tag || '->' === tag || '=>' === tag)) {
if ((tag === 'IF' || tag === 'ELSE' || tag === 'UNLESS' || tag === '->' || tag === '=>')) {
seenSingle = true;
}
if (tag === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT') {
@ -227,7 +227,7 @@
tokens.splice.apply(tokens, [i, 0].concat(this.indentation(token)));
return 2;
}
if (tag === 'CATCH' && ('TERMINATOR' === (_ref = this.tag(i + 2)) || 'FINALLY' === _ref)) {
if (tag === 'CATCH' && ((_ref = this.tag(i + 2)) === 'TERMINATOR' || _ref === 'FINALLY')) {
tokens.splice.apply(tokens, [i + 2, 0].concat(this.indentation(token)));
return 4;
}
@ -240,7 +240,7 @@
indent.generated = (outdent.generated = true);
tokens.splice(i + 1, 0, indent);
condition = function(token, i) {
return token[1] !== ';' && include(SINGLE_CLOSERS, token[0]) && !(token[0] === 'ELSE' && !('IF' === starter || 'THEN' === starter));
return token[1] !== ';' && include(SINGLE_CLOSERS, token[0]) && !(token[0] === 'ELSE' && !(starter === 'IF' || starter === 'THEN'));
};
action = function(token, i) {
return this.tokens.splice(this.tag(i - 1) === ',' ? i - 1 : i, 0, outdent);
@ -258,11 +258,11 @@
var condition;
condition = function(token, i) {
var _ref;
return ('TERMINATOR' === (_ref = token[0]) || 'INDENT' === _ref);
return ((_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT');
};
return this.scanTokens(function(token, i) {
var _ref, original;
if (!('IF' === (_ref = token[0]) || 'UNLESS' === _ref)) {
if (!((_ref = token[0]) === 'IF' || _ref === 'UNLESS')) {
return 1;
}
original = token;

View File

@ -89,7 +89,7 @@
};
Scope.prototype.hasDeclarations = function(body) {
return body === this.expressions && this.any(function(k, val) {
return ('var' === val || 'reuse' === val);
return (val === 'var' || val === 'reuse');
});
};
Scope.prototype.hasAssignments = function(body) {
@ -104,7 +104,7 @@
for (key in _ref2 = this.variables) {
if (!__hasProp.call(_ref2, key)) continue;
val = _ref2[key];
if (('var' === val || 'reuse' === val)) {
if ((val === 'var' || val === 'reuse')) {
_result.push(key);
}
}

View File

@ -1276,7 +1276,7 @@ exports.In = class In extends Base
compileOrTest: (o) ->
tests = for item, i in @array.base.objects
"#{item.compile(o)} === #{if i then @obj2 else @obj1}"
"#{if i then @obj2 else @obj1} === #{item.compile(o)}"
"(#{tests.join(' || ')})"
compileLoopTest: (o) ->