Fixing Issue #589. Compound assignment to an operation should have lower precedence.

This commit is contained in:
Jeremy Ashkenas
2010-08-08 00:07:00 -04:00
parent 1c903450c8
commit b902377304
4 changed files with 13 additions and 3 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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}"

View File

@@ -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