diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d318b32f..91bcef821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http: - Fixed list spread doc example. - Better unused bind conflict message. - Narrowed parsing of structure refinements to avoid conflicting with spreads in lists. +- Account for documented expressions in bind recurrence relations. ## 0.9.34 2024-02-24 diff --git a/src/nodes/Bind.ts b/src/nodes/Bind.ts index a2a02c62a..4027d22a2 100644 --- a/src/nodes/Bind.ts +++ b/src/nodes/Bind.ts @@ -49,6 +49,7 @@ import ExpressionPlaceholder from './ExpressionPlaceholder'; import Refer from '../edit/Refer'; import UnknownType from './UnknownType'; import type Locales from '../locale/Locales'; +import DocumentedExpression from './DocumentedExpression'; export default class Bind extends Expression { readonly docs?: Docs; @@ -603,18 +604,20 @@ export default class Bind extends Expression { ] : [ new Start(this, (evaluator) => { + const value = + this.value instanceof DocumentedExpression + ? this.value.expression + : this.value; + // Before evaluating the bind's value, see if the value expression previously evaluated to // a stream, and if so, bind this Bind's names to the previous value. This allows // for stream-based recurrence relations, where a stream or reaction's future values can be // affected by their past values. if ( - this.value instanceof Evaluate || - this.value instanceof Reaction + value instanceof Evaluate || + value instanceof Reaction ) { - const stream = evaluator.getStreamFor( - this.value, - true, - ); + const stream = evaluator.getStreamFor(value, true); const latest = stream?.latest(); if (latest) evaluator.bind(this.names, latest); }