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 +1 -0
- package/dist/esm/interpreter/interpreter.js +105 -12
- package/dist/esm/runtime/environment.js +23 -3
- package/dist/index.cjs +105 -16
- package/dist/index.d.cts +129 -15
- package/dist/index.d.ts +129 -15
- package/dist/index.js +105 -16
- package/dist/validator/index.cjs +3 -0
- package/dist/validator/index.js +3 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -11964,17 +11964,19 @@ class Environment {
|
|
|
11964
11964
|
constructor(parent = null) {
|
|
11965
11965
|
this.parent = parent;
|
|
11966
11966
|
this.vars = new Map();
|
|
11967
|
+
this.liveBindings = new Map();
|
|
11967
11968
|
this.consts = new Set(); // Track const variables
|
|
11968
11969
|
}
|
|
11969
11970
|
|
|
11970
11971
|
define(name, value, isConst = false) {
|
|
11971
|
-
if (this.vars.has(name)) {
|
|
11972
|
+
if (this.vars.has(name) || this.liveBindings.has(name)) {
|
|
11972
11973
|
// Allow redeclaration for non-const (REPL-style behavior)
|
|
11973
11974
|
// But cannot redeclare a const
|
|
11974
11975
|
if (this.consts.has(name)) {
|
|
11975
11976
|
throw new Error(`Cannot redeclare const '${name}'`);
|
|
11976
11977
|
}
|
|
11977
11978
|
// Update existing variable
|
|
11979
|
+
this.liveBindings.delete(name);
|
|
11978
11980
|
this.vars.set(name, value);
|
|
11979
11981
|
if (isConst) {
|
|
11980
11982
|
this.consts.add(name);
|
|
@@ -11988,7 +11990,24 @@ class Environment {
|
|
|
11988
11990
|
return value;
|
|
11989
11991
|
}
|
|
11990
11992
|
|
|
11993
|
+
defineLive(name, getter, isConst = true) {
|
|
11994
|
+
if (this.vars.has(name) || this.liveBindings.has(name)) {
|
|
11995
|
+
if (this.consts.has(name)) {
|
|
11996
|
+
throw new Error(`Cannot redeclare const '${name}'`);
|
|
11997
|
+
}
|
|
11998
|
+
this.vars.delete(name);
|
|
11999
|
+
}
|
|
12000
|
+
this.liveBindings.set(name, getter);
|
|
12001
|
+
if (isConst) {
|
|
12002
|
+
this.consts.add(name);
|
|
12003
|
+
}
|
|
12004
|
+
return getter();
|
|
12005
|
+
}
|
|
12006
|
+
|
|
11991
12007
|
get(name) {
|
|
12008
|
+
if (this.liveBindings.has(name)) {
|
|
12009
|
+
return this.liveBindings.get(name)();
|
|
12010
|
+
}
|
|
11992
12011
|
if (this.vars.has(name)) {
|
|
11993
12012
|
return this.vars.get(name);
|
|
11994
12013
|
}
|
|
@@ -11999,11 +12018,12 @@ class Environment {
|
|
|
11999
12018
|
}
|
|
12000
12019
|
|
|
12001
12020
|
set(name, value) {
|
|
12002
|
-
if (this.vars.has(name)) {
|
|
12021
|
+
if (this.vars.has(name) || this.liveBindings.has(name)) {
|
|
12003
12022
|
// Check if trying to reassign a const variable
|
|
12004
12023
|
if (this.consts.has(name)) {
|
|
12005
12024
|
throw new TypeError(`Cannot reassign const variable '${name}'`);
|
|
12006
12025
|
}
|
|
12026
|
+
this.liveBindings.delete(name);
|
|
12007
12027
|
this.vars.set(name, value);
|
|
12008
12028
|
return value;
|
|
12009
12029
|
}
|
|
@@ -12014,7 +12034,7 @@ class Environment {
|
|
|
12014
12034
|
}
|
|
12015
12035
|
|
|
12016
12036
|
has(name) {
|
|
12017
|
-
return this.vars.has(name) || (this.parent ? this.parent.has(name) : false);
|
|
12037
|
+
return this.vars.has(name) || this.liveBindings.has(name) || (this.parent ? this.parent.has(name) : false);
|
|
12018
12038
|
}
|
|
12019
12039
|
|
|
12020
12040
|
// For let/const block scoping
|
|
@@ -12195,6 +12215,20 @@ function createMethodNotFoundError(objectName, methodName, objectValue) {
|
|
|
12195
12215
|
});
|
|
12196
12216
|
}
|
|
12197
12217
|
|
|
12218
|
+
const ASYNC_EXPRESSION_COMPLETION = Symbol('jslike.asyncExpressionCompletion');
|
|
12219
|
+
|
|
12220
|
+
function createAsyncExpressionCompletion(value) {
|
|
12221
|
+
return { [ASYNC_EXPRESSION_COMPLETION]: true, value };
|
|
12222
|
+
}
|
|
12223
|
+
|
|
12224
|
+
function isAsyncExpressionCompletion(value) {
|
|
12225
|
+
return value && value[ASYNC_EXPRESSION_COMPLETION] === true;
|
|
12226
|
+
}
|
|
12227
|
+
|
|
12228
|
+
function unwrapAsyncExpressionCompletion(value) {
|
|
12229
|
+
return isAsyncExpressionCompletion(value) ? value.value : value;
|
|
12230
|
+
}
|
|
12231
|
+
|
|
12198
12232
|
function isTypeScriptPath$1(sourcePath) {
|
|
12199
12233
|
return typeof sourcePath === 'string' && /\.(ts|tsx|mts|cts)$/i.test(sourcePath);
|
|
12200
12234
|
}
|
|
@@ -12591,6 +12625,45 @@ class Interpreter {
|
|
|
12591
12625
|
return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
|
|
12592
12626
|
}
|
|
12593
12627
|
|
|
12628
|
+
if (node.type === 'AssignmentExpression') {
|
|
12629
|
+
const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
|
|
12630
|
+
|
|
12631
|
+
if (node.left.type === 'Identifier') {
|
|
12632
|
+
const name = node.left.name;
|
|
12633
|
+
if (node.operator === '=') {
|
|
12634
|
+
if (env.has(name)) {
|
|
12635
|
+
env.set(name, value);
|
|
12636
|
+
} else {
|
|
12637
|
+
env.define(name, value);
|
|
12638
|
+
}
|
|
12639
|
+
return { value };
|
|
12640
|
+
}
|
|
12641
|
+
|
|
12642
|
+
const current = env.get(name);
|
|
12643
|
+
const newValue = this.applyCompoundAssignment(node.operator, current, value);
|
|
12644
|
+
env.set(name, newValue);
|
|
12645
|
+
return { value: newValue };
|
|
12646
|
+
}
|
|
12647
|
+
|
|
12648
|
+
if (node.left.type === 'MemberExpression') {
|
|
12649
|
+
const obj = await this.evaluateAsync(node.left.object, env);
|
|
12650
|
+
const prop = node.left.computed
|
|
12651
|
+
? await this.evaluateAsync(node.left.property, env)
|
|
12652
|
+
: node.left.property.name;
|
|
12653
|
+
|
|
12654
|
+
if (node.operator === '=') {
|
|
12655
|
+
obj[prop] = value;
|
|
12656
|
+
return { value };
|
|
12657
|
+
}
|
|
12658
|
+
|
|
12659
|
+
const newValue = this.applyCompoundAssignment(node.operator, obj[prop], value);
|
|
12660
|
+
obj[prop] = newValue;
|
|
12661
|
+
return { value: newValue };
|
|
12662
|
+
}
|
|
12663
|
+
|
|
12664
|
+
throw new Error('Invalid assignment target');
|
|
12665
|
+
}
|
|
12666
|
+
|
|
12594
12667
|
if (node.type === 'NewExpression') {
|
|
12595
12668
|
return { value: this.evaluateNewExpression(node, env) };
|
|
12596
12669
|
}
|
|
@@ -12630,7 +12703,7 @@ class Interpreter {
|
|
|
12630
12703
|
|
|
12631
12704
|
const rawArgs = [];
|
|
12632
12705
|
for (const arg of node.arguments) {
|
|
12633
|
-
rawArgs.push(await this.
|
|
12706
|
+
rawArgs.push((await this.evaluateAsyncRawValue(arg, env)).value);
|
|
12634
12707
|
}
|
|
12635
12708
|
const args = this.flattenSpreadArgs(rawArgs);
|
|
12636
12709
|
|
|
@@ -12663,10 +12736,14 @@ class Interpreter {
|
|
|
12663
12736
|
return undefined;
|
|
12664
12737
|
}
|
|
12665
12738
|
|
|
12666
|
-
if (node.type === 'TSExportAssignment'
|
|
12739
|
+
if (node.type === 'TSExportAssignment') {
|
|
12667
12740
|
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
12668
12741
|
}
|
|
12669
12742
|
|
|
12743
|
+
if (node.type === 'TSImportEqualsDeclaration') {
|
|
12744
|
+
return await this.evaluateTSImportEqualsDeclaration(node, env);
|
|
12745
|
+
}
|
|
12746
|
+
|
|
12670
12747
|
if (node.type === 'TSEnumDeclaration') {
|
|
12671
12748
|
return this.evaluateTSEnumDeclaration(node, env);
|
|
12672
12749
|
}
|
|
@@ -12702,7 +12779,7 @@ class Interpreter {
|
|
|
12702
12779
|
|
|
12703
12780
|
// For expression statements, evaluate the expression async
|
|
12704
12781
|
if (node.type === 'ExpressionStatement') {
|
|
12705
|
-
return await this.
|
|
12782
|
+
return createAsyncExpressionCompletion((await this.evaluateAsyncRawValue(node.expression, env)).value);
|
|
12706
12783
|
}
|
|
12707
12784
|
|
|
12708
12785
|
// For variable declarations with await in init
|
|
@@ -12737,7 +12814,7 @@ class Interpreter {
|
|
|
12737
12814
|
return result;
|
|
12738
12815
|
}
|
|
12739
12816
|
}
|
|
12740
|
-
return result;
|
|
12817
|
+
return unwrapAsyncExpressionCompletion(result);
|
|
12741
12818
|
} finally {
|
|
12742
12819
|
this.runtimeIdentifierReferences = previousReferences;
|
|
12743
12820
|
}
|
|
@@ -13215,7 +13292,7 @@ class Interpreter {
|
|
|
13215
13292
|
throw new TypeError('Spread syntax requires an iterable');
|
|
13216
13293
|
}
|
|
13217
13294
|
} else {
|
|
13218
|
-
result.push(await this.
|
|
13295
|
+
result.push((await this.evaluateAsyncRawValue(elem, env)).value);
|
|
13219
13296
|
}
|
|
13220
13297
|
}
|
|
13221
13298
|
return result;
|
|
@@ -13234,7 +13311,7 @@ class Interpreter {
|
|
|
13234
13311
|
const key = prop.key.type === 'Identifier' && !prop.computed
|
|
13235
13312
|
? prop.key.name
|
|
13236
13313
|
: await this.evaluateAsync(prop.key, env);
|
|
13237
|
-
const value = prop.value ? await this.
|
|
13314
|
+
const value = prop.value ? (await this.evaluateAsyncRawValue(prop.value, env)).value : env.get(key);
|
|
13238
13315
|
if (prop.method && prop.value.type === 'FunctionExpression') {
|
|
13239
13316
|
obj[key] = (...args) => {
|
|
13240
13317
|
const funcValue = this.evaluate(prop.value, env);
|
|
@@ -13341,10 +13418,14 @@ class Interpreter {
|
|
|
13341
13418
|
return undefined;
|
|
13342
13419
|
}
|
|
13343
13420
|
|
|
13344
|
-
if (node.type === 'TSExportAssignment'
|
|
13421
|
+
if (node.type === 'TSExportAssignment') {
|
|
13345
13422
|
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
13346
13423
|
}
|
|
13347
13424
|
|
|
13425
|
+
if (node.type === 'TSImportEqualsDeclaration') {
|
|
13426
|
+
return this.evaluateTSImportEqualsDeclaration(node, env);
|
|
13427
|
+
}
|
|
13428
|
+
|
|
13348
13429
|
if (node.type === 'TSEnumDeclaration') {
|
|
13349
13430
|
return this.evaluateTSEnumDeclaration(node, env);
|
|
13350
13431
|
}
|
|
@@ -14462,6 +14543,13 @@ class Interpreter {
|
|
|
14462
14543
|
return undefined;
|
|
14463
14544
|
}
|
|
14464
14545
|
|
|
14546
|
+
const moduleExports = await this.loadModuleExports(modulePath);
|
|
14547
|
+
|
|
14548
|
+
this.bindImportSpecifiers(node, env, modulePath, moduleExports);
|
|
14549
|
+
return undefined;
|
|
14550
|
+
}
|
|
14551
|
+
|
|
14552
|
+
async loadModuleExports(modulePath) {
|
|
14465
14553
|
// Check if module resolver is configured
|
|
14466
14554
|
if (!this.moduleResolver) {
|
|
14467
14555
|
throw new Error('Module resolver not configured - cannot import modules');
|
|
@@ -14492,8 +14580,7 @@ class Interpreter {
|
|
|
14492
14580
|
: resolution.path || modulePath;
|
|
14493
14581
|
this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
|
|
14494
14582
|
if (this.moduleCache.has(resolvedPath)) {
|
|
14495
|
-
|
|
14496
|
-
return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
|
|
14583
|
+
return this.moduleCache.get(resolvedPath);
|
|
14497
14584
|
}
|
|
14498
14585
|
|
|
14499
14586
|
// Handle native module exports (for libraries like React)
|
|
@@ -14534,7 +14621,33 @@ class Interpreter {
|
|
|
14534
14621
|
}
|
|
14535
14622
|
}
|
|
14536
14623
|
|
|
14537
|
-
|
|
14624
|
+
return moduleExports;
|
|
14625
|
+
}
|
|
14626
|
+
|
|
14627
|
+
async evaluateTSImportEqualsDeclaration(node, env) {
|
|
14628
|
+
if (node.importKind === 'type') {
|
|
14629
|
+
return undefined;
|
|
14630
|
+
}
|
|
14631
|
+
|
|
14632
|
+
const localName = node.id?.name;
|
|
14633
|
+
const moduleReference = node.moduleReference;
|
|
14634
|
+
|
|
14635
|
+
if (moduleReference?.type !== 'TSExternalModuleReference') {
|
|
14636
|
+
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
14637
|
+
}
|
|
14638
|
+
|
|
14639
|
+
const modulePath = moduleReference.expression?.value;
|
|
14640
|
+
if (typeof modulePath !== 'string') {
|
|
14641
|
+
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
14642
|
+
}
|
|
14643
|
+
|
|
14644
|
+
const moduleExports = await this.loadModuleExports(modulePath);
|
|
14645
|
+
env.define(localName, moduleExports);
|
|
14646
|
+
|
|
14647
|
+
if (node.isExport) {
|
|
14648
|
+
this.moduleExports[localName] = moduleExports;
|
|
14649
|
+
}
|
|
14650
|
+
|
|
14538
14651
|
return undefined;
|
|
14539
14652
|
}
|
|
14540
14653
|
|
|
@@ -14554,7 +14667,7 @@ class Interpreter {
|
|
|
14554
14667
|
throw new Error(`Module '${modulePath}' has no export '${importedName}'`);
|
|
14555
14668
|
}
|
|
14556
14669
|
|
|
14557
|
-
env.
|
|
14670
|
+
env.defineLive(localName, () => moduleExports[importedName]);
|
|
14558
14671
|
} else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
14559
14672
|
// Default import: import foo from "module"
|
|
14560
14673
|
const localName = specifier.local.name;
|
|
@@ -14563,7 +14676,7 @@ class Interpreter {
|
|
|
14563
14676
|
throw new Error(`Module '${modulePath}' has no default export`);
|
|
14564
14677
|
}
|
|
14565
14678
|
|
|
14566
|
-
env.
|
|
14679
|
+
env.defineLive(localName, () => moduleExports.default);
|
|
14567
14680
|
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
14568
14681
|
// Namespace import: import * as foo from "module"
|
|
14569
14682
|
const localName = specifier.local.name;
|
|
@@ -16544,6 +16657,7 @@ function containsModuleDeclarations(node) {
|
|
|
16544
16657
|
if (!node || typeof node !== 'object') return false;
|
|
16545
16658
|
|
|
16546
16659
|
if (node.type === 'ImportDeclaration' ||
|
|
16660
|
+
node.type === 'TSImportEqualsDeclaration' ||
|
|
16547
16661
|
node.type === 'ExportNamedDeclaration' ||
|
|
16548
16662
|
node.type === 'ExportDefaultDeclaration' ||
|
|
16549
16663
|
node.type === 'ExportAllDeclaration') {
|
package/dist/index.d.ts
CHANGED
|
@@ -11964,17 +11964,19 @@ class Environment {
|
|
|
11964
11964
|
constructor(parent = null) {
|
|
11965
11965
|
this.parent = parent;
|
|
11966
11966
|
this.vars = new Map();
|
|
11967
|
+
this.liveBindings = new Map();
|
|
11967
11968
|
this.consts = new Set(); // Track const variables
|
|
11968
11969
|
}
|
|
11969
11970
|
|
|
11970
11971
|
define(name, value, isConst = false) {
|
|
11971
|
-
if (this.vars.has(name)) {
|
|
11972
|
+
if (this.vars.has(name) || this.liveBindings.has(name)) {
|
|
11972
11973
|
// Allow redeclaration for non-const (REPL-style behavior)
|
|
11973
11974
|
// But cannot redeclare a const
|
|
11974
11975
|
if (this.consts.has(name)) {
|
|
11975
11976
|
throw new Error(`Cannot redeclare const '${name}'`);
|
|
11976
11977
|
}
|
|
11977
11978
|
// Update existing variable
|
|
11979
|
+
this.liveBindings.delete(name);
|
|
11978
11980
|
this.vars.set(name, value);
|
|
11979
11981
|
if (isConst) {
|
|
11980
11982
|
this.consts.add(name);
|
|
@@ -11988,7 +11990,24 @@ class Environment {
|
|
|
11988
11990
|
return value;
|
|
11989
11991
|
}
|
|
11990
11992
|
|
|
11993
|
+
defineLive(name, getter, isConst = true) {
|
|
11994
|
+
if (this.vars.has(name) || this.liveBindings.has(name)) {
|
|
11995
|
+
if (this.consts.has(name)) {
|
|
11996
|
+
throw new Error(`Cannot redeclare const '${name}'`);
|
|
11997
|
+
}
|
|
11998
|
+
this.vars.delete(name);
|
|
11999
|
+
}
|
|
12000
|
+
this.liveBindings.set(name, getter);
|
|
12001
|
+
if (isConst) {
|
|
12002
|
+
this.consts.add(name);
|
|
12003
|
+
}
|
|
12004
|
+
return getter();
|
|
12005
|
+
}
|
|
12006
|
+
|
|
11991
12007
|
get(name) {
|
|
12008
|
+
if (this.liveBindings.has(name)) {
|
|
12009
|
+
return this.liveBindings.get(name)();
|
|
12010
|
+
}
|
|
11992
12011
|
if (this.vars.has(name)) {
|
|
11993
12012
|
return this.vars.get(name);
|
|
11994
12013
|
}
|
|
@@ -11999,11 +12018,12 @@ class Environment {
|
|
|
11999
12018
|
}
|
|
12000
12019
|
|
|
12001
12020
|
set(name, value) {
|
|
12002
|
-
if (this.vars.has(name)) {
|
|
12021
|
+
if (this.vars.has(name) || this.liveBindings.has(name)) {
|
|
12003
12022
|
// Check if trying to reassign a const variable
|
|
12004
12023
|
if (this.consts.has(name)) {
|
|
12005
12024
|
throw new TypeError(`Cannot reassign const variable '${name}'`);
|
|
12006
12025
|
}
|
|
12026
|
+
this.liveBindings.delete(name);
|
|
12007
12027
|
this.vars.set(name, value);
|
|
12008
12028
|
return value;
|
|
12009
12029
|
}
|
|
@@ -12014,7 +12034,7 @@ class Environment {
|
|
|
12014
12034
|
}
|
|
12015
12035
|
|
|
12016
12036
|
has(name) {
|
|
12017
|
-
return this.vars.has(name) || (this.parent ? this.parent.has(name) : false);
|
|
12037
|
+
return this.vars.has(name) || this.liveBindings.has(name) || (this.parent ? this.parent.has(name) : false);
|
|
12018
12038
|
}
|
|
12019
12039
|
|
|
12020
12040
|
// For let/const block scoping
|
|
@@ -12195,6 +12215,20 @@ function createMethodNotFoundError(objectName, methodName, objectValue) {
|
|
|
12195
12215
|
});
|
|
12196
12216
|
}
|
|
12197
12217
|
|
|
12218
|
+
const ASYNC_EXPRESSION_COMPLETION = Symbol('jslike.asyncExpressionCompletion');
|
|
12219
|
+
|
|
12220
|
+
function createAsyncExpressionCompletion(value) {
|
|
12221
|
+
return { [ASYNC_EXPRESSION_COMPLETION]: true, value };
|
|
12222
|
+
}
|
|
12223
|
+
|
|
12224
|
+
function isAsyncExpressionCompletion(value) {
|
|
12225
|
+
return value && value[ASYNC_EXPRESSION_COMPLETION] === true;
|
|
12226
|
+
}
|
|
12227
|
+
|
|
12228
|
+
function unwrapAsyncExpressionCompletion(value) {
|
|
12229
|
+
return isAsyncExpressionCompletion(value) ? value.value : value;
|
|
12230
|
+
}
|
|
12231
|
+
|
|
12198
12232
|
function isTypeScriptPath$1(sourcePath) {
|
|
12199
12233
|
return typeof sourcePath === 'string' && /\.(ts|tsx|mts|cts)$/i.test(sourcePath);
|
|
12200
12234
|
}
|
|
@@ -12591,6 +12625,45 @@ class Interpreter {
|
|
|
12591
12625
|
return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
|
|
12592
12626
|
}
|
|
12593
12627
|
|
|
12628
|
+
if (node.type === 'AssignmentExpression') {
|
|
12629
|
+
const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
|
|
12630
|
+
|
|
12631
|
+
if (node.left.type === 'Identifier') {
|
|
12632
|
+
const name = node.left.name;
|
|
12633
|
+
if (node.operator === '=') {
|
|
12634
|
+
if (env.has(name)) {
|
|
12635
|
+
env.set(name, value);
|
|
12636
|
+
} else {
|
|
12637
|
+
env.define(name, value);
|
|
12638
|
+
}
|
|
12639
|
+
return { value };
|
|
12640
|
+
}
|
|
12641
|
+
|
|
12642
|
+
const current = env.get(name);
|
|
12643
|
+
const newValue = this.applyCompoundAssignment(node.operator, current, value);
|
|
12644
|
+
env.set(name, newValue);
|
|
12645
|
+
return { value: newValue };
|
|
12646
|
+
}
|
|
12647
|
+
|
|
12648
|
+
if (node.left.type === 'MemberExpression') {
|
|
12649
|
+
const obj = await this.evaluateAsync(node.left.object, env);
|
|
12650
|
+
const prop = node.left.computed
|
|
12651
|
+
? await this.evaluateAsync(node.left.property, env)
|
|
12652
|
+
: node.left.property.name;
|
|
12653
|
+
|
|
12654
|
+
if (node.operator === '=') {
|
|
12655
|
+
obj[prop] = value;
|
|
12656
|
+
return { value };
|
|
12657
|
+
}
|
|
12658
|
+
|
|
12659
|
+
const newValue = this.applyCompoundAssignment(node.operator, obj[prop], value);
|
|
12660
|
+
obj[prop] = newValue;
|
|
12661
|
+
return { value: newValue };
|
|
12662
|
+
}
|
|
12663
|
+
|
|
12664
|
+
throw new Error('Invalid assignment target');
|
|
12665
|
+
}
|
|
12666
|
+
|
|
12594
12667
|
if (node.type === 'NewExpression') {
|
|
12595
12668
|
return { value: this.evaluateNewExpression(node, env) };
|
|
12596
12669
|
}
|
|
@@ -12630,7 +12703,7 @@ class Interpreter {
|
|
|
12630
12703
|
|
|
12631
12704
|
const rawArgs = [];
|
|
12632
12705
|
for (const arg of node.arguments) {
|
|
12633
|
-
rawArgs.push(await this.
|
|
12706
|
+
rawArgs.push((await this.evaluateAsyncRawValue(arg, env)).value);
|
|
12634
12707
|
}
|
|
12635
12708
|
const args = this.flattenSpreadArgs(rawArgs);
|
|
12636
12709
|
|
|
@@ -12663,10 +12736,14 @@ class Interpreter {
|
|
|
12663
12736
|
return undefined;
|
|
12664
12737
|
}
|
|
12665
12738
|
|
|
12666
|
-
if (node.type === 'TSExportAssignment'
|
|
12739
|
+
if (node.type === 'TSExportAssignment') {
|
|
12667
12740
|
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
12668
12741
|
}
|
|
12669
12742
|
|
|
12743
|
+
if (node.type === 'TSImportEqualsDeclaration') {
|
|
12744
|
+
return await this.evaluateTSImportEqualsDeclaration(node, env);
|
|
12745
|
+
}
|
|
12746
|
+
|
|
12670
12747
|
if (node.type === 'TSEnumDeclaration') {
|
|
12671
12748
|
return this.evaluateTSEnumDeclaration(node, env);
|
|
12672
12749
|
}
|
|
@@ -12702,7 +12779,7 @@ class Interpreter {
|
|
|
12702
12779
|
|
|
12703
12780
|
// For expression statements, evaluate the expression async
|
|
12704
12781
|
if (node.type === 'ExpressionStatement') {
|
|
12705
|
-
return await this.
|
|
12782
|
+
return createAsyncExpressionCompletion((await this.evaluateAsyncRawValue(node.expression, env)).value);
|
|
12706
12783
|
}
|
|
12707
12784
|
|
|
12708
12785
|
// For variable declarations with await in init
|
|
@@ -12737,7 +12814,7 @@ class Interpreter {
|
|
|
12737
12814
|
return result;
|
|
12738
12815
|
}
|
|
12739
12816
|
}
|
|
12740
|
-
return result;
|
|
12817
|
+
return unwrapAsyncExpressionCompletion(result);
|
|
12741
12818
|
} finally {
|
|
12742
12819
|
this.runtimeIdentifierReferences = previousReferences;
|
|
12743
12820
|
}
|
|
@@ -13215,7 +13292,7 @@ class Interpreter {
|
|
|
13215
13292
|
throw new TypeError('Spread syntax requires an iterable');
|
|
13216
13293
|
}
|
|
13217
13294
|
} else {
|
|
13218
|
-
result.push(await this.
|
|
13295
|
+
result.push((await this.evaluateAsyncRawValue(elem, env)).value);
|
|
13219
13296
|
}
|
|
13220
13297
|
}
|
|
13221
13298
|
return result;
|
|
@@ -13234,7 +13311,7 @@ class Interpreter {
|
|
|
13234
13311
|
const key = prop.key.type === 'Identifier' && !prop.computed
|
|
13235
13312
|
? prop.key.name
|
|
13236
13313
|
: await this.evaluateAsync(prop.key, env);
|
|
13237
|
-
const value = prop.value ? await this.
|
|
13314
|
+
const value = prop.value ? (await this.evaluateAsyncRawValue(prop.value, env)).value : env.get(key);
|
|
13238
13315
|
if (prop.method && prop.value.type === 'FunctionExpression') {
|
|
13239
13316
|
obj[key] = (...args) => {
|
|
13240
13317
|
const funcValue = this.evaluate(prop.value, env);
|
|
@@ -13341,10 +13418,14 @@ class Interpreter {
|
|
|
13341
13418
|
return undefined;
|
|
13342
13419
|
}
|
|
13343
13420
|
|
|
13344
|
-
if (node.type === 'TSExportAssignment'
|
|
13421
|
+
if (node.type === 'TSExportAssignment') {
|
|
13345
13422
|
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
13346
13423
|
}
|
|
13347
13424
|
|
|
13425
|
+
if (node.type === 'TSImportEqualsDeclaration') {
|
|
13426
|
+
return this.evaluateTSImportEqualsDeclaration(node, env);
|
|
13427
|
+
}
|
|
13428
|
+
|
|
13348
13429
|
if (node.type === 'TSEnumDeclaration') {
|
|
13349
13430
|
return this.evaluateTSEnumDeclaration(node, env);
|
|
13350
13431
|
}
|
|
@@ -14462,6 +14543,13 @@ class Interpreter {
|
|
|
14462
14543
|
return undefined;
|
|
14463
14544
|
}
|
|
14464
14545
|
|
|
14546
|
+
const moduleExports = await this.loadModuleExports(modulePath);
|
|
14547
|
+
|
|
14548
|
+
this.bindImportSpecifiers(node, env, modulePath, moduleExports);
|
|
14549
|
+
return undefined;
|
|
14550
|
+
}
|
|
14551
|
+
|
|
14552
|
+
async loadModuleExports(modulePath) {
|
|
14465
14553
|
// Check if module resolver is configured
|
|
14466
14554
|
if (!this.moduleResolver) {
|
|
14467
14555
|
throw new Error('Module resolver not configured - cannot import modules');
|
|
@@ -14492,8 +14580,7 @@ class Interpreter {
|
|
|
14492
14580
|
: resolution.path || modulePath;
|
|
14493
14581
|
this.moduleResolutionCache.set(resolutionCacheKey, resolvedPath);
|
|
14494
14582
|
if (this.moduleCache.has(resolvedPath)) {
|
|
14495
|
-
|
|
14496
|
-
return this.bindImportSpecifiers(node, env, modulePath, moduleExports);
|
|
14583
|
+
return this.moduleCache.get(resolvedPath);
|
|
14497
14584
|
}
|
|
14498
14585
|
|
|
14499
14586
|
// Handle native module exports (for libraries like React)
|
|
@@ -14534,7 +14621,33 @@ class Interpreter {
|
|
|
14534
14621
|
}
|
|
14535
14622
|
}
|
|
14536
14623
|
|
|
14537
|
-
|
|
14624
|
+
return moduleExports;
|
|
14625
|
+
}
|
|
14626
|
+
|
|
14627
|
+
async evaluateTSImportEqualsDeclaration(node, env) {
|
|
14628
|
+
if (node.importKind === 'type') {
|
|
14629
|
+
return undefined;
|
|
14630
|
+
}
|
|
14631
|
+
|
|
14632
|
+
const localName = node.id?.name;
|
|
14633
|
+
const moduleReference = node.moduleReference;
|
|
14634
|
+
|
|
14635
|
+
if (moduleReference?.type !== 'TSExternalModuleReference') {
|
|
14636
|
+
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
14637
|
+
}
|
|
14638
|
+
|
|
14639
|
+
const modulePath = moduleReference.expression?.value;
|
|
14640
|
+
if (typeof modulePath !== 'string') {
|
|
14641
|
+
throw createUnsupportedTypeScriptRuntimeError(node);
|
|
14642
|
+
}
|
|
14643
|
+
|
|
14644
|
+
const moduleExports = await this.loadModuleExports(modulePath);
|
|
14645
|
+
env.define(localName, moduleExports);
|
|
14646
|
+
|
|
14647
|
+
if (node.isExport) {
|
|
14648
|
+
this.moduleExports[localName] = moduleExports;
|
|
14649
|
+
}
|
|
14650
|
+
|
|
14538
14651
|
return undefined;
|
|
14539
14652
|
}
|
|
14540
14653
|
|
|
@@ -14554,7 +14667,7 @@ class Interpreter {
|
|
|
14554
14667
|
throw new Error(`Module '${modulePath}' has no export '${importedName}'`);
|
|
14555
14668
|
}
|
|
14556
14669
|
|
|
14557
|
-
env.
|
|
14670
|
+
env.defineLive(localName, () => moduleExports[importedName]);
|
|
14558
14671
|
} else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
14559
14672
|
// Default import: import foo from "module"
|
|
14560
14673
|
const localName = specifier.local.name;
|
|
@@ -14563,7 +14676,7 @@ class Interpreter {
|
|
|
14563
14676
|
throw new Error(`Module '${modulePath}' has no default export`);
|
|
14564
14677
|
}
|
|
14565
14678
|
|
|
14566
|
-
env.
|
|
14679
|
+
env.defineLive(localName, () => moduleExports.default);
|
|
14567
14680
|
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
14568
14681
|
// Namespace import: import * as foo from "module"
|
|
14569
14682
|
const localName = specifier.local.name;
|
|
@@ -16544,6 +16657,7 @@ function containsModuleDeclarations(node) {
|
|
|
16544
16657
|
if (!node || typeof node !== 'object') return false;
|
|
16545
16658
|
|
|
16546
16659
|
if (node.type === 'ImportDeclaration' ||
|
|
16660
|
+
node.type === 'TSImportEqualsDeclaration' ||
|
|
16547
16661
|
node.type === 'ExportNamedDeclaration' ||
|
|
16548
16662
|
node.type === 'ExportDefaultDeclaration' ||
|
|
16549
16663
|
node.type === 'ExportAllDeclaration') {
|