mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #3783 from lydell/issue-3671
Fix #3671: Allow step in optimized range comprehensions
This commit is contained in:
@@ -421,6 +421,11 @@
|
||||
return {
|
||||
source: LOC(2)(new Value($2))
|
||||
};
|
||||
}), o('FOR Range BY Expression', function() {
|
||||
return {
|
||||
source: LOC(2)(new Value($2)),
|
||||
step: $4
|
||||
};
|
||||
}), o('ForStart ForSource', function() {
|
||||
$2.own = $1.own;
|
||||
$2.name = $1[0];
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -451,7 +451,8 @@ grammar =
|
||||
]
|
||||
|
||||
ForBody: [
|
||||
o 'FOR Range', -> source: LOC(2) new Value($2)
|
||||
o 'FOR Range', -> source: (LOC(2) new Value($2))
|
||||
o 'FOR Range BY Expression', -> source: (LOC(2) new Value($2)), step: $4
|
||||
o 'ForStart ForSource', -> $2.own = $1.own; $2.name = $1[0]; $2.index = $1[1]; $2
|
||||
]
|
||||
|
||||
|
||||
@@ -246,6 +246,17 @@ test "Optimized range comprehensions.", ->
|
||||
ok exxes.join(' ') is 'x x x x x x x x x x'
|
||||
|
||||
|
||||
test "#3671: Allow step in optimized range comprehensions.", ->
|
||||
|
||||
exxes = ('x' for [0...10] by 2)
|
||||
eq exxes.join(' ') , 'x x x x x'
|
||||
|
||||
|
||||
test "#3671: Disallow guard in optimized range comprehensions.", ->
|
||||
|
||||
throws -> CoffeeScript.compile "exxes = ('x' for [0...10] when a)"
|
||||
|
||||
|
||||
test "Loop variables should be able to reference outer variables", ->
|
||||
outer = 1
|
||||
do ->
|
||||
|
||||
Reference in New Issue
Block a user