diff options
Diffstat (limited to 'src/data/composite.js')
| -rw-r--r-- | src/data/composite.js | 32 |
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'); |