juxscript 1.0.72 → 1.0.73
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/machinery/compiler.js +73 -3
- package/package.json +1 -1
package/machinery/compiler.js
CHANGED
|
@@ -367,7 +367,19 @@ function transformJuxToViewFunction(juxContent, functionName, pageName, relative
|
|
|
367
367
|
}
|
|
368
368
|
result = result.replace(/\.renderTo\(container\)/g, '.render("#app")').replace(/\.render\(\s*\)/g, '.render("#app")');
|
|
369
369
|
const cleanName = functionName.replace(/[-_]/g, ' ').split(' ').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join('');
|
|
370
|
-
|
|
370
|
+
|
|
371
|
+
// ✅ Wrap View implementation in underscore function, then export Wrapped version
|
|
372
|
+
return `
|
|
373
|
+
// View: ${cleanName}
|
|
374
|
+
function _${cleanName}() {
|
|
375
|
+
${result}
|
|
376
|
+
|
|
377
|
+
return document.getElementById('app');
|
|
378
|
+
}
|
|
379
|
+
const ${cleanName} = JuxError.wrap('${cleanName}', _${cleanName});
|
|
380
|
+
// Register Source
|
|
381
|
+
JuxError.register('${cleanName}', '${relativePath}');
|
|
382
|
+
`;
|
|
371
383
|
}
|
|
372
384
|
|
|
373
385
|
function resolveImportPath(importPath, currentFilePath) {
|
|
@@ -428,13 +440,71 @@ function generateRouterBundle(views, routes, sharedModules = new Map(), allImpor
|
|
|
428
440
|
else if (parts.length > 0) filteredImports.push(`import ${parts.join(', ')} from '${source}';`);
|
|
429
441
|
});
|
|
430
442
|
|
|
443
|
+
const juxDebugUtils = `
|
|
444
|
+
// ============================================
|
|
445
|
+
// JUX DEBUG UTILITIES
|
|
446
|
+
// ============================================
|
|
447
|
+
const JUX_DEBUG = true;
|
|
448
|
+
|
|
449
|
+
const JuxError = {
|
|
450
|
+
sourceMap: {},
|
|
451
|
+
|
|
452
|
+
register(viewName, sourceFile) {
|
|
453
|
+
this.sourceMap[viewName] = sourceFile;
|
|
454
|
+
},
|
|
455
|
+
|
|
456
|
+
wrap(viewName, viewFn) {
|
|
457
|
+
return function() {
|
|
458
|
+
const sourceFile = JuxError.sourceMap[viewName] || 'unknown';
|
|
459
|
+
if (JUX_DEBUG) console.log(\`🚀 [JUX] Rendering: \${viewName} (\${sourceFile})\`);
|
|
460
|
+
|
|
461
|
+
try {
|
|
462
|
+
return viewFn.apply(this, arguments);
|
|
463
|
+
} catch (error) {
|
|
464
|
+
console.error(\`🚨 JUX RUNTIME ERROR\\nView: \${viewName}\\nSource: \${sourceFile}\`);
|
|
465
|
+
console.error(error);
|
|
466
|
+
|
|
467
|
+
const app = document.getElementById('app');
|
|
468
|
+
if (app) {
|
|
469
|
+
app.innerHTML = \`
|
|
470
|
+
<div style="font-family: monospace; background: #1e1e1e; color: #ff6b6b; min-height: 100vh; padding: 2rem;">
|
|
471
|
+
<div style="display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem;">
|
|
472
|
+
<div style="font-size: 2rem;">🚨</div>
|
|
473
|
+
<div>
|
|
474
|
+
<h1 style="margin:0; font-size: 1.5rem; color: #ff6b6b;">JUX Runtime Error</h1>
|
|
475
|
+
</div>
|
|
476
|
+
</div>
|
|
477
|
+
|
|
478
|
+
<div style="margin-bottom: 1rem;">
|
|
479
|
+
<div style="color: #888; margin-bottom: 4px;">View:</div>
|
|
480
|
+
<span style="color: #fff; font-weight: bold;">\${viewName}</span>
|
|
481
|
+
</div>
|
|
482
|
+
|
|
483
|
+
<div style="margin-bottom: 2rem;">
|
|
484
|
+
<div style="color: #888; margin-bottom: 4px;">Source:</div>
|
|
485
|
+
<span style="color: #4caf50; font-family: monospace;">\${sourceFile}</span>
|
|
486
|
+
</div>
|
|
487
|
+
|
|
488
|
+
<pre style="background: #2d2d2d; padding: 20px; border-radius: 8px; overflow-x: auto; color: #e0e0e0; border-left: 4px solid #ff6b6b;">\${error.message}\\n\\n\${error.stack}</pre>
|
|
489
|
+
</div>
|
|
490
|
+
\`;
|
|
491
|
+
}
|
|
492
|
+
throw error;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
`;
|
|
498
|
+
|
|
431
499
|
return `// Generated Jux Router Bundle
|
|
432
500
|
${filteredImports.join('\n')}
|
|
433
501
|
|
|
502
|
+
${juxDebugUtils}
|
|
503
|
+
|
|
434
504
|
// SHARED MODULES
|
|
435
505
|
${Array.from(sharedModules.values()).filter(c => c.trim()).join('\n\n')}
|
|
436
506
|
|
|
437
|
-
// VIEWS
|
|
507
|
+
// VIEWS (Wrapped in JuxError)
|
|
438
508
|
${views.filter(v => v.trim()).join('\n\n')}
|
|
439
509
|
|
|
440
510
|
function JuxNotFound() { jux.heading(1, { text: '404 - Page Not Found' }).render('#app'); return document.getElementById('app'); }
|
|
@@ -459,7 +529,7 @@ document.addEventListener('click', e => {
|
|
|
459
529
|
const a = e.target.closest('a');
|
|
460
530
|
if (!a || a.dataset.router === 'false' || new URL(a.href).origin !== location.origin) return;
|
|
461
531
|
e.preventDefault();
|
|
462
|
-
history.pushState({}, '',
|
|
532
|
+
history.pushState({}, '', a.href);
|
|
463
533
|
render();
|
|
464
534
|
});
|
|
465
535
|
window.addEventListener('popstate', render);
|