starlight-cli 1.0.36 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +18 -8
- package/package.json +1 -1
- package/src/evaluator.js +18 -8
package/dist/index.js
CHANGED
|
@@ -1537,6 +1537,7 @@ async evalProgram(node, env) {
|
|
|
1537
1537
|
return result;
|
|
1538
1538
|
}
|
|
1539
1539
|
|
|
1540
|
+
|
|
1540
1541
|
async evalImport(node, env) {
|
|
1541
1542
|
const spec = node.path;
|
|
1542
1543
|
let lib;
|
|
@@ -1745,9 +1746,11 @@ async evalWhile(node, env) {
|
|
|
1745
1746
|
}
|
|
1746
1747
|
return null;
|
|
1747
1748
|
}
|
|
1748
|
-
|
|
1749
1749
|
async evalFor(node, env) {
|
|
1750
|
-
|
|
1750
|
+
|
|
1751
|
+
// -------------------------------
|
|
1752
|
+
// Python-style: for x in iterable
|
|
1753
|
+
// -------------------------------
|
|
1751
1754
|
if (node.type === 'ForInStatement') {
|
|
1752
1755
|
const iterable = await this.evaluate(node.iterable, env);
|
|
1753
1756
|
|
|
@@ -1755,11 +1758,13 @@ async evalFor(node, env) {
|
|
|
1755
1758
|
throw new Error('Cannot iterate over non-iterable');
|
|
1756
1759
|
}
|
|
1757
1760
|
|
|
1758
|
-
//
|
|
1761
|
+
const loopVar = node.variable; // STRING from parser
|
|
1762
|
+
|
|
1763
|
+
// Arrays
|
|
1759
1764
|
if (Array.isArray(iterable)) {
|
|
1760
|
-
for (
|
|
1765
|
+
for (const value of iterable) {
|
|
1761
1766
|
const loopEnv = new Environment(env);
|
|
1762
|
-
loopEnv.define(
|
|
1767
|
+
loopEnv.define(loopVar, value);
|
|
1763
1768
|
|
|
1764
1769
|
try {
|
|
1765
1770
|
await this.evaluate(node.body, loopEnv);
|
|
@@ -1769,11 +1774,12 @@ async evalFor(node, env) {
|
|
|
1769
1774
|
throw e;
|
|
1770
1775
|
}
|
|
1771
1776
|
}
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1777
|
+
}
|
|
1778
|
+
// Objects (keys)
|
|
1779
|
+
else {
|
|
1774
1780
|
for (const key of Object.keys(iterable)) {
|
|
1775
1781
|
const loopEnv = new Environment(env);
|
|
1776
|
-
loopEnv.define(
|
|
1782
|
+
loopEnv.define(loopVar, key);
|
|
1777
1783
|
|
|
1778
1784
|
try {
|
|
1779
1785
|
await this.evaluate(node.body, loopEnv);
|
|
@@ -1788,7 +1794,11 @@ async evalFor(node, env) {
|
|
|
1788
1794
|
return null;
|
|
1789
1795
|
}
|
|
1790
1796
|
|
|
1797
|
+
// -------------------------------
|
|
1798
|
+
// C-style for loop
|
|
1799
|
+
// -------------------------------
|
|
1791
1800
|
const local = new Environment(env);
|
|
1801
|
+
|
|
1792
1802
|
if (node.init) await this.evaluate(node.init, local);
|
|
1793
1803
|
|
|
1794
1804
|
while (!node.test || await this.evaluate(node.test, local)) {
|
package/package.json
CHANGED
package/src/evaluator.js
CHANGED
|
@@ -194,6 +194,7 @@ async evalProgram(node, env) {
|
|
|
194
194
|
return result;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
|
|
197
198
|
async evalImport(node, env) {
|
|
198
199
|
const spec = node.path;
|
|
199
200
|
let lib;
|
|
@@ -402,9 +403,11 @@ async evalWhile(node, env) {
|
|
|
402
403
|
}
|
|
403
404
|
return null;
|
|
404
405
|
}
|
|
405
|
-
|
|
406
406
|
async evalFor(node, env) {
|
|
407
|
-
|
|
407
|
+
|
|
408
|
+
// -------------------------------
|
|
409
|
+
// Python-style: for x in iterable
|
|
410
|
+
// -------------------------------
|
|
408
411
|
if (node.type === 'ForInStatement') {
|
|
409
412
|
const iterable = await this.evaluate(node.iterable, env);
|
|
410
413
|
|
|
@@ -412,11 +415,13 @@ async evalFor(node, env) {
|
|
|
412
415
|
throw new Error('Cannot iterate over non-iterable');
|
|
413
416
|
}
|
|
414
417
|
|
|
415
|
-
//
|
|
418
|
+
const loopVar = node.variable; // STRING from parser
|
|
419
|
+
|
|
420
|
+
// Arrays
|
|
416
421
|
if (Array.isArray(iterable)) {
|
|
417
|
-
for (
|
|
422
|
+
for (const value of iterable) {
|
|
418
423
|
const loopEnv = new Environment(env);
|
|
419
|
-
loopEnv.define(
|
|
424
|
+
loopEnv.define(loopVar, value);
|
|
420
425
|
|
|
421
426
|
try {
|
|
422
427
|
await this.evaluate(node.body, loopEnv);
|
|
@@ -426,11 +431,12 @@ async evalFor(node, env) {
|
|
|
426
431
|
throw e;
|
|
427
432
|
}
|
|
428
433
|
}
|
|
429
|
-
}
|
|
430
|
-
|
|
434
|
+
}
|
|
435
|
+
// Objects (keys)
|
|
436
|
+
else {
|
|
431
437
|
for (const key of Object.keys(iterable)) {
|
|
432
438
|
const loopEnv = new Environment(env);
|
|
433
|
-
loopEnv.define(
|
|
439
|
+
loopEnv.define(loopVar, key);
|
|
434
440
|
|
|
435
441
|
try {
|
|
436
442
|
await this.evaluate(node.body, loopEnv);
|
|
@@ -445,7 +451,11 @@ async evalFor(node, env) {
|
|
|
445
451
|
return null;
|
|
446
452
|
}
|
|
447
453
|
|
|
454
|
+
// -------------------------------
|
|
455
|
+
// C-style for loop
|
|
456
|
+
// -------------------------------
|
|
448
457
|
const local = new Environment(env);
|
|
458
|
+
|
|
449
459
|
if (node.init) await this.evaluate(node.init, local);
|
|
450
460
|
|
|
451
461
|
while (!node.test || await this.evaluate(node.test, local)) {
|