« get me outta code hell

composite: always allow non-composable step as base - 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>2024-03-06 13:13:06 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-05-01 07:06:05 -0300
commitf0d3e127cb138e435652a134d94656d6c457759a (patch)
treee59ca2423498591d6c491b30a015e48de1f7ac38 /src
parentd8ac315809796da6988211fa2887c599a312bee3 (diff)
composite: always allow non-composable step as base
This is intended to allow, for example, using exposeDependency
as the final step in a nestable composition which raises (without
exiting) in a previous step if a particular condition is met.
Diffstat (limited to 'src')
-rw-r--r--src/data/composite.js36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/data/composite.js b/src/data/composite.js
index 0ace26e..33d69a6 100644
--- a/src/data/composite.js
+++ b/src/data/composite.js
@@ -780,16 +780,9 @@ export function compositeFrom(description) {
       (step.annotation ? ` (${step.annotation})` : ``);
 
     aggregate.nest({message}, ({push}) => {
-      if (isBase && stepComposes !== compositionNests) {
+      if (!isBase && !stepComposes) {
         return push(new TypeError(
-          (compositionNests
-            ? `Base must compose, this composition is nestable`
-            : `Base must not compose, this composition isn't nestable`)));
-      } else if (!isBase && !stepComposes) {
-        return push(new TypeError(
-          (compositionNests
-            ? `All steps must compose`
-            : `All steps (except base) must compose`)));
+          `All steps leading up to base must compose`));
       }
 
       if (
@@ -915,8 +908,16 @@ export function compositeFrom(description) {
       debug(() => colors.bright(`begin composition - not transforming`));
     }
 
-    for (let i = 0; i < steps.length; i++) {
-      const step = steps[i];
+    for (
+      const [i, {
+        step,
+        stepComposes,
+      }] of
+        stitchArrays({
+          step: steps,
+          stepComposes: stepsCompose,
+        }).entries()
+    ) {
       const isBase = i === steps.length - 1;
 
       debug(() => [
@@ -1029,10 +1030,7 @@ export function compositeFrom(description) {
 
         let args;
 
-        if (isBase && !compositionNests) {
-          args =
-            argsLayout.filter(arg => arg !== continuationSymbol);
-        } else {
+        if (stepComposes) {
           let continuation;
 
           ({continuation, continuationStorage} =
@@ -1043,6 +1041,9 @@ export function compositeFrom(description) {
               (arg === continuationSymbol
                 ? continuation
                 : arg));
+        } else {
+          args =
+            argsLayout.filter(arg => arg !== continuationSymbol);
         }
 
         return expose[name](...args);
@@ -1102,11 +1103,6 @@ export function compositeFrom(description) {
 
       if (result !== continuationSymbol) {
         debug(() => [`step #${i+1} - result: exit (inferred) ->`, result]);
-
-        if (compositionNests) {
-          throw new TypeError(`Inferred early-exit is disallowed in nested compositions`);
-        }
-
         debug(() => colors.bright(`end composition - exit (inferred)`));
 
         return result;