jslike 1.8.5 → 1.8.6

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.
@@ -229,6 +229,78 @@ function collectRuntimeIdentifierReferences(node) {
229
229
  return references;
230
230
  }
231
231
 
232
+ function getExportName(nameNode) {
233
+ return nameNode?.name ?? nameNode?.value;
234
+ }
235
+
236
+ function collectDeclarationExportNames(declaration) {
237
+ const names = [];
238
+
239
+ if (!declaration || isTypeOnlyDeclaration(declaration)) {
240
+ return names;
241
+ }
242
+
243
+ if (declaration.type === 'FunctionDeclaration' ||
244
+ declaration.type === 'ClassDeclaration' ||
245
+ declaration.type === 'TSEnumDeclaration') {
246
+ const name = getPatternName(declaration.id);
247
+ if (name) names.push(name);
248
+ return names;
249
+ }
250
+
251
+ if (declaration.type === 'VariableDeclaration') {
252
+ for (const declarator of declaration.declarations || []) {
253
+ const name = getPatternName(declarator.id);
254
+ if (name) names.push(name);
255
+ }
256
+ }
257
+
258
+ return names;
259
+ }
260
+
261
+ function collectStaticExportNames(moduleAst) {
262
+ const names = new Set();
263
+
264
+ for (const statement of moduleAst?.body || []) {
265
+ if (statement.type === 'ExportDefaultDeclaration') {
266
+ names.add('default');
267
+ continue;
268
+ }
269
+
270
+ if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') {
271
+ continue;
272
+ }
273
+
274
+ if (statement.declaration) {
275
+ for (const name of collectDeclarationExportNames(statement.declaration)) {
276
+ names.add(name);
277
+ }
278
+ continue;
279
+ }
280
+
281
+ for (const specifier of statement.specifiers || []) {
282
+ if (specifier.exportKind === 'type') {
283
+ continue;
284
+ }
285
+
286
+ const exportedName = getExportName(specifier.exported);
287
+ if (exportedName) {
288
+ names.add(exportedName);
289
+ }
290
+ }
291
+ }
292
+
293
+ return names;
294
+ }
295
+
296
+ function predeclareModuleExports(moduleAst, moduleExports) {
297
+ for (const name of collectStaticExportNames(moduleAst)) {
298
+ if (!Object.prototype.hasOwnProperty.call(moduleExports, name)) {
299
+ moduleExports[name] = undefined;
300
+ }
301
+ }
302
+ }
303
+
232
304
  export class Interpreter {
233
305
  constructor(globalEnv, options = {}) {
234
306
  this.globalEnv = globalEnv;
@@ -2255,12 +2327,17 @@ export class Interpreter {
2255
2327
  });
2256
2328
  moduleInterpreter.moduleCache = this.moduleCache; // Share cache
2257
2329
 
2258
- // Execute module and collect exports
2259
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
2260
-
2261
- // Cache the module exports
2262
2330
  moduleExports = moduleInterpreter.moduleExports;
2331
+ predeclareModuleExports(moduleAst, moduleExports);
2263
2332
  this.moduleCache.set(resolvedPath, moduleExports);
2333
+
2334
+ try {
2335
+ // Execute module and populate the cached exports object.
2336
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
2337
+ } catch (error) {
2338
+ this.moduleCache.delete(resolvedPath);
2339
+ throw error;
2340
+ }
2264
2341
  }
2265
2342
  }
2266
2343
 
package/dist/index.cjs CHANGED
@@ -11710,6 +11710,62 @@ function collectRuntimeIdentifierReferences(node) {
11710
11710
  visit(node);
11711
11711
  return references;
11712
11712
  }
