Skip to content

Commit 30b34e6

Browse files
committed
Fixwd #455. Replaced Binds with Input's in Evaluate to prevent invalid bind metadata in evaluations.
1 parent b01ee00 commit 30b34e6

36 files changed

Lines changed: 398 additions & 163 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http:
1717
- [#504](https://github.com/wordplaydev/wordplay/issues/504). Account for non-fixed-width characters in caret positioning.
1818
- [#488](https://github.com/wordplaydev/wordplay/issues/488). Added animations off indicator on stage.
1919
- [#500](https://github.com/wordplaydev/wordplay/issues/500). Improved explanation when there's a space between an evaluation's name and inputs.
20+
- [#455](https://github.com/wordplaydev/wordplay/issues/455). Replaced `Bind`s with `Input`'s in `Evaluate` to prevent invalid bind metadata in evaluations.
2021

2122
### Maintenance
2223

src/basis/Basis.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Project from '../models/Project';
99
import Example from '../nodes/Example';
1010
import { Basis } from './Basis';
1111
import DefaultLocale, { DefaultLocales } from '../locale/DefaultLocale';
12+
import Templates from '@concepts/Templates';
1213

1314
const basis = Basis.getLocalizedBasis(DefaultLocales);
1415

@@ -43,7 +44,9 @@ function checkBasisNodes(node: Node) {
4344
!(conflict instanceof UnusedBind) &&
4445
!context
4546
.getRoot(node)
46-
?.getAncestors(conflict.getConflictingNodes().primary.node)
47+
?.getAncestors(
48+
conflict.getConflictingNodes(Templates).primary.node,
49+
)
4750
.some((n) => n instanceof Example),
4851
);
4952

@@ -52,7 +55,7 @@ function checkBasisNodes(node: Node) {
5255
conflicts
5356
.map((c) =>
5457
c
55-
.getConflictingNodes()
58+
.getConflictingNodes(Templates)
5659
.primary.explanation(DefaultLocales, context)
5760
.toText(),
5861
)

src/components/annotations/Annotations.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import Context from '@nodes/Context';
4242
import CommandButton from '@components/widgets/CommandButton.svelte';
4343
import Expander from '@components/widgets/Expander.svelte';
44+
import Templates from '@concepts/Templates';
4445
4546
/** The project for which annotations should be shown */
4647
export let project: Project;
@@ -138,7 +139,7 @@
138139
// Conflict all of the active conflicts to a list of annotations.
139140
annotations = conflicts
140141
.map((conflict: Conflict) => {
141-
const nodes = conflict.getConflictingNodes();
142+
const nodes = conflict.getConflictingNodes(Templates);
142143
const primary = nodes.primary;
143144
const secondary = nodes.secondary;
144145
// Based on the primary and secondary nodes given, decide what to show.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<svelte:options immutable={true} />
2+
3+
<script lang="ts">
4+
import type Input from '@nodes/Input';
5+
import NodeView from './NodeView.svelte';
6+
7+
export let node: Input;
8+
</script>
9+
10+
<NodeView node={node.name} /><NodeView node={node.bind} /><NodeView
11+
node={node.value}
12+
/>

src/components/editor/Menu.svelte

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import Token from '../../nodes/Token';
1414
import Bind from '../../nodes/Bind';
1515
import Evaluate from '../../nodes/Evaluate';
16+
import Input from '@nodes/Input';
1617
1718
export let menu: Menu;
1819
/* What to run when hiding the menu */
@@ -48,13 +49,13 @@
4849
let evaluateBind: Bind | undefined;
4950
$: if (
5051
selectedRevision instanceof Revision &&
51-
newNode instanceof Bind &&
52+
newNode instanceof Input &&
5253
newParent instanceof Evaluate
5354
) {
5455
const fun = newParent.getFunction(selectedRevision.context);
5556
evaluateBind = fun?.inputs.find(
5657
(input) =>
57-
newNode instanceof Bind && input.hasName(newNode.getNames()[0])
58+
newNode instanceof Input && input.hasName(newNode.getName()),
5859
);
5960
}
6061
$: selectedConcept =
@@ -108,11 +109,11 @@
108109
.some(
109110
(node) =>
110111
node instanceof Token &&
111-
node.getText().startsWith(event.key)
112+
node.getText().startsWith(event.key),
112113
)
113114
: $locales
114115
.get((l) => l.term[revision.purpose])
115-
.startsWith(event.key)
116+
.startsWith(event.key),
116117
);
117118
if (match)
118119
menu = menu.inSubmenu()
@@ -194,8 +195,8 @@
194195
`/${$locales.get((l) =>
195196
entry instanceof RevisionSet
196197
? l.term[entry.purpose]
197-
: ''
198-
)}…/`
198+
: '',
199+
)}…/`,
199200
)}
200201
/>
201202
{/if}

src/components/editor/util/nodeToView.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import FormattedTranslationView from '../FormattedTranslationView.svelte';
8484
import IsLocaleView from '../IsLocaleView.svelte';
8585
import SpreadView from '../SpreadView.svelte';
8686
import MatchView from '../MatchView.svelte';
87+
import InputView from '../InputView.svelte';
8788

8889
import type Node from '@nodes/Node';
8990
import Program from '@nodes/Program';
@@ -172,6 +173,7 @@ import Spread from '@nodes/Spread';
172173
import NoneOrView from '../OtherwiseView.svelte';
173174
import Otherwise from '@nodes/Otherwise';
174175
import Match from '@nodes/Match';
176+
import Input from '@nodes/Input';
175177

176178
const nodeToView = new Map<Function, ComponentType<SvelteComponent>>();
177179

@@ -217,6 +219,7 @@ nodeToView.set(TextType, TextTypeView);
217219
nodeToView.set(FunctionDefinition, FunctionDefinitionView);
218220
nodeToView.set(FunctionType, FunctionTypeView);
219221
nodeToView.set(Evaluate, EvaluateView);
222+
nodeToView.set(Input, InputView);
220223

221224
nodeToView.set(ExpressionPlaceholder, ExpressionPlaceholderView);
222225
nodeToView.set(BinaryEvaluate, BinaryEvaluateView);

src/components/palette/editOutput.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import { toExpression } from '../../parser/parseExpression';
2222
import { getPlaceExpression } from '../../output/getOrCreatePlace';
2323
import type Spread from '../../nodes/Spread';
2424
import type Locales from '../../locale/Locales';
25+
import Input from '@nodes/Input';
2526

2627
export function getNumber(given: Expression): number | undefined {
2728
const measurement =
2829
given instanceof NumberLiteral
2930
? given
30-
: given instanceof Bind && given.value instanceof NumberLiteral
31+
: given instanceof Input && given.value instanceof NumberLiteral
3132
? given.value
3233
: given instanceof UnaryEvaluate &&
3334
given.isNegation() &&

src/components/project/SourceTileToggle.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Toggle from '../widgets/Toggle.svelte';
77
import { locales } from '../../db/Database';
88
import Emoji from '@components/app/Emoji.svelte';
9+
import Templates from '@concepts/Templates';
910
1011
export let source: Source;
1112
export let expanded: boolean;
@@ -22,7 +23,7 @@
2223
secondaryCount = 0;
2324
if ($conflicts) {
2425
for (const conflict of $conflicts) {
25-
const nodes = conflict.getConflictingNodes();
26+
const nodes = conflict.getConflictingNodes(Templates);
2627
if (source.has(nodes.primary.node)) {
2728
if (!conflict.isMinor()) primaryCount++;
2829
else secondaryCount++;

src/concepts/Templates.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ import Borrow from '../nodes/Borrow';
7676
import Otherwise from '@nodes/Otherwise';
7777
import Match from '@nodes/Match';
7878
import Spread from '@nodes/Spread';
79+
import Input from '@nodes/Input';
7980

8081
/** These are ordered by appearance in the docs. */
8182
const Templates: Node[] = [
8283
// Evaluation
8384
Evaluate.make(ExpressionPlaceholder.make(), []),
85+
Input.make('_', ExpressionPlaceholder.make()),
86+
8487
FunctionDefinition.make(
8588
undefined,
8689
Names.make(['_']),

src/conflicts/Conflict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default abstract class Conflict {
2828
* and "secondary" ones, which are involved. We use this distiction in the editor to decide what to highlight,
2929
* but also how to position the various parties involved in the visual portrayal of the conflict.
3030
*/
31-
abstract getConflictingNodes(): {
31+
abstract getConflictingNodes(concepts: Node[]): {
3232
primary: ConflictingNode;
3333
secondary?: ConflictingNode;
3434
resolutions?: Resolution[];

0 commit comments

Comments
 (0)