starlight-cli 1.0.42 → 1.0.44
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
|
@@ -1389,6 +1389,37 @@ class Evaluator {
|
|
|
1389
1389
|
this.global = new Environment();
|
|
1390
1390
|
this.setupBuiltins();
|
|
1391
1391
|
}
|
|
1392
|
+
formatValue(value, seen = new Set()) {
|
|
1393
|
+
if (typeof value === 'object' && value !== null) {
|
|
1394
|
+
if (seen.has(value)) return '[Circular]';
|
|
1395
|
+
seen.add(value);
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
if (value === null) return 'null';
|
|
1399
|
+
if (value === undefined) return 'undefined';
|
|
1400
|
+
|
|
1401
|
+
const t = typeof value;
|
|
1402
|
+
|
|
1403
|
+
if (t === 'string') return value;
|
|
1404
|
+
if (t === 'number' || t === 'boolean') return String(value);
|
|
1405
|
+
|
|
1406
|
+
if (t === 'function') {
|
|
1407
|
+
return '[function]';
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
if (Array.isArray(value)) {
|
|
1411
|
+
return '[' + value.map(v => this.formatValue(v, seen)).join(', ') + ']';
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
if (t === 'object') {
|
|
1415
|
+
const entries = Object.entries(value).map(
|
|
1416
|
+
([k, v]) => `${k}: ${this.formatValue(v, seen)}`
|
|
1417
|
+
);
|
|
1418
|
+
return '{ ' + entries.join(', ') + ' }';
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
return String(value);
|
|
1422
|
+
}
|
|
1392
1423
|
|
|
1393
1424
|
setupBuiltins() {
|
|
1394
1425
|
this.global.define('len', arg => {
|
|
@@ -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
|
@@ -46,6 +46,37 @@ class Evaluator {
|
|
|
46
46
|
this.global = new Environment();
|
|
47
47
|
this.setupBuiltins();
|
|
48
48
|
}
|
|
49
|
+
formatValue(value, seen = new Set()) {
|
|
50
|
+
if (typeof value === 'object' && value !== null) {
|
|
51
|
+
if (seen.has(value)) return '[Circular]';
|
|
52
|
+
seen.add(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (value === null) return 'null';
|
|
56
|
+
if (value === undefined) return 'undefined';
|
|
57
|
+
|
|
58
|
+
const t = typeof value;
|
|
59
|
+
|
|
60
|
+
if (t === 'string') return value;
|
|
61
|
+
if (t === 'number' || t === 'boolean') return String(value);
|
|
62
|
+
|
|
63
|
+
if (t === 'function') {
|
|
64
|
+
return '[function]';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
return '[' + value.map(v => this.formatValue(v, seen)).join(', ') + ']';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (t === 'object') {
|
|
72
|
+
const entries = Object.entries(value).map(
|
|
73
|
+
([k, v]) => `${k}: ${this.formatValue(v, seen)}`
|
|
74
|
+
);
|
|
75
|
+
return '{ ' + entries.join(', ') + ' }';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return String(value);
|
|
79
|
+
}
|
|
49
80
|
|
|
50
81
|
setupBuiltins() {
|
|
51
82
|
this.global.define('len', arg => {
|
|
@@ -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 + ' ');
|