« get me outta code hell

composite: warn/error for tokens inside tokens - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-03-31 13:45:09 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-03-31 13:45:09 -0300
commit0786efd015df8bc856953fded07ef432cf0295a6 (patch)
treec8cf08e3e40f5fb7cda6c9bcf02ff7bc709ac549 /src
parentcab396d92152d2c75625dcef099093c136f538b5 (diff)
composite: warn/error for tokens inside tokens
Diffstat (limited to 'src')
-rw-r--r--src/data/composite.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/data/composite.js b/src/data/composite.js
index 8ac906c7..3b462ef5 100644
--- a/src/data/composite.js
+++ b/src/data/composite.js
@@ -10,17 +10,27 @@ import {TupleMap} from '#wiki-data';
 
 const globalCompositeCache = {};
 
-const _valueIntoToken = shape =>
-  (value = null) =>
-    (value === null
-      ? Symbol.for(`hsmusic.composite.${shape}`)
-   : typeof value === 'string'
-      ? Symbol.for(`hsmusic.composite.${shape}:${value}`)
-      : {
-          symbol: Symbol.for(`hsmusic.composite.${shape.split('.')[0]}`),
-          shape,
-          value,
-        });
+const _valueIntoToken = shape => (value = null) => {
+  if (value === null) {
+    return Symbol.for(`hsmusic.composite.${shape}`);
+  }
+
+  if (typeof value === 'string') {
+    return Symbol.for(`hsmusic.composite.${shape}:${value}`);
+  }
+
+  if (typeof value === 'object') {
+    if (Object.values(value).some(isInputToken)) {
+      throw new TypeError(`Don't nest input tokens inside ${shape}()`);
+    }
+  }
+
+  return {
+    symbol: Symbol.for(`hsmusic.composite.${shape.split('.')[0]}`),
+    shape,
+    value,
+  };
+};
 
 export const input = _valueIntoToken('input');
 input.symbol = Symbol.for('hsmusic.composite.input');