mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 17:27:59 -05:00
reverting ?= optimization, for the repl's sake.
This commit is contained in:
13
lib/nodes.js
13
lib/nodes.js
@@ -1069,7 +1069,7 @@
|
||||
} else {
|
||||
ref = param;
|
||||
if (param.value) {
|
||||
exprs.push(new Assign(new Value(param.name), param.value, '?='));
|
||||
exprs.push(new Op('||', new Literal("" + param.name.value + " != null"), new Assign(param.name, param.value)));
|
||||
}
|
||||
}
|
||||
if (!splats) {
|
||||
@@ -1320,20 +1320,15 @@
|
||||
return o.level < LEVEL_OP ? code : "(" + code + ")";
|
||||
};
|
||||
Op.prototype.compileExistence = function(o) {
|
||||
var end, fst, ref;
|
||||
if (this.first.isComplex() && o.level > LEVEL_TOP) {
|
||||
var fst, ref;
|
||||
if (this.first.isComplex()) {
|
||||
ref = o.scope.freeVariable('ref');
|
||||
fst = new Parens(new Assign(new Literal(ref), this.first));
|
||||
} else {
|
||||
fst = this.first;
|
||||
ref = fst.compile(o);
|
||||
}
|
||||
if (o.level === LEVEL_TOP) {
|
||||
end = " || " + (this.second.compile(o, LEVEL_OP));
|
||||
} else {
|
||||
end = " ? " + ref + " : " + (this.second.compile(o, LEVEL_LIST));
|
||||
}
|
||||
return new Existence(fst).compile(o) + end;
|
||||
return new Existence(fst).compile(o) + (" ? " + ref + " : " + (this.second.compile(o, LEVEL_LIST)));
|
||||
};
|
||||
Op.prototype.compileUnary = function(o) {
|
||||
var op, parts;
|
||||
|
||||
@@ -882,7 +882,11 @@ exports.Code = class Code extends Base
|
||||
if param.value then new Op '?', ref, param.value else ref
|
||||
else
|
||||
ref = param
|
||||
exprs.push new Assign new Value(param.name), param.value, '?=' if param.value
|
||||
if param.value
|
||||
exprs.push new Op('||',
|
||||
new Literal("#{param.name.value} != null"),
|
||||
new Assign(param.name, param.value)
|
||||
)
|
||||
vars.push ref unless splats
|
||||
scope.startLevel()
|
||||
wasEmpty = @body.isEmpty()
|
||||
@@ -1084,17 +1088,13 @@ exports.Op = class Op extends Base
|
||||
if o.level < LEVEL_OP then code else "(#{code})"
|
||||
|
||||
compileExistence: (o) ->
|
||||
if @first.isComplex() and o.level > LEVEL_TOP
|
||||
if @first.isComplex()
|
||||
ref = o.scope.freeVariable 'ref'
|
||||
fst = new Parens new Assign new Literal(ref), @first
|
||||
else
|
||||
fst = @first
|
||||
ref = fst.compile o
|
||||
if o.level is LEVEL_TOP
|
||||
end = " || #{@second.compile o, LEVEL_OP}"
|
||||
else
|
||||
end = " ? #{ref} : #{@second.compile o, LEVEL_LIST}"
|
||||
new Existence(fst).compile(o) + end
|
||||
new Existence(fst).compile(o) + " ? #{ref} : #{ @second.compile o, LEVEL_LIST }"
|
||||
|
||||
# Compile a unary **Op**.
|
||||
compileUnary: (o) ->
|
||||
|
||||
Reference in New Issue
Block a user