diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-06 13:13:06 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-04-24 12:22:49 -0300 |
commit | 929afa1b7ca19e44ba6bc950beadd87b0ca44f15 (patch) | |
tree | a5108fc3337bd64b7c83570d39c5e0a539de551a /src/data/composite.js | |
parent | 459d8b3fc37c85411107e3943e37812c20849c98 (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/data/composite.js')
-rw-r--r-- | src/data/composite.js | 36 |
1 files changed, 16 insertions, 20 deletions
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; |