11713
+ function getExportName(nameNode) {
11714
+ return (nameNode == null ? void 0 : nameNode.name) ?? (nameNode == null ? void 0 : nameNode.value);
11715
+ }
11716
+ function collectDeclarationExportNames(declaration) {
11717
+ const names = [];
11718
+ if (!declaration || isTypeOnlyDeclaration(declaration)) {
11719
+ return names;
11720
+ }
11721
+ if (declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration" || declaration.type === "TSEnumDeclaration") {
11722
+ const name = getPatternName(declaration.id);
11723
+ if (name) names.push(name);
11724
+ return names;
11725
+ }
11726
+ if (declaration.type === "VariableDeclaration") {
11727
+ for (const declarator of declaration.declarations || []) {
11728
+ const name = getPatternName(declarator.id);
11729
+ if (name) names.push(name);
11730
+ }
11731
+ }
11732
+ return names;
11733
+ }
11734
+ function collectStaticExportNames(moduleAst) {
11735
+ const names = /* @__PURE__ */ new Set();
11736
+ for (const statement of (moduleAst == null ? void 0 : moduleAst.body) || []) {
11737
+ if (statement.type === "ExportDefaultDeclaration") {
11738
+ names.add("default");
11739
+ continue;
11740
+ }
11741
+ if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") {
11742
+ continue;
11743
+ }
11744
+ if (statement.declaration) {
11745
+ for (const name of collectDeclarationExportNames(statement.declaration)) {
11746
+ names.add(name);
11747
+ }
11748
+ continue;
11749
+ }
11750
+ for (const specifier of statement.specifiers || []) {
11751
+ if (specifier.exportKind === "type") {
11752
+ continue;
11753
+ }
11754
+ const exportedName = getExportName(specifier.exported);
11755
+ if (exportedName) {
11756
+ names.add(exportedName);
11757
+ }
11758
+ }
11759
+ }
11760
+ return names;
11761
+ }
11762
+ function predeclareModuleExports(moduleAst, moduleExports) {
11763
+ for (const name of collectStaticExportNames(moduleAst)) {
11764
+ if (!Object.prototype.hasOwnProperty.call(moduleExports, name)) {
11765
+ moduleExports[name] = void 0;
11766
+ }
11767
+ }
11768
+ }
11713
11769
  var Interpreter = class _Interpreter {
11714
11770
  constructor(globalEnv, options = {}) {
11715
11771
  this.globalEnv = globalEnv;
@@ -13279,9 +13335,15 @@ var Interpreter = class _Interpreter {
13279
13335
  executionController: this.executionController
13280
13336
  });
13281
13337
  moduleInterpreter.moduleCache = this.moduleCache;
13282
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
13283
13338
  moduleExports = moduleInterpreter.moduleExports;
13339
+ predeclareModuleExports(moduleAst, moduleExports);
13284
13340
  this.moduleCache.set(resolvedPath, moduleExports);
13341
+ try {
13342
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
13343
+ } catch (error) {
13344
+ this.moduleCache.delete(resolvedPath);
13345
+ throw error;
13346
+ }
13285
13347
  }
13286
13348
  }
13287
13349
  this.bindImportSpecifiers(node, env, modulePath, moduleExports);
package/dist/index.d.cts CHANGED
@@ -12422,6 +12422,78 @@ function collectRuntimeIdentifierReferences(node) {
12422
12422
  return references;
12423
12423
  }
12424
12424
 
12425
+ function getExportName(nameNode) {
12426
+ return nameNode?.name ?? nameNode?.value;
12427
+ }
12428
+
12429
+ function collectDeclarationExportNames(declaration) {
12430
+ const names = [];
12431
+
12432
+ if (!declaration || isTypeOnlyDeclaration(declaration)) {
12433
+ return names;
12434
+ }
12435
+
12436
+ if (declaration.type === 'FunctionDeclaration' ||
12437
+ declaration.type === 'ClassDeclaration' ||
12438
+ declaration.type === 'TSEnumDeclaration') {
12439
+ const name = getPatternName(declaration.id);
12440
+ if (name) names.push(name);
12441
+ return names;
12442
+ }
12443
+
12444
+ if (declaration.type === 'VariableDeclaration') {
12445
+ for (const declarator of declaration.declarations || []) {
12446
+ const name = getPatternName(declarator.id);
12447
+ if (name) names.push(name);
12448
+ }
12449
+ }
12450
+
12451
+ return names;
12452
+ }
12453
+
12454
+ function collectStaticExportNames(moduleAst) {
12455
+ const names = new Set();
12456
+
12457
+ for (const statement of moduleAst?.body || []) {
12458
+ if (statement.type === 'ExportDefaultDeclaration') {
12459
+ names.add('default');
12460
+ continue;
12461
+ }
12462
+
12463
+ if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') {
12464
+ continue;
12465
+ }
12466
+
12467
+ if (statement.declaration) {
12468
+ for (const name of collectDeclarationExportNames(statement.declaration)) {
12469
+ names.add(name);
12470
+ }
12471
+ continue;
12472
+ }
12473
+
12474
+ for (const specifier of statement.specifiers || []) {
12475
+ if (specifier.exportKind === 'type') {
12476
+ continue;
12477
+ }
12478
+
12479
+ const exportedName = getExportName(specifier.exported);
12480
+ if (exportedName) {
12481
+ names.add(exportedName);
12482
+ }
12483
+ }
12484
+ }
12485
+
12486
+ return names;
12487
+ }
12488
+
12489
+ function predeclareModuleExports(moduleAst, moduleExports) {
12490
+ for (const name of collectStaticExportNames(moduleAst)) {
12491
+ if (!Object.prototype.hasOwnProperty.call(moduleExports, name)) {
12492
+ moduleExports[name] = undefined;
12493
+ }
12494
+ }
12495
+ }
12496
+
12425
12497
  class Interpreter {
12426
12498
  constructor(globalEnv, options = {}) {
12427
12499
  this.globalEnv = globalEnv;
@@ -14448,12 +14520,17 @@ class Interpreter {
14448
14520
  });
14449
14521
  moduleInterpreter.moduleCache = this.moduleCache; // Share cache
14450
14522
 
14451
- // Execute module and collect exports
14452
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
14453
-
14454
- // Cache the module exports
14455
14523
  moduleExports = moduleInterpreter.moduleExports;
14524
+ predeclareModuleExports(moduleAst, moduleExports);
14456
14525
  this.moduleCache.set(resolvedPath, moduleExports);
14526
+
14527
+ try {
14528
+ // Execute module and populate the cached exports object.
14529
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
14530
+ } catch (error) {
14531
+ this.moduleCache.delete(resolvedPath);
14532
+ throw error;
14533
+ }
14457
14534
  }
