This commit is contained in:
parent
6c9ef76b95
commit
51b7142805
28
lib/nodes.js
28
lib/nodes.js
|
@ -1286,7 +1286,10 @@
|
|||
Assign.prototype.compileConditional = function(o) {
|
||||
var left, rite, _ref2;
|
||||
_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, '='), void 0, __indexOf.call(this.context, "?") >= 0).compile(o);
|
||||
if (__indexOf.call(this.context, "?") >= 0) {
|
||||
o.isExistentialEquals = true;
|
||||
}
|
||||
return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o);
|
||||
};
|
||||
Assign.prototype.compileSplice = function(o) {
|
||||
var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
|
||||
|
@ -1584,9 +1587,8 @@
|
|||
exports.Op = Op = (function() {
|
||||
var CONVERSIONS, INVERSIONS;
|
||||
__extends(Op, Base);
|
||||
function Op(op, first, second, flip, isExistentialEquals) {
|
||||
function Op(op, first, second, flip) {
|
||||
var call;
|
||||
this.isExistentialEquals = isExistentialEquals;
|
||||
if (op === 'in') {
|
||||
return new In(first, second);
|
||||
}
|
||||
|
@ -1699,15 +1701,9 @@
|
|||
fst = this.first;
|
||||
ref = fst;
|
||||
}
|
||||
if (this.isExistentialEquals) {
|
||||
return new If(new Existence(fst).invert(), this.second, {
|
||||
type: 'if'
|
||||
}).addElse(fst).compile(o);
|
||||
} else {
|
||||
return new If(new Existence(fst), ref, {
|
||||
type: 'if'
|
||||
}).addElse(this.second).compile(o);
|
||||
}
|
||||
return new If(new Existence(fst), ref, {
|
||||
type: 'if'
|
||||
}).addElse(this.second).compile(o);
|
||||
};
|
||||
Op.prototype.compileUnary = function(o) {
|
||||
var op, parts;
|
||||
|
@ -2158,8 +2154,14 @@
|
|||
}
|
||||
};
|
||||
If.prototype.compileStatement = function(o) {
|
||||
var body, child, cond, ifPart;
|
||||
var body, child, cond, exeq, ifPart;
|
||||
child = del(o, 'chainChild');
|
||||
exeq = del(o, 'isExistentialEquals');
|
||||
if (exeq) {
|
||||
return new If(this.condition.invert(), this.elseBodyNode(), {
|
||||
type: 'if'
|
||||
}).compile(o);
|
||||
}
|
||||
cond = this.condition.compile(o, LEVEL_PAREN);
|
||||
o.indent += TAB;
|
||||
body = this.ensureBlock(this.body).compile(o);
|
||||
|
|
|
@ -1009,7 +1009,8 @@ exports.Assign = class Assign extends Base
|
|||
# more than once.
|
||||
compileConditional: (o) ->
|
||||
[left, rite] = @variable.cacheReference o
|
||||
new Op(@context.slice(0, -1), left, new Assign(rite, @value, '='), undefined, "?" in @context ).compile o
|
||||
if "?" in @context then o.isExistentialEquals = true
|
||||
new Op(@context.slice(0, -1), left, new Assign(rite, @value, '=') ).compile o
|
||||
|
||||
# Compile the assignment from an array splice literal, using JavaScript's
|
||||
# `Array#splice` method.
|
||||
|
@ -1218,10 +1219,7 @@ exports.While = class While extends Base
|
|||
# Simple Arithmetic and logical operations. Performs some conversion from
|
||||
# CoffeeScript operations into their JavaScript equivalents.
|
||||
exports.Op = class Op extends Base
|
||||
|
||||
|
||||
|
||||
constructor: (op, first, second, flip, @isExistentialEquals ) ->
|
||||
constructor: (op, first, second, flip ) ->
|
||||
return new In first, second if op is 'in'
|
||||
if op is 'do'
|
||||
call = new Call first, first.params or []
|
||||
|
@ -1316,10 +1314,7 @@ exports.Op = class Op extends Base
|
|||
else
|
||||
fst = @first
|
||||
ref = fst
|
||||
if @isExistentialEquals
|
||||
new If(new Existence(fst).invert(), @second, type: 'if').addElse(fst).compile o
|
||||
else
|
||||
new If(new Existence(fst), ref, type: 'if').addElse(@second).compile o
|
||||
new If(new Existence(fst), ref, type: 'if').addElse(@second).compile o
|
||||
|
||||
# Compile a unary **Op**.
|
||||
compileUnary: (o) ->
|
||||
|
@ -1662,6 +1657,11 @@ exports.If = class If extends Base
|
|||
# force inner *else* bodies into statement form.
|
||||
compileStatement: (o) ->
|
||||
child = del o, 'chainChild'
|
||||
exeq = del o, 'isExistentialEquals'
|
||||
|
||||
if exeq
|
||||
return new If(@condition.invert(), @elseBodyNode(), type: 'if').compile o
|
||||
|
||||
cond = @condition.compile o, LEVEL_PAREN
|
||||
o.indent += TAB
|
||||
body = @ensureBlock(@body).compile o
|
||||
|
|
Loading…
Reference in New Issue