jslike 1.6.0 → 1.6.1

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.
@@ -1671,29 +1671,36 @@ export class Interpreter {
1671
1671
  throw new Error(`Cannot find module '${modulePath}'`);
1672
1672
  }
1673
1673
 
1674
- // Handle both old (string) and new (ModuleResolution) formats
1675
- const moduleCode = typeof resolution === 'string' ? resolution : resolution.code;
1676
-
1677
- // Parse and execute module in its own environment
1678
- const moduleAst = acornParse(moduleCode, {
1679
- ecmaVersion: 2020,
1680
- sourceType: 'module',
1681
- locations: false
1682
- });
1683
- const moduleEnv = new Environment(this.globalEnv);
1684
-
1685
- // Create a new interpreter for the module with shared module cache
1686
- const moduleInterpreter = new Interpreter(this.globalEnv, {
1687
- moduleResolver: this.moduleResolver
1688
- });
1689
- moduleInterpreter.moduleCache = this.moduleCache; // Share cache
1690
-
1691
- // Execute module and collect exports
1692
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
1693
-
1694
- // Cache the module exports
1695
- moduleExports = moduleInterpreter.moduleExports;
1696
- this.moduleCache.set(modulePath, moduleExports);
1674
+ // Handle native module exports (for libraries like React)
1675
+ // If resolution has 'exports' property, use it directly without parsing
1676
+ if (resolution.exports) {
1677
+ moduleExports = resolution.exports;
1678
+ this.moduleCache.set(modulePath, moduleExports);
1679
+ } else {
1680
+ // Handle both old (string) and new (ModuleResolution) formats
1681
+ const moduleCode = typeof resolution === 'string' ? resolution : resolution.code;
1682
+
1683
+ // Parse and execute module in its own environment
1684
+ const moduleAst = acornParse(moduleCode, {
1685
+ ecmaVersion: 2020,
1686
+ sourceType: 'module',
1687
+ locations: false
1688
+ });
1689
+ const moduleEnv = new Environment(this.globalEnv);
1690
+
1691
+ // Create a new interpreter for the module with shared module cache
1692
+ const moduleInterpreter = new Interpreter(this.globalEnv, {
1693
+ moduleResolver: this.moduleResolver
1694
+ });
1695
+ moduleInterpreter.moduleCache = this.moduleCache; // Share cache
1696
+
1697
+ // Execute module and collect exports
1698
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
1699
+
1700
+ // Cache the module exports
1701
+ moduleExports = moduleInterpreter.moduleExports;
1702
+ this.moduleCache.set(modulePath, moduleExports);
1703
+ }
1697
1704
  }
1698
1705
 
1699
1706
  // Import specified bindings into current environment
package/dist/index.cjs CHANGED
@@ -7765,20 +7765,25 @@ var Interpreter = class _Interpreter {
7765
7765
  if (!resolution) {
7766
7766
  throw new Error(`Cannot find module '${modulePath}'`);
7767
7767
  }
7768
- const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
7769
- const moduleAst = jsxParse(moduleCode, {
7770
- ecmaVersion: 2020,
7771
- sourceType: "module",
7772
- locations: false
7773
- });
7774
- const moduleEnv = new Environment(this.globalEnv);
7775
- const moduleInterpreter = new _Interpreter(this.globalEnv, {
7776
- moduleResolver: this.moduleResolver
7777
- });
7778
- moduleInterpreter.moduleCache = this.moduleCache;
7779
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
7780
- moduleExports = moduleInterpreter.moduleExports;
7781
- this.moduleCache.set(modulePath, moduleExports);
7768
+ if (resolution.exports) {
7769
+ moduleExports = resolution.exports;
7770
+ this.moduleCache.set(modulePath, moduleExports);
7771
+ } else {
7772
+ const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
7773
+ const moduleAst = jsxParse(moduleCode, {
7774
+ ecmaVersion: 2020,
7775
+ sourceType: "module",
7776
+ locations: false
7777
+ });
7778
+ const moduleEnv = new Environment(this.globalEnv);
7779
+ const moduleInterpreter = new _Interpreter(this.globalEnv, {
7780
+ moduleResolver: this.moduleResolver
7781
+ });
7782
+ moduleInterpreter.moduleCache = this.moduleCache;
7783
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
7784
+ moduleExports = moduleInterpreter.moduleExports;
7785
+ this.moduleCache.set(modulePath, moduleExports);
7786
+ }
7782
7787
  }
