1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

disallow index mentions for range loops.

This commit is contained in:
Jeremy Ashkenas 2010-11-28 15:54:39 -08:00
parent c3f1820ebc
commit b52a1ed60a
2 changed files with 6 additions and 2 deletions

View file

@ -1716,8 +1716,11 @@
}
this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
this.pattern = this.name instanceof Value;
if (this.range && this.index) {
throw SyntaxError('indexes do not apply to range loops');
}
if (this.range && this.pattern) {
throw SyntaxError('cannot pattern match a range loop');
throw SyntaxError('cannot pattern match over range loops');
}
this.returns = false;
}

View file

@ -1380,7 +1380,8 @@ exports.For = class For extends Base
throw SyntaxError 'index cannot be a pattern matching expression' if @index instanceof Value
@range = @source instanceof Value and @source.base instanceof Range and not @source.properties.length
@pattern = @name instanceof Value
throw SyntaxError 'cannot pattern match a range loop' if @range and @pattern
throw SyntaxError 'indexes do not apply to range loops' if @range and @index
throw SyntaxError 'cannot pattern match over range loops' if @range and @pattern
@returns = false
children: ['body', 'source', 'guard', 'step']