diff --git a/packages/xforms-engine/src/instance/Note.ts b/packages/xforms-engine/src/instance/Note.ts index ecefbfea8..d664c097c 100644 --- a/packages/xforms-engine/src/instance/Note.ts +++ b/packages/xforms-engine/src/instance/Note.ts @@ -83,7 +83,7 @@ export class Note clientStateFactory: this.engineConfig.stateFactory, }; - const isReadonly = createNoteReadonlyThunk(this, definition.bind.readonly); + const isReadonly = createNoteReadonlyThunk(this, definition); const noteTextComputation = createNoteText(this, definition.noteTextDefinition); let noteText: ComputedNoteText; diff --git a/packages/xforms-engine/src/lib/reactivity/createNoteReadonlyThunk.ts b/packages/xforms-engine/src/lib/reactivity/createNoteReadonlyThunk.ts index e4bbffa97..313140954 100644 --- a/packages/xforms-engine/src/lib/reactivity/createNoteReadonlyThunk.ts +++ b/packages/xforms-engine/src/lib/reactivity/createNoteReadonlyThunk.ts @@ -1,31 +1,36 @@ import type { Accessor } from 'solid-js'; import type { EvaluationContext } from '../../instance/internal-api/EvaluationContext.ts'; -import type { BindComputationExpression } from '../../parse/expression/BindComputationExpression.ts'; +import type { NoteNodeDefinition } from '../../parse/model/NoteNodeDefinition.ts'; +import { resolveDependencyNodesets } from '../../parse/xpath/dependency-analysis.ts'; import { createComputedExpression } from './createComputedExpression.ts'; export const createNoteReadonlyThunk = ( context: EvaluationContext, - readonlyDefinition: BindComputationExpression<'readonly'> + definition: NoteNodeDefinition ): Accessor => { - if (!readonlyDefinition.isConstantTruthyExpression()) { + const { reference } = definition.bodyElement; + const { readonly } = definition.bind; + + if (!readonly.isConstantTruthyExpression()) { throw new Error('Expected a static readonly expression'); } let result = true; if (import.meta.env.DEV) { - const { expression } = readonlyDefinition; + const { expression } = readonly; + const dependencyReferences = resolveDependencyNodesets(reference, expression); - if (readonlyDefinition.dependencyReferences.size > 0) { + if (dependencyReferences.length > 0) { throw new Error(`Expected expression ${expression} to have no dependencies`); } - const computedExpression = createComputedExpression(context, readonlyDefinition); + const computedExpression = createComputedExpression(context, readonly); result = computedExpression(); if (result !== true) { - throw new Error(`Expected expression ${readonlyDefinition.expression} to return true`); + throw new Error(`Expected expression ${readonly.expression} to return true`); } } diff --git a/packages/xforms-engine/src/parse/body/control/select/ItemsetNodesetContext.ts b/packages/xforms-engine/src/parse/body/control/select/ItemsetNodesetContext.ts index 487432057..194c1b35f 100644 --- a/packages/xforms-engine/src/parse/body/control/select/ItemsetNodesetContext.ts +++ b/packages/xforms-engine/src/parse/body/control/select/ItemsetNodesetContext.ts @@ -1,5 +1,4 @@ import { DependencyContext } from '../../../expression/abstract/DependencyContext.ts'; -import type { AnyDependentExpression } from '../../../expression/abstract/DependentExpression.ts'; import type { ItemsetDefinition } from './ItemsetDefinition.ts'; export class ItemsetNodesetContext extends DependencyContext { @@ -19,8 +18,4 @@ export class ItemsetNodesetContext extends DependencyContext { super.isTranslated = value; this.itemset.isTranslated = value; } - - override registerDependentExpression(expression: AnyDependentExpression): void { - this.itemset.registerDependentExpression(expression); - } } diff --git a/packages/xforms-engine/src/parse/expression/abstract/DependencyContext.ts b/packages/xforms-engine/src/parse/expression/abstract/DependencyContext.ts index d827c86f3..13ffe7359 100644 --- a/packages/xforms-engine/src/parse/expression/abstract/DependencyContext.ts +++ b/packages/xforms-engine/src/parse/expression/abstract/DependencyContext.ts @@ -1,28 +1,7 @@ -import type { AnyDependentExpression } from './DependentExpression.ts'; - export abstract class DependencyContext { abstract get parentReference(): string | null; abstract get reference(): string | null; - protected readonly dependentExpressions = new Set(); - - protected dependencyExpressionsCache: ReadonlySet | null = null; - - get dependencyExpressions(): ReadonlySet { - let { dependencyExpressionsCache } = this; - - if (dependencyExpressionsCache == null) { - dependencyExpressionsCache = new Set( - Array.from(this.dependentExpressions).flatMap((expression) => { - return Array.from(expression.dependencyReferences); - }) - ); - this.dependencyExpressionsCache = dependencyExpressionsCache; - } - - return dependencyExpressionsCache; - } - get isTranslated(): boolean { return this._isTranslated; } @@ -45,9 +24,4 @@ export abstract class DependencyContext { // Update note on `set isTranslated` if this internal storage changes. protected _isTranslated = false; - - registerDependentExpression(expression: AnyDependentExpression): void { - this.dependencyExpressionsCache = null; - this.dependentExpressions.add(expression); - } } diff --git a/packages/xforms-engine/src/parse/expression/abstract/DependentExpression.ts b/packages/xforms-engine/src/parse/expression/abstract/DependentExpression.ts index 57ef077d8..5ab160998 100644 --- a/packages/xforms-engine/src/parse/expression/abstract/DependentExpression.ts +++ b/packages/xforms-engine/src/parse/expression/abstract/DependentExpression.ts @@ -1,5 +1,4 @@ import type { EngineXPathEvaluator } from '../../../integration/xpath/EngineXPathEvaluator.ts'; -import { resolveDependencyNodesets } from '../../xpath/dependency-analysis.ts'; import type { ConstantExpression, ConstantTruthyExpression, @@ -55,7 +54,6 @@ export interface ConstantTruthyDependentExpression extends ConstantDependentExpr } export abstract class DependentExpression { - readonly dependencyReferences: ReadonlySet = new Set(); readonly isTranslated: boolean = false; readonly evaluatorMethod: DependentExpressionEvaluatorMethod; readonly constantExpression: ConstantExpression | null; @@ -81,26 +79,17 @@ export abstract class DependentExpression { diff --git a/packages/xforms-engine/src/parse/model/DescendentNodeDefinition.ts b/packages/xforms-engine/src/parse/model/DescendentNodeDefinition.ts index 9dcdaecd7..6aca359b6 100644 --- a/packages/xforms-engine/src/parse/model/DescendentNodeDefinition.ts +++ b/packages/xforms-engine/src/parse/model/DescendentNodeDefinition.ts @@ -29,7 +29,6 @@ export abstract class DescendentNodeDefinition< readonly root: RootDefinition; readonly nodeset: string; - readonly dependencyExpressions: ReadonlySet; readonly isTranslated: boolean = false; constructor( @@ -43,11 +42,6 @@ export abstract class DescendentNodeDefinition< if (bind.isTranslated || bodyElement?.isTranslated) { this.isTranslated = true; } - - this.dependencyExpressions = new Set([ - ...bind.dependencyExpressions, - ...(bodyElement?.dependencyExpressions ?? []), - ]); } } diff --git a/packages/xforms-engine/src/parse/model/NodeDefinition.ts b/packages/xforms-engine/src/parse/model/NodeDefinition.ts index 4ea40ad68..2ef3e1db3 100644 --- a/packages/xforms-engine/src/parse/model/NodeDefinition.ts +++ b/packages/xforms-engine/src/parse/model/NodeDefinition.ts @@ -121,10 +121,7 @@ export interface NodeDefinition { readonly nodeset: string; readonly nodeName: string; readonly bodyElement: AnyBodyElementDefinition | RepeatElementDefinition | null; - readonly isTranslated: boolean; - readonly dependencyExpressions: ReadonlySet; - readonly root: RootDefinition; readonly parent: NodeParent; readonly children: NodeChildren; diff --git a/packages/xforms-engine/src/parse/model/RootDefinition.ts b/packages/xforms-engine/src/parse/model/RootDefinition.ts index 6b50e374b..681b34cc7 100644 --- a/packages/xforms-engine/src/parse/model/RootDefinition.ts +++ b/packages/xforms-engine/src/parse/model/RootDefinition.ts @@ -27,7 +27,6 @@ export class RootDefinition implements NodeDefinition<'root'> { readonly defaultValue = null; readonly isTranslated = false; - readonly dependencyExpressions: ReadonlySet = new Set(); constructor( protected readonly form: XFormDefinition, diff --git a/packages/xforms-engine/src/parse/text/abstract/TextRangeDefinition.ts b/packages/xforms-engine/src/parse/text/abstract/TextRangeDefinition.ts index 91695a58a..2fb8b94e6 100644 --- a/packages/xforms-engine/src/parse/text/abstract/TextRangeDefinition.ts +++ b/packages/xforms-engine/src/parse/text/abstract/TextRangeDefinition.ts @@ -2,7 +2,6 @@ import type { LocalNamedElement } from '@getodk/common/types/dom.ts'; import type { TextRole } from '../../../client/TextRange.ts'; import type { XFormDefinition } from '../../../parse/XFormDefinition.ts'; import { DependencyContext } from '../../expression/abstract/DependencyContext.ts'; -import type { AnyDependentExpression } from '../../expression/abstract/DependentExpression.ts'; import type { AnyTextChunkExpression } from '../../expression/abstract/TextChunkExpression.ts'; import type { AnyMessageDefinition } from '../MessageDefinition.ts'; import type { AnyTextElementDefinition } from './TextElementDefinition.ts'; @@ -52,11 +51,6 @@ export abstract class TextRangeDefinition extends Depende this.parentReference = ownerContext.parentReference; } - override registerDependentExpression(expression: AnyDependentExpression): void { - this.ownerContext.registerDependentExpression(expression); - super.registerDependentExpression(expression); - } - toJSON(): object { const { form, ownerContext, ...rest } = this;