jslike 1.8.6 → 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 +1 -0
- package/dist/esm/interpreter/interpreter.js +79 -6
- package/dist/index.cjs +66 -7
- package/dist/index.d.cts +80 -6
- package/dist/index.d.ts +80 -6
- package/dist/index.js +66 -7
- package/package.json +1 -1
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'
|
|
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'
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -2846,6 +2886,14 @@ export class Interpreter {
|
|
|
2846
2886
|
for (const [name, method] of Object.entries(methods)) {
|
|
2847
2887
|
classConstructor.prototype[name] = function(...args) {
|
|
2848
2888
|
const result = interpreter.callMethodFunction(method, this, args, env, superClass);
|
|
2889
|
+
if (result && typeof result.then === 'function') {
|
|
2890
|
+
return result.then(resolved => {
|
|
2891
|
+
if (resolved && resolved.__explicitReturn) {
|
|
2892
|
+
return resolved.value;
|
|
2893
|
+
}
|
|
2894
|
+
return resolved;
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2849
2897
|
// Unwrap explicit return marker
|
|
2850
2898
|
if (result && result.__explicitReturn) {
|
|
2851
2899
|
return result.value;
|
|
@@ -2858,6 +2906,14 @@ export class Interpreter {
|
|
|
2858
2906
|
for (const [name, method] of Object.entries(staticMethods)) {
|
|
2859
2907
|
classConstructor[name] = function(...args) {
|
|
2860
2908
|
const result = interpreter.callMethodFunction(method, classConstructor, args, env);
|
|
2909
|
+
if (result && typeof result.then === 'function') {
|
|
2910
|
+
return result.then(resolved => {
|
|
2911
|
+
if (resolved && resolved.__explicitReturn) {
|
|
2912
|
+
return resolved.value;
|
|
2913
|
+
}
|
|
2914
|
+
return resolved;
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2861
2917
|
// Unwrap explicit return marker
|
|
2862
2918
|
if (result && result.__explicitReturn) {
|
|
2863
2919
|
return result.value;
|
|
@@ -2974,7 +3030,8 @@ export class Interpreter {
|
|
|
2974
3030
|
__params: funcNode.params,
|
|
2975
3031
|
__body: funcNode.body,
|
|
2976
3032
|
__env: env,
|
|
2977
|
-
__className: className
|
|
3033
|
+
__className: className,
|
|
3034
|
+
__async: funcNode.async || false
|
|
2978
3035
|
};
|
|
2979
3036
|
return func;
|
|
2980
3037
|
}
|
|
@@ -2992,6 +3049,22 @@ export class Interpreter {
|
|
|
2992
3049
|
|
|
2993
3050
|
this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
|
|
2994
3051
|
|
|
3052
|
+
if (methodFunc.__async) {
|
|
3053
|
+
return (async () => {
|
|
3054
|
+
const result = await this.evaluateAsync(methodFunc.__body, funcEnv);
|
|
3055
|
+
|
|
3056
|
+
if (result instanceof ReturnValue) {
|
|
3057
|
+
return { __explicitReturn: true, value: result.value };
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
if (result instanceof ThrowSignal) {
|
|
3061
|
+
throw result.value;
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
return result;
|
|
3065
|
+
})();
|
|
3066
|
+
}
|
|
3067
|
+
|
|
2995
3068
|
const result = this.evaluate(methodFunc.__body, funcEnv);
|
|
2996
3069
|
|
|
2997
3070
|
if (result instanceof ReturnValue) {
|
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"
|
|
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"
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -13721,6 +13751,14 @@ var Interpreter = class _Interpreter {
|
|
|
13721
13751
|
for (const [name, method] of Object.entries(methods)) {
|
|
13722
13752
|
classConstructor.prototype[name] = function(...args) {
|
|
13723
13753
|
const result = interpreter.callMethodFunction(method, this, args, env, superClass);
|
|
13754
|
+
if (result && typeof result.then === "function") {
|
|
13755
|
+
return result.then((resolved) => {
|
|
13756
|
+
if (resolved && resolved.__explicitReturn) {
|
|
13757
|
+
return resolved.value;
|
|
13758
|
+
}
|
|
13759
|
+
return resolved;
|
|
13760
|
+
});
|
|
13761
|
+
}
|
|
13724
13762
|
if (result && result.__explicitReturn) {
|
|
13725
13763
|
return result.value;
|
|
13726
13764
|
}
|
|
@@ -13730,6 +13768,14 @@ var Interpreter = class _Interpreter {
|
|
|
13730
13768
|
for (const [name, method] of Object.entries(staticMethods)) {
|
|
13731
13769
|
classConstructor[name] = function(...args) {
|
|
13732
13770
|
const result = interpreter.callMethodFunction(method, classConstructor, args, env);
|
|
13771
|
+
if (result && typeof result.then === "function") {
|
|
13772
|
+
return result.then((resolved) => {
|
|
13773
|
+
if (resolved && resolved.__explicitReturn) {
|
|
13774
|
+
return resolved.value;
|
|
13775
|
+
}
|
|
13776
|
+
return resolved;
|
|
13777
|
+
});
|
|
13778
|
+
}
|
|
13733
13779
|
if (result && result.__explicitReturn) {
|
|
13734
13780
|
return result.value;
|
|
13735
13781
|
}
|
|
@@ -13828,7 +13874,8 @@ var Interpreter = class _Interpreter {
|
|
|
13828
13874
|
__params: funcNode.params,
|
|
13829
13875
|
__body: funcNode.body,
|
|
13830
13876
|
__env: env,
|
|
13831
|
-
__className: className
|
|
13877
|
+
__className: className,
|
|
13878
|
+
__async: funcNode.async || false
|
|
13832
13879
|
};
|
|
13833
13880
|
return func;
|
|
13834
13881
|
}
|
|
@@ -13839,6 +13886,18 @@ var Interpreter = class _Interpreter {
|
|
|
13839
13886
|
funcEnv.define("super", this.createSuperBinding(superClass, thisContext, true, afterSuper));
|
|
13840
13887
|
}
|
|
13841
13888
|
this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
|
|
13889
|
+
if (methodFunc.__async) {
|
|
13890
|
+
return (async () => {
|
|
13891
|
+
const result2 = await this.evaluateAsync(methodFunc.__body, funcEnv);
|
|
13892
|
+
if (result2 instanceof ReturnValue) {
|
|
13893
|
+
return { __explicitReturn: true, value: result2.value };
|
|
13894
|
+
}
|
|
13895
|
+
if (result2 instanceof ThrowSignal) {
|
|
13896
|
+
throw result2.value;
|
|
13897
|
+
}
|
|
13898
|
+
return result2;
|
|
13899
|
+
})();
|
|
13900
|
+
}
|
|
13842
13901
|
const result = this.evaluate(methodFunc.__body, funcEnv);
|
|
13843
13902
|
if (result instanceof ReturnValue) {
|
|
13844
13903
|
return { __explicitReturn: true, value: result.value };
|
|
@@ -14878,7 +14937,7 @@ function parse3(code, options = {}) {
|
|
|
14878
14937
|
}
|
|
14879
14938
|
function containsModuleDeclarations(node) {
|
|
14880
14939
|
if (!node || typeof node !== "object") return false;
|
|
14881
|
-
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") {
|
|
14882
14941
|
return true;
|
|
14883
14942
|
}
|
|
14884
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'
|
|
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'
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -15039,6 +15079,14 @@ class Interpreter {
|
|
|
15039
15079
|
for (const [name, method] of Object.entries(methods)) {
|
|
15040
15080
|
classConstructor.prototype[name] = function(...args) {
|
|
15041
15081
|
const result = interpreter.callMethodFunction(method, this, args, env, superClass);
|
|
15082
|
+
if (result && typeof result.then === 'function') {
|
|
15083
|
+
return result.then(resolved => {
|
|
15084
|
+
if (resolved && resolved.__explicitReturn) {
|
|
15085
|
+
return resolved.value;
|
|
15086
|
+
}
|
|
15087
|
+
return resolved;
|
|
15088
|
+
});
|
|
15089
|
+
}
|
|
15042
15090
|
// Unwrap explicit return marker
|
|
15043
15091
|
if (result && result.__explicitReturn) {
|
|
15044
15092
|
return result.value;
|
|
@@ -15051,6 +15099,14 @@ class Interpreter {
|
|
|
15051
15099
|
for (const [name, method] of Object.entries(staticMethods)) {
|
|
15052
15100
|
classConstructor[name] = function(...args) {
|
|
15053
15101
|
const result = interpreter.callMethodFunction(method, classConstructor, args, env);
|
|
15102
|
+
if (result && typeof result.then === 'function') {
|
|
15103
|
+
return result.then(resolved => {
|
|
15104
|
+
if (resolved && resolved.__explicitReturn) {
|
|
15105
|
+
return resolved.value;
|
|
15106
|
+
}
|
|
15107
|
+
return resolved;
|
|
15108
|
+
});
|
|
15109
|
+
}
|
|
15054
15110
|
// Unwrap explicit return marker
|
|
15055
15111
|
if (result && result.__explicitReturn) {
|
|
15056
15112
|
return result.value;
|
|
@@ -15167,7 +15223,8 @@ class Interpreter {
|
|
|
15167
15223
|
__params: funcNode.params,
|
|
15168
15224
|
__body: funcNode.body,
|
|
15169
15225
|
__env: env,
|
|
15170
|
-
__className: className
|
|
15226
|
+
__className: className,
|
|
15227
|
+
__async: funcNode.async || false
|
|
15171
15228
|
};
|
|
15172
15229
|
return func;
|
|
15173
15230
|
}
|
|
@@ -15185,6 +15242,22 @@ class Interpreter {
|
|
|
15185
15242
|
|
|
15186
15243
|
this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
|
|
15187
15244
|
|
|
15245
|
+
if (methodFunc.__async) {
|
|
15246
|
+
return (async () => {
|
|
15247
|
+
const result = await this.evaluateAsync(methodFunc.__body, funcEnv);
|
|
15248
|
+
|
|
15249
|
+
if (result instanceof ReturnValue) {
|
|
15250
|
+
return { __explicitReturn: true, value: result.value };
|
|
15251
|
+
}
|
|
15252
|
+
|
|
15253
|
+
if (result instanceof ThrowSignal) {
|
|
15254
|
+
throw result.value;
|
|
15255
|
+
}
|
|
15256
|
+
|
|
15257
|
+
return result;
|
|
15258
|
+
})();
|
|
15259
|
+
}
|
|
15260
|
+
|
|
15188
15261
|
const result = this.evaluate(methodFunc.__body, funcEnv);
|
|
15189
15262
|
|
|
15190
15263
|
if (result instanceof ReturnValue) {
|
|
@@ -16511,6 +16584,7 @@ function containsModuleDeclarations(node) {
|
|
|
16511
16584
|
if (!node || typeof node !== 'object') return false;
|
|
16512
16585
|
|
|
16513
16586
|
if (node.type === 'ImportDeclaration' ||
|
|
16587
|
+
node.type === 'TSImportEqualsDeclaration' ||
|
|
16514
16588
|
node.type === 'ExportNamedDeclaration' ||
|
|
16515
16589
|
node.type === 'ExportDefaultDeclaration' ||
|
|
16516
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'
|
|
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'
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -15039,6 +15079,14 @@ class Interpreter {
|
|
|
15039
15079
|
for (const [name, method] of Object.entries(methods)) {
|
|
15040
15080
|
classConstructor.prototype[name] = function(...args) {
|
|
15041
15081
|
const result = interpreter.callMethodFunction(method, this, args, env, superClass);
|
|
15082
|
+
if (result && typeof result.then === 'function') {
|
|
15083
|
+
return result.then(resolved => {
|
|
15084
|
+
if (resolved && resolved.__explicitReturn) {
|
|
15085
|
+
return resolved.value;
|
|
15086
|
+
}
|
|
15087
|
+
return resolved;
|
|
15088
|
+
});
|
|
15089
|
+
}
|
|
15042
15090
|
// Unwrap explicit return marker
|
|
15043
15091
|
if (result && result.__explicitReturn) {
|
|
15044
15092
|
return result.value;
|
|
@@ -15051,6 +15099,14 @@ class Interpreter {
|
|
|
15051
15099
|
for (const [name, method] of Object.entries(staticMethods)) {
|
|
15052
15100
|
classConstructor[name] = function(...args) {
|
|
15053
15101
|
const result = interpreter.callMethodFunction(method, classConstructor, args, env);
|
|
15102
|
+
if (result && typeof result.then === 'function') {
|
|
15103
|
+
return result.then(resolved => {
|
|
15104
|
+
if (resolved && resolved.__explicitReturn) {
|
|
15105
|
+
return resolved.value;
|
|
15106
|
+
}
|
|
15107
|
+
return resolved;
|
|
15108
|
+
});
|
|
15109
|
+
}
|
|
15054
15110
|
// Unwrap explicit return marker
|
|
15055
15111
|
if (result && result.__explicitReturn) {
|
|
15056
15112
|
return result.value;
|
|
@@ -15167,7 +15223,8 @@ class Interpreter {
|
|
|
15167
15223
|
__params: funcNode.params,
|
|
15168
15224
|
__body: funcNode.body,
|
|
15169
15225
|
__env: env,
|
|
15170
|
-
__className: className
|
|
15226
|
+
__className: className,
|
|
15227
|
+
__async: funcNode.async || false
|
|
15171
15228
|
};
|
|
15172
15229
|
return func;
|
|
15173
15230
|
}
|
|
@@ -15185,6 +15242,22 @@ class Interpreter {
|
|
|
15185
15242
|
|
|
15186
15243
|
this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
|
|
15187
15244
|
|
|
15245
|
+
if (methodFunc.__async) {
|
|
15246
|
+
return (async () => {
|
|
15247
|
+
const result = await this.evaluateAsync(methodFunc.__body, funcEnv);
|
|
15248
|
+
|
|
15249
|
+
if (result instanceof ReturnValue) {
|
|
15250
|
+
return { __explicitReturn: true, value: result.value };
|
|
15251
|
+
}
|
|
15252
|
+
|
|
15253
|
+
if (result instanceof ThrowSignal) {
|
|
15254
|
+
throw result.value;
|
|
15255
|
+
}
|
|
15256
|
+
|
|
15257
|
+
return result;
|
|
15258
|
+
})();
|
|
15259
|
+
}
|
|
15260
|
+
|
|
15188
15261
|
const result = this.evaluate(methodFunc.__body, funcEnv);
|
|
15189
15262
|
|
|
15190
15263
|
if (result instanceof ReturnValue) {
|
|
@@ -16511,6 +16584,7 @@ function containsModuleDeclarations(node) {
|
|
|
16511
16584
|
if (!node || typeof node !== 'object') return false;
|
|
16512
16585
|
|
|
16513
16586
|
if (node.type === 'ImportDeclaration' ||
|
|
16587
|
+
node.type === 'TSImportEqualsDeclaration' ||
|
|
16514
16588
|
node.type === 'ExportNamedDeclaration' ||
|
|
16515
16589
|
node.type === 'ExportDefaultDeclaration' ||
|
|
16516
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"
|
|
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"
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -13687,6 +13717,14 @@ var Interpreter = class _Interpreter {
|
|
|
13687
13717
|
for (const [name, method] of Object.entries(methods)) {
|
|
13688
13718
|
classConstructor.prototype[name] = function(...args) {
|
|
13689
13719
|
const result = interpreter.callMethodFunction(method, this, args, env, superClass);
|
|
13720
|
+
if (result && typeof result.then === "function") {
|
|
13721
|
+
return result.then((resolved) => {
|
|
13722
|
+
if (resolved && resolved.__explicitReturn) {
|
|
13723
|
+
return resolved.value;
|
|
13724
|
+
}
|
|
13725
|
+
return resolved;
|
|
13726
|
+
});
|
|
13727
|
+
}
|
|
13690
13728
|
if (result && result.__explicitReturn) {
|
|
13691
13729
|
return result.value;
|
|
13692
13730
|
}
|
|
@@ -13696,6 +13734,14 @@ var Interpreter = class _Interpreter {
|
|
|
13696
13734
|
for (const [name, method] of Object.entries(staticMethods)) {
|
|
13697
13735
|
classConstructor[name] = function(...args) {
|
|
13698
13736
|
const result = interpreter.callMethodFunction(method, classConstructor, args, env);
|
|
13737
|
+
if (result && typeof result.then === "function") {
|
|
13738
|
+
return result.then((resolved) => {
|
|
13739
|
+
if (resolved && resolved.__explicitReturn) {
|
|
13740
|
+
return resolved.value;
|
|
13741
|
+
}
|
|
13742
|
+
return resolved;
|
|
13743
|
+
});
|
|
13744
|
+
}
|
|
13699
13745
|
if (result && result.__explicitReturn) {
|
|
13700
13746
|
return result.value;
|
|
13701
13747
|
}
|
|
@@ -13794,7 +13840,8 @@ var Interpreter = class _Interpreter {
|
|
|
13794
13840
|
__params: funcNode.params,
|
|
13795
13841
|
__body: funcNode.body,
|
|
13796
13842
|
__env: env,
|
|
13797
|
-
__className: className
|
|
13843
|
+
__className: className,
|
|
13844
|
+
__async: funcNode.async || false
|
|
13798
13845
|
};
|
|
13799
13846
|
return func;
|
|
13800
13847
|
}
|
|
@@ -13805,6 +13852,18 @@ var Interpreter = class _Interpreter {
|
|
|
13805
13852
|
funcEnv.define("super", this.createSuperBinding(superClass, thisContext, true, afterSuper));
|
|
13806
13853
|
}
|
|
13807
13854
|
this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
|
|
13855
|
+
if (methodFunc.__async) {
|
|
13856
|
+
return (async () => {
|
|
13857
|
+
const result2 = await this.evaluateAsync(methodFunc.__body, funcEnv);
|
|
13858
|
+
if (result2 instanceof ReturnValue) {
|
|
13859
|
+
return { __explicitReturn: true, value: result2.value };
|
|
13860
|
+
}
|
|
13861
|
+
if (result2 instanceof ThrowSignal) {
|
|
13862
|
+
throw result2.value;
|
|
13863
|
+
}
|
|
13864
|
+
return result2;
|
|
13865
|
+
})();
|
|
13866
|
+
}
|
|
13808
13867
|
const result = this.evaluate(methodFunc.__body, funcEnv);
|
|
13809
13868
|
if (result instanceof ReturnValue) {
|
|
13810
13869
|
return { __explicitReturn: true, value: result.value };
|
|
@@ -14844,7 +14903,7 @@ function parse3(code, options = {}) {
|
|
|
14844
14903
|
}
|
|
14845
14904
|
function containsModuleDeclarations(node) {
|
|
14846
14905
|
if (!node || typeof node !== "object") return false;
|
|
14847
|
-
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") {
|
|
14848
14907
|
return true;
|
|
14849
14908
|
}
|
|
14850
14909
|
if (node.type === "Program" && node.body) {
|