fixes #1513 -- top level bare obj literals now wrapped in parens for unary and exists operations
This commit is contained in:
parent
7e4d6198d4
commit
2fb2ddb9b4
|
@ -1542,13 +1542,12 @@
|
|||
return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
|
||||
};
|
||||
Op.prototype.compileNode = function(o) {
|
||||
var code;
|
||||
var code, isChain;
|
||||
isChain = this.isChainable() && this.first.isChainable();
|
||||
if (!isChain) this.first.front = this.front;
|
||||
if (this.isUnary()) return this.compileUnary(o);
|
||||
if (this.isChainable() && this.first.isChainable()) {
|
||||
return this.compileChain(o);
|
||||
}
|
||||
if (isChain) return this.compileChain(o);
|
||||
if (this.operator === '?') return this.compileExistence(o);
|
||||
this.first.front = this.front;
|
||||
code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP);
|
||||
if (o.level <= LEVEL_OP) {
|
||||
return code;
|
||||
|
@ -1708,6 +1707,7 @@
|
|||
Existence.prototype.invert = NEGATE;
|
||||
Existence.prototype.compileNode = function(o) {
|
||||
var cmp, cnj, code, _ref2;
|
||||
this.expression.front = this.front;
|
||||
code = this.expression.compile(o, LEVEL_OP);
|
||||
if (IDENTIFIER.test(code) && !o.scope.check(code)) {
|
||||
_ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1];
|
||||
|
|
|
@ -1324,11 +1324,14 @@ exports.Op = class Op extends Base
|
|||
unfoldSoak: (o) ->
|
||||
@operator in ['++', '--', 'delete'] and unfoldSoak o, this, 'first'
|
||||
|
||||
compileNode: (o) ->
|
||||
compileNode: (o) ->
|
||||
isChain = @isChainable() and @first.isChainable()
|
||||
# In chains, there's no need to wrap bare obj literals in parens,
|
||||
# as the chained expression is wrapped.
|
||||
@first.front = @front unless isChain
|
||||
return @compileUnary o if @isUnary()
|
||||
return @compileChain o if @isChainable() and @first.isChainable()
|
||||
return @compileChain o if isChain
|
||||
return @compileExistence o if @operator is '?'
|
||||
@first.front = @front
|
||||
code = @first.compile(o, LEVEL_OP) + ' ' + @operator + ' ' +
|
||||
@second.compile(o, LEVEL_OP)
|
||||
if o.level <= LEVEL_OP then code else "(#{code})"
|
||||
|
@ -1469,6 +1472,7 @@ exports.Existence = class Existence extends Base
|
|||
invert: NEGATE
|
||||
|
||||
compileNode: (o) ->
|
||||
@expression.front = @front
|
||||
code = @expression.compile o, LEVEL_OP
|
||||
if IDENTIFIER.test(code) and not o.scope.check code
|
||||
[cmp, cnj] = if @negated then ['===', '||'] else ['!==', '&&']
|
||||
|
|
Loading…
Reference in New Issue