7783
7788
  for (const specifier of node.specifiers) {
7784
7789
  if (specifier.type === "ImportSpecifier") {
package/dist/index.d.cts CHANGED
@@ -8836,29 +8836,36 @@ class Interpreter {
8836
8836
  throw new Error(`Cannot find module '${modulePath}'`);
8837
8837
  }
8838
8838
 
8839
- // Handle both old (string) and new (ModuleResolution) formats
8840
- const moduleCode = typeof resolution === 'string' ? resolution : resolution.code;
8841
-
8842
- // Parse and execute module in its own environment
8843
- const moduleAst = jsxParse(moduleCode, {
8844
- ecmaVersion: 2020,
8845
- sourceType: 'module',
8846
- locations: false
8847
- });
8848
- const moduleEnv = new Environment(this.globalEnv);
8839
+ // Handle native module exports (for libraries like React)
8840
+ // If resolution has 'exports' property, use it directly without parsing
8841
+ if (resolution.exports) {
8842
+ moduleExports = resolution.exports;
8843
+ this.moduleCache.set(modulePath, moduleExports);
8844
+ } else {
8845
+ // Handle both old (string) and new (ModuleResolution) formats
8846
+ const moduleCode = typeof resolution === 'string' ? resolution : resolution.code;
8847
+
8848
+ // Parse and execute module in its own environment
8849
+ const moduleAst = jsxParse(moduleCode, {
8850
+ ecmaVersion: 2020,
8851
+ sourceType: 'module',
8852
+ locations: false
8853
+ });
8854
+ const moduleEnv = new Environment(this.globalEnv);
8849
8855
 
8850
- // Create a new interpreter for the module with shared module cache
8851
- const moduleInterpreter = new Interpreter(this.globalEnv, {
8852
- moduleResolver: this.moduleResolver
8853
- });
8854
- moduleInterpreter.moduleCache = this.moduleCache; // Share cache
8856
+ // Create a new interpreter for the module with shared module cache
8857
+ const moduleInterpreter = new Interpreter(this.globalEnv, {
8858
+ moduleResolver: this.moduleResolver
8859
+ });
8860
+ moduleInterpreter.moduleCache = this.moduleCache; // Share cache
8855
8861
 
8856
- // Execute module and collect exports
8857
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
8862
+ // Execute module and collect exports
8863
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
8858
8864
 
8859
- // Cache the module exports
8860
- moduleExports = moduleInterpreter.moduleExports;
8861
- this.moduleCache.set(modulePath, moduleExports);
8865
+ // Cache the module exports
8866
+ moduleExports = moduleInterpreter.moduleExports;
8867
+ this.moduleCache.set(modulePath, moduleExports);
8868
+ }
8862
8869
  }
8863
8870
 
8864
8871
  // Import specified bindings into current environment
package/dist/index.d.ts CHANGED
@@ -8836,29 +8836,36 @@ class Interpreter {
8836
8836
  throw new Error(`Cannot find module '${modulePath}'`);
8837
8837
  }
8838
8838
 
8839
- // Handle both old (string) and new (ModuleResolution) formats
8840
- const moduleCode = typeof resolution === 'string' ? resolution : resolution.code;
8841
-
8842
- // Parse and execute module in its own environment
8843
- const moduleAst = jsxParse(moduleCode, {
8844
- ecmaVersion: 2020,
8845
- sourceType: 'module',
8846
- locations: false
8847
- });
8848
- const moduleEnv = new Environment(this.globalEnv);
8839
+ // Handle native module exports (for libraries like React)
8840
+ // If resolution has 'exports' property, use it directly without parsing
8841
+ if (resolution.exports) {
8842
+ moduleExports = resolution.exports;
8843
+ this.moduleCache.set(modulePath, moduleExports);
8844
+ } else {
8845
+ // Handle both old (string) and new (ModuleResolution) formats
8846
+ const moduleCode = typeof resolution === 'string' ? resolution : resolution.code;
8847
+
8848
+ // Parse and execute module in its own environment
8849
+ const moduleAst = jsxParse(moduleCode, {
8850
+ ecmaVersion: 2020,
8851
+ sourceType: 'module',
8852
+ locations: false
8853
+ });
8854
+ const moduleEnv = new Environment(this.globalEnv);
8849
8855
 
8850
- // Create a new interpreter for the module with shared module cache
8851
- const moduleInterpreter = new Interpreter(this.globalEnv, {
8852
- moduleResolver: this.moduleResolver
8853
- });
8854
- moduleInterpreter.moduleCache = this.moduleCache; // Share cache
8856
+ // Create a new interpreter for the module with shared module cache
8857
+ const moduleInterpreter = new Interpreter(this.globalEnv, {
8858
+ moduleResolver: this.moduleResolver
8859
+ });
8860
+ moduleInterpreter.moduleCache = this.moduleCache; // Share cache
8855
8861
 
8856
- // Execute module and collect exports
8857
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
8862
+ // Execute module and collect exports
8863
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
8858
8864
 
8859
- // Cache the module exports
8860
- moduleExports = moduleInterpreter.moduleExports;
8861
- this.moduleCache.set(modulePath, moduleExports);
8865
+ // Cache the module exports
8866
+ moduleExports = moduleInterpreter.moduleExports;
8867
+ this.moduleCache.set(modulePath, moduleExports);
8868
+ }
8862
8869
  }