14458
14535
  }
14459
14536
 
package/dist/index.d.ts CHANGED
@@ -12422,6 +12422,78 @@ function collectRuntimeIdentifierReferences(node) {
12422
12422
  return references;
12423
12423
  }
12424
12424
 
12425
+ function getExportName(nameNode) {
12426
+ return nameNode?.name ?? nameNode?.value;
12427
+ }
12428
+
12429
+ function collectDeclarationExportNames(declaration) {
12430
+ const names = [];
12431
+
12432
+ if (!declaration || isTypeOnlyDeclaration(declaration)) {
12433
+ return names;
12434
+ }
12435
+
12436
+ if (declaration.type === 'FunctionDeclaration' ||
12437
+ declaration.type === 'ClassDeclaration' ||
12438
+ declaration.type === 'TSEnumDeclaration') {
12439
+ const name = getPatternName(declaration.id);
12440
+ if (name) names.push(name);
12441
+ return names;
12442
+ }
12443
+
12444
+ if (declaration.type === 'VariableDeclaration') {
12445
+ for (const declarator of declaration.declarations || []) {
12446
+ const name = getPatternName(declarator.id);
12447
+ if (name) names.push(name);
12448
+ }
12449
+ }
12450
+
12451
+ return names;
12452
+ }
12453
+
12454
+ function collectStaticExportNames(moduleAst) {
12455
+ const names = new Set();
12456
+
12457
+ for (const statement of moduleAst?.body || []) {
12458
+ if (statement.type === 'ExportDefaultDeclaration') {
12459
+ names.add('default');
12460
+ continue;
12461
+ }
12462
+
12463
+ if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') {
12464
+ continue;
12465
+ }
12466
+
12467
+ if (statement.declaration) {
12468
+ for (const name of collectDeclarationExportNames(statement.declaration)) {
12469
+ names.add(name);
12470
+ }
12471
+ continue;
12472
+ }
12473
+
12474
+ for (const specifier of statement.specifiers || []) {
12475
+ if (specifier.exportKind === 'type') {
12476
+ continue;
12477
+ }
12478
+
12479
+ const exportedName = getExportName(specifier.exported);
12480
+ if (exportedName) {
12481
+ names.add(exportedName);
12482
+ }
12483
+ }
12484
+ }
12485
+
12486
+ return names;
12487
+ }
12488
+
12489
+ function predeclareModuleExports(moduleAst, moduleExports) {
12490
+ for (const name of collectStaticExportNames(moduleAst)) {
12491
+ if (!Object.prototype.hasOwnProperty.call(moduleExports, name)) {
12492
+ moduleExports[name] = undefined;
12493
+ }
12494
+ }
12495
+ }
12496
+
12425
12497
  class Interpreter {
12426
12498
  constructor(globalEnv, options = {}) {
12427
12499
  this.globalEnv = globalEnv;
@@ -14448,12 +14520,17 @@ class Interpreter {
14448
14520
  });
14449
14521
  moduleInterpreter.moduleCache = this.moduleCache; // Share cache
14450
14522
 
14451
- // Execute module and collect exports
14452
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
14453
-
14454
- // Cache the module exports
14455
14523
  moduleExports = moduleInterpreter.moduleExports;
14524
+ predeclareModuleExports(moduleAst, moduleExports);
14456
14525
  this.moduleCache.set(resolvedPath, moduleExports);
14526
+
14527
+ try {
14528
+ // Execute module and populate the cached exports object.
14529
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
14530
+ } catch (error) {
14531
+ this.moduleCache.delete(resolvedPath);
14532
+ throw error;
14533
+ }
14457
14534
  }
