Skip to content

Commit

Permalink
allowed ...: o as {...o}
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Jul 12, 2012
1 parent ff9f887 commit 4319d45
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,9 @@ exports.Prop = Prop = (function(superclass){
var that, fun, __i, __len, __this = this instanceof __ctor ? this : new __ctor;
__this.key = key;
__this.val = val;
if (key.value === '...') {
return Splat(__this.val);
}
if (that = val.getAccessors()) {
__this.val = that;
for (__i = 0, __len = that.length; __i < __len; ++__i) {
Expand Down
10 changes: 9 additions & 1 deletion lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,15 @@ exports.doLiteral = function(code, index){
}
break;
case ':':
if ((__ref = this.last[0]) !== 'ID' && __ref !== 'STRNUM' && __ref !== ')') {
switch (this.last[0]) {
case 'ID':
case 'STRNUM':
case ')':
break;
case '...':
this.last[0] = 'STRNUM';
break;
default:
tag = 'LABEL';
val = '';
}
Expand Down
1 change: 1 addition & 0 deletions src/ast.co
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ class exports.Obj extends List
# `x: y`
class exports.Prop extends Node
(@key, @val) ~>
return Splat @val if key.value is \...
if val.getAccessors!
@val = that
for fun of that
Expand Down
7 changes: 5 additions & 2 deletions src/lexer.co
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,11 @@ exports import
fallthrough
case \] \)
@lpar = @parens.pop! if \) is tag = val = @pair val
case \: then if @last.0 not of <[ ID STRNUM ) ]>
tag = \LABEL; val = ''
case \:
switch @last.0
case \ID \STRNUM \) then break
case \... then @last.0 = \STRNUM
default tag = \LABEL; val = ''
case <[ = := += -= *= /= %= &= ^= |= <<= >>= >>>= <?= >?= **= ]>
if @last.1 is \. or @last.0 is \? and @adi!
@last.1 += val
Expand Down
2 changes: 1 addition & 1 deletion test/literal.co
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ obj = {
(--i) or 'default value'
/* splat */
...o
...{splatMe: 'too'}
...: splatMe: 'too'
/* normal keys */
key: ok
's': ok
Expand Down

0 comments on commit 4319d45

Please sign in to comment.