aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-manager.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-05-27 06:00:43 +0200
committerAgando <roduccomm@gmail.com>2026-05-27 06:00:43 +0200
commit212708b464c2bdbdd9670c00804623dca0729d2c (patch)
treeee190cbb0d1524350baea641df65aa19817744b5 /modules/core/module-manager.js
parentf4d934d341056142da1212c845eeeb170fd452c2 (diff)
auto: 2026-05-27_06:00 changes
Diffstat (limited to 'modules/core/module-manager.js')
-rw-r--r--modules/core/module-manager.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/modules/core/module-manager.js b/modules/core/module-manager.js
index 8e9e911..c508778 100644
--- a/modules/core/module-manager.js
+++ b/modules/core/module-manager.js
@@ -42,10 +42,12 @@
}
createModuleClass(code, url) {
try {
- const classMatch = code.match(/class\s+(\w+)\s+(extends\s+\S+)?\s*\{/);
+ // Strip leading comments to avoid ASI: `return\n/**` → `return; /**`
+ const cleanCode = code.replace(/^\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/\s*)*\s*/, '');
+ const classMatch = cleanCode.match(/class\s+(\w+)\s+(extends\s+\S+)?\s*\{/);
if (classMatch) {
const className = classMatch[1];
- const mod = new Function('return ' + code + '\nreturn ' + className)();
+ const mod = new Function('return ' + cleanCode + '\nreturn ' + className)();
return mod;
}
throw new Error('No valid module class found');
@@ -78,6 +80,24 @@
}
return false;
}
+ loadModuleFromCode(code, url) {
+ try {
+ this.terminal.print('Loading module from editor...', 'info');
+ const ModuleClass = this.createModuleClass(code, url);
+ if (ModuleClass) {
+ const instance = new ModuleClass();
+ this.registerModule(instance, url);
+ if (instance.init) {
+ instance.init();
+ }
+ this.terminal.print(`Module loaded from editor: ${instance.constructor.name}`, 'success');
+ return true;
+ }
+ } catch (error) {
+ this.terminal.print(`Failed to load module from code: ${error.message}`, 'error');
+ return false;
+ }
+ }
getModuleList() {
const allNames = new Set([...this.moduleRegistry.map(m => m.name), ...Object.keys(this.modules)]);
return Array.from(allNames).map(name => ({