14458
14535
  }
14459
14536
 
package/dist/index.js CHANGED
@@ -11676,6 +11676,62 @@ function collectRuntimeIdentifierReferences(node) {
11676
11676
  visit(node);
11677
11677
  return references;
11678
11678
  }
11679
+ function getExportName(nameNode) {
11680
+ return (nameNode == null ? void 0 : nameNode.name) ?? (nameNode == null ? void 0 : nameNode.value);
11681
+ }
11682
+ function collectDeclarationExportNames(declaration) {
11683
+ const names = [];
11684
+ if (!declaration || isTypeOnlyDeclaration(declaration)) {
11685
+ return names;
11686
+ }
11687
+ if (declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration" || declaration.type === "TSEnumDeclaration") {
11688
+ const name = getPatternName(declaration.id);
11689
+ if (name) names.push(name);
11690
+ return names;
11691
+ }
11692
+ if (declaration.type === "VariableDeclaration") {
11693
+ for (const declarator of declaration.declarations || []) {
11694
+ const name = getPatternName(declarator.id);
11695
+ if (name) names.push(name);
11696
+ }
11697
+ }
11698
+ return names;
11699
+ }
11700
+ function collectStaticExportNames(moduleAst) {
11701
+ const names = /* @__PURE__ */ new Set();
11702
+ for (const statement of (moduleAst == null ? void 0 : moduleAst.body) || []) {
11703
+ if (statement.type === "ExportDefaultDeclaration") {
11704
+ names.add("default");
11705
+ continue;
11706
+ }
11707
+ if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") {
11708
+ continue;
11709
+ }
11710
+ if (statement.declaration) {
11711
+ for (const name of collectDeclarationExportNames(statement.declaration)) {
11712
+ names.add(name);
11713
+ }
11714
+ continue;
11715
+ }
11716
+ for (const specifier of statement.specifiers || []) {
11717
+ if (specifier.exportKind === "type") {
11718
+ continue;
11719
+ }
11720
+ const exportedName = getExportName(specifier.exported);
11721
+ if (exportedName) {
11722
+ names.add(exportedName);
11723
+ }
11724
+ }
11725
+ }
11726
+ return names;
11727
+ }
11728
+ function predeclareModuleExports(moduleAst, moduleExports) {
11729
+ for (const name of collectStaticExportNames(moduleAst)) {
11730
+ if (!Object.prototype.hasOwnProperty.call(moduleExports, name)) {
11731
+ moduleExports[name] = void 0;
11732
+ }
11733
+ }
11734
+ }
11679
11735
  var Interpreter = class _Interpreter {
11680
11736
  constructor(globalEnv, options = {}) {
11681
11737
  this.globalEnv = globalEnv;
@@ -13245,9 +13301,15 @@ var Interpreter = class _Interpreter {
13245
13301
  executionController: this.executionController
13246
13302
  });
13247
13303
  moduleInterpreter.moduleCache = this.moduleCache;
13248
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
13249
13304
  moduleExports = moduleInterpreter.moduleExports;
13305
+ predeclareModuleExports(moduleAst, moduleExports);
13250
13306
  this.moduleCache.set(resolvedPath, moduleExports);
13307
+ try {
13308
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
13309
+ } catch (error) {
13310
+ this.moduleCache.delete(resolvedPath);
13311
+ throw error;
13312
+ }
13251
13313
  }
13252
13314
  }
13253
13315
  this.bindImportSpecifiers(node, env, modulePath, moduleExports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jslike",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "Production-ready JavaScript interpreter with full ES6+ support using Acorn parser",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -62,7 +62,7 @@
62
62
  }
63
63
  },
64
64
  "bin": {
65
- "jslike": "./bin/jslike.js"
65
+ "jslike": "bin/jslike.js"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "node scripts/bundle-acorn.js && tsup && node scripts/post-build.js",