refactor: underscore-prefix all non-exported functions

This commit is contained in:
c0dev0id
2026-07-06 21:14:36 +02:00
parent 3beaa1d2ec
commit 884955195a
4 changed files with 120 additions and 120 deletions

View File

@@ -25,7 +25,7 @@ export function parseAstLog(text) {
slot = slotFull.slice(dotIdx + 1);
}
const { positionals, props } = parseRest(rest);
const { positionals, props } = _parseRest(rest);
const node = { slot, parentSlot, depth, positionals, props, children: [] };
@@ -46,7 +46,7 @@ export function parseAstLog(text) {
return root;
}
function parseRest(rest) {
function _parseRest(rest) {
const positionals = [];
const props = {};
let i = 0;
@@ -100,7 +100,7 @@ function parseRest(rest) {
// ── Second pass: build typed model ──────────────────────────────────────────
function collectUnknownProps(nodeProps, knownKeys) {
function _collectUnknownProps(nodeProps, knownKeys) {
return Object.fromEntries(Object.entries(nodeProps).filter(([k]) => !knownKeys.has(k)));
}
@@ -143,7 +143,7 @@ export function buildModel(rawTree) {
score.info = { ...node.props };
break;
case 'tuning':
score.tuning = buildTuning(node);
score.tuning = _buildTuning(node);
break;
case 'stage.cone':
score.stageCone = { type: 'stage_cone', ...node.props };
@@ -157,16 +157,16 @@ export function buildModel(rawTree) {
});
break;
case 'instrument':
score.instruments.push(buildInstrument(node));
score.instruments.push(_buildInstrument(node));
break;
case 'bar':
score.bars.push(buildBar(node));
score.bars.push(_buildBar(node));
break;
default:
if (node.parentSlot === 'articles') {
mergeArticleEntry(score, node);
_mergeArticleEntry(score, node);
} else {
score[node.slot] = buildGeneric(node);
score[node.slot] = _buildGeneric(node);
}
}
}
@@ -178,7 +178,7 @@ export function buildModel(rawTree) {
// — e.g. `articles.defaults 'f'` and (future) `articles.overwrites 'f'`.
// We merge them into one entry per label whose properties carry the scope
// of their originating subtype, so the UI can toggle scope per property.
function mergeArticleEntry(score, node) {
function _mergeArticleEntry(score, node) {
const name = node.positionals[0];
let entry = score.articles.find(a => a.name === name);
if (!entry) {
@@ -192,7 +192,7 @@ function mergeArticleEntry(score, node) {
return entry;
}
function buildTuning(node) {
function _buildTuning(node) {
const t = { type: 'tuning', base: node.props.base, scales: {}, chords: {}, frequencyFactors: null };
for (const child of node.children) {
if (child.slot === 'scales') {
@@ -209,7 +209,7 @@ function buildTuning(node) {
return t;
}
function buildInstrument(node) {
function _buildInstrument(node) {
const instr = {
type: 'instrument',
name: node.positionals[0],
@@ -228,16 +228,16 @@ function buildInstrument(node) {
for (const child of node.children) {
switch (child.parentSlot + '.' + child.slot) {
case 'character.variation':
instr.variations.push(buildVariation(child));
instr.variations.push(_buildVariation(child));
break;
case 'character.basic_properties':
instr.basicProperties = buildBasicProperties(child);
instr.basicProperties = _buildBasicProperties(child);
break;
case 'VOLUMES.shape':
instr.volumes = buildShape(child);
instr.volumes = _buildShape(child);
break;
case 'TIMBRE.shape':
instr.timbre = buildShape(child);
instr.timbre = _buildShape(child);
break;
case 'FM.modulation':
instr.fmModulations.push({ ...child.props });
@@ -246,14 +246,14 @@ function buildInstrument(node) {
instr.amModulations.push({ ...child.props });
break;
default:
instr.unknownSlots.push(buildGeneric(child));
instr.unknownSlots.push(_buildGeneric(child));
}
}
return instr;
}
function buildVariation(node) {
function _buildVariation(node) {
const v = {
type: 'variation',
dependsOn: node.props.depends_on ?? node.props.for_value ?? null,
@@ -269,29 +269,29 @@ function buildVariation(node) {
const key = (child.parentSlot ?? child.slot) + '.' + child.slot;
switch (key) {
case 'variation.basic_properties':
v.basicProperties = buildBasicProperties(child);
v.basicProperties = _buildBasicProperties(child);
break;
case 'variation.label_spec':
v.labelSpecs.push(buildLabelSpec(child));
v.labelSpecs.push(_buildLabelSpec(child));
break;
case 'variation.subvariation':
v.subvariations.push(buildVariation(child));
v.subvariations.push(_buildVariation(child));
break;
case 'variation.SPREAD':
v.spread = child.positionals;
break;
case 'RAILSBACK_CURVE.shape':
v.railsbackCurve = buildShape(child);
v.railsbackCurve = _buildShape(child);
break;
default:
v.unknownSlots.push(buildGeneric(child));
v.unknownSlots.push(_buildGeneric(child));
}
}
return v;
}
function buildBasicProperties(node) {
function _buildBasicProperties(node) {
const bp = {
type: 'basic_properties',
A: null, S: null, R: null,
@@ -304,32 +304,32 @@ function buildBasicProperties(node) {
for (const child of node.children) {
const fqSlot = (child.parentSlot ?? '') + (child.parentSlot ? '.' : '') + child.slot;
if (child.parentSlot === 'A' && child.slot === 'shape') {
bp.A = buildShape(child);
bp.A = _buildShape(child);
} else if (child.parentSlot === 'S' && child.slot === 'shape') {
bp.S = buildShape(child);
bp.S = _buildShape(child);
} else if (child.parentSlot === 'R' && child.slot === 'shape') {
bp.R = buildShape(child);
bp.R = _buildShape(child);
} else if (child.parentSlot === 'variation' && child.slot === 'O') {
bp.oscillator = child.props.ref ?? child.positionals[0];
} else if (child.parentSlot === 'FM' && child.slot === 'modulation') {
const fm = { ...child.props };
const envChild = child.children.find(c => c.slot === 'shape');
if (envChild) fm.shape = buildShape(envChild);
if (envChild) fm.shape = _buildShape(envChild);
bp.fmModulations.push(fm);
} else if (child.parentSlot === 'AM' && child.slot === 'modulation') {
const am = { ...child.props };
const envChild = child.children.find(c => c.slot === 'shape');
if (envChild) am.shape = buildShape(envChild);
if (envChild) am.shape = _buildShape(envChild);
bp.amModulations.push(am);
} else {
bp.unknownSlots.push(buildGeneric(child));
bp.unknownSlots.push(_buildGeneric(child));
}
}
return bp;
}
function buildLabelSpec(node) {
function _buildLabelSpec(node) {
const ls = {
type: 'label_spec',
label: node.positionals[0],
@@ -340,7 +340,7 @@ function buildLabelSpec(node) {
const directBpChildren = [];
for (const child of node.children) {
if (child.parentSlot === 'variation' && child.slot === 'basic_properties') {
ls.basicProperties = buildBasicProperties(child);
ls.basicProperties = _buildBasicProperties(child);
} else if (
(child.slot === 'shape' && (child.parentSlot === 'A' || child.parentSlot === 'S' || child.parentSlot === 'R')) ||
(child.parentSlot === 'variation' && child.slot === 'O') ||
@@ -348,17 +348,17 @@ function buildLabelSpec(node) {
) {
directBpChildren.push(child);
} else {
ls.unknownSlots.push(buildGeneric(child));
ls.unknownSlots.push(_buildGeneric(child));
}
}
if (!ls.basicProperties && directBpChildren.length > 0) {
ls.basicProperties = buildBasicProperties({ children: directBpChildren });
ls.basicProperties = _buildBasicProperties({ children: directBpChildren });
}
return ls;
}
function buildShape(node) {
function _buildShape(node) {
return {
type: 'shape',
length: node.props.length,
@@ -374,7 +374,7 @@ function buildShape(node) {
};
}
function buildBar(node) {
function _buildBar(node) {
const bar = {
type: 'bar',
id: node.positionals[0] ?? '',
@@ -393,35 +393,35 @@ function buildBar(node) {
const fqSlot = (child.parentSlot ?? '') + (child.parentSlot ? '.' : '') + child.slot;
switch (fqSlot) {
case 'stress_pattern.stressor':
bar.stressor = buildStressor(child);
bar.stressor = _buildStressor(child);
break;
case 'tempo.shape':
bar.tempoShape = buildShape(child);
bar.tempoShape = _buildShape(child);
break;
case 'tempo.levels':
bar.tempoLevels = child.positionals[0];
break;
case 'lower_stress_bound.shape':
bar.lowerStressBound = buildShape(child);
bar.lowerStressBound = _buildShape(child);
break;
case 'upper_stress_bound.shape':
bar.upperStressBound = buildShape(child);
bar.upperStressBound = _buildShape(child);
break;
case 'bar.tuning':
bar.tunings.push({ ...child.props });
break;
case 'bar.voice':
bar.voices[child.positionals[0]] = buildVoice(child);
bar.voices[child.positionals[0]] = _buildVoice(child);
break;
default:
bar.unknownSlots.push(buildGeneric(child));
bar.unknownSlots.push(_buildGeneric(child));
}
}
return bar;
}
function buildStressor(node) {
function _buildStressor(node) {
const levels = [];
let currentGroup = [];
for (const child of node.children) {
@@ -436,7 +436,7 @@ function buildStressor(node) {
return { type: 'stressor', groups: levels };
}
function buildVoice(node) {
function _buildVoice(node) {
const voice = {
type: 'voice',
name: node.positionals[0],
@@ -449,13 +449,13 @@ function buildVoice(node) {
const fqSlot = (child.parentSlot ?? '') + (child.parentSlot ? '.' : '') + child.slot;
switch (fqSlot) {
case 'voice.offset':
voice.offsets.push(buildOffset(child));
voice.offsets.push(_buildOffset(child));
break;
case 'voice.article':
voice.articles.push(child.positionals[0]);
break;
case 'voice.motif':
voice.motifs.push(buildMotif(child));
voice.motifs.push(_buildMotif(child));
break;
default:
// ignore
@@ -465,24 +465,24 @@ function buildVoice(node) {
return voice;
}
function buildOffset(node) {
function _buildOffset(node) {
const offset = {
type: 'offset',
tick: node.props.tick,
stemNotes: [],
motifRefs: [],
unknownProps: collectUnknownProps(node.props, new Set(['tick'])),
unknownProps: _collectUnknownProps(node.props, new Set(['tick'])),
};
for (const child of node.children) {
if (child.parentSlot === 'line' && child.slot === 'stem_note')
offset.stemNotes.push(buildStemNote(child));
offset.stemNotes.push(_buildStemNote(child));
else if (child.parentSlot === 'line' && child.slot === 'motif')
offset.motifRefs.push({ label: child.positionals[0], chord: child.props.chord ?? null });
}
return offset;
}
function buildStemNote(node) {
function _buildStemNote(node) {
const KNOWN = new Set(['pitch', 'eff_length', 'adj_stress', 'adjacent']);
const chainNode = node.children.find(c => c.parentSlot === 'stem_note' && c.slot === 'chain');
const writeToNode = node.children.find(c => c.parentSlot === 'stem_note' && c.slot === 'write_to');
@@ -498,13 +498,13 @@ function buildStemNote(node) {
writeToName: writeToNode?.positionals[0] ?? null,
clauses: (chainNode?.children ?? [])
.filter(c => c.parentSlot === 'chain' && c.slot === 'clause')
.map(buildClause),
.map(_buildClause),
isDirty: false,
unknownProps: collectUnknownProps(node.props, KNOWN),
unknownProps: _collectUnknownProps(node.props, KNOWN),
};
}
function buildClause(node) {
function _buildClause(node) {
return {
type: 'clause',
index: node.positionals[0] ?? 0,
@@ -518,28 +518,28 @@ function buildClause(node) {
};
}
function buildMotif(node) {
function _buildMotif(node) {
const m = {
type: 'motif',
label: node.props.label,
stemNotes: [],
unknownProps: collectUnknownProps(node.props, new Set(['label'])),
unknownProps: _collectUnknownProps(node.props, new Set(['label'])),
};
for (const child of node.children) {
if (child.parentSlot === 'line' && child.slot === 'stem_note')
m.stemNotes.push(buildStemNote(child));
m.stemNotes.push(_buildStemNote(child));
}
m.isStatic = m.stemNotes.length > 0 && !m.stemNotes.some(sn => Number.isInteger(sn.pitch));
return m;
}
function buildGeneric(node) {
function _buildGeneric(node) {
return {
type: node.slot,
parentSlot: node.parentSlot,
depth: node.depth,
positionals: node.positionals,
props: node.props,
children: node.children.map(buildGeneric),
children: node.children.map(_buildGeneric),
};
}