starlight-cli 1.0.49 → 1.0.51

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 CHANGED
@@ -1741,15 +1741,27 @@ async evalBlock(node, env) {
1741
1741
  try {
1742
1742
  result = await this.evaluate(stmt, env);
1743
1743
  } catch (e) {
1744
- if (e instanceof ReturnValue || e instanceof BreakSignal || e instanceof ContinueSignal) throw e;
1745
- // Wrap any other error in RuntimeError with the current block node
1746
- throw new RuntimeError(e.message || 'Error in block', stmt, this.source);
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
+ );
1747
1758
  }
1748
1759
  }
1749
1760
  return result;
1750
1761
  }
1751
1762
 
1752
1763
 
1764
+
1753
1765
  async evalVarDeclaration(node, env) {
1754
1766
  if (!node.expr) {
1755
1767
  throw new RuntimeError('Variable declaration requires an initializer', node, this.source);
@@ -2057,9 +2069,15 @@ async evalCall(node, env) {
2057
2069
  const callEnv = new Environment(fn.env);
2058
2070
 
2059
2071
  for (let i = 0; i < fn.params.length; i++) {
2060
- const argVal = node.arguments[i] ? await this.evaluate(node.arguments[i], env) : null;
2061
- callEnv.define(fn.params[i], argVal);
2062
- }
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
+ }
2063
2081
 
2064
2082
  try {
2065
2083
  const result = await this.evaluate(fn.body, callEnv);
@@ -2368,7 +2386,7 @@ class ParseError extends Error {
2368
2386
  const line = token?.line ?? '?';
2369
2387
  const column = token?.column ?? '?';
2370
2388
 
2371
- let output = `SyntaxError: ${message}\n`;
2389
+ let output = `${message}\n`;
2372
2390
 
2373
2391
  if (source && token?.line != null) {
2374
2392
  const lines = source.split('\n');
@@ -3301,7 +3319,7 @@ const Lexer = __nccwpck_require__(211);
3301
3319
  const Parser = __nccwpck_require__(222);
3302
3320
  const Evaluator = __nccwpck_require__(112);
3303
3321
 
3304
- const VERSION = '1.0.49';
3322
+ const VERSION = '1.0.51';
3305
3323
 
3306
3324
  const COLOR = {
3307
3325
  reset: '\x1b[0m',
@@ -3466,12 +3484,26 @@ function savePrompt(lines) {
3466
3484
  }
3467
3485
 
3468
3486
  async function runFile(filePath, isTemp = false, callback) {
3469
- const code = fs.readFileSync(filePath, 'utf8');
3487
+ let code;
3488
+ try {
3489
+ code = fs.readFileSync(filePath, 'utf8');
3490
+ } catch (e) {
3491
+ console.error(COLOR.white + `Failed to read file: ${e.message}` + COLOR.reset);
3492
+ return waitAndExit(1);
3493
+ }
3494
+
3495
+ let tokens, ast;
3496
+ try {
3497
+ const lexer = new Lexer(code);
3498
+ tokens = lexer.getTokens();
3499
+
3500
+ const parser = new Parser(tokens, code);
3501
+ ast = parser.parse(); // <-- parser errors caught here
3502
+ } catch (e) {
3503
+ console.error(COLOR.white + ` ${e.message}` + COLOR.reset);
3504
+ return waitAndExit(1); // stop execution without Node.js stack trace
3505
+ }
3470
3506
 
3471
- const lexer = new Lexer(code);
3472
- const tokens = lexer.getTokens();
3473
- const parser = new Parser(tokens, code);
3474
- const ast = parser.parse();
3475
3507
  const evaluator = new Evaluator(code);
3476
3508
 
3477
3509
  try {
@@ -3493,7 +3525,6 @@ async function runFile(filePath, isTemp = false, callback) {
3493
3525
  }
3494
3526
 
3495
3527
 
3496
-
3497
3528
  if (!args[0].startsWith('--')) {
3498
3529
  runFile(path.resolve(args[0]));
3499
3530
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -398,15 +398,27 @@ async evalBlock(node, env) {
398
398
  try {
399
399
  result = await this.evaluate(stmt, env);
400
400
  } catch (e) {
401
- if (e instanceof ReturnValue || e instanceof BreakSignal || e instanceof ContinueSignal) throw e;
402
- // Wrap any other error in RuntimeError with the current block node
403
- throw new RuntimeError(e.message || 'Error in block', stmt, this.source);
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
+ );
404
415
  }
405
416
  }
406
417
  return result;
407
418
  }
408
419
 
409
420
 
421
+
410
422
  async evalVarDeclaration(node, env) {
411
423
  if (!node.expr) {
412
424
  throw new RuntimeError('Variable declaration requires an initializer', node, this.source);
@@ -714,9 +726,15 @@ async evalCall(node, env) {
714
726
  const callEnv = new Environment(fn.env);
715
727
 
716
728
  for (let i = 0; i < fn.params.length; i++) {
717
- const argVal = node.arguments[i] ? await this.evaluate(node.arguments[i], env) : null;
718
- callEnv.define(fn.params[i], argVal);
719
- }
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
+ }
720
738
 
721
739
  try {
722
740
  const result = await this.evaluate(fn.body, callEnv);
package/src/parser.js CHANGED
@@ -3,7 +3,7 @@ class ParseError extends Error {
3
3
  const line = token?.line ?? '?';
4
4
  const column = token?.column ?? '?';
5
5
 
6
- let output = `SyntaxError: ${message}\n`;
6
+ let output = `${message}\n`;
7
7
 
8
8
  if (source && token?.line != null) {
9
9
  const lines = source.split('\n');
package/src/starlight.js CHANGED
@@ -9,7 +9,7 @@ const Lexer = require('./lexer');
9
9
  const Parser = require('./parser');
10
10
  const Evaluator = require('./evaluator');
11
11
 
12
- const VERSION = '1.0.49';
12
+ const VERSION = '1.0.51';
13
13
 
14
14
  const COLOR = {
15
15
  reset: '\x1b[0m',
@@ -174,12 +174,26 @@ function savePrompt(lines) {
174
174
  }
175
175
 
176
176
  async function runFile(filePath, isTemp = false, callback) {
177
- const code = fs.readFileSync(filePath, 'utf8');
177
+ let code;
178
+ try {
179
+ code = fs.readFileSync(filePath, 'utf8');
180
+ } catch (e) {
181
+ console.error(COLOR.white + `Failed to read file: ${e.message}` + COLOR.reset);
182
+ return waitAndExit(1);
183
+ }
184
+
185
+ let tokens, ast;
186
+ try {
187
+ const lexer = new Lexer(code);
188
+ tokens = lexer.getTokens();
189
+
190
+ const parser = new Parser(tokens, code);
191
+ ast = parser.parse(); // <-- parser errors caught here
192
+ } catch (e) {
193
+ console.error(COLOR.white + ` ${e.message}` + COLOR.reset);
194
+ return waitAndExit(1); // stop execution without Node.js stack trace
195
+ }
178
196
 
179
- const lexer = new Lexer(code);
180
- const tokens = lexer.getTokens();
181
- const parser = new Parser(tokens, code);
182
- const ast = parser.parse();
183
197
  const evaluator = new Evaluator(code);
184
198
 
185
199
  try {
@@ -201,7 +215,6 @@ async function runFile(filePath, isTemp = false, callback) {
201
215
  }
202
216
 
203
217
 
204
-
205
218
  if (!args[0].startsWith('--')) {
206
219
  runFile(path.resolve(args[0]));
207
220
  }