starlight-cli 1.0.48 → 1.0.50
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 +32 -13
- package/package.json +1 -1
- package/src/evaluator.js +31 -12
- package/src/starlight.js +1 -1
package/dist/index.js
CHANGED
|
@@ -1388,12 +1388,13 @@ class Environment {
|
|
|
1388
1388
|
return false;
|
|
1389
1389
|
}
|
|
1390
1390
|
|
|
1391
|
-
get(name, node) {
|
|
1391
|
+
get(name, node, source) {
|
|
1392
1392
|
if (name in this.store) return this.store[name];
|
|
1393
|
-
if (this.parent) return this.parent.get(name, node);
|
|
1394
|
-
throw new RuntimeError(`Undefined variable: ${name}`, node);
|
|
1393
|
+
if (this.parent) return this.parent.get(name, node, source);
|
|
1394
|
+
throw new RuntimeError(`Undefined variable: ${name}`, node, source);
|
|
1395
1395
|
}
|
|
1396
1396
|
|
|
1397
|
+
|
|
1397
1398
|
set(name, value) {
|
|
1398
1399
|
if (name in this.store) { this.store[name] = value; return value; }
|
|
1399
1400
|
if (this.parent && this.parent.has(name)) { return this.parent.set(name, value); }
|
|
@@ -1577,7 +1578,7 @@ async evaluate(node, env = this.global) {
|
|
|
1577
1578
|
case 'LogicalExpression': return await this.evalLogical(node, env);
|
|
1578
1579
|
case 'UnaryExpression': return await this.evalUnary(node, env);
|
|
1579
1580
|
case 'Literal': return node.value;
|
|
1580
|
-
case 'Identifier': return env.get(node.name, node);
|
|
1581
|
+
case 'Identifier': return env.get(node.name, node, this.source);
|
|
1581
1582
|
case 'IfStatement': return await this.evalIf(node, env);
|
|
1582
1583
|
case 'WhileStatement': return await this.evalWhile(node, env);
|
|
1583
1584
|
case 'ForStatement':
|
|
@@ -1740,15 +1741,27 @@ async evalBlock(node, env) {
|
|
|
1740
1741
|
try {
|
|
1741
1742
|
result = await this.evaluate(stmt, env);
|
|
1742
1743
|
} catch (e) {
|
|
1743
|
-
if (
|
|
1744
|
-
|
|
1745
|
-
|
|
1744
|
+
if (
|
|
1745
|
+
e instanceof RuntimeError ||
|
|
1746
|
+
e instanceof ReturnValue ||
|
|
1747
|
+
e instanceof BreakSignal ||
|
|
1748
|
+
e instanceof ContinueSignal
|
|
1749
|
+
) {
|
|
1750
|
+
throw e;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
throw new RuntimeError(
|
|
1754
|
+
e.message || 'Error in block',
|
|
1755
|
+
stmt,
|
|
1756
|
+
this.source
|
|
1757
|
+
);
|
|
1746
1758
|
}
|
|
1747
1759
|
}
|
|
1748
1760
|
return result;
|
|
1749
1761
|
}
|
|
1750
1762
|
|
|
1751
1763
|
|
|
1764
|
+
|
|
1752
1765
|
async evalVarDeclaration(node, env) {
|
|
1753
1766
|
if (!node.expr) {
|
|
1754
1767
|
throw new RuntimeError('Variable declaration requires an initializer', node, this.source);
|
|
@@ -1805,7 +1818,7 @@ async evalCompoundAssignment(node, env) {
|
|
|
1805
1818
|
const left = node.left;
|
|
1806
1819
|
let current;
|
|
1807
1820
|
|
|
1808
|
-
if (left.type === 'Identifier') current = env.get(left.name);
|
|
1821
|
+
if (left.type === 'Identifier') current = env.get(left.name, left, this.source);
|
|
1809
1822
|
else if (left.type === 'MemberExpression') current = await this.evalMember(left, env);
|
|
1810
1823
|
else if (left.type === 'IndexExpression') current = await this.evalIndex(left, env);
|
|
1811
1824
|
else throw new RuntimeError('Invalid compound assignment target', node, this.source);
|
|
@@ -2056,9 +2069,15 @@ async evalCall(node, env) {
|
|
|
2056
2069
|
const callEnv = new Environment(fn.env);
|
|
2057
2070
|
|
|
2058
2071
|
for (let i = 0; i < fn.params.length; i++) {
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2072
|
+
const argVal = node.arguments[i]
|
|
2073
|
+
? await this.evaluate(node.arguments[i], env)
|
|
2074
|
+
: null;
|
|
2075
|
+
|
|
2076
|
+
const param = fn.params[i];
|
|
2077
|
+
const paramName = typeof param === 'string' ? param : param.name;
|
|
2078
|
+
|
|
2079
|
+
callEnv.define(paramName, argVal);
|
|
2080
|
+
}
|
|
2062
2081
|
|
|
2063
2082
|
try {
|
|
2064
2083
|
const result = await this.evaluate(fn.body, callEnv);
|
|
@@ -2109,7 +2128,7 @@ if (!(node.property in obj)) throw new RuntimeError(`Property '${node.property}'
|
|
|
2109
2128
|
async evalUpdate(node, env) {
|
|
2110
2129
|
const arg = node.argument;
|
|
2111
2130
|
const getCurrent = async () => {
|
|
2112
|
-
if (arg.type === 'Identifier') return env.get(arg.name);
|
|
2131
|
+
if (arg.type === 'Identifier') return env.get(arg.name, arg, this.source);
|
|
2113
2132
|
if (arg.type === 'MemberExpression') return await this.evalMember(arg, env);
|
|
2114
2133
|
if (arg.type === 'IndexExpression') return await this.evalIndex(arg, env);
|
|
2115
2134
|
throw new RuntimeError('Invalid update target', node, this.source);
|
|
@@ -3300,7 +3319,7 @@ const Lexer = __nccwpck_require__(211);
|
|
|
3300
3319
|
const Parser = __nccwpck_require__(222);
|
|
3301
3320
|
const Evaluator = __nccwpck_require__(112);
|
|
3302
3321
|
|
|
3303
|
-
const VERSION = '1.0.
|
|
3322
|
+
const VERSION = '1.0.50';
|
|
3304
3323
|
|
|
3305
3324
|
const COLOR = {
|
|
3306
3325
|
reset: '\x1b[0m',
|
package/package.json
CHANGED
package/src/evaluator.js
CHANGED
|
@@ -45,12 +45,13 @@ class Environment {
|
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
get(name, node) {
|
|
48
|
+
get(name, node, source) {
|
|
49
49
|
if (name in this.store) return this.store[name];
|
|
50
|
-
if (this.parent) return this.parent.get(name, node);
|
|
51
|
-
throw new RuntimeError(`Undefined variable: ${name}`, node);
|
|
50
|
+
if (this.parent) return this.parent.get(name, node, source);
|
|
51
|
+
throw new RuntimeError(`Undefined variable: ${name}`, node, source);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
|
|
54
55
|
set(name, value) {
|
|
55
56
|
if (name in this.store) { this.store[name] = value; return value; }
|
|
56
57
|
if (this.parent && this.parent.has(name)) { return this.parent.set(name, value); }
|
|
@@ -234,7 +235,7 @@ async evaluate(node, env = this.global) {
|
|
|
234
235
|
case 'LogicalExpression': return await this.evalLogical(node, env);
|
|
235
236
|
case 'UnaryExpression': return await this.evalUnary(node, env);
|
|
236
237
|
case 'Literal': return node.value;
|
|
237
|
-
case 'Identifier': return env.get(node.name, node);
|
|
238
|
+
case 'Identifier': return env.get(node.name, node, this.source);
|
|
238
239
|
case 'IfStatement': return await this.evalIf(node, env);
|
|
239
240
|
case 'WhileStatement': return await this.evalWhile(node, env);
|
|
240
241
|
case 'ForStatement':
|
|
@@ -397,15 +398,27 @@ async evalBlock(node, env) {
|
|
|
397
398
|
try {
|
|
398
399
|
result = await this.evaluate(stmt, env);
|
|
399
400
|
} catch (e) {
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
|
|
401
|
+
if (
|
|
402
|
+
e instanceof RuntimeError ||
|
|
403
|
+
e instanceof ReturnValue ||
|
|
404
|
+
e instanceof BreakSignal ||
|
|
405
|
+
e instanceof ContinueSignal
|
|
406
|
+
) {
|
|
407
|
+
throw e;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
throw new RuntimeError(
|
|
411
|
+
e.message || 'Error in block',
|
|
412
|
+
stmt,
|
|
413
|
+
this.source
|
|
414
|
+
);
|
|
403
415
|
}
|
|
404
416
|
}
|
|
405
417
|
return result;
|
|
406
418
|
}
|
|
407
419
|
|
|
408
420
|
|
|
421
|
+
|
|
409
422
|
async evalVarDeclaration(node, env) {
|
|
410
423
|
if (!node.expr) {
|
|
411
424
|
throw new RuntimeError('Variable declaration requires an initializer', node, this.source);
|
|
@@ -462,7 +475,7 @@ async evalCompoundAssignment(node, env) {
|
|
|
462
475
|
const left = node.left;
|
|
463
476
|
let current;
|
|
464
477
|
|
|
465
|
-
if (left.type === 'Identifier') current = env.get(left.name);
|
|
478
|
+
if (left.type === 'Identifier') current = env.get(left.name, left, this.source);
|
|
466
479
|
else if (left.type === 'MemberExpression') current = await this.evalMember(left, env);
|
|
467
480
|
else if (left.type === 'IndexExpression') current = await this.evalIndex(left, env);
|
|
468
481
|
else throw new RuntimeError('Invalid compound assignment target', node, this.source);
|
|
@@ -713,9 +726,15 @@ async evalCall(node, env) {
|
|
|
713
726
|
const callEnv = new Environment(fn.env);
|
|
714
727
|
|
|
715
728
|
for (let i = 0; i < fn.params.length; i++) {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
729
|
+
const argVal = node.arguments[i]
|
|
730
|
+
? await this.evaluate(node.arguments[i], env)
|
|
731
|
+
: null;
|
|
732
|
+
|
|
733
|
+
const param = fn.params[i];
|
|
734
|
+
const paramName = typeof param === 'string' ? param : param.name;
|
|
735
|
+
|
|
736
|
+
callEnv.define(paramName, argVal);
|
|
737
|
+
}
|
|
719
738
|
|
|
720
739
|
try {
|
|
721
740
|
const result = await this.evaluate(fn.body, callEnv);
|
|
@@ -766,7 +785,7 @@ if (!(node.property in obj)) throw new RuntimeError(`Property '${node.property}'
|
|
|
766
785
|
async evalUpdate(node, env) {
|
|
767
786
|
const arg = node.argument;
|
|
768
787
|
const getCurrent = async () => {
|
|
769
|
-
if (arg.type === 'Identifier') return env.get(arg.name);
|
|
788
|
+
if (arg.type === 'Identifier') return env.get(arg.name, arg, this.source);
|
|
770
789
|
if (arg.type === 'MemberExpression') return await this.evalMember(arg, env);
|
|
771
790
|
if (arg.type === 'IndexExpression') return await this.evalIndex(arg, env);
|
|
772
791
|
throw new RuntimeError('Invalid update target', node, this.source);
|