jslike 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/interpreter/interpreter.js +229 -23
- package/dist/index.cjs +212 -20
- package/dist/index.d.cts +231 -24
- package/dist/index.d.ts +231 -24
- package/dist/index.js +212 -20
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12224,6 +12224,174 @@ function getPatternName(pattern) {
|
|
|
12224
12224
|
return pattern.name;
|
|
12225
12225
|
}
|
|
12226
12226
|
|
|
12227
|
+
function collectRuntimeIdentifierReferences(node) {
|
|
12228
|
+
const references = new Set();
|
|
12229
|
+
const skipKeys = new Set([
|
|
12230
|
+
'type',
|
|
12231
|
+
'start',
|
|
12232
|
+
'end',
|
|
12233
|
+
'loc',
|
|
12234
|
+
'range',
|
|
12235
|
+
'raw',
|
|
12236
|
+
'typeAnnotation',
|
|
12237
|
+
'returnType',
|
|
12238
|
+
'typeParameters',
|
|
12239
|
+
'typeArguments',
|
|
12240
|
+
'implements'
|
|
12241
|
+
]);
|
|
12242
|
+
|
|
12243
|
+
const visitPatternDefaults = (pattern) => {
|
|
12244
|
+
if (!pattern || typeof pattern !== 'object') return;
|
|
12245
|
+
if (pattern.type === 'AssignmentPattern') {
|
|
12246
|
+
visit(pattern.right);
|
|
12247
|
+
visitPatternDefaults(pattern.left);
|
|
12248
|
+
} else if (pattern.type === 'ObjectPattern') {
|
|
12249
|
+
for (const property of pattern.properties || []) {
|
|
12250
|
+
visitPatternDefaults(property.value || property.argument);
|
|
12251
|
+
}
|
|
12252
|
+
} else if (pattern.type === 'ArrayPattern') {
|
|
12253
|
+
for (const element of pattern.elements || []) {
|
|
12254
|
+
visitPatternDefaults(element);
|
|
12255
|
+
}
|
|
12256
|
+
} else if (pattern.type === 'RestElement') {
|
|
12257
|
+
visitPatternDefaults(pattern.argument);
|
|
12258
|
+
} else if (pattern.type === 'TSParameterProperty') {
|
|
12259
|
+
visitPatternDefaults(pattern.parameter);
|
|
12260
|
+
}
|
|
12261
|
+
};
|
|
12262
|
+
|
|
12263
|
+
const visitFunction = (fn) => {
|
|
12264
|
+
for (const param of fn.params || []) {
|
|
12265
|
+
visitPatternDefaults(param);
|
|
12266
|
+
}
|
|
12267
|
+
visit(fn.body);
|
|
12268
|
+
};
|
|
12269
|
+
|
|
12270
|
+
const visitJSXName = (jsxName) => {
|
|
12271
|
+
if (!jsxName || typeof jsxName !== 'object') return;
|
|
12272
|
+
if (jsxName.type === 'JSXIdentifier') {
|
|
12273
|
+
if (/^[A-Z]/.test(jsxName.name)) {
|
|
12274
|
+
references.add(jsxName.name);
|
|
12275
|
+
}
|
|
12276
|
+
} else if (jsxName.type === 'JSXMemberExpression') {
|
|
12277
|
+
visitJSXName(jsxName.object);
|
|
12278
|
+
} else if (jsxName.type === 'JSXNamespacedName') {
|
|
12279
|
+
visitJSXName(jsxName.namespace);
|
|
12280
|
+
}
|
|
12281
|
+
};
|
|
12282
|
+
|
|
12283
|
+
const visit = (current, parent = null, parentKey = null) => {
|
|
12284
|
+
if (!current || typeof current !== 'object') return;
|
|
12285
|
+
|
|
12286
|
+
if (Array.isArray(current)) {
|
|
12287
|
+
for (const item of current) visit(item, parent, parentKey);
|
|
12288
|
+
return;
|
|
12289
|
+
}
|
|
12290
|
+
|
|
12291
|
+
if (current.type?.startsWith('TS')) {
|
|
12292
|
+
if (isTypeWrapperExpression(current)) {
|
|
12293
|
+
visit(getTypeWrapperInnerExpression(current), current, 'expression');
|
|
12294
|
+
} else if (current.type === 'TSEnumDeclaration') {
|
|
12295
|
+
for (const member of current.members || []) {
|
|
12296
|
+
visit(member.initializer);
|
|
12297
|
+
}
|
|
12298
|
+
}
|
|
12299
|
+
return;
|
|
12300
|
+
}
|
|
12301
|
+
|
|
12302
|
+
switch (current.type) {
|
|
12303
|
+
case 'Identifier':
|
|
12304
|
+
references.add(current.name);
|
|
12305
|
+
return;
|
|
12306
|
+
case 'ImportDeclaration':
|
|
12307
|
+
return;
|
|
12308
|
+
case 'ExportNamedDeclaration':
|
|
12309
|
+
if (current.declaration) {
|
|
12310
|
+
visit(current.declaration, current, 'declaration');
|
|
12311
|
+
} else if (current.exportKind !== 'type') {
|
|
12312
|
+
for (const specifier of current.specifiers || []) {
|
|
12313
|
+
if (specifier.exportKind !== 'type' && specifier.local?.name) {
|
|
12314
|
+
references.add(specifier.local.name);
|
|
12315
|
+
}
|
|
12316
|
+
}
|
|
12317
|
+
}
|
|
12318
|
+
return;
|
|
12319
|
+
case 'ExportDefaultDeclaration':
|
|
12320
|
+
visit(current.declaration, current, 'declaration');
|
|
12321
|
+
return;
|
|
12322
|
+
case 'VariableDeclarator':
|
|
12323
|
+
visitPatternDefaults(current.id);
|
|
12324
|
+
visit(current.init, current, 'init');
|
|
12325
|
+
return;
|
|
12326
|
+
case 'FunctionDeclaration':
|
|
12327
|
+
visitFunction(current);
|
|
12328
|
+
return;
|
|
12329
|
+
case 'FunctionExpression':
|
|
12330
|
+
case 'ArrowFunctionExpression':
|
|
12331
|
+
visitFunction(current);
|
|
12332
|
+
return;
|
|
12333
|
+
case 'ClassDeclaration':
|
|
12334
|
+
case 'ClassExpression':
|
|
12335
|
+
visit(current.superClass, current, 'superClass');
|
|
12336
|
+
visit(current.body, current, 'body');
|
|
12337
|
+
return;
|
|
12338
|
+
case 'MemberExpression':
|
|
12339
|
+
case 'OptionalMemberExpression':
|
|
12340
|
+
visit(current.object, current, 'object');
|
|
12341
|
+
if (current.computed) {
|
|
12342
|
+
visit(current.property, current, 'property');
|
|
12343
|
+
}
|
|
12344
|
+
return;
|
|
12345
|
+
case 'Property':
|
|
12346
|
+
if (current.computed) {
|
|
12347
|
+
visit(current.key, current, 'key');
|
|
12348
|
+
}
|
|
12349
|
+
visit(current.value, current, 'value');
|
|
12350
|
+
return;
|
|
12351
|
+
case 'MethodDefinition':
|
|
12352
|
+
case 'PropertyDefinition':
|
|
12353
|
+
if (current.computed) {
|
|
12354
|
+
visit(current.key, current, 'key');
|
|
12355
|
+
}
|
|
12356
|
+
if (!current.declare && !current.abstract) {
|
|
12357
|
+
visit(current.value, current, 'value');
|
|
12358
|
+
}
|
|
12359
|
+
return;
|
|
12360
|
+
case 'AssignmentPattern':
|
|
12361
|
+
visit(current.right, current, 'right');
|
|
12362
|
+
return;
|
|
12363
|
+
case 'RestElement':
|
|
12364
|
+
return;
|
|
12365
|
+
case 'ObjectPattern':
|
|
12366
|
+
case 'ArrayPattern':
|
|
12367
|
+
visitPatternDefaults(current);
|
|
12368
|
+
return;
|
|
12369
|
+
case 'JSXElement':
|
|
12370
|
+
visitJSXName(current.openingElement?.name);
|
|
12371
|
+
for (const child of current.children || []) {
|
|
12372
|
+
visit(child);
|
|
12373
|
+
}
|
|
12374
|
+
return;
|
|
12375
|
+
case 'JSXFragment':
|
|
12376
|
+
for (const child of current.children || []) {
|
|
12377
|
+
visit(child);
|
|
12378
|
+
}
|
|
12379
|
+
return;
|
|
12380
|
+
case 'JSXExpressionContainer':
|
|
12381
|
+
visit(current.expression, current, 'expression');
|
|
12382
|
+
return;
|
|
12383
|
+
}
|
|
12384
|
+
|
|
12385
|
+
for (const [key, value] of Object.entries(current)) {
|
|
12386
|
+
if (skipKeys.has(key)) continue;
|
|
12387
|
+
visit(value, current, key);
|
|
12388
|
+
}
|
|
12389
|
+
};
|
|
12390
|
+
|
|
12391
|
+
visit(node);
|
|
12392
|
+
return references;
|
|
12393
|
+
}
|
|
12394
|
+
|
|
12227
12395
|
class Interpreter {
|
|
12228
12396
|
constructor(globalEnv, options = {}) {
|
|
12229
12397
|
this.globalEnv = globalEnv;
|
|
@@ -12232,6 +12400,8 @@ class Interpreter {
|
|
|
12232
12400
|
this.moduleResolutionCache = options.moduleResolutionCache || new Map();
|
|
12233
12401
|
this.moduleExports = {}; // Track exports in current module
|
|
12234
12402
|
this.currentModulePath = options.currentModulePath;
|
|
12403
|
+
this.isTypeScriptModule = options.isTypeScriptModule || false;
|
|
12404
|
+
this.runtimeIdentifierReferences = null;
|
|
12235
12405
|
this.abortSignal = options.abortSignal;
|
|
12236
12406
|
this.executionController = options.executionController;
|
|
12237
12407
|
}
|
|
@@ -12454,15 +12624,21 @@ class Interpreter {
|
|
|
12454
12624
|
|
|
12455
12625
|
// For Program nodes (evaluate all statements async)
|
|
12456
12626
|
if (node.type === 'Program') {
|
|
12627
|
+
const previousReferences = this.runtimeIdentifierReferences;
|
|
12628
|
+
this.runtimeIdentifierReferences = collectRuntimeIdentifierReferences(node);
|
|
12457
12629
|
let result = undefined;
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12630
|
+
try {
|
|
12631
|
+
for (const statement of node.body) {
|
|
12632
|
+
result = await this.evaluateAsync(statement, env);
|
|
12633
|
+
// Handle top-level return and throw
|
|
12634
|
+
if (result instanceof ReturnValue || result instanceof ThrowSignal) {
|
|
12635
|
+
return result;
|
|
12636
|
+
}
|
|
12463
12637
|
}
|
|
12638
|
+
return result;
|
|
12639
|
+
} finally {
|
|
12640
|
+
this.runtimeIdentifierReferences = previousReferences;
|
|
12464
12641
|
}
|
|
12465
|
-
return result;
|
|
12466
12642
|
}
|
|
12467
12643
|
|
|
12468
12644
|
// For import declarations (always async)
|
|
@@ -13265,27 +13441,33 @@ class Interpreter {
|
|
|
13265
13441
|
}
|
|
13266
13442
|
|
|
13267
13443
|
evaluateProgram(node, env) {
|
|
13444
|
+
const previousReferences = this.runtimeIdentifierReferences;
|
|
13445
|
+
this.runtimeIdentifierReferences = collectRuntimeIdentifierReferences(node);
|
|
13268
13446
|
let result = undefined;
|
|
13269
|
-
|
|
13270
|
-
|
|
13271
|
-
|
|
13272
|
-
|
|
13273
|
-
|
|
13274
|
-
|
|
13275
|
-
|
|
13276
|
-
|
|
13277
|
-
|
|
13278
|
-
|
|
13447
|
+
try {
|
|
13448
|
+
for (let i = 0; i < node.body.length; i++) {
|
|
13449
|
+
const statement = node.body[i];
|
|
13450
|
+
const isLast = i === node.body.length - 1;
|
|
13451
|
+
|
|
13452
|
+
// Special case: Last statement is a BlockStatement that looks like object literal
|
|
13453
|
+
// Handle both shorthand { x, y } and full syntax { key: value, key2: value2 }
|
|
13454
|
+
if (isLast && statement.type === 'BlockStatement') {
|
|
13455
|
+
const objLiteral = this.tryConvertBlockToObjectLiteral(statement, env);
|
|
13456
|
+
if (objLiteral !== null) {
|
|
13457
|
+
return objLiteral;
|
|
13458
|
+
}
|
|
13279
13459
|
}
|
|
13280
|
-
}
|
|
13281
13460
|
|
|
13282
|
-
|
|
13283
|
-
|
|
13284
|
-
|
|
13461
|
+
const statementResult = this.evaluate(statement, env);
|
|
13462
|
+
if (statementResult instanceof ReturnValue || statementResult instanceof ThrowSignal) {
|
|
13463
|
+
return statementResult;
|
|
13464
|
+
}
|
|
13465
|
+
result = statementResult;
|
|
13285
13466
|
}
|
|
13286
|
-
result
|
|
13467
|
+
return result;
|
|
13468
|
+
} finally {
|
|
13469
|
+
this.runtimeIdentifierReferences = previousReferences;
|
|
13287
13470
|
}
|
|
13288
|
-
return result;
|
|
13289
13471
|
}
|
|
13290
13472
|
|
|
13291
13473
|
// Try to convert a BlockStatement to an object literal
|
|
@@ -14127,6 +14309,12 @@ class Interpreter {
|
|
|
14127
14309
|
return undefined;
|
|
14128
14310
|
}
|
|
14129
14311
|
|
|
14312
|
+
if (this.isTypeScriptModule &&
|
|
14313
|
+
node.specifiers.length > 0 &&
|
|
14314
|
+
node.specifiers.every(specifier => !this.isRuntimeImportSpecifier(specifier))) {
|
|
14315
|
+
return undefined;
|
|
14316
|
+
}
|
|
14317
|
+
|
|
14130
14318
|
// Check if module resolver is configured
|
|
14131
14319
|
if (!this.moduleResolver) {
|
|
14132
14320
|
throw new Error('Module resolver not configured - cannot import modules');
|
|
@@ -14179,6 +14367,7 @@ class Interpreter {
|
|
|
14179
14367
|
moduleResolver: this.moduleResolver,
|
|
14180
14368
|
moduleResolutionCache: this.moduleResolutionCache,
|
|
14181
14369
|
currentModulePath: resolvedPath,
|
|
14370
|
+
isTypeScriptModule: isTypeScriptPath$1(resolvedPath),
|
|
14182
14371
|
abortSignal: this.abortSignal,
|
|
14183
14372
|
executionController: this.executionController
|
|
14184
14373
|
});
|
|
@@ -14200,7 +14389,7 @@ class Interpreter {
|
|
|
14200
14389
|
bindImportSpecifiers(node, env, modulePath, moduleExports) {
|
|
14201
14390
|
// Import specified bindings into current environment
|
|
14202
14391
|
for (const specifier of node.specifiers) {
|
|
14203
|
-
if (specifier
|
|
14392
|
+
if (!this.isRuntimeImportSpecifier(specifier)) {
|
|
14204
14393
|
continue;
|
|
14205
14394
|
}
|
|
14206
14395
|
|
|
@@ -14233,6 +14422,23 @@ class Interpreter {
|
|
|
14233
14422
|
return undefined;
|
|
14234
14423
|
}
|
|
14235
14424
|
|
|
14425
|
+
isRuntimeImportSpecifier(specifier) {
|
|
14426
|
+
if (specifier.importKind === 'type') {
|
|
14427
|
+
return false;
|
|
14428
|
+
}
|
|
14429
|
+
|
|
14430
|
+
if (!this.isTypeScriptModule) {
|
|
14431
|
+
return true;
|
|
14432
|
+
}
|
|
14433
|
+
|
|
14434
|
+
const localName = specifier.local?.name;
|
|
14435
|
+
if (!localName || !this.runtimeIdentifierReferences) {
|
|
14436
|
+
return true;
|
|
14437
|
+
}
|
|
14438
|
+
|
|
14439
|
+
return this.runtimeIdentifierReferences.has(localName);
|
|
14440
|
+
}
|
|
14441
|
+
|
|
14236
14442
|
evaluateExportNamedDeclaration(node, env) {
|
|
14237
14443
|
if (node.exportKind === 'type' || isTypeOnlyDeclaration(node.declaration)) {
|
|
14238
14444
|
return undefined;
|
|
@@ -16175,7 +16381,8 @@ async function execute(code, env = null, options = {}) {
|
|
|
16175
16381
|
moduleResolver: options.moduleResolver,
|
|
16176
16382
|
abortSignal: options.abortSignal,
|
|
16177
16383
|
executionController: controller,
|
|
16178
|
-
currentModulePath: options.sourcePath
|
|
16384
|
+
currentModulePath: options.sourcePath,
|
|
16385
|
+
isTypeScriptModule: options.typescript || options.tsx || isTypeScriptPath(options.sourcePath)
|
|
16179
16386
|
});
|
|
16180
16387
|
|
|
16181
16388
|
// Use async evaluation if:
|
package/dist/index.js
CHANGED
|
@@ -11493,6 +11493,165 @@ function getPatternName(pattern) {
|
|
|
11493
11493
|
if (pattern.type === "TSParameterProperty") return getPatternName(pattern.parameter);
|
|
11494
11494
|
return pattern.name;
|
|
11495
11495
|
}
|
|
11496
|
+
function collectRuntimeIdentifierReferences(node) {
|
|
11497
|
+
const references = /* @__PURE__ */ new Set();
|
|
11498
|
+
const skipKeys = /* @__PURE__ */ new Set([
|
|
11499
|
+
"type",
|
|
11500
|
+
"start",
|
|
11501
|
+
"end",
|
|
11502
|
+
"loc",
|
|
11503
|
+
"range",
|
|
11504
|
+
"raw",
|
|
11505
|
+
"typeAnnotation",
|
|
11506
|
+
"returnType",
|
|
11507
|
+
"typeParameters",
|
|
11508
|
+
"typeArguments",
|
|
11509
|
+
"implements"
|
|
11510
|
+
]);
|
|
11511
|
+
const visitPatternDefaults = (pattern) => {
|
|
11512
|
+
if (!pattern || typeof pattern !== "object") return;
|
|
11513
|
+
if (pattern.type === "AssignmentPattern") {
|
|
11514
|
+
visit(pattern.right);
|
|
11515
|
+
visitPatternDefaults(pattern.left);
|
|
11516
|
+
} else if (pattern.type === "ObjectPattern") {
|
|
11517
|
+
for (const property of pattern.properties || []) {
|
|
11518
|
+
visitPatternDefaults(property.value || property.argument);
|
|
11519
|
+
}
|
|
11520
|
+
} else if (pattern.type === "ArrayPattern") {
|
|
11521
|
+
for (const element of pattern.elements || []) {
|
|
11522
|
+
visitPatternDefaults(element);
|
|
11523
|
+
}
|
|
11524
|
+
} else if (pattern.type === "RestElement") {
|
|
11525
|
+
visitPatternDefaults(pattern.argument);
|
|
11526
|
+
} else if (pattern.type === "TSParameterProperty") {
|
|
11527
|
+
visitPatternDefaults(pattern.parameter);
|
|
11528
|
+
}
|
|
11529
|
+
};
|
|
11530
|
+
const visitFunction = (fn) => {
|
|
11531
|
+
for (const param of fn.params || []) {
|
|
11532
|
+
visitPatternDefaults(param);
|
|
11533
|
+
}
|
|
11534
|
+
visit(fn.body);
|
|
11535
|
+
};
|
|
11536
|
+
const visitJSXName = (jsxName) => {
|
|
11537
|
+
if (!jsxName || typeof jsxName !== "object") return;
|
|
11538
|
+
if (jsxName.type === "JSXIdentifier") {
|
|
11539
|
+
if (/^[A-Z]/.test(jsxName.name)) {
|
|
11540
|
+
references.add(jsxName.name);
|
|
11541
|
+
}
|
|
11542
|
+
} else if (jsxName.type === "JSXMemberExpression") {
|
|
11543
|
+
visitJSXName(jsxName.object);
|
|
11544
|
+
} else if (jsxName.type === "JSXNamespacedName") {
|
|
11545
|
+
visitJSXName(jsxName.namespace);
|
|
11546
|
+
}
|
|
11547
|
+
};
|
|
11548
|
+
const visit = (current2, parent = null, parentKey = null) => {
|
|
11549
|
+
var _a, _b, _c;
|
|
11550
|
+
if (!current2 || typeof current2 !== "object") return;
|
|
11551
|
+
if (Array.isArray(current2)) {
|
|
11552
|
+
for (const item of current2) visit(item, parent, parentKey);
|
|
11553
|
+
return;
|
|
11554
|
+
}
|
|
11555
|
+
if ((_a = current2.type) == null ? void 0 : _a.startsWith("TS")) {
|
|
11556
|
+
if (isTypeWrapperExpression(current2)) {
|
|
11557
|
+
visit(getTypeWrapperInnerExpression(current2), current2, "expression");
|
|
11558
|
+
} else if (current2.type === "TSEnumDeclaration") {
|
|
11559
|
+
for (const member of current2.members || []) {
|
|
11560
|
+
visit(member.initializer);
|
|
11561
|
+
}
|
|
11562
|
+
}
|
|
11563
|
+
return;
|
|
11564
|
+
}
|
|
11565
|
+
switch (current2.type) {
|
|
11566
|
+
case "Identifier":
|
|
11567
|
+
references.add(current2.name);
|
|
11568
|
+
return;
|
|
11569
|
+
case "ImportDeclaration":
|
|
11570
|
+
return;
|
|
11571
|
+
case "ExportNamedDeclaration":
|
|
11572
|
+
if (current2.declaration) {
|
|
11573
|
+
visit(current2.declaration, current2, "declaration");
|
|
11574
|
+
} else if (current2.exportKind !== "type") {
|
|
11575
|
+
for (const specifier of current2.specifiers || []) {
|
|
11576
|
+
if (specifier.exportKind !== "type" && ((_b = specifier.local) == null ? void 0 : _b.name)) {
|
|
11577
|
+
references.add(specifier.local.name);
|
|
11578
|
+
}
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11581
|
+
return;
|
|
11582
|
+
case "ExportDefaultDeclaration":
|
|
11583
|
+
visit(current2.declaration, current2, "declaration");
|
|
11584
|
+
return;
|
|
11585
|
+
case "VariableDeclarator":
|
|
11586
|
+
visitPatternDefaults(current2.id);
|
|
11587
|
+
visit(current2.init, current2, "init");
|
|
11588
|
+
return;
|
|
11589
|
+
case "FunctionDeclaration":
|
|
11590
|
+
visitFunction(current2);
|
|
11591
|
+
return;
|
|
11592
|
+
case "FunctionExpression":
|
|
11593
|
+
case "ArrowFunctionExpression":
|
|
11594
|
+
visitFunction(current2);
|
|
11595
|
+
return;
|
|
11596
|
+
case "ClassDeclaration":
|
|
11597
|
+
case "ClassExpression":
|
|
11598
|
+
visit(current2.superClass, current2, "superClass");
|
|
11599
|
+
visit(current2.body, current2, "body");
|
|
11600
|
+
return;
|
|
11601
|
+
case "MemberExpression":
|
|
11602
|
+
case "OptionalMemberExpression":
|
|
11603
|
+
visit(current2.object, current2, "object");
|
|
11604
|
+
if (current2.computed) {
|
|
11605
|
+
visit(current2.property, current2, "property");
|
|
11606
|
+
}
|
|
11607
|
+
return;
|
|
11608
|
+
case "Property":
|
|
11609
|
+
if (current2.computed) {
|
|
11610
|
+
visit(current2.key, current2, "key");
|
|
11611
|
+
}
|
|
11612
|
+
visit(current2.value, current2, "value");
|
|
11613
|
+
return;
|
|
11614
|
+
case "MethodDefinition":
|
|
11615
|
+
case "PropertyDefinition":
|
|
11616
|
+
if (current2.computed) {
|
|
11617
|
+
visit(current2.key, current2, "key");
|
|
11618
|
+
}
|
|
11619
|
+
if (!current2.declare && !current2.abstract) {
|
|
11620
|
+
visit(current2.value, current2, "value");
|
|
11621
|
+
}
|
|
11622
|
+
return;
|
|
11623
|
+
case "AssignmentPattern":
|
|
11624
|
+
visit(current2.right, current2, "right");
|
|
11625
|
+
return;
|
|
11626
|
+
case "RestElement":
|
|
11627
|
+
return;
|
|
11628
|
+
case "ObjectPattern":
|
|
11629
|
+
case "ArrayPattern":
|
|
11630
|
+
visitPatternDefaults(current2);
|
|
11631
|
+
return;
|
|
11632
|
+
case "JSXElement":
|
|
11633
|
+
visitJSXName((_c = current2.openingElement) == null ? void 0 : _c.name);
|
|
11634
|
+
for (const child of current2.children || []) {
|
|
11635
|
+
visit(child);
|
|
11636
|
+
}
|
|
11637
|
+
return;
|
|
11638
|
+
case "JSXFragment":
|
|
11639
|
+
for (const child of current2.children || []) {
|
|
11640
|
+
visit(child);
|
|
11641
|
+
}
|
|
11642
|
+
return;
|
|
11643
|
+
case "JSXExpressionContainer":
|
|
11644
|
+
visit(current2.expression, current2, "expression");
|
|
11645
|
+
return;
|
|
11646
|
+
}
|
|
11647
|
+
for (const [key, value] of Object.entries(current2)) {
|
|
11648
|
+
if (skipKeys.has(key)) continue;
|
|
11649
|
+
visit(value, current2, key);
|
|
11650
|
+
}
|
|
11651
|
+
};
|
|
11652
|
+
visit(node);
|
|
11653
|
+
return references;
|
|
11654
|
+
}
|
|
11496
11655
|
var Interpreter = class _Interpreter {
|
|
11497
11656
|
constructor(globalEnv, options = {}) {
|
|
11498
11657
|
this.globalEnv = globalEnv;
|
|
@@ -11501,6 +11660,8 @@ var Interpreter = class _Interpreter {
|
|
|
11501
11660
|
this.moduleResolutionCache = options.moduleResolutionCache || /* @__PURE__ */ new Map();
|
|
11502
11661
|
this.moduleExports = {};
|
|
11503
11662
|
this.currentModulePath = options.currentModulePath;
|
|
11663
|
+
this.isTypeScriptModule = options.isTypeScriptModule || false;
|
|
11664
|
+
this.runtimeIdentifierReferences = null;
|
|
11504
11665
|
this.abortSignal = options.abortSignal;
|
|
11505
11666
|
this.executionController = options.executionController;
|
|
11506
11667
|
}
|
|
@@ -11666,14 +11827,20 @@ var Interpreter = class _Interpreter {
|
|
|
11666
11827
|
return void 0;
|
|
11667
11828
|
}
|
|
11668
11829
|
if (node.type === "Program") {
|
|
11830
|
+
const previousReferences = this.runtimeIdentifierReferences;
|
|
11831
|
+
this.runtimeIdentifierReferences = collectRuntimeIdentifierReferences(node);
|
|
11669
11832
|
let result = void 0;
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11833
|
+
try {
|
|
11834
|
+
for (const statement of node.body) {
|
|
11835
|
+
result = await this.evaluateAsync(statement, env);
|
|
11836
|
+
if (result instanceof ReturnValue || result instanceof ThrowSignal) {
|
|
11837
|
+
return result;
|
|
11838
|
+
}
|
|
11674
11839
|
}
|
|
11840
|
+
return result;
|
|
11841
|
+
} finally {
|
|
11842
|
+
this.runtimeIdentifierReferences = previousReferences;
|
|
11675
11843
|
}
|
|
11676
|
-
return result;
|
|
11677
11844
|
}
|
|
11678
11845
|
if (node.type === "ImportDeclaration") {
|
|
11679
11846
|
return await this.evaluateImportDeclaration(node, env);
|
|
@@ -12297,23 +12464,29 @@ var Interpreter = class _Interpreter {
|
|
|
12297
12464
|
}
|
|
12298
12465
|
}
|
|
12299
12466
|
evaluateProgram(node, env) {
|
|
12467
|
+
const previousReferences = this.runtimeIdentifierReferences;
|
|
12468
|
+
this.runtimeIdentifierReferences = collectRuntimeIdentifierReferences(node);
|
|
12300
12469
|
let result = void 0;
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12470
|
+
try {
|
|
12471
|
+
for (let i = 0; i < node.body.length; i++) {
|
|
12472
|
+
const statement = node.body[i];
|
|
12473
|
+
const isLast = i === node.body.length - 1;
|
|
12474
|
+
if (isLast && statement.type === "BlockStatement") {
|
|
12475
|
+
const objLiteral = this.tryConvertBlockToObjectLiteral(statement, env);
|
|
12476
|
+
if (objLiteral !== null) {
|
|
12477
|
+
return objLiteral;
|
|
12478
|
+
}
|
|
12308
12479
|
}
|
|
12480
|
+
const statementResult = this.evaluate(statement, env);
|
|
12481
|
+
if (statementResult instanceof ReturnValue || statementResult instanceof ThrowSignal) {
|
|
12482
|
+
return statementResult;
|
|
12483
|
+
}
|
|
12484
|
+
result = statementResult;
|
|
12309
12485
|
}
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
}
|
|
12314
|
-
result = statementResult;
|
|
12486
|
+
return result;
|
|
12487
|
+
} finally {
|
|
12488
|
+
this.runtimeIdentifierReferences = previousReferences;
|
|
12315
12489
|
}
|
|
12316
|
-
return result;
|
|
12317
12490
|
}
|
|
12318
12491
|
// Try to convert a BlockStatement to an object literal
|
|
12319
12492
|
// Returns null if the block doesn't look like an object literal
|
|
@@ -12961,6 +13134,9 @@ var Interpreter = class _Interpreter {
|
|
|
12961
13134
|
if (node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every((specifier) => specifier.importKind === "type")) {
|
|
12962
13135
|
return void 0;
|
|
12963
13136
|
}
|
|
13137
|
+
if (this.isTypeScriptModule && node.specifiers.length > 0 && node.specifiers.every((specifier) => !this.isRuntimeImportSpecifier(specifier))) {
|
|
13138
|
+
return void 0;
|
|
13139
|
+
}
|
|
12964
13140
|
if (!this.moduleResolver) {
|
|
12965
13141
|
throw new Error("Module resolver not configured - cannot import modules");
|
|
12966
13142
|
}
|
|
@@ -12996,6 +13172,7 @@ var Interpreter = class _Interpreter {
|
|
|
12996
13172
|
moduleResolver: this.moduleResolver,
|
|
12997
13173
|
moduleResolutionCache: this.moduleResolutionCache,
|
|
12998
13174
|
currentModulePath: resolvedPath,
|
|
13175
|
+
isTypeScriptModule: isTypeScriptPath(resolvedPath),
|
|
12999
13176
|
abortSignal: this.abortSignal,
|
|
13000
13177
|
executionController: this.executionController
|
|
13001
13178
|
});
|
|
@@ -13010,7 +13187,7 @@ var Interpreter = class _Interpreter {
|
|
|
13010
13187
|
}
|
|
13011
13188
|
bindImportSpecifiers(node, env, modulePath, moduleExports) {
|
|
13012
13189
|
for (const specifier of node.specifiers) {
|
|
13013
|
-
if (specifier
|
|
13190
|
+
if (!this.isRuntimeImportSpecifier(specifier)) {
|
|
13014
13191
|
continue;
|
|
13015
13192
|
}
|
|
13016
13193
|
if (specifier.type === "ImportSpecifier") {
|
|
@@ -13033,6 +13210,20 @@ var Interpreter = class _Interpreter {
|
|
|
13033
13210
|
}
|
|
13034
13211
|
return void 0;
|
|
13035
13212
|
}
|
|
13213
|
+
isRuntimeImportSpecifier(specifier) {
|
|
13214
|
+
var _a;
|
|
13215
|
+
if (specifier.importKind === "type") {
|
|
13216
|
+
return false;
|
|
13217
|
+
}
|
|
13218
|
+
if (!this.isTypeScriptModule) {
|
|
13219
|
+
return true;
|
|
13220
|
+
}
|
|
13221
|
+
const localName = (_a = specifier.local) == null ? void 0 : _a.name;
|
|
13222
|
+
if (!localName || !this.runtimeIdentifierReferences) {
|
|
13223
|
+
return true;
|
|
13224
|
+
}
|
|
13225
|
+
return this.runtimeIdentifierReferences.has(localName);
|
|
13226
|
+
}
|
|
13036
13227
|
evaluateExportNamedDeclaration(node, env) {
|
|
13037
13228
|
if (node.exportKind === "type" || isTypeOnlyDeclaration(node.declaration)) {
|
|
13038
13229
|
return void 0;
|
|
@@ -14517,7 +14708,8 @@ async function execute(code, env = null, options = {}) {
|
|
|
14517
14708
|
moduleResolver: options.moduleResolver,
|
|
14518
14709
|
abortSignal: options.abortSignal,
|
|
14519
14710
|
executionController: controller,
|
|
14520
|
-
currentModulePath: options.sourcePath
|
|
14711
|
+
currentModulePath: options.sourcePath,
|
|
14712
|
+
isTypeScriptModule: options.typescript || options.tsx || isTypeScriptPath2(options.sourcePath)
|
|
14521
14713
|
});
|
|
14522
14714
|
const needsAsync = options.sourceType === "module" || containsModuleDeclarations(ast) || containsTopLevelAwait(ast) || controller != null;
|
|
14523
14715
|
if (needsAsync) {
|