mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fixing Issue #589. Compound assignment to an operation should have lower precedence.
This commit is contained in:
@@ -218,7 +218,7 @@
|
||||
var o;
|
||||
optionParser = new optparse.OptionParser(SWITCHES, BANNER);
|
||||
o = (options = optionParser.parse(process.argv.slice(2, process.argv.length)));
|
||||
options.compile = options.compile || !!o.output;
|
||||
options.compile = options.compile || (!!o.output);
|
||||
options.run = !(o.compile || o.print || o.lint);
|
||||
options.print = !!(o.print || (o.eval || o.stdio && o.compile));
|
||||
return (sources = options.arguments);
|
||||
|
||||
@@ -1288,6 +1288,9 @@
|
||||
first = _b[0];
|
||||
firstVar = _b[1];
|
||||
second = this.second.compile(o);
|
||||
if (this.second instanceof OpNode) {
|
||||
second = ("(" + (second) + ")");
|
||||
}
|
||||
if (first.match(IDENTIFIER)) {
|
||||
o.scope.find(first);
|
||||
}
|
||||
@@ -1672,7 +1675,7 @@
|
||||
return this;
|
||||
};
|
||||
IfNode.prototype.isStatement = function() {
|
||||
return this.statement = this.statement || !!(this.tags.statement || this.bodyNode().isStatement() || (this.elseBody && this.elseBodyNode().isStatement()));
|
||||
return this.statement = this.statement || (!!(this.tags.statement || this.bodyNode().isStatement() || (this.elseBody && this.elseBodyNode().isStatement())));
|
||||
};
|
||||
IfNode.prototype.compileCondition = function(o) {
|
||||
var _b, _c, _d, _e, cond;
|
||||
|
||||
@@ -1110,6 +1110,7 @@ exports.OpNode = class OpNode extends BaseNode
|
||||
compileAssignment: (o) ->
|
||||
[first, firstVar] = @first.compileReference o, precompile: yes, assignment: yes
|
||||
second = @second.compile o
|
||||
second = "(#{second})" if @second instanceof OpNode
|
||||
o.scope.find(first) if first.match(IDENTIFIER)
|
||||
return "#{first} = #{ ExistenceNode.compileTest(o, literal(firstVar)) } ? #{firstVar} : #{second}" if @operator is '?='
|
||||
"#{first} = #{firstVar} #{ @operator.substr(0, 2) } #{second}"
|
||||
|
||||
@@ -93,4 +93,10 @@ ok list.join(' ') is '0 5 10'
|
||||
count = 0
|
||||
|
||||
list[key()] ?= 100
|
||||
ok list.join(' ') is '0 100 5 10'
|
||||
ok list.join(' ') is '0 100 5 10'
|
||||
|
||||
|
||||
# Ensure that RHS is treated as a group.
|
||||
a = b = false
|
||||
a and= b or true
|
||||
ok a is false
|
||||
|
||||
Reference in New Issue
Block a user