From 32d669deea4d65e230f4b2f1f0b4a6274e249484 Mon Sep 17 00:00:00 2001 From: Doxa Maps Date: Fri, 2 Oct 2026 08:05:44 +0000 Subject: [PATCH] check:label-key-coverage follows the region table to data/upg100-regions.js, and reads the labels regionOf returns as literals (a removed 'China + Mongolia' key FAILS it) --- internal/check-label-key-coverage.mjs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/check-label-key-coverage.mjs b/internal/check-label-key-coverage.mjs index 00b910e72..6b4f91d15 100644 --- a/internal/check-label-key-coverage.mjs +++ b/internal/check-label-key-coverage.mjs @@ -50,11 +50,14 @@ const ok = (cond, msg) => { if (!cond) fails.push(msg) } // directly (legend-tree's regionFor returns 'India' / 'China + Mongolia' / 'Other' without a helper call). const TABLES = [ { - file: 'plugin-designs/my-upg-100-list/poster-wall.vue', + // the poster wall's region sections (and ): the table moved out of + // poster-wall.vue into data/upg100-regions.js; regionOf RETURNS 'India' / 'China + Mongolia' / 'Other' directly + file: 'plugin-designs/my-upg-100-list/data/upg100-regions.js', produces: 'REGION_OF', mapsFile: 'plugin-designs/my-upg-100-list/data/legend-tree.js', maps: 'REGION_KEY', - via: 'regionLabel', + via: 'regionTitle', + producerReturns: 'regionOf', area: 'poster', }, { @@ -87,6 +90,13 @@ function producerLabels(src, fn) { const m = new RegExp(`const ${fn}\\s*=\\s*\\([^)]*\\)\\s*=>([\\s\\S]*?);\\n`).exec(src) return m ? [...m[1].matchAll(/[?:]\s*'([^']+)'/g)].map((x) => x[1]) : null } +/** The labels a function declaration RETURNS as literals: `return 'India'`. */ +function returnedLabels(src, fn) { + const at = src.search(new RegExp(`function ${fn}\\s*\\(`)) + if (at < 0) return null + const body = src.slice(at, src.indexOf('\n}\n', at)) + return [...body.matchAll(/return\s+'([^']+)'/g)].map((x) => x[1]) +} /** Quoted values on the right of a colon — the English labels a table produces. */ const valuesOf = (body) => new Set([...body.matchAll(/:\s*'([^']+)'/g)].map((m) => m[1])) /** Quoted keys on the left of a colon — the English labels a table covers. */ @@ -119,6 +129,11 @@ for (const t of TABLES) { if (!got || !got.length) { ok(false, `${t.file}: no \`const ${t.producerFn} = (…) =>\` returning labels — this gate has gone blind`); continue } fromFn = got } + if (t.producerReturns) { + const got = returnedLabels(src, t.producerReturns) + if (!got || !got.length) { ok(false, `${t.file}: no \`function ${t.producerReturns}(…)\` returning labels — this gate has gone blind`); continue } + fromFn = [...fromFn, ...got] + } const produced = new Set([...fromTable, ...fromCalls, ...fromFn]) const covered = keysOf(maps)