Skip to content

Commit

Permalink
fixed a && b ||= c (jashkenas/coffeescript#2506)
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Sep 3, 2012
1 parent 3e8e54b commit 3737564
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,7 @@ exports.Assign = Assign = (function(superclass){
o.scope.declare(left.value, left);
}
lefts = Chain(left).cacheReference(o);
o.level += LEVEL_OP < o.level;
morph = Binary(this.logic, lefts[0], (this.logic = false, this.left = lefts[1], this));
return (morph['void'] = this['void'], morph).compileNode(o);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/coco.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parser.lexer = {
return '';
}
};
exports.VERSION = '0.8.1';
exports.VERSION = '0.8.2b';
exports.compile = function(code, options){
var e, that;
try {
Expand Down
2 changes: 2 additions & 0 deletions src/ast.co
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,8 @@ class exports.Assign extends Node
if left instanceof Var and @logic of <[ ? !? ]> and @op is \=
o.scope.declare left.value, left
lefts = Chain(left)cacheReference o
# Deal with `a && b ||= c`.
o.level += LEVEL_OP < o.level
morph = Binary @logic, lefts.0, @<<<{-logic, left: lefts.1}
(morph <<< {@void})compileNode o

Expand Down
2 changes: 1 addition & 1 deletion src/coco.co
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parser import
upcomingInput : -> ''

exports import
VERSION: \0.8.1
VERSION: \0.8.2b

# Compiles a string of Coco code to JavaScript.
compile: (code, options) ->
Expand Down
6 changes: 6 additions & 0 deletions test/operator.co
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ a = "1#{2}3" +
eq a, '123456'


# [coffee#2506](https://github.com/jashkenas/coffee-script/issues/2506)
a = 0
eq false, false && a ||= 1
eq a, 0


### Unary `+`/`-`
eq 0, +[]
eq -1, -true
Expand Down

0 comments on commit 3737564

Please sign in to comment.