jslike 1.8.7 → 1.8.8

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/esm/index.js CHANGED
@@ -64,6 +64,7 @@ function containsModuleDeclarations(node) {
64
64
  if (!node || typeof node !== 'object') return false;
65
65
 
66
66
  if (node.type === 'ImportDeclaration' ||
67
+ node.type === 'TSImportEqualsDeclaration' ||
67
68
  node.type === 'ExportNamedDeclaration' ||
68
69
  node.type === 'ExportDefaultDeclaration' ||
69
70
  node.type === 'ExportAllDeclaration') {
@@ -470,10 +470,14 @@ export class Interpreter {
470
470
  return undefined;
471
471
  }
472
472
 
473
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
473
+ if (node.type === 'TSExportAssignment') {
474
474
  throw createUnsupportedTypeScriptRuntimeError(node);
475
475
  }
476
476
 
477
+ if (node.type === 'TSImportEqualsDeclaration') {
478
+ return await this.evaluateTSImportEqualsDeclaration(node, env);
479
+ }
480
+
477
481
  if (node.type === 'TSEnumDeclaration') {
478
482
  return this.evaluateTSEnumDeclaration(node, env);
479
483
  }
@@ -1148,10 +1152,14 @@ export class Interpreter {
1148
1152
  return undefined;
1149
1153
  }
1150
1154
 
1151
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
1155
+ if (node.type === 'TSExportAssignment') {
1152
1156
  throw createUnsupportedTypeScriptRuntimeError(node);
1153
1157
  }
1154
1158
 
1159
+ if (node.type === 'TSImportEqualsDeclaration') {
1160
+ return this.evaluateTSImportEqualsDeclaration(node, env);
1161
+ }
1162
+
1155
1163
  if (node.type === 'TSEnumDeclaration') {
1156
1164
  return this.evaluateTSEnumDeclaration(node, env);
1157
1165
  }
@@ -2269,6 +2277,13 @@ export class Interpreter {
2269
2277
  return undefined;
2270
2278
  }
2271
2279
 
2280
+ const moduleExports = await this.loadModuleExports(modulePath);
2281
+
2282
+ this.bindImportSpecifiers(node, env, modulePath, moduleExports);
2283
+ return undefined;
2284
+ }
2285
+
2286
+ async loadModuleExports(modulePath) {
2272
2287
  // Check if module resolver is configured
2273
2288
  if (!this.moduleResolver) {
2274
2289
  throw new Error('Module resolver not configured - cannot import modules');
@@ -2299,8 +2314,7 @@ export class Interpreter {
2299
2314
  : resolution.path || modulePath;
2300
2315
  this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
2301
2316
  if (this.moduleCache.has(resolvedPath)) {
2302
- moduleExports = this.moduleCache.get(resolvedPath);
2303
- return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
2317
+ return this.moduleCache.get(resolvedPath);
2304
2318
  }
2305
2319
 
2306
2320
  // Handle native module exports (for libraries like React)
@@ -2341,7 +2355,33 @@ export class Interpreter {
2341
2355
  }
2342
2356
  }
2343
2357
 
2344
- this.bindImportSpecifiers(node, env, modulePath, moduleExports);
2358
+ return moduleExports;
2359
+ }
2360
+
2361
+ async evaluateTSImportEqualsDeclaration(node, env) {
2362
+ if (node.importKind === 'type') {
2363
+ return undefined;
2364
+ }
2365
+
2366
+ const localName = node.id?.name;
2367
+ const moduleReference = node.moduleReference;
2368
+
2369
+ if (moduleReference?.type !== 'TSExternalModuleReference') {
2370
+ throw createUnsupportedTypeScriptRuntimeError(node);
2371
+ }
2372
+
2373
+ const modulePath = moduleReference.expression?.value;
2374
+ if (typeof modulePath !== 'string') {
2375
+ throw createUnsupportedTypeScriptRuntimeError(node);
2376
+ }
2377
+
2378
+ const moduleExports = await this.loadModuleExports(modulePath);
2379
+ env.define(localName, moduleExports);
2380
+
2381
+ if (node.isExport) {
2382
+ this.moduleExports[localName] = moduleExports;
2383
+ }
2384
+
2345
2385
  return undefined;
2346
2386
  }
2347
2387
 
package/dist/index.cjs CHANGED
@@ -11895,9 +11895,12 @@ var Interpreter = class _Interpreter {
11895
11895
  if (isTypeOnlyDeclaration(node)) {
11896
11896
  return void 0;
11897
11897
  }
11898
- if (node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration") {
11898
+ if (node.type === "TSExportAssignment") {
11899
11899
  throw createUnsupportedTypeScriptRuntimeError(node);
11900
11900
  }
11901
+ if (node.type === "TSImportEqualsDeclaration") {
11902
+ return await this.evaluateTSImportEqualsDeclaration(node, env);
11903
+ }
11901
11904
  if (node.type === "TSEnumDeclaration") {
11902
11905
  return this.evaluateTSEnumDeclaration(node, env);
11903
11906
  }
@@ -12438,9 +12441,12 @@ var Interpreter = class _Interpreter {
12438
12441
  if (isTypeOnlyDeclaration(node)) {
12439
12442
  return void 0;
12440
12443
  }
12441
- if (node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration") {
12444
+ if (node.type === "TSExportAssignment") {
12442
12445
  throw createUnsupportedTypeScriptRuntimeError(node);
12443
12446
  }
12447
+ if (node.type === "TSImportEqualsDeclaration") {
12448
+ return this.evaluateTSImportEqualsDeclaration(node, env);
12449
+ }
12444
12450
  if (node.type === "TSEnumDeclaration") {
12445
12451
  return this.evaluateTSEnumDeclaration(node, env);
12446
12452
  }
@@ -13295,6 +13301,11 @@ var Interpreter = class _Interpreter {
13295
13301
  if (this.isTypeScriptModule && node.specifiers.length > 0 && node.specifiers.every((specifier) => !this.isRuntimeImportSpecifier(specifier))) {
13296
13302
  return void 0;
13297
13303
  }
13304
+ const moduleExports = await this.loadModuleExports(modulePath);
13305
+ this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13306
+ return void 0;
13307
+ }
13308
+ async loadModuleExports(modulePath) {
13298
13309
  if (!this.moduleResolver) {
13299
13310
  throw new Error("Module resolver not configured - cannot import modules");
13300
13311
  }
@@ -13316,8 +13327,7 @@ var Interpreter = class _Interpreter {
13316
13327
  resolvedPath = typeof resolution === "string" ? modulePath : resolution.path || modulePath;
13317
13328
  this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
13318
13329
  if (this.moduleCache.has(resolvedPath)) {
13319
- moduleExports = this.moduleCache.get(resolvedPath);
13320
- return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13330
+ return this.moduleCache.get(resolvedPath);
13321
13331
  }
13322
13332
  if (resolution.exports) {
13323
13333
  moduleExports = resolution.exports;
@@ -13346,7 +13356,27 @@ var Interpreter = class _Interpreter {
13346
13356
  }
13347
13357
  }
13348
13358
  }
13349
- this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13359
+ return moduleExports;
13360
+ }
13361
+ async evaluateTSImportEqualsDeclaration(node, env) {
13362
+ var _a, _b;
13363
+ if (node.importKind === "type") {
13364
+ return void 0;
13365
+ }
13366
+ const localName = (_a = node.id) == null ? void 0 : _a.name;
13367
+ const moduleReference = node.moduleReference;
13368
+ if ((moduleReference == null ? void 0 : moduleReference.type) !== "TSExternalModuleReference") {
13369
+ throw createUnsupportedTypeScriptRuntimeError(node);
13370
+ }
13371
+ const modulePath = (_b = moduleReference.expression) == null ? void 0 : _b.value;
13372
+ if (typeof modulePath !== "string") {
13373
+ throw createUnsupportedTypeScriptRuntimeError(node);
13374
+ }
13375
+ const moduleExports = await this.loadModuleExports(modulePath);
13376
+ env.define(localName, moduleExports);
13377
+ if (node.isExport) {
13378
+ this.moduleExports[localName] = moduleExports;
13379
+ }
13350
13380
  return void 0;
13351
13381
  }
13352
13382
  bindImportSpecifiers(node, env, modulePath, moduleExports) {
@@ -14907,7 +14937,7 @@ function parse3(code, options = {}) {
14907
14937
  }
14908
14938
  function containsModuleDeclarations(node) {
14909
14939
  if (!node || typeof node !== "object") return false;
14910
- if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration") {
14940
+ if (node.type === "ImportDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration") {
14911
14941
  return true;
14912
14942
  }
14913
14943
  if (node.type === "Program" && node.body) {
package/dist/index.d.cts CHANGED
@@ -12663,10 +12663,14 @@ class Interpreter {
12663
12663
  return undefined;
12664
12664
  }
12665
12665
 
12666
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
12666
+ if (node.type === 'TSExportAssignment') {
12667
12667
  throw createUnsupportedTypeScriptRuntimeError(node);
12668
12668
  }
12669
12669
 
12670
+ if (node.type === 'TSImportEqualsDeclaration') {
12671
+ return await this.evaluateTSImportEqualsDeclaration(node, env);
12672
+ }
12673
+
12670
12674
  if (node.type === 'TSEnumDeclaration') {
12671
12675
  return this.evaluateTSEnumDeclaration(node, env);
12672
12676
  }
@@ -13341,10 +13345,14 @@ class Interpreter {
13341
13345
  return undefined;
13342
13346
  }
13343
13347
 
13344
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
13348
+ if (node.type === 'TSExportAssignment') {
13345
13349
  throw createUnsupportedTypeScriptRuntimeError(node);
13346
13350
  }
13347
13351
 
13352
+ if (node.type === 'TSImportEqualsDeclaration') {
13353
+ return this.evaluateTSImportEqualsDeclaration(node, env);
13354
+ }
13355
+
13348
13356
  if (node.type === 'TSEnumDeclaration') {
13349
13357
  return this.evaluateTSEnumDeclaration(node, env);
13350
13358
  }
@@ -14462,6 +14470,13 @@ class Interpreter {
14462
14470
  return undefined;
14463
14471
  }
14464
14472
 
14473
+ const moduleExports = await this.loadModuleExports(modulePath);
14474
+
14475
+ this.bindImportSpecifiers(node, env, modulePath, moduleExports);
14476
+ return undefined;
14477
+ }
14478
+
14479
+ async loadModuleExports(modulePath) {
14465
14480
  // Check if module resolver is configured
14466
14481
  if (!this.moduleResolver) {
14467
14482
  throw new Error('Module resolver not configured - cannot import modules');
@@ -14492,8 +14507,7 @@ class Interpreter {
14492
14507
  : resolution.path || modulePath;
14493
14508
  this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
14494
14509
  if (this.moduleCache.has(resolvedPath)) {
14495
- moduleExports = this.moduleCache.get(resolvedPath);
14496
- return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
14510
+ return this.moduleCache.get(resolvedPath);
14497
14511
  }
14498
14512
 
14499
14513
  // Handle native module exports (for libraries like React)
@@ -14534,7 +14548,33 @@ class Interpreter {
14534
14548
  }
14535
14549
  }
14536
14550
 
14537
- this.bindImportSpecifiers(node, env, modulePath, moduleExports);
14551
+ return moduleExports;
14552
+ }
14553
+
14554
+ async evaluateTSImportEqualsDeclaration(node, env) {
14555
+ if (node.importKind === 'type') {
14556
+ return undefined;
14557
+ }
14558
+
14559
+ const localName = node.id?.name;
14560
+ const moduleReference = node.moduleReference;
14561
+
14562
+ if (moduleReference?.type !== 'TSExternalModuleReference') {
14563
+ throw createUnsupportedTypeScriptRuntimeError(node);
14564
+ }
14565
+
14566
+ const modulePath = moduleReference.expression?.value;
14567
+ if (typeof modulePath !== 'string') {
14568
+ throw createUnsupportedTypeScriptRuntimeError(node);
14569
+ }
14570
+
14571
+ const moduleExports = await this.loadModuleExports(modulePath);
14572
+ env.define(localName, moduleExports);
14573
+
14574
+ if (node.isExport) {
14575
+ this.moduleExports[localName] = moduleExports;
14576
+ }
14577
+
14538
14578
  return undefined;
14539
14579
  }
14540
14580
 
@@ -16544,6 +16584,7 @@ function containsModuleDeclarations(node) {
16544
16584
  if (!node || typeof node !== 'object') return false;
16545
16585
 
16546
16586
  if (node.type === 'ImportDeclaration' ||
16587
+ node.type === 'TSImportEqualsDeclaration' ||
16547
16588
  node.type === 'ExportNamedDeclaration' ||
16548
16589
  node.type === 'ExportDefaultDeclaration' ||
16549
16590
  node.type === 'ExportAllDeclaration') {
package/dist/index.d.ts CHANGED
@@ -12663,10 +12663,14 @@ class Interpreter {
12663
12663
  return undefined;
12664
12664
  }
12665
12665
 
12666
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
12666
+ if (node.type === 'TSExportAssignment') {
12667
12667
  throw createUnsupportedTypeScriptRuntimeError(node);
12668
12668
  }
12669
12669
 
12670
+ if (node.type === 'TSImportEqualsDeclaration') {
12671
+ return await this.evaluateTSImportEqualsDeclaration(node, env);
12672
+ }
12673
+
12670
12674
  if (node.type === 'TSEnumDeclaration') {
12671
12675
  return this.evaluateTSEnumDeclaration(node, env);
12672
12676
  }
@@ -13341,10 +13345,14 @@ class Interpreter {
13341
13345
  return undefined;
13342
13346
  }
13343
13347
 
13344
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
13348
+ if (node.type === 'TSExportAssignment') {
13345
13349
  throw createUnsupportedTypeScriptRuntimeError(node);
13346
13350
  }
13347
13351
 
13352
+ if (node.type === 'TSImportEqualsDeclaration') {
13353
+ return this.evaluateTSImportEqualsDeclaration(node, env);
13354
+ }
13355
+
13348
13356
  if (node.type === 'TSEnumDeclaration') {
13349
13357
  return this.evaluateTSEnumDeclaration(node, env);
13350
13358
  }
@@ -14462,6 +14470,13 @@ class Interpreter {
14462
14470
  return undefined;
14463
14471
  }
14464
14472
 
14473
+ const moduleExports = await this.loadModuleExports(modulePath);
14474
+
14475
+ this.bindImportSpecifiers(node, env, modulePath, moduleExports);
14476
+ return undefined;
14477
+ }
14478
+
14479
+ async loadModuleExports(modulePath) {
14465
14480
  // Check if module resolver is configured
14466
14481
  if (!this.moduleResolver) {
14467
14482
  throw new Error('Module resolver not configured - cannot import modules');
@@ -14492,8 +14507,7 @@ class Interpreter {
14492
14507
  : resolution.path || modulePath;
14493
14508
  this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
14494
14509
  if (this.moduleCache.has(resolvedPath)) {
14495
- moduleExports = this.moduleCache.get(resolvedPath);
14496
- return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
14510
+ return this.moduleCache.get(resolvedPath);
14497
14511
  }
14498
14512
 
14499
14513
  // Handle native module exports (for libraries like React)
@@ -14534,7 +14548,33 @@ class Interpreter {
14534
14548
  }
14535
14549
  }
14536
14550
 
14537
- this.bindImportSpecifiers(node, env, modulePath, moduleExports);
14551
+ return moduleExports;
14552
+ }
14553
+
14554
+ async evaluateTSImportEqualsDeclaration(node, env) {
14555
+ if (node.importKind === 'type') {
14556
+ return undefined;
14557
+ }
14558
+
14559
+ const localName = node.id?.name;
14560
+ const moduleReference = node.moduleReference;
14561
+
14562
+ if (moduleReference?.type !== 'TSExternalModuleReference') {
14563
+ throw createUnsupportedTypeScriptRuntimeError(node);
14564
+ }
14565
+
14566
+ const modulePath = moduleReference.expression?.value;
14567
+ if (typeof modulePath !== 'string') {
14568
+ throw createUnsupportedTypeScriptRuntimeError(node);
14569
+ }
14570
+
14571
+ const moduleExports = await this.loadModuleExports(modulePath);
14572
+ env.define(localName, moduleExports);
14573
+
14574
+ if (node.isExport) {
14575
+ this.moduleExports[localName] = moduleExports;
14576
+ }
14577
+
14538
14578
  return undefined;
14539
14579
  }
14540
14580
 
@@ -16544,6 +16584,7 @@ function containsModuleDeclarations(node) {
16544
16584
  if (!node || typeof node !== 'object') return false;
16545
16585
 
16546
16586
  if (node.type === 'ImportDeclaration' ||
16587
+ node.type === 'TSImportEqualsDeclaration' ||
16547
16588
  node.type === 'ExportNamedDeclaration' ||
16548
16589
  node.type === 'ExportDefaultDeclaration' ||
16549
16590
  node.type === 'ExportAllDeclaration') {
package/dist/index.js CHANGED
@@ -11861,9 +11861,12 @@ var Interpreter = class _Interpreter {
11861
11861
  if (isTypeOnlyDeclaration(node)) {
11862
11862
  return void 0;
11863
11863
  }
11864
- if (node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration") {
11864
+ if (node.type === "TSExportAssignment") {
11865
11865
  throw createUnsupportedTypeScriptRuntimeError(node);
11866
11866
  }
11867
+ if (node.type === "TSImportEqualsDeclaration") {
11868
+ return await this.evaluateTSImportEqualsDeclaration(node, env);
11869
+ }
11867
11870
  if (node.type === "TSEnumDeclaration") {
11868
11871
  return this.evaluateTSEnumDeclaration(node, env);
11869
11872
  }
@@ -12404,9 +12407,12 @@ var Interpreter = class _Interpreter {
12404
12407
  if (isTypeOnlyDeclaration(node)) {
12405
12408
  return void 0;
12406
12409
  }
12407
- if (node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration") {
12410
+ if (node.type === "TSExportAssignment") {
12408
12411
  throw createUnsupportedTypeScriptRuntimeError(node);
12409
12412
  }
12413
+ if (node.type === "TSImportEqualsDeclaration") {
12414
+ return this.evaluateTSImportEqualsDeclaration(node, env);
12415
+ }
12410
12416
  if (node.type === "TSEnumDeclaration") {
12411
12417
  return this.evaluateTSEnumDeclaration(node, env);
12412
12418
  }
@@ -13261,6 +13267,11 @@ var Interpreter = class _Interpreter {
13261
13267
  if (this.isTypeScriptModule && node.specifiers.length > 0 && node.specifiers.every((specifier) => !this.isRuntimeImportSpecifier(specifier))) {
13262
13268
  return void 0;
13263
13269
  }
13270
+ const moduleExports = await this.loadModuleExports(modulePath);
13271
+ this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13272
+ return void 0;
13273
+ }
13274
+ async loadModuleExports(modulePath) {
13264
13275
  if (!this.moduleResolver) {
13265
13276
  throw new Error("Module resolver not configured - cannot import modules");
13266
13277
  }
@@ -13282,8 +13293,7 @@ var Interpreter = class _Interpreter {
13282
13293
  resolvedPath = typeof resolution === "string" ? modulePath : resolution.path || modulePath;
13283
13294
  this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
13284
13295
  if (this.moduleCache.has(resolvedPath)) {
13285
- moduleExports = this.moduleCache.get(resolvedPath);
13286
- return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13296
+ return this.moduleCache.get(resolvedPath);
13287
13297
  }
13288
13298
  if (resolution.exports) {
13289
13299
  moduleExports = resolution.exports;
@@ -13312,7 +13322,27 @@ var Interpreter = class _Interpreter {
13312
13322
  }
13313
13323
  }
13314
13324
  }
13315
- this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13325
+ return moduleExports;
13326
+ }
13327
+ async evaluateTSImportEqualsDeclaration(node, env) {
13328
+ var _a, _b;
13329
+ if (node.importKind === "type") {
13330
+ return void 0;
13331
+ }
13332
+ const localName = (_a = node.id) == null ? void 0 : _a.name;
13333
+ const moduleReference = node.moduleReference;
13334
+ if ((moduleReference == null ? void 0 : moduleReference.type) !== "TSExternalModuleReference") {
13335
+ throw createUnsupportedTypeScriptRuntimeError(node);
13336
+ }
13337
+ const modulePath = (_b = moduleReference.expression) == null ? void 0 : _b.value;
13338
+ if (typeof modulePath !== "string") {
13339
+ throw createUnsupportedTypeScriptRuntimeError(node);
13340
+ }
13341
+ const moduleExports = await this.loadModuleExports(modulePath);
13342
+ env.define(localName, moduleExports);
13343
+ if (node.isExport) {
13344
+ this.moduleExports[localName] = moduleExports;
13345
+ }
13316
13346
  return void 0;
13317
13347
  }
13318
13348
  bindImportSpecifiers(node, env, modulePath, moduleExports) {
@@ -14873,7 +14903,7 @@ function parse3(code, options = {}) {
14873
14903
  }
14874
14904
  function containsModuleDeclarations(node) {
14875
14905
  if (!node || typeof node !== "object") return false;
14876
- if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration") {
14906
+ if (node.type === "ImportDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration") {
14877
14907
  return true;
14878
14908
  }
14879
14909
  if (node.type === "Program" && node.body) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jslike",
3
- "version": "1.8.7",
3
+ "version": "1.8.8",
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",