fixing #768, preserving execution order of `in` arguments when compiled
to an `or`.
This commit is contained in:
parent
1d4d7e96fa
commit
1ea38d2f93
|
@ -245,7 +245,7 @@
|
||||||
prev = last(this.tokens, 1);
|
prev = last(this.tokens, 1);
|
||||||
size = indent.length - 1 - indent.lastIndexOf('\n');
|
size = indent.length - 1 - indent.lastIndexOf('\n');
|
||||||
nextCharacter = NEXT_CHARACTER.exec(this.chunk)[1];
|
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 (size - this.indebt === this.indent) {
|
||||||
if (noNewlines) {
|
if (noNewlines) {
|
||||||
return this.suppressNewlines();
|
return this.suppressNewlines();
|
||||||
|
@ -335,7 +335,7 @@
|
||||||
if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
|
if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
|
||||||
this.assignmentError();
|
this.assignmentError();
|
||||||
}
|
}
|
||||||
if (('||' === (_ref2 = prev[1]) || '&&' === _ref2)) {
|
if (((_ref2 = prev[1]) === '||' || _ref2 === '&&')) {
|
||||||
prev[0] = 'COMPOUND_ASSIGN';
|
prev[0] = 'COMPOUND_ASSIGN';
|
||||||
prev[1] += '=';
|
prev[1] += '=';
|
||||||
return true;
|
return true;
|
||||||
|
@ -575,7 +575,7 @@
|
||||||
return quote + quote;
|
return quote + quote;
|
||||||
}
|
}
|
||||||
body = body.replace(/\\([\s\S])/g, function(match, contents) {
|
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"), '\\$&');
|
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
||||||
return quote + this.escapeLines(body, heredoc) + quote;
|
return quote + this.escapeLines(body, heredoc) + quote;
|
||||||
|
|
|
@ -259,7 +259,7 @@
|
||||||
};
|
};
|
||||||
Literal.prototype.isStatement = function() {
|
Literal.prototype.isStatement = function() {
|
||||||
var _ref2;
|
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.isPureStatement = Literal.prototype.isStatement;
|
||||||
Literal.prototype.isComplex = NO;
|
Literal.prototype.isComplex = NO;
|
||||||
|
@ -1398,14 +1398,14 @@
|
||||||
};
|
};
|
||||||
Op.prototype.isMutator = function() {
|
Op.prototype.isMutator = function() {
|
||||||
var _ref2;
|
var _ref2;
|
||||||
return ends(this.operator, '=') && !('===' === (_ref2 = this.operator) || '!==' === _ref2);
|
return ends(this.operator, '=') && !((_ref2 = this.operator) === '===' || _ref2 === '!==');
|
||||||
};
|
};
|
||||||
Op.prototype.isChainable = function() {
|
Op.prototype.isChainable = function() {
|
||||||
return include(this.CHAINABLE, this.operator);
|
return include(this.CHAINABLE, this.operator);
|
||||||
};
|
};
|
||||||
Op.prototype.invert = function() {
|
Op.prototype.invert = function() {
|
||||||
var _ref2;
|
var _ref2;
|
||||||
if (('===' === (_ref2 = this.operator) || '!==' === _ref2)) {
|
if (((_ref2 = this.operator) === '===' || _ref2 === '!==')) {
|
||||||
this.operator = this.INVERSIONS[this.operator];
|
this.operator = this.INVERSIONS[this.operator];
|
||||||
return this;
|
return this;
|
||||||
} else return this.second ? new Parens(this).invert() : Op.__super__.invert.call(this);
|
} else return this.second ? new Parens(this).invert() : Op.__super__.invert.call(this);
|
||||||
|
@ -1497,7 +1497,7 @@
|
||||||
_result = [];
|
_result = [];
|
||||||
for (i = 0, _len = (_ref2 = this.array.base.objects).length; i < _len; i++) {
|
for (i = 0, _len = (_ref2 = this.array.base.objects).length; i < _len; i++) {
|
||||||
item = _ref2[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;
|
return _result;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
} else {
|
} else {
|
||||||
tokens.splice(i, 0, after);
|
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') {
|
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)));
|
tokens.splice.apply(tokens, [i + 2, 0].concat(tokens.splice(i, 2)));
|
||||||
if (tokens[i + 2][0] !== 'TERMINATOR') {
|
if (tokens[i + 2][0] !== 'TERMINATOR') {
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
var action, condition;
|
var action, condition;
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _ref;
|
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) {
|
action = function(token, i) {
|
||||||
return (this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END');
|
return (this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END');
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
var action, condition;
|
var action, condition;
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _ref;
|
var _ref;
|
||||||
return (']' === (_ref = token[0]) || 'INDEX_END' === _ref);
|
return ((_ref = token[0]) === ']' || _ref === 'INDEX_END');
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
return (token[0] = 'INDEX_END');
|
return (token[0] = 'INDEX_END');
|
||||||
|
@ -136,12 +136,12 @@
|
||||||
stack = [];
|
stack = [];
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _ref, _ref2, one, tag, three, two;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
_ref = this.tokens.slice(i + 1, i + 4), one = _ref[0], two = _ref[1], three = _ref[2];
|
_ref = this.tokens.slice(i + 1, i + 4), one = _ref[0], two = _ref[1], three = _ref[2];
|
||||||
tag = token[0];
|
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) {
|
action = function(token, i) {
|
||||||
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
||||||
|
@ -205,7 +205,7 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
tag = token[0];
|
tag = token[0];
|
||||||
if (('IF' === tag || 'ELSE' === tag || 'UNLESS' === tag || '->' === tag || '=>' === tag)) {
|
if ((tag === 'IF' || tag === 'ELSE' || tag === 'UNLESS' || tag === '->' || tag === '=>')) {
|
||||||
seenSingle = true;
|
seenSingle = true;
|
||||||
}
|
}
|
||||||
if (tag === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT') {
|
if (tag === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT') {
|
||||||
|
@ -227,7 +227,7 @@
|
||||||
tokens.splice.apply(tokens, [i, 0].concat(this.indentation(token)));
|
tokens.splice.apply(tokens, [i, 0].concat(this.indentation(token)));
|
||||||
return 2;
|
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)));
|
tokens.splice.apply(tokens, [i + 2, 0].concat(this.indentation(token)));
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@
|
||||||
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) {
|
||||||
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) {
|
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);
|
||||||
|
@ -258,11 +258,11 @@
|
||||||
var condition;
|
var condition;
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _ref;
|
var _ref;
|
||||||
return ('TERMINATOR' === (_ref = token[0]) || 'INDENT' === _ref);
|
return ((_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT');
|
||||||
};
|
};
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
var _ref, original;
|
var _ref, original;
|
||||||
if (!('IF' === (_ref = token[0]) || 'UNLESS' === _ref)) {
|
if (!((_ref = token[0]) === 'IF' || _ref === 'UNLESS')) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
original = token;
|
original = token;
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
};
|
};
|
||||||
Scope.prototype.hasDeclarations = function(body) {
|
Scope.prototype.hasDeclarations = function(body) {
|
||||||
return body === this.expressions && this.any(function(k, val) {
|
return body === this.expressions && this.any(function(k, val) {
|
||||||
return ('var' === val || 'reuse' === val);
|
return (val === 'var' || val === 'reuse');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Scope.prototype.hasAssignments = function(body) {
|
Scope.prototype.hasAssignments = function(body) {
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
for (key in _ref2 = this.variables) {
|
for (key in _ref2 = this.variables) {
|
||||||
if (!__hasProp.call(_ref2, key)) continue;
|
if (!__hasProp.call(_ref2, key)) continue;
|
||||||
val = _ref2[key];
|
val = _ref2[key];
|
||||||
if (('var' === val || 'reuse' === val)) {
|
if ((val === 'var' || val === 'reuse')) {
|
||||||
_result.push(key);
|
_result.push(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1276,7 +1276,7 @@ exports.In = class In extends Base
|
||||||
|
|
||||||
compileOrTest: (o) ->
|
compileOrTest: (o) ->
|
||||||
tests = for item, i in @array.base.objects
|
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(' || ')})"
|
"(#{tests.join(' || ')})"
|
||||||
|
|
||||||
compileLoopTest: (o) ->
|
compileLoopTest: (o) ->
|
||||||
|
|
Loading…
Reference in New Issue