starlight-cli 1.0.42 → 1.0.43
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 +33 -7
- package/package.json +1 -1
- package/src/evaluator.js +33 -7
package/dist/index.js
CHANGED
|
@@ -1370,6 +1370,37 @@ class Environment {
|
|
|
1370
1370
|
if (this.parent) return this.parent.get(name);
|
|
1371
1371
|
throw new Error(`Undefined variable: ${name}`);
|
|
1372
1372
|
}
|
|
1373
|
+
formatValue(value, seen = new Set()) {
|
|
1374
|
+
if (typeof value === 'object' && value !== null) {
|
|
1375
|
+
if (seen.has(value)) return '[Circular]';
|
|
1376
|
+
seen.add(value);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
if (value === null) return 'null';
|
|
1380
|
+
if (value === undefined) return 'undefined';
|
|
1381
|
+
|
|
1382
|
+
const t = typeof value;
|
|
1383
|
+
|
|
1384
|
+
if (t === 'string') return value;
|
|
1385
|
+
if (t === 'number' || t === 'boolean') return String(value);
|
|
1386
|
+
|
|
1387
|
+
if (t === 'function') {
|
|
1388
|
+
return '[function]';
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
if (Array.isArray(value)) {
|
|
1392
|
+
return '[' + value.map(v => this.formatValue(v, seen)).join(', ') + ']';
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
if (t === 'object') {
|
|
1396
|
+
const entries = Object.entries(value).map(
|
|
1397
|
+
([k, v]) => `${k}: ${this.formatValue(v, seen)}`
|
|
1398
|
+
);
|
|
1399
|
+
return '{ ' + entries.join(', ') + ' }';
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
return String(value);
|
|
1403
|
+
}
|
|
1373
1404
|
|
|
1374
1405
|
set(name, value) {
|
|
1375
1406
|
if (name in this.store) { this.store[name] = value; return value; }
|
|
@@ -1720,16 +1751,11 @@ async evalCompoundAssignment(node, env) {
|
|
|
1720
1751
|
|
|
1721
1752
|
async evalSldeploy(node, env) {
|
|
1722
1753
|
const val = await this.evaluate(node.expr, env);
|
|
1723
|
-
|
|
1724
|
-
if (typeof val === 'object' && val !== null) {
|
|
1725
|
-
console.log(JSON.stringify(val, null, 2));
|
|
1726
|
-
} else {
|
|
1727
|
-
console.log(val);
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1754
|
+
console.log(this.formatValue(val));
|
|
1730
1755
|
return val;
|
|
1731
1756
|
}
|
|
1732
1757
|
|
|
1758
|
+
|
|
1733
1759
|
async evalAsk(node, env) {
|
|
1734
1760
|
const prompt = await this.evaluate(node.prompt, env);
|
|
1735
1761
|
const input = readlineSync.question(prompt + ' ');
|
package/package.json
CHANGED
package/src/evaluator.js
CHANGED
|
@@ -27,6 +27,37 @@ class Environment {
|
|
|
27
27
|
if (this.parent) return this.parent.get(name);
|
|
28
28
|
throw new Error(`Undefined variable: ${name}`);
|
|
29
29
|
}
|
|
30
|
+
formatValue(value, seen = new Set()) {
|
|
31
|
+
if (typeof value === 'object' && value !== null) {
|
|
32
|
+
if (seen.has(value)) return '[Circular]';
|
|
33
|
+
seen.add(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (value === null) return 'null';
|
|
37
|
+
if (value === undefined) return 'undefined';
|
|
38
|
+
|
|
39
|
+
const t = typeof value;
|
|
40
|
+
|
|
41
|
+
if (t === 'string') return value;
|
|
42
|
+
if (t === 'number' || t === 'boolean') return String(value);
|
|
43
|
+
|
|
44
|
+
if (t === 'function') {
|
|
45
|
+
return '[function]';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
return '[' + value.map(v => this.formatValue(v, seen)).join(', ') + ']';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (t === 'object') {
|
|
53
|
+
const entries = Object.entries(value).map(
|
|
54
|
+
([k, v]) => `${k}: ${this.formatValue(v, seen)}`
|
|
55
|
+
);
|
|
56
|
+
return '{ ' + entries.join(', ') + ' }';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return String(value);
|
|
60
|
+
}
|
|
30
61
|
|
|
31
62
|
set(name, value) {
|
|
32
63
|
if (name in this.store) { this.store[name] = value; return value; }
|
|
@@ -377,16 +408,11 @@ async evalCompoundAssignment(node, env) {
|
|
|
377
408
|
|
|
378
409
|
async evalSldeploy(node, env) {
|
|
379
410
|
const val = await this.evaluate(node.expr, env);
|
|
380
|
-
|
|
381
|
-
if (typeof val === 'object' && val !== null) {
|
|
382
|
-
console.log(JSON.stringify(val, null, 2));
|
|
383
|
-
} else {
|
|
384
|
-
console.log(val);
|
|
385
|
-
}
|
|
386
|
-
|
|
411
|
+
console.log(this.formatValue(val));
|
|
387
412
|
return val;
|
|
388
413
|
}
|
|
389
414
|
|
|
415
|
+
|
|
390
416
|
async evalAsk(node, env) {
|
|
391
417
|
const prompt = await this.evaluate(node.prompt, env);
|
|
392
418
|
const input = readlineSync.question(prompt + ' ');
|