jslike 1.8.7 → 1.8.10

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') {
@@ -2,6 +2,20 @@ import { Environment, ReturnValue, BreakSignal, ContinueSignal, ThrowSignal } fr
2
2
  import { parse as acornParse, tsParse, tsxParse } from '../parser.js';
3
3
  import { createMethodNotFoundError } from '../errors/enhanced-error.js';
4
4
 
5
+ const ASYNC_EXPRESSION_COMPLETION = Symbol('jslike.asyncExpressionCompletion');
6
+
7
+ function createAsyncExpressionCompletion(value) {
8
+ return { [ASYNC_EXPRESSION_COMPLETION]: true, value };
9
+ }
10
+
11
+ function isAsyncExpressionCompletion(value) {
12
+ return value && value[ASYNC_EXPRESSION_COMPLETION] === true;
13
+ }
14
+
15
+ function unwrapAsyncExpressionCompletion(value) {
16
+ return isAsyncExpressionCompletion(value) ? value.value : value;
17
+ }
18
+
5
19
  function isTypeScriptPath(sourcePath) {
6
20
  return typeof sourcePath === 'string' && /\.(ts|tsx|mts|cts)$/i.test(sourcePath);
7
21
  }
@@ -398,6 +412,45 @@ export class Interpreter {
398
412
  return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
399
413
  }
400
414
 
415
+ if (node.type === 'AssignmentExpression') {
416
+ const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
417
+
418
+ if (node.left.type === 'Identifier') {
419
+ const name = node.left.name;
420
+ if (node.operator === '=') {
421
+ if (env.has(name)) {
422
+ env.set(name, value);
423
+ } else {
424
+ env.define(name, value);
425
+ }
426
+ return { value };
427
+ }
428
+
429
+ const current = env.get(name);
430
+ const newValue = this.applyCompoundAssignment(node.operator, current, value);
431
+ env.set(name, newValue);
432
+ return { value: newValue };
433
+ }
434
+
435
+ if (node.left.type === 'MemberExpression') {
436
+ const obj = await this.evaluateAsync(node.left.object, env);
437
+ const prop = node.left.computed
438
+ ? await this.evaluateAsync(node.left.property, env)
439
+ : node.left.property.name;
440
+
441
+ if (node.operator === '=') {
442
+ obj[prop] = value;
443
+ return { value };
444
+ }
445
+
446
+ const newValue = this.applyCompoundAssignment(node.operator, obj[prop], value);
447
+ obj[prop] = newValue;
448
+ return { value: newValue };
449
+ }
450
+
451
+ throw new Error('Invalid assignment target');
452
+ }
453
+
401
454
  if (node.type === 'NewExpression') {
402
455
  return { value: this.evaluateNewExpression(node, env) };
403
456
  }
@@ -437,7 +490,7 @@ export class Interpreter {
437
490
 
438
491
  const rawArgs = [];
439
492
  for (const arg of node.arguments) {
440
- rawArgs.push(await this.evaluateAsync(arg, env));
493
+ rawArgs.push((await this.evaluateAsyncRawValue(arg, env)).value);
441
494
  }
442
495
  const args = this.flattenSpreadArgs(rawArgs);
443
496
 
@@ -470,10 +523,14 @@ export class Interpreter {
470
523
  return undefined;
471
524
  }
472
525
 
473
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
526
+ if (node.type === 'TSExportAssignment') {
474
527
  throw createUnsupportedTypeScriptRuntimeError(node);
475
528
  }
476
529
 
530
+ if (node.type === 'TSImportEqualsDeclaration') {
531
+ return await this.evaluateTSImportEqualsDeclaration(node, env);
532
+ }
533
+
477
534
  if (node.type === 'TSEnumDeclaration') {
478
535
  return this.evaluateTSEnumDeclaration(node, env);
479
536
  }
@@ -509,7 +566,7 @@ export class Interpreter {
509
566
 
510
567
  // For expression statements, evaluate the expression async
511
568
  if (node.type === 'ExpressionStatement') {
512
- return await this.evaluateAsync(node.expression, env);
569
+ return createAsyncExpressionCompletion((await this.evaluateAsyncRawValue(node.expression, env)).value);
513
570
  }
514
571
 
515
572
  // For variable declarations with await in init
@@ -544,7 +601,7 @@ export class Interpreter {
544
601
  return result;
545
602
  }
546
603
  }
547
- return result;
604
+ return unwrapAsyncExpressionCompletion(result);
548
605
  } finally {
549
606
  this.runtimeIdentifierReferences = previousReferences;
550
607
  }
