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)
This commit is contained in:
parent
1faf1c9d49
commit
32d669deea
1 changed files with 17 additions and 2 deletions
|
|
@ -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 <dxm-poster-section type="upg100-list">): 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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue