From 929afa1b7ca19e44ba6bc950beadd87b0ca44f15 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 6 Mar 2024 13:13:06 -0400 Subject: 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. --- src/data/composite.js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/data/composite.js b/src/data/composite.js index 0ace26e5..33d69a68 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; -- cgit 1.3.0-6-gf8a5