8863
8870
 
8864
8871
  // Import specified bindings into current environment
package/dist/index.js CHANGED
@@ -7731,20 +7731,25 @@ var Interpreter = class _Interpreter {
7731
7731
  if (!resolution) {
7732
7732
  throw new Error(`Cannot find module '${modulePath}'`);
7733
7733
  }
7734
- const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
7735
- const moduleAst = jsxParse(moduleCode, {
7736
- ecmaVersion: 2020,
7737
- sourceType: "module",
7738
- locations: false
7739
- });
7740
- const moduleEnv = new Environment(this.globalEnv);
7741
- const moduleInterpreter = new _Interpreter(this.globalEnv, {
7742
- moduleResolver: this.moduleResolver
7743
- });
7744
- moduleInterpreter.moduleCache = this.moduleCache;
7745
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
7746
- moduleExports = moduleInterpreter.moduleExports;
7747
- this.moduleCache.set(modulePath, moduleExports);
7734
+ if (resolution.exports) {
7735
+ moduleExports = resolution.exports;
7736
+ this.moduleCache.set(modulePath, moduleExports);
7737
+ } else {
7738
+ const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
7739
+ const moduleAst = jsxParse(moduleCode, {
7740
+ ecmaVersion: 2020,
7741
+ sourceType: "module",
7742
+ locations: false
7743
+ });
7744
+ const moduleEnv = new Environment(this.globalEnv);
7745
+ const moduleInterpreter = new _Interpreter(this.globalEnv, {
7746
+ moduleResolver: this.moduleResolver
7747
+ });
7748
+ moduleInterpreter.moduleCache = this.moduleCache;
7749
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
7750
+ moduleExports = moduleInterpreter.moduleExports;
7751
+ this.moduleCache.set(modulePath, moduleExports);
7752
+ }
7748
7753
  }
7749
7754
  for (const specifier of node.specifiers) {
7750
7755
  if (specifier.type === "ImportSpecifier") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jslike",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
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",