jslike 1.8.4 → 1.8.5

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.
@@ -2768,7 +2768,7 @@ export class Interpreter {
2768
2768
  // Add methods to prototype
2769
2769
  for (const [name, method] of Object.entries(methods)) {
2770
2770
  classConstructor.prototype[name] = function(...args) {
2771
- const result = interpreter.callMethodFunction(method, this, args, env);
2771
+ const result = interpreter.callMethodFunction(method, this, args, env, superClass);
2772
2772
  // Unwrap explicit return marker
2773
2773
  if (result && result.__explicitReturn) {
2774
2774
  return result.value;
@@ -2841,6 +2841,9 @@ export class Interpreter {
2841
2841
  for (const field of classConstructor.__instanceFields || []) {
2842
2842
  const fieldEnv = new Environment(env);
2843
2843
  fieldEnv.define('this', instance);
2844
+ if (classConstructor.__superClass) {
2845
+ fieldEnv.define('super', this.createSuperBinding(classConstructor.__superClass, instance, false));
2846
+ }
2844
2847
  const name = this.getClassFieldName(field, fieldEnv);
2845
2848
  instance[name] = field.value ? this.evaluate(field.value, fieldEnv) : undefined;
2846
2849
  }
@@ -2856,6 +2859,38 @@ export class Interpreter {
2856
2859
  return field.key.value;
2857
2860
  }
2858
2861
 
2862
+ createSuperBinding(superClass, thisContext, allowConstructor = false, afterSuper = null) {
2863
+ const superConstructor = (...superArgs) => {
2864
+ if (!allowConstructor) {
2865
+ throw new ReferenceError("'super' keyword is unexpected here");
2866
+ }
2867
+ const result = this.initializeSuperClass(superClass, thisContext, superArgs);
2868
+ if (afterSuper) {
2869
+ afterSuper();
2870
+ }
2871
+ return result && result.__explicitReturn ? result.value : undefined;
2872
+ };
2873
+
2874
+ superConstructor.__isSuperConstructor = true;
2875
+ superConstructor.__superClass = superClass;
2876
+
2877
+ return new Proxy(superConstructor, {
2878
+ get(target, prop, receiver) {
2879
+ if (prop in target) {
2880
+ return Reflect.get(target, prop, receiver);
2881
+ }
2882
+
2883
+ const prototype = superClass?.prototype;
2884
+ if (!prototype) {
2885
+ return undefined;
2886
+ }
2887
+
2888
+ const value = Reflect.get(prototype, prop, thisContext);
2889
+ return typeof value === 'function' ? value.bind(thisContext) : value;
2890
+ }
2891
+ });
2892
+ }
2893
+
2859
2894
  createMethodFunction(funcNode, env, className) {
2860
2895
  const func = {
2861
2896
  __isFunction: true,
@@ -2875,18 +2910,7 @@ export class Interpreter {
2875
2910
 
2876
2911
  // Bind 'super' if superClass exists
2877
2912
  if (superClass) {
2878
- // Create a super function that calls the parent constructor
2879
- const superFunc = (...superArgs) => {
2880
- const result = this.initializeSuperClass(superClass, thisContext, superArgs);
2881
- if (afterSuper) {
2882
- afterSuper();
2883
- }
2884
- return result && result.__explicitReturn ? result.value : undefined;
2885
- };
2886
- // Store both the function and mark it as super
2887
- superFunc.__isSuperConstructor = true;
2888
- superFunc.__superClass = superClass;
2889
- funcEnv.define('super', superFunc);
2913
+ funcEnv.define('super', this.createSuperBinding(superClass, thisContext, true, afterSuper));
2890
2914
  }
2891
2915
 
2892
2916
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
package/dist/index.cjs CHANGED
@@ -13658,7 +13658,7 @@ var Interpreter = class _Interpreter {
13658
13658
  }
13659
13659
  for (const [name, method] of Object.entries(methods)) {
13660
13660
  classConstructor.prototype[name] = function(...args) {
13661
- const result = interpreter.callMethodFunction(method, this, args, env);
13661
+ const result = interpreter.callMethodFunction(method, this, args, env, superClass);
13662
13662
  if (result && result.__explicitReturn) {
13663
13663
  return result.value;
13664
13664
  }
@@ -13717,6 +13717,9 @@ var Interpreter = class _Interpreter {
13717
13717
  for (const field of classConstructor.__instanceFields || []) {
13718
13718
  const fieldEnv = new Environment(env);
13719
13719
  fieldEnv.define("this", instance);
13720
+ if (classConstructor.__superClass) {
13721
+ fieldEnv.define("super", this.createSuperBinding(classConstructor.__superClass, instance, false));
13722
+ }
13720
13723
  const name = this.getClassFieldName(field, fieldEnv);
13721
13724
  instance[name] = field.value ? this.evaluate(field.value, fieldEnv) : void 0;
13722
13725
  }
@@ -13730,6 +13733,33 @@ var Interpreter = class _Interpreter {
13730
13733
  }
13731
13734
  return field.key.value;
13732
13735
  }
13736
+ createSuperBinding(superClass, thisContext, allowConstructor = false, afterSuper = null) {
13737
+ const superConstructor = (...superArgs) => {
13738
+ if (!allowConstructor) {
13739
+ throw new ReferenceError("'super' keyword is unexpected here");
13740
+ }
13741
+ const result = this.initializeSuperClass(superClass, thisContext, superArgs);
13742
+ if (afterSuper) {
13743
+ afterSuper();
13744
+ }
13745
+ return result && result.__explicitReturn ? result.value : void 0;
13746
+ };
13747
+ superConstructor.__isSuperConstructor = true;
13748
+ superConstructor.__superClass = superClass;
13749
+ return new Proxy(superConstructor, {
13750
+ get(target, prop, receiver) {
13751
+ if (prop in target) {
13752
+ return Reflect.get(target, prop, receiver);
13753
+ }
13754
+ const prototype = superClass == null ? void 0 : superClass.prototype;
13755
+ if (!prototype) {
13756
+ return void 0;
13757
+ }
13758
+ const value = Reflect.get(prototype, prop, thisContext);
13759
+ return typeof value === "function" ? value.bind(thisContext) : value;
13760
+ }
13761
+ });
13762
+ }
13733
13763
  createMethodFunction(funcNode, env, className) {
13734
13764
  const func = {
13735
13765
  __isFunction: true,
@@ -13744,16 +13774,7 @@ var Interpreter = class _Interpreter {
13744
13774
  const funcEnv = new Environment(methodFunc.__env || env);
13745
13775
  funcEnv.define("this", thisContext);
13746
13776
  if (superClass) {
13747
- const superFunc = (...superArgs) => {
13748
- const result2 = this.initializeSuperClass(superClass, thisContext, superArgs);
13749
- if (afterSuper) {
13750
- afterSuper();
13751
- }
13752
- return result2 && result2.__explicitReturn ? result2.value : void 0;
13753
- };
13754
- superFunc.__isSuperConstructor = true;
13755
- superFunc.__superClass = superClass;
13756
- funcEnv.define("super", superFunc);
13777
+ funcEnv.define("super", this.createSuperBinding(superClass, thisContext, true, afterSuper));
13757
13778
  }
13758
13779
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
13759
13780
  const result = this.evaluate(methodFunc.__body, funcEnv);
package/dist/index.d.cts CHANGED
@@ -14961,7 +14961,7 @@ class Interpreter {
14961
14961
  // Add methods to prototype
14962
14962
  for (const [name, method] of Object.entries(methods)) {
14963
14963
  classConstructor.prototype[name] = function(...args) {
14964
- const result = interpreter.callMethodFunction(method, this, args, env);
14964
+ const result = interpreter.callMethodFunction(method, this, args, env, superClass);
14965
14965
  // Unwrap explicit return marker
14966
14966
  if (result && result.__explicitReturn) {
14967
14967
  return result.value;
@@ -15034,6 +15034,9 @@ class Interpreter {
15034
15034
  for (const field of classConstructor.__instanceFields || []) {
15035
15035
  const fieldEnv = new Environment(env);
15036
15036
  fieldEnv.define('this', instance);
15037
+ if (classConstructor.__superClass) {
15038
+ fieldEnv.define('super', this.createSuperBinding(classConstructor.__superClass, instance, false));
15039
+ }
15037
15040
  const name = this.getClassFieldName(field, fieldEnv);
15038
15041
  instance[name] = field.value ? this.evaluate(field.value, fieldEnv) : undefined;
15039
15042
  }
@@ -15049,6 +15052,38 @@ class Interpreter {
15049
15052
  return field.key.value;
15050
15053
  }
15051
15054
 
15055
+ createSuperBinding(superClass, thisContext, allowConstructor = false, afterSuper = null) {
15056
+ const superConstructor = (...superArgs) => {
15057
+ if (!allowConstructor) {
15058
+ throw new ReferenceError("'super' keyword is unexpected here");
15059
+ }
15060
+ const result = this.initializeSuperClass(superClass, thisContext, superArgs);
15061
+ if (afterSuper) {
15062
+ afterSuper();
15063
+ }
15064
+ return result && result.__explicitReturn ? result.value : undefined;
15065
+ };
15066
+
15067
+ superConstructor.__isSuperConstructor = true;
15068
+ superConstructor.__superClass = superClass;
15069
+
15070
+ return new Proxy(superConstructor, {
15071
+ get(target, prop, receiver) {
15072
+ if (prop in target) {
15073
+ return Reflect.get(target, prop, receiver);
15074
+ }
15075
+
15076
+ const prototype = superClass?.prototype;
15077
+ if (!prototype) {
15078
+ return undefined;
15079
+ }
15080
+
15081
+ const value = Reflect.get(prototype, prop, thisContext);
15082
+ return typeof value === 'function' ? value.bind(thisContext) : value;
15083
+ }
15084
+ });
15085
+ }
15086
+
15052
15087
  createMethodFunction(funcNode, env, className) {
15053
15088
  const func = {
15054
15089
  __isFunction: true,
@@ -15068,18 +15103,7 @@ class Interpreter {
15068
15103
 
15069
15104
  // Bind 'super' if superClass exists
15070
15105
  if (superClass) {
15071
- // Create a super function that calls the parent constructor
15072
- const superFunc = (...superArgs) => {
15073
- const result = this.initializeSuperClass(superClass, thisContext, superArgs);
15074
- if (afterSuper) {
15075
- afterSuper();
15076
- }
15077
- return result && result.__explicitReturn ? result.value : undefined;
15078
- };
15079
- // Store both the function and mark it as super
15080
- superFunc.__isSuperConstructor = true;
15081
- superFunc.__superClass = superClass;
15082
- funcEnv.define('super', superFunc);
15106
+ funcEnv.define('super', this.createSuperBinding(superClass, thisContext, true, afterSuper));
15083
15107
  }
15084
15108
 
15085
15109
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
package/dist/index.d.ts CHANGED
@@ -14961,7 +14961,7 @@ class Interpreter {
14961
14961
  // Add methods to prototype
14962
14962
  for (const [name, method] of Object.entries(methods)) {
14963
14963
  classConstructor.prototype[name] = function(...args) {
14964
- const result = interpreter.callMethodFunction(method, this, args, env);
14964
+ const result = interpreter.callMethodFunction(method, this, args, env, superClass);
14965
14965
  // Unwrap explicit return marker
14966
14966
  if (result && result.__explicitReturn) {
14967
14967
  return result.value;
@@ -15034,6 +15034,9 @@ class Interpreter {
15034
15034
  for (const field of classConstructor.__instanceFields || []) {
15035
15035
  const fieldEnv = new Environment(env);
15036
15036
  fieldEnv.define('this', instance);
15037
+ if (classConstructor.__superClass) {
15038
+ fieldEnv.define('super', this.createSuperBinding(classConstructor.__superClass, instance, false));
15039
+ }
15037
15040
  const name = this.getClassFieldName(field, fieldEnv);
15038
15041
  instance[name] = field.value ? this.evaluate(field.value, fieldEnv) : undefined;
15039
15042
  }
@@ -15049,6 +15052,38 @@ class Interpreter {
15049
15052
  return field.key.value;
15050
15053
  }
15051
15054
 
15055
+ createSuperBinding(superClass, thisContext, allowConstructor = false, afterSuper = null) {
15056
+ const superConstructor = (...superArgs) => {
15057
+ if (!allowConstructor) {
15058
+ throw new ReferenceError("'super' keyword is unexpected here");
15059
+ }
15060
+ const result = this.initializeSuperClass(superClass, thisContext, superArgs);
15061
+ if (afterSuper) {
15062
+ afterSuper();
15063
+ }
15064
+ return result && result.__explicitReturn ? result.value : undefined;
15065
+ };
15066
+
15067
+ superConstructor.__isSuperConstructor = true;
15068
+ superConstructor.__superClass = superClass;
15069
+
15070
+ return new Proxy(superConstructor, {
15071
+ get(target, prop, receiver) {
15072
+ if (prop in target) {
15073
+ return Reflect.get(target, prop, receiver);
15074
+ }
15075
+
15076
+ const prototype = superClass?.prototype;
15077
+ if (!prototype) {
15078
+ return undefined;
15079
+ }
15080
+
15081
+ const value = Reflect.get(prototype, prop, thisContext);
15082
+ return typeof value === 'function' ? value.bind(thisContext) : value;
15083
+ }
15084
+ });
15085
+ }
15086
+
15052
15087
  createMethodFunction(funcNode, env, className) {
15053
15088
  const func = {
15054
15089
  __isFunction: true,
@@ -15068,18 +15103,7 @@ class Interpreter {
15068
15103
 
15069
15104
  // Bind 'super' if superClass exists
15070
15105
  if (superClass) {
15071
- // Create a super function that calls the parent constructor
15072
- const superFunc = (...superArgs) => {
15073
- const result = this.initializeSuperClass(superClass, thisContext, superArgs);
15074
- if (afterSuper) {
15075
- afterSuper();
15076
- }
15077
- return result && result.__explicitReturn ? result.value : undefined;
15078
- };
15079
- // Store both the function and mark it as super
15080
- superFunc.__isSuperConstructor = true;
15081
- superFunc.__superClass = superClass;
15082
- funcEnv.define('super', superFunc);
15106
+ funcEnv.define('super', this.createSuperBinding(superClass, thisContext, true, afterSuper));
15083
15107
  }
15084
15108
 
15085
15109
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
package/dist/index.js CHANGED
@@ -13624,7 +13624,7 @@ var Interpreter = class _Interpreter {
13624
13624
  }
13625
13625
  for (const [name, method] of Object.entries(methods)) {
13626
13626
  classConstructor.prototype[name] = function(...args) {
13627
- const result = interpreter.callMethodFunction(method, this, args, env);
13627
+ const result = interpreter.callMethodFunction(method, this, args, env, superClass);
13628
13628
  if (result && result.__explicitReturn) {
13629
13629
  return result.value;
13630
13630
  }
@@ -13683,6 +13683,9 @@ var Interpreter = class _Interpreter {
13683
13683
  for (const field of classConstructor.__instanceFields || []) {
13684
13684
  const fieldEnv = new Environment(env);
13685
13685
  fieldEnv.define("this", instance);
13686
+ if (classConstructor.__superClass) {
13687
+ fieldEnv.define("super", this.createSuperBinding(classConstructor.__superClass, instance, false));
13688
+ }
13686
13689
  const name = this.getClassFieldName(field, fieldEnv);
13687
13690
  instance[name] = field.value ? this.evaluate(field.value, fieldEnv) : void 0;
13688
13691
  }
@@ -13696,6 +13699,33 @@ var Interpreter = class _Interpreter {
13696
13699
  }
13697
13700
  return field.key.value;
13698
13701
  }
13702
+ createSuperBinding(superClass, thisContext, allowConstructor = false, afterSuper = null) {
13703
+ const superConstructor = (...superArgs) => {
13704
+ if (!allowConstructor) {
13705
+ throw new ReferenceError("'super' keyword is unexpected here");
13706
+ }
13707
+ const result = this.initializeSuperClass(superClass, thisContext, superArgs);
13708
+ if (afterSuper) {
13709
+ afterSuper();
13710
+ }
13711
+ return result && result.__explicitReturn ? result.value : void 0;
13712
+ };
13713
+ superConstructor.__isSuperConstructor = true;
13714
+ superConstructor.__superClass = superClass;
13715
+ return new Proxy(superConstructor, {
13716
+ get(target, prop, receiver) {
13717
+ if (prop in target) {
13718
+ return Reflect.get(target, prop, receiver);
13719
+ }
13720
+ const prototype = superClass == null ? void 0 : superClass.prototype;
13721
+ if (!prototype) {
13722
+ return void 0;
13723
+ }
13724
+ const value = Reflect.get(prototype, prop, thisContext);
13725
+ return typeof value === "function" ? value.bind(thisContext) : value;
13726
+ }
13727
+ });
13728
+ }
13699
13729
  createMethodFunction(funcNode, env, className) {
13700
13730
  const func = {
13701
13731
  __isFunction: true,
@@ -13710,16 +13740,7 @@ var Interpreter = class _Interpreter {
13710
13740
  const funcEnv = new Environment(methodFunc.__env || env);
13711
13741
  funcEnv.define("this", thisContext);
13712
13742
  if (superClass) {
13713
- const superFunc = (...superArgs) => {
13714
- const result2 = this.initializeSuperClass(superClass, thisContext, superArgs);
13715
- if (afterSuper) {
13716
- afterSuper();
13717
- }
13718
- return result2 && result2.__explicitReturn ? result2.value : void 0;
13719
- };
13720
- superFunc.__isSuperConstructor = true;
13721
- superFunc.__superClass = superClass;
13722
- funcEnv.define("super", superFunc);
13743
+ funcEnv.define("super", this.createSuperBinding(superClass, thisContext, true, afterSuper));
13723
13744
  }
13724
13745
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
13725
13746
  const result = this.evaluate(methodFunc.__body, funcEnv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jslike",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
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",