frontend: Warnungs-Modell vereinheitlichen (strukturiert: Typ + Zeile)
TASKS Phase 1 (abgeschlossen). Warnungen sind jetzt maschinenlesbare Objekte
{type, line, ...data} statt vorformatierter Strings: der Renderer emittiert
{type:'mixedGate', line, label}; src/warnings.js `formatWarning(w, t)` macht
daraus an EINER Stelle den lokalisierten, HTML-escapten Anzeigetext. Damit sind
Typ und Zeilennummer sortier-/filter-/testbar, und Phase 2 (unbekannte
Statuszeichen -> {type:'unknownStatus', line, code}) dockt ohne Formatstreuung an.
tests/warnings.test.js + Mixed-Gate-Test im Renderer (29 Tests grün).
Ende-zu-Ende im Browser verifiziert (lokalisierte Warnung mit Zeile + Label).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
5905712aa5
commit
32a02021ed
+2
-1
@@ -2,6 +2,7 @@ import './style.css';
|
||||
import { parse } from './parser.js';
|
||||
import { computeCheapSet } from './model.js';
|
||||
import { esc, renderTreeHtml } from './render.js';
|
||||
import { formatWarning } from './warnings.js';
|
||||
|
||||
const INITIAL = `%% Project structure – Sprint 14
|
||||
[~] Website relaunch (XL) https://wiki.example.com/relaunch
|
||||
@@ -57,7 +58,7 @@ function render(){
|
||||
});
|
||||
out.innerHTML = html;
|
||||
|
||||
warnBox.innerHTML = warnings.map(w => `<div>⚠ ${w}</div>`).join('');
|
||||
warnBox.innerHTML = warnings.map(w => `<div>⚠ ${formatWarning(w, t)}</div>`).join('');
|
||||
drawCheapPath();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ function renderChildren(node, warnings, opts){
|
||||
if(!kids.length) return '';
|
||||
const types = new Set(kids.map(k => k.type));
|
||||
if(types.size > 1){
|
||||
warnings.push(opts.t('mixedWarn', {line: kids[0].line, label: esc(node.label)}));
|
||||
/* strukturierte Warnung (Typ + Zeile); Formatierung in warnings.js */
|
||||
warnings.push({type: 'mixedGate', line: kids[0].line, label: node.label});
|
||||
}
|
||||
const gate = gateOf(kids);
|
||||
const items = kids.map(k => {
|
||||
@@ -62,7 +63,8 @@ function renderChildren(node, warnings, opts){
|
||||
}
|
||||
|
||||
/* Baut den inneren HTML-String für #out aus (bereits gefilterten) Wurzeln und
|
||||
sammelt Warnungen (gemischte Gates). Leere Wurzelliste ⇒ leerer String. */
|
||||
sammelt strukturierte Warnungen ({type, line, ...}, siehe warnings.js).
|
||||
Leere Wurzelliste ⇒ leerer String. */
|
||||
export function renderTreeHtml(roots, opts){
|
||||
const warnings = [];
|
||||
const html = roots.map(root => {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Vereinheitlichtes Warnungs-Modell.
|
||||
Producer (Renderer, künftig auch Parser) liefern strukturierte Objekte
|
||||
{ type, line, ...data }
|
||||
statt fertig formatierter Strings — so bleiben Typ und Zeilennummer
|
||||
maschinenlesbar (sortierbar, filterbar, testbar). Die i18n-/HTML-Aufbereitung
|
||||
passiert an genau einer Stelle: formatWarning(). Vgl. SPEC §3 (gemischte
|
||||
Gates) und TASKS Phase 2 (unbekannte Statuszeichen).
|
||||
|
||||
Bekannte Typen:
|
||||
- mixedGate { line, label } — Geschwister mit gemischtem Gate (SPEC §3)
|
||||
- unknownStatus { line, code } — unbekanntes Statuszeichen (Phase 2) */
|
||||
|
||||
import { esc } from './render.js';
|
||||
|
||||
/* Strukturierte Warnung -> lokalisierter Anzeigetext (HTML-escaped Daten).
|
||||
`t` ist die i18n-Funktion (key, vars) -> String. */
|
||||
export function formatWarning(w, t){
|
||||
switch(w.type){
|
||||
case 'mixedGate':
|
||||
return t('mixedWarn', {line: w.line, label: esc(w.label)});
|
||||
case 'unknownStatus':
|
||||
return t('unknownStatusWarn', {line: w.line, code: esc(w.code)});
|
||||
default:
|
||||
return `${esc(String(w.type))} (${w.line ?? '?'})`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user