forked from lightscript/babel-plugin-lightscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced comprehensions use
…
syntax
- Loading branch information
Showing
44 changed files
with
159 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "`await` is not allowed within Comprehensions; instead, await the Comprehension (eg; `y <- [for x of xs: x]`)." | ||
"throws": "`await` is not allowed within Comprehensions; instead, await the Comprehension." | ||
} |
2 changes: 1 addition & 1 deletion
2
test/fixtures/enhanced-comprehensions/assignment-expr/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[for idx i in Array(10): | ||
[...for idx i in Array(10): | ||
now x = f(i) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
f() -/> | ||
<- [for now x of arr: | ||
<- [...for now x of arr: | ||
<- x | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "`await` is not allowed within Comprehensions; instead, await the Comprehension (eg; `y <- [for x of xs: x]`)." | ||
"throws": "`await` is not allowed within Comprehensions; instead, await the Comprehension." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[for elem x in y: x] | ||
[...for elem x in y: x] |
6 changes: 3 additions & 3 deletions
6
test/fixtures/enhanced-comprehensions/closure-nested-deep/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[for idx i in Array(10): | ||
[...for idx i in Array(10): | ||
for idx j in a: | ||
if i < 5: | ||
f() -> | ||
{for idx k in Array(10): | ||
{...for idx k in Array(10): | ||
if k > 7: | ||
(k, g() -> function h() { [i,j,k] }) | ||
{[k]: g() -> function h() { [i,j,k] }} | ||
} | ||
] |
4 changes: 0 additions & 4 deletions
4
test/fixtures/enhanced-comprehensions/closure-nested-semantic.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[ for idx i in Array(10): f() -> g() -> i ] | ||
[ ...for idx i in Array(10): f() -> g() -> i ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
closures = [ ...for idx i in Array(10): f() -> g() -> i ] | ||
closureResults = [ ...for elem f in closures: f()() ] | ||
|
||
assert.deepEqual(closureResults, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[ for idx i in Array(10): f() -> i ] | ||
[ ...for idx i in Array(10): f() -> i ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
closures = [ ...for idx i in Array(10): f() -> i ] | ||
closureResults = [ ...for elem f in closures: f() ] | ||
|
||
assert.deepEqual(closureResults, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) |
7 changes: 0 additions & 7 deletions
7
test/fixtures/enhanced-comprehensions/declared-inner-function-semantic.js
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
test/fixtures/enhanced-comprehensions/declared-inner-function/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
closures = [for idx i in Array(3): | ||
closures = [...for idx i in Array(3): | ||
x = g(i) | ||
g(x) -> x+1 | ||
] |
7 changes: 7 additions & 0 deletions
7
test/fixtures/enhanced-comprehensions/declared-inner-function/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
closures = [...for idx i in Array(3): | ||
x = g(i) | ||
g(x) -> x+i | ||
] | ||
results = [...for elem f in closures: f(1)] | ||
|
||
assert.deepEqual(results, [1,2,3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
arr = [4, 5, 6] | ||
|
||
c = [ for idx i, elem x in arr: [i, x] ] | ||
c = [ ...for idx i, elem x in arr: [i, x] ] | ||
assert.deepEqual(c, [[0, 4], [1, 5], [2, 6]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
c = [ for let i=0; i<10; i++: if i > 5: i elif i > 3: i * 2 ] | ||
c = [ ...for let i=0; i<10; i++: if i > 5: i elif i > 3: i * 2 ] | ||
assert.deepEqual(c, [8, 10, 6, 7, 8, 9]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
c = [ for let i=0; i<10; i++: if i > 5: i else if i > 3: i * 2 ] | ||
c = [ ...for let i=0; i<10; i++: if i > 5: i else if i > 3: i * 2 ] | ||
assert.deepEqual(c, [8, 10, 6, 7, 8, 9]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
c = [ for let i=0; i<10; i++: if i > 5: i else: 0 ] | ||
c = [ ...for let i=0; i<10; i++: if i > 5: i else: 0 ] | ||
assert.deepEqual(c, [0, 0, 0, 0, 0, 0, 6, 7, 8, 9]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
c = [ for let i=0; i<10; i++: if i > 5: i ] | ||
c = [ ...for let i=0; i<10; i++: if i > 5: i ] | ||
assert.deepEqual(c, [6, 7, 8, 9]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
arr = [4, 5, 6] | ||
|
||
x = [ for const i in arr: parseInt(i) ] | ||
x = [ ...for const i in arr: parseInt(i) ] | ||
assert.deepEqual(x, [0, 1, 2]) | ||
|
||
y = [ for const i in arr: parseInt(i) + 1 ] | ||
y = [ ...for const i in arr: parseInt(i) + 1 ] | ||
assert.deepEqual(y, [1, 2, 3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
c = [ for let i=0;i<3;i++: for let j=5;j<7;j++: [i, j] ] | ||
c = [ ...for let i=0;i<3;i++: for let j=5;j<7;j++: [i, j] ] | ||
assert.deepEqual(c, [ [0, 5], [0, 6], [1, 5], [1, 6], [2, 5], [2, 6] ]) | ||
|
||
d = [ for let i=0;i<3;i++: for let j=5;j<7;j++: if i > 1: [i, j] ] | ||
d = [ ...for let i=0;i<3;i++: for let j=5;j<7;j++: if i > 1: [i, j] ] | ||
assert.deepEqual(d, [ [2, 5], [2, 6] ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[...for elem e in x: [...for elem d in y: [d]]] |
2 changes: 1 addition & 1 deletion
2
...ixtures/enhanced-comprehensions/nested.js → ...es/enhanced-comprehensions/nested/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
c = [ for let i=0; i<4; i++: [ for let i=0; i<3; i++: 2 ] ] | ||
c = [ ...for let i=0; i<4; i++: [ ...for let i=0; i<3; i++: 2 ] ] | ||
assert.deepEqual(c, [ [2, 2, 2], [2, 2, 2], [2, 2, 2], [2, 2, 2] ]) |
Oops, something went wrong.