@@ -1022,7 +1079,7 @@ export class Interpreter {
1022
1079
  throw new TypeError('Spread syntax requires an iterable');
1023
1080
  }
1024
1081
  } else {
1025
- result.push(await this.evaluateAsync(elem, env));
1082
+ result.push((await this.evaluateAsyncRawValue(elem, env)).value);
1026
1083
  }
1027
1084
  }
1028
1085
  return result;
@@ -1041,7 +1098,7 @@ export class Interpreter {
1041
1098
  const key = prop.key.type === 'Identifier' && !prop.computed
1042
1099
  ? prop.key.name
1043
1100
  : await this.evaluateAsync(prop.key, env);
1044
- const value = prop.value ? await this.evaluateAsync(prop.value, env) : env.get(key);
1101
+ const value = prop.value ? (await this.evaluateAsyncRawValue(prop.value, env)).value : env.get(key);
1045
1102
  if (prop.method && prop.value.type === 'FunctionExpression') {
1046
1103
  obj[key] = (...args) => {
1047
1104
  const funcValue = this.evaluate(prop.value, env);
@@ -1148,10 +1205,14 @@ export class Interpreter {
1148
1205
  return undefined;
1149
1206
  }
1150
1207
 
1151
- if (node.type === 'TSExportAssignment' || node.type === 'TSImportEqualsDeclaration') {
1208
+ if (node.type === 'TSExportAssignment') {
1152
1209
  throw createUnsupportedTypeScriptRuntimeError(node);
1153
1210
  }
1154
1211
 
1212
+ if (node.type === 'TSImportEqualsDeclaration') {
1213
+ return this.evaluateTSImportEqualsDeclaration(node, env);
1214
+ }
1215
+
1155
1216
  if (node.type === 'TSEnumDeclaration') {
1156
1217
  return this.evaluateTSEnumDeclaration(node, env);
1157
1218
  }
@@ -2269,6 +2330,13 @@ export class Interpreter {
2269
2330
  return undefined;
2270
2331
  }
2271
2332
 
2333
+ const moduleExports = await this.loadModuleExports(modulePath);
2334
+
2335
+ this.bindImportSpecifiers(node, env, modulePath, moduleExports);
2336
+ return undefined;
2337
+ }
2338
+
2339
+ async loadModuleExports(modulePath) {
2272
2340
  // Check if module resolver is configured
2273
2341
  if (!this.moduleResolver) {
2274
2342
  throw new Error('Module resolver not configured - cannot import modules');
@@ -2299,8 +2367,7 @@ export class Interpreter {
2299
2367
  : resolution.path || modulePath;
2300
2368
  this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
2301
2369
  if (this.moduleCache.has(resolvedPath)) {
2302
- moduleExports = this.moduleCache.get(resolvedPath);
2303
- return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
2370
+ return this.moduleCache.get(resolvedPath);
2304
2371
  }
2305
2372
 
2306
2373
  // Handle native module exports (for libraries like React)
@@ -2341,7 +2408,33 @@ export class Interpreter {
2341
2408
  }
2342
2409
  }
2343
2410
 
2344
- this.bindImportSpecifiers(node, env, modulePath, moduleExports);
2411
+ return moduleExports;
2412
+ }
2413
+
2414
+ async evaluateTSImportEqualsDeclaration(node, env) {
2415
+ if (node.importKind === 'type') {
2416
+ return undefined;
2417
+ }
2418
+
2419
+ const localName = node.id?.name;
2420
+ const moduleReference = node.moduleReference;
2421
+
2422
+ if (moduleReference?.type !== 'TSExternalModuleReference') {
2423
+ throw createUnsupportedTypeScriptRuntimeError(node);
2424
+ }
2425
+
2426
+ const modulePath = moduleReference.expression?.value;
2427
+ if (typeof modulePath !== 'string') {
2428
+ throw createUnsupportedTypeScriptRuntimeError(node);
2429
+ }
2430
+
2431
+ const moduleExports = await this.loadModuleExports(modulePath);
2432
+ env.define(localName, moduleExports);
2433
+
2434
+ if (node.isExport) {
2435
+ this.moduleExports[localName] = moduleExports;
2436
+ }
2437
+
2345
2438
  return undefined;
2346
2439
  }
2347
2440
 
@@ -2361,7 +2454,7 @@ export class Interpreter {
2361
2454
  throw new Error(`Module '${modulePath}' has no export '${importedName}'`);
2362
2455
  }
2363
2456
 
2364
- env.define(localName, moduleExports[importedName]);
2457
+ env.defineLive(localName, () => moduleExports[importedName]);
2365
2458
  } else if (specifier.type === 'ImportDefaultSpecifier') {
2366
2459
  // Default import: import foo from "module"
2367
2460
  const localName = specifier.local.name;
@@ -2370,7 +2463,7 @@ export class Interpreter {
2370
2463
  throw new Error(`Module '${modulePath}' has no default export`);
2371
2464
  }
2372
2465
 
2373
- env.define(localName, moduleExports.default);
2466
+ env.defineLive(localName, () => moduleExports.default);
2374
2467
  } else if (specifier.type === 'ImportNamespaceSpecifier') {
2375
2468
  // Namespace import: import * as foo from "module"
2376
2469
  const localName = specifier.local.name;
@@ -4,17 +4,19 @@ export class Environment {
4
4
  constructor(parent = null) {
5
5
  this.parent = parent;
6
6
  this.vars = new Map();
7
+ this.liveBindings = new Map();
7
8
  this.consts = new Set(); // Track const variables
8
9
  }
9
10
 
10
11
  define(name, value, isConst = false) {
11
- if (this.vars.has(name)) {
12
+ if (this.vars.has(name) || this.liveBindings.has(name)) {
12
13
  // Allow redeclaration for non-const (REPL-style behavior)
13
14
  // But cannot redeclare a const
14
15
  if (this.consts.has(name)) {
15
16
  throw new Error(`Cannot redeclare const '${name}'`);
16
17
  }
17
18
  // Update existing variable
19
+ this.liveBindings.delete(name);
18
20
  this.vars.set(name, value);
19
21
  if (isConst) {
20
22
  this.consts.add(name);
@@ -28,7 +30,24 @@ export class Environment {
28
30
  return value;
29
31
  }
30
32
 
33
+ defineLive(name, getter, isConst = true) {
34
+ if (this.vars.has(name) || this.liveBindings.has(name)) {
35
+ if (this.consts.has(name)) {
36
+ throw new Error(`Cannot redeclare const '${name}'`);
37
+ }
38
+ this.vars.delete(name);
39
+ }
40
+ this.liveBindings.set(name, getter);
41
+ if (isConst) {
42
+ this.consts.add(name);
43
+ }
44
+ return getter();
45
+ }
46
+
31
47
  get(name) {
48
+ if (this.liveBindings.has(name)) {
49
+ return this.liveBindings.get(name)();
50
+ }
32
51
  if (this.vars.has(name)) {
33
52
  return this.vars.get(name);
34
53
  }
@@ -39,11 +58,12 @@ export class Environment {
39
58
  }
40
59
 
41
60
  set(name, value) {
42
- if (this.vars.has(name)) {
61
+ if (this.vars.has(name) || this.liveBindings.has(name)) {
43
62
  // Check if trying to reassign a const variable
44
63
  if (this.consts.has(name)) {
45
64
  throw new TypeError(`Cannot reassign const variable '${name}'`);
46
65
  }
66
+ this.liveBindings.delete(name);
47
67
  this.vars.set(name, value);
48
68
  return value;
49
69
  }
@@ -54,7 +74,7 @@ export class Environment {
54
74
  }
55
75
 
56
76
  has(name) {
57
- return this.vars.has(name) || (this.parent ? this.parent.has(name) : false);
77
+ return this.vars.has(name) || this.liveBindings.has(name) || (this.parent ? this.parent.has(name) : false);
58
78
  }
59
79
 
60
80
  // For let/const block scoping
package/dist/index.cjs CHANGED
@@ -11320,13 +11320,15 @@ var Environment = class _Environment {
11320
11320
  constructor(parent = null) {
11321
11321
  this.parent = parent;
11322
11322
  this.vars = /* @__PURE__ */ new Map();
11323
+ this.liveBindings = /* @__PURE__ */ new Map();
11323
11324
  this.consts = /* @__PURE__ */ new Set();
11324
11325
  }
11325
11326
  define(name, value, isConst = false) {
11326
- if (this.vars.has(name)) {
11327
+ if (this.vars.has(name) || this.liveBindings.has(name)) {
11327
11328
  if (this.consts.has(name)) {
11328
11329
  throw new Error(`Cannot redeclare const '${name}'`);
11329
11330
  }
11331
+ this.liveBindings.delete(name);
11330
11332
  this.vars.set(name, value);
11331
11333
  if (isConst) {
11332
11334
  this.consts.add(name);
@@ -11339,7 +11341,23 @@ var Environment = class _Environment {
11339
11341
  }
11340
11342
  return value;
11341
11343
  }
11344
+ defineLive(name, getter, isConst = true) {
11345
+ if (this.vars.has(name) || this.liveBindings.has(name)) {
11346
+ if (this.consts.has(name)) {
11347
+ throw new Error(`Cannot redeclare const '${name}'`);
11348
+ }
11349
+ this.vars.delete(name);
11350
+ }
11351
+ this.liveBindings.set(name, getter);
11352
+ if (isConst) {
11353
+ this.consts.add(name);
11354
+ }
11355
+ return getter();
11356
+ }
11342
11357
  get(name) {
11358
+ if (this.liveBindings.has(name)) {
11359
+ return this.liveBindings.get(name)();
11360
+ }
11343
11361
  if (this.vars.has(name)) {
11344
11362
  return this.vars.get(name);
11345
11363
  }
@@ -11349,10 +11367,11 @@ var Environment = class _Environment {
11349
11367
  throw new ReferenceError(`Variable "${name}" is not defined`);
11350
11368
  }
11351
11369
  set(name, value) {
11352
- if (this.vars.has(name)) {
11370
+ if (this.vars.has(name) || this.liveBindings.has(name)) {
11353
11371
  if (this.consts.has(name)) {
11354
11372
  throw new TypeError(`Cannot reassign const variable '${name}'`);
11355
11373
  }
11374
+ this.liveBindings.delete(name);
11356
11375
  this.vars.set(name, value);
11357
11376
  return value;
11358
11377
  }
@@ -11362,7 +11381,7 @@ var Environment = class _Environment {
11362
11381
  throw new ReferenceError(`Variable "${name}" is not defined`);
11363
11382
  }
11364
11383
  has(name) {
11365
- return this.vars.has(name) || (this.parent ? this.parent.has(name) : false);
11384
+ return this.vars.has(name) || this.liveBindings.has(name) || (this.parent ? this.parent.has(name) : false);
11366
11385
  }
11367
11386
  // For let/const block scoping
11368
11387
  extend() {
@@ -11503,6 +11522,16 @@ function createMethodNotFoundError(objectName, methodName, objectValue) {
11503
11522
  }
11504
11523
 
11505
11524
  // src/interpreter/interpreter.js
11525
+ var ASYNC_EXPRESSION_COMPLETION = Symbol("jslike.asyncExpressionCompletion");
11526
+ function createAsyncExpressionCompletion(value) {
11527
+ return { [ASYNC_EXPRESSION_COMPLETION]: true, value };
11528
+ }
11529
+ function isAsyncExpressionCompletion(value) {
11530
+ return value && value[ASYNC_EXPRESSION_COMPLETION] === true;
11531
+ }
11532
+ function unwrapAsyncExpressionCompletion(value) {
11533
+ return isAsyncExpressionCompletion(value) ? value.value : value;
11534
+ }
11506
11535
  function isTypeScriptPath(sourcePath) {
11507
11536
  return typeof sourcePath === "string" && /\.(ts|tsx|mts|cts)$/i.test(sourcePath);
11508
11537
  }
@@ -11843,6 +11872,36 @@ var Interpreter = class _Interpreter {
11843
11872
  }
11844
11873
  return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
11845
11874
  }
11875
+ if (node.type === "AssignmentExpression") {
11876
+ const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
11877
+ if (node.left.type === "Identifier") {
11878
+ const name = node.left.name;
11879
+ if (node.operator === "=") {
11880
+ if (env.has(name)) {
11881
+ env.set(name, value);
11882
+ } else {
11883
+ env.define(name, value);
11884
+ }
11885
+ return { value };
11886
+ }
11887
+ const current2 = env.get(name);
11888
+ const newValue = this.applyCompoundAssignment(node.operator, current2, value);
11889
+ env.set(name, newValue);
11890
+ return { value: newValue };
11891
+ }
11892
+ if (node.left.type === "MemberExpression") {
11893
+ const obj = await this.evaluateAsync(node.left.object, env);
11894
+ const prop = node.left.computed ? await this.evaluateAsync(node.left.property, env) : node.left.property.name;
11895
+ if (node.operator === "=") {
11896
+ obj[prop] = value;
11897
+ return { value };
11898
+ }
11899
+ const newValue = this.applyCompoundAssignment(node.operator, obj[prop], value);
11900
+ obj[prop] = newValue;
11901
+ return { value: newValue };
11902
+ }
11903
+ throw new Error("Invalid assignment target");
11904
+ }
11846
11905
  if (node.type === "NewExpression") {
11847
11906
  return { value: this.evaluateNewExpression(node, env) };
11848
11907
  }
@@ -11873,7 +11932,7 @@ var Interpreter = class _Interpreter {
11873
11932
  }
11874
11933
  const rawArgs = [];
11875
11934
  for (const arg of node.arguments) {
11876
- rawArgs.push(await this.evaluateAsync(arg, env));
11935
+ rawArgs.push((await this.evaluateAsyncRawValue(arg, env)).value);
11877
11936
  }
11878
11937
  const args = this.flattenSpreadArgs(rawArgs);
11879
11938
  if (typeof callee === "function") {
@@ -11895,9 +11954,12 @@ var Interpreter = class _Interpreter {
11895
11954
  if (isTypeOnlyDeclaration(node)) {
11896
11955
  return void 0;
11897
11956
  }
11898
- if (node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration") {
11957
+ if (node.type === "TSExportAssignment") {
11899
11958
  throw createUnsupportedTypeScriptRuntimeError(node);
11900
11959
  }
11960
+ if (node.type === "TSImportEqualsDeclaration") {
11961
+ return await this.evaluateTSImportEqualsDeclaration(node, env);
11962
+ }
11901
11963
  if (node.type === "TSEnumDeclaration") {
11902
11964
  return this.evaluateTSEnumDeclaration(node, env);
11903
11965
  }
@@ -11924,7 +11986,7 @@ var Interpreter = class _Interpreter {
11924
11986
  return result;
11925
11987
  }
11926
11988
  if (node.type === "ExpressionStatement") {
11927
- return await this.evaluateAsync(node.expression, env);
11989
+ return createAsyncExpressionCompletion((await this.evaluateAsyncRawValue(node.expression, env)).value);
11928
11990
  }
11929
11991
  if (node.type === "VariableDeclaration") {
11930
11992
  for (const declarator of node.declarations) {
@@ -11951,7 +12013,7 @@ var Interpreter = class _Interpreter {
11951
12013
  return result;
11952
12014
  }
11953
12015
  }
11954
- return result;
12016
+ return unwrapAsyncExpressionCompletion(result);
11955
12017
  } finally {
11956
12018
  this.runtimeIdentifierReferences = previousReferences;
11957
12019
  }
@@ -12338,7 +12400,7 @@ var Interpreter = class _Interpreter {
12338
12400
  throw new TypeError("Spread syntax requires an iterable");
12339
12401
  }
12340
12402
  } else {
12341
- result.push(await this.evaluateAsync(elem, env));
12403
+ result.push((await this.evaluateAsyncRawValue(elem, env)).value);
12342
12404
  }
12343
12405
  }
12344
12406
  return result;
@@ -12353,7 +12415,7 @@ var Interpreter = class _Interpreter {
12353
12415
  }
12354
12416
  } else {
12355
12417
  const key = prop.key.type === "Identifier" && !prop.computed ? prop.key.name : await this.evaluateAsync(prop.key, env);
12356
- const value = prop.value ? await this.evaluateAsync(prop.value, env) : env.get(key);
12418
+ const value = prop.value ? (await this.evaluateAsyncRawValue(prop.value, env)).value : env.get(key);
12357
12419
  if (prop.method && prop.value.type === "FunctionExpression") {
12358
12420
  obj[key] = (...args) => {
12359
12421
  const funcValue = this.evaluate(prop.value, env);
@@ -12438,9 +12500,12 @@ var Interpreter = class _Interpreter {
12438
12500
  if (isTypeOnlyDeclaration(node)) {
12439
12501
  return void 0;
12440
12502
  }
12441
- if (node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration") {
12503
+ if (node.type === "TSExportAssignment") {
12442
12504
  throw createUnsupportedTypeScriptRuntimeError(node);
12443
12505
  }
12506
+ if (node.type === "TSImportEqualsDeclaration") {
12507
+ return this.evaluateTSImportEqualsDeclaration(node, env);
12508
+ }
12444
12509
  if (node.type === "TSEnumDeclaration") {
12445
12510
  return this.evaluateTSEnumDeclaration(node, env);
12446
12511
  }
@@ -13295,6 +13360,11 @@ var Interpreter = class _Interpreter {
13295
13360
  if (this.isTypeScriptModule && node.specifiers.length > 0 && node.specifiers.every((specifier) => !this.isRuntimeImportSpecifier(specifier))) {
13296
13361
  return void 0;
13297
13362
  }
13363
+ const moduleExports = await this.loadModuleExports(modulePath);
13364
+ this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13365
+ return void 0;
13366
+ }
13367
+ async loadModuleExports(modulePath) {
13298
13368
  if (!this.moduleResolver) {
13299
13369
  throw new Error("Module resolver not configured - cannot import modules");
13300
13370
  }
@@ -13316,8 +13386,7 @@ var Interpreter = class _Interpreter {
13316
13386
  resolvedPath = typeof resolution === "string" ? modulePath : resolution.path || modulePath;
13317
13387
  this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
13318
13388
  if (this.moduleCache.has(resolvedPath)) {
13319
- moduleExports = this.moduleCache.get(resolvedPath);
13320
- return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13389
+ return this.moduleCache.get(resolvedPath);
13321
13390
  }
13322
13391
  if (resolution.exports) {
13323
13392
  moduleExports = resolution.exports;
@@ -13346,7 +13415,27 @@ var Interpreter = class _Interpreter {
13346
13415
  }
13347
13416
  }
13348
13417
  }
13349
- this.bindImportSpecifiers(node, env, modulePath, moduleExports);
13418
+ return moduleExports;
13419
+ }
13420
+ async evaluateTSImportEqualsDeclaration(node, env) {
13421
+ var _a, _b;
13422
+ if (node.importKind === "type") {
13423
+ return void 0;
13424
+ }
13425
+ const localName = (_a = node.id) == null ? void 0 : _a.name;
13426
+ const moduleReference = node.moduleReference;
13427
+ if ((moduleReference == null ? void 0 : moduleReference.type) !== "TSExternalModuleReference") {
13428
+ throw createUnsupportedTypeScriptRuntimeError(node);
13429
+ }
13430
+ const modulePath = (_b = moduleReference.expression) == null ? void 0 : _b.value;
13431
+ if (typeof modulePath !== "string") {
13432
+ throw createUnsupportedTypeScriptRuntimeError(node);
13433
+ }
13434
+ const moduleExports = await this.loadModuleExports(modulePath);
13435
+ env.define(localName, moduleExports);
13436
+ if (node.isExport) {
13437
+ this.moduleExports[localName] = moduleExports;
13438
+ }
13350
13439
  return void 0;
13351
13440
  }
13352
13441
  bindImportSpecifiers(node, env, modulePath, moduleExports) {
@@ -13360,13 +13449,13 @@ var Interpreter = class _Interpreter {
13360
13449
  if (!(importedName in moduleExports)) {
13361
13450
  throw new Error(`Module '${modulePath}' has no export '${importedName}'`);
13362
13451
  }
13363
- env.define(localName, moduleExports[importedName]);
13452
+ env.defineLive(localName, () => moduleExports[importedName]);
13364
13453
  } else if (specifier.type === "ImportDefaultSpecifier") {
13365
13454
  const localName = specifier.local.name;
13366
13455
  if (!("default" in moduleExports)) {
13367
13456
  throw new Error(`Module '${modulePath}' has no default export`);
13368
13457
  }
13369
- env.define(localName, moduleExports.default);
13458
+ env.defineLive(localName, () => moduleExports.default);
13370
13459
  } else if (specifier.type === "ImportNamespaceSpecifier") {
13371
13460
  const localName = specifier.local.name;
13372
13461
  env.define(localName, moduleExports);
@@ -14907,7 +14996,7 @@ function parse3(code, options = {}) {
14907
14996
  }
14908
14997
  function containsModuleDeclarations(node) {
14909
14998
  if (!node || typeof node !== "object") return false;
14910
- if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration") {
14999
+ if (node.type === "ImportDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration") {
14911
15000
  return true;
14912
15001
  }
14913
15002
  if (node.type === "Program" && node.body) {