jslike 1.4.2 → 1.4.4

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.
@@ -1103,7 +1103,8 @@ export class Interpreter {
1103
1103
  return undefined;
1104
1104
  }
1105
1105
 
1106
- const args = node.arguments.map(arg => this.evaluate(arg, env));
1106
+ const rawArgs = node.arguments.map(arg => this.evaluate(arg, env));
1107
+ const args = this.flattenSpreadArgs(rawArgs);
1107
1108
 
1108
1109
  if (typeof callee === 'function') {
1109
1110
  // Native JavaScript function or class method
@@ -1124,6 +1125,19 @@ export class Interpreter {
1124
1125
  throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
1125
1126
  }
1126
1127
 
1128
+ // Helper to flatten spread elements in argument arrays
1129
+ flattenSpreadArgs(args) {
1130
+ const result = [];
1131
+ for (const arg of args) {
1132
+ if (arg && arg.__spread === true && Array.isArray(arg.__values)) {
1133
+ result.push(...arg.__values);
1134
+ } else {
1135
+ result.push(arg);
1136
+ }
1137
+ }
1138
+ return result;
1139
+ }
1140
+
1127
1141
  // Helper to get a readable name for an expression (for error messages)
1128
1142
  getExpressionName(node) {
1129
1143
  if (!node) return 'object';
@@ -1340,7 +1354,8 @@ export class Interpreter {
1340
1354
 
1341
1355
  evaluateNewExpression(node, env) {
1342
1356
  const constructor = this.evaluate(node.callee, env);
1343
- const args = node.arguments.map(arg => this.evaluate(arg, env));
1357
+ const rawArgs = node.arguments.map(arg => this.evaluate(arg, env));
1358
+ const args = this.flattenSpreadArgs(rawArgs);
1344
1359
 
1345
1360
  // Handle user-defined functions (including async and arrow functions)
1346
1361
  if (constructor && constructor.__isFunction) {
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Result of module resolution
3
+ */
4
+ export interface ModuleResolution {
5
+ /** The module source code */
6
+ code: string;
7
+ /** The resolved module path */
8
+ path: string;
9
+ /** Optional metadata about the module */
10
+ metadata?: any;
11
+ }
package/dist/index.cjs CHANGED
@@ -6682,7 +6682,8 @@ var Interpreter = class _Interpreter {
6682
6682
  if (node.optional && (callee === null || callee === void 0)) {
6683
6683
  return void 0;
6684
6684
  }
6685
- const args = node.arguments.map((arg) => this.evaluate(arg, env));
6685
+ const rawArgs = node.arguments.map((arg) => this.evaluate(arg, env));
6686
+ const args = this.flattenSpreadArgs(rawArgs);
6686
6687
  if (typeof callee === "function") {
6687
6688
  if (thisContext !== void 0) {
6688
6689
  return callee.call(thisContext, ...args);
@@ -6696,6 +6697,18 @@ var Interpreter = class _Interpreter {
6696
6697
  }
6697
6698
  throw new TypeError(`${node.callee.name || "Expression"} is not a function`);
6698
6699
  }
6700
+ // Helper to flatten spread elements in argument arrays
6701
+ flattenSpreadArgs(args) {
6702
+ const result = [];
6703
+ for (const arg of args) {
6704
+ if (arg && arg.__spread === true && Array.isArray(arg.__values)) {
6705
+ result.push(...arg.__values);
6706
+ } else {
6707
+ result.push(arg);
6708
+ }
6709
+ }
6710
+ return result;
6711
+ }
6699
6712
  // Helper to get a readable name for an expression (for error messages)
6700
6713
  getExpressionName(node) {
6701
6714
  if (!node) return "object";
@@ -6852,7 +6865,8 @@ var Interpreter = class _Interpreter {
6852
6865
  }
6853
6866
  evaluateNewExpression(node, env) {
6854
6867
  const constructor = this.evaluate(node.callee, env);
6855
- const args = node.arguments.map((arg) => this.evaluate(arg, env));
6868
+ const rawArgs = node.arguments.map((arg) => this.evaluate(arg, env));
6869
+ const args = this.flattenSpreadArgs(rawArgs);
6856
6870
  if (constructor && constructor.__isFunction) {
6857
6871
  const result = this.callUserFunction(constructor, args, env);
6858
6872
  if (result && typeof result.then === "function") {
package/dist/index.d.cts CHANGED
@@ -7534,7 +7534,8 @@ class Interpreter {
7534
7534
  return undefined;
7535
7535
  }
7536
7536
 
7537
- const args = node.arguments.map(arg => this.evaluate(arg, env));
7537
+ const rawArgs = node.arguments.map(arg => this.evaluate(arg, env));
7538
+ const args = this.flattenSpreadArgs(rawArgs);
7538
7539
 
7539
7540
  if (typeof callee === 'function') {
7540
7541
  // Native JavaScript function or class method
@@ -7555,6 +7556,19 @@ class Interpreter {
7555
7556
  throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
7556
7557
  }
7557
7558
 
7559
+ // Helper to flatten spread elements in argument arrays
7560
+ flattenSpreadArgs(args) {
7561
+ const result = [];
7562
+ for (const arg of args) {
7563
+ if (arg && arg.__spread === true && Array.isArray(arg.__values)) {
7564
+ result.push(...arg.__values);
7565
+ } else {
7566
+ result.push(arg);
7567
+ }
7568
+ }
7569
+ return result;
7570
+ }
7571
+
7558
7572
  // Helper to get a readable name for an expression (for error messages)
7559
7573
  getExpressionName(node) {
7560
7574
  if (!node) return 'object';
@@ -7771,7 +7785,8 @@ class Interpreter {
7771
7785
 
7772
7786
  evaluateNewExpression(node, env) {
7773
7787
  const constructor = this.evaluate(node.callee, env);
7774
- const args = node.arguments.map(arg => this.evaluate(arg, env));
7788
+ const rawArgs = node.arguments.map(arg => this.evaluate(arg, env));
7789
+ const args = this.flattenSpreadArgs(rawArgs);
7775
7790
 
7776
7791
  // Handle user-defined functions (including async and arrow functions)
7777
7792
  if (constructor && constructor.__isFunction) {
package/dist/index.d.ts CHANGED
@@ -7534,7 +7534,8 @@ class Interpreter {
7534
7534
  return undefined;
7535
7535
  }
7536
7536
 
7537
- const args = node.arguments.map(arg => this.evaluate(arg, env));
7537
+ const rawArgs = node.arguments.map(arg => this.evaluate(arg, env));
7538
+ const args = this.flattenSpreadArgs(rawArgs);
7538
7539
 
7539
7540
  if (typeof callee === 'function') {
7540
7541
  // Native JavaScript function or class method
@@ -7555,6 +7556,19 @@ class Interpreter {
7555
7556
  throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
7556
7557
  }
7557
7558
 
7559
+ // Helper to flatten spread elements in argument arrays
7560
+ flattenSpreadArgs(args) {
7561
+ const result = [];
7562
+ for (const arg of args) {
7563
+ if (arg && arg.__spread === true && Array.isArray(arg.__values)) {
7564
+ result.push(...arg.__values);
7565
+ } else {
7566
+ result.push(arg);
7567
+ }
7568
+ }
7569
+ return result;
7570
+ }
7571
+
7558
7572
  // Helper to get a readable name for an expression (for error messages)
7559
7573
  getExpressionName(node) {
7560
7574
  if (!node) return 'object';
@@ -7771,7 +7785,8 @@ class Interpreter {
7771
7785
 
7772
7786
  evaluateNewExpression(node, env) {
7773
7787
  const constructor = this.evaluate(node.callee, env);
7774
- const args = node.arguments.map(arg => this.evaluate(arg, env));
7788
+ const rawArgs = node.arguments.map(arg => this.evaluate(arg, env));
7789
+ const args = this.flattenSpreadArgs(rawArgs);
7775
7790
 
7776
7791
  // Handle user-defined functions (including async and arrow functions)
7777
7792
  if (constructor && constructor.__isFunction) {
package/dist/index.js CHANGED
@@ -6649,7 +6649,8 @@ var Interpreter = class _Interpreter {
6649
6649
  if (node.optional && (callee === null || callee === void 0)) {
6650
6650
  return void 0;
6651
6651
  }
6652
- const args = node.arguments.map((arg) => this.evaluate(arg, env));
6652
+ const rawArgs = node.arguments.map((arg) => this.evaluate(arg, env));
6653
+ const args = this.flattenSpreadArgs(rawArgs);
6653
6654
  if (typeof callee === "function") {
6654
6655
  if (thisContext !== void 0) {
6655
6656
  return callee.call(thisContext, ...args);
@@ -6663,6 +6664,18 @@ var Interpreter = class _Interpreter {
6663
6664
  }
6664
6665
  throw new TypeError(`${node.callee.name || "Expression"} is not a function`);
6665
6666
  }
6667
+ // Helper to flatten spread elements in argument arrays
6668
+ flattenSpreadArgs(args) {
6669
+ const result = [];
6670
+ for (const arg of args) {
6671
+ if (arg && arg.__spread === true && Array.isArray(arg.__values)) {
6672
+ result.push(...arg.__values);
6673
+ } else {
6674
+ result.push(arg);
6675
+ }
6676
+ }
6677
+ return result;
6678
+ }
6666
6679
  // Helper to get a readable name for an expression (for error messages)
6667
6680
  getExpressionName(node) {
6668
6681
  if (!node) return "object";
@@ -6819,7 +6832,8 @@ var Interpreter = class _Interpreter {
6819
6832
  }
6820
6833
  evaluateNewExpression(node, env) {
6821
6834
  const constructor = this.evaluate(node.callee, env);
6822
- const args = node.arguments.map((arg) => this.evaluate(arg, env));
6835
+ const rawArgs = node.arguments.map((arg) => this.evaluate(arg, env));
6836
+ const args = this.flattenSpreadArgs(rawArgs);
6823
6837
  if (constructor && constructor.__isFunction) {
6824
6838
  const result = this.callUserFunction(constructor, args, env);
6825
6839
  if (result && typeof result.then === "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jslike",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Production-ready JavaScript interpreter with full ES6+ support using Acorn parser",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -56,6 +56,9 @@
56
56
  "types": "./dist/editor/wang-prism.d.cts",
57
57
  "default": "./dist/editor/wang-prism.cjs"
58
58
  }
59
+ },
60
+ "./types": {
61
+ "types": "./dist/esm/types.d.ts"
59
62
  }
60
63
  },
61
64
  "bin": {