aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-manager.js
diff options
context:
space:
mode:
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 => ({