@arkitektio/bsx 5.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/bsx/analyze.d.ts +6 -5
- package/dist/bsx/analyze.d.ts.map +1 -1
- package/dist/bsx/analyze.js +12 -10
- package/dist/bsx/analyze.js.map +1 -1
- package/dist/bsx/declared.d.ts +111 -0
- package/dist/bsx/declared.d.ts.map +1 -0
- package/dist/bsx/declared.js +311 -0
- package/dist/bsx/declared.js.map +1 -0
- package/dist/bsx/index.d.ts +1 -0
- package/dist/bsx/index.d.ts.map +1 -1
- package/dist/bsx/index.js +1 -0
- package/dist/bsx/index.js.map +1 -1
- package/dist/bsx/infer.d.ts +40 -17
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +105 -49
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts +6 -2
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +65 -21
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +6 -1
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +32 -3
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +3 -0
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +45 -51
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +265 -138
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +2 -2
- package/dist/catalogs/index.d.ts +49 -71
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +1 -1
- package/dist/catalogs/logo.d.ts +14 -28
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +1 -2
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +1 -1
- package/dist/catalogs/parts/feedback.d.ts +3 -3
- package/dist/catalogs/parts/forms.d.ts +4 -4
- package/dist/catalogs/parts/html.d.ts +2 -2
- package/dist/catalogs/parts/icons.d.ts +2 -2
- package/dist/catalogs/parts/index.d.ts +35 -57
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +10 -25
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +12 -14
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +4 -4
- package/dist/catalogs/parts/overlays.d.ts +11 -11
- package/dist/catalogs/parts/run.d.ts +2 -10
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.d.ts +7 -15
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +1 -5
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/typography.d.ts +3 -3
- package/dist/catalogs/props.d.ts +2 -2
- package/dist/catalogs/scene.d.ts +5 -13
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/shadcn.d.ts +11 -11
- package/dist/catalogs/ui.d.ts +16 -16
- package/dist/logo/actionLogoSource.d.ts +3 -3
- package/dist/logo/actionLogoSource.d.ts.map +1 -1
- package/dist/logo/actionLogoSource.js +4 -4
- package/dist/logo/actionLogoSource.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +16 -6
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +32 -13
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +3 -3
- package/dist/renderer/baseCatalog.js +2 -2
- package/dist/renderer/bloks/control.d.ts +18 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +85 -14
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +1 -1
- package/dist/renderer/bloks/feedback.d.ts +3 -3
- package/dist/renderer/bloks/forms.d.ts +4 -4
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/icons.d.ts +1 -1
- package/dist/renderer/bloks/index.d.ts +30 -37
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +1 -8
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +1 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
- package/dist/renderer/bloks/navigation.d.ts +4 -4
- package/dist/renderer/bloks/overlays.d.ts +11 -11
- package/dist/renderer/bloks/run/components.d.ts +1 -5
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.js +4 -2
- package/dist/renderer/bloks/scene/Scene.js.map +1 -1
- package/dist/renderer/bloks/scene/host.d.ts +2 -0
- package/dist/renderer/bloks/scene/host.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/host.js +8 -0
- package/dist/renderer/bloks/scene/host.js.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +4 -8
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.js +3 -2
- package/dist/renderer/bloks/scene/interaction.js.map +1 -1
- package/dist/renderer/bloks/shared/props.d.ts +2 -2
- package/dist/renderer/bloks/typography.d.ts +3 -3
- package/dist/renderer/declarations.d.ts +40 -33
- package/dist/renderer/declarations.d.ts.map +1 -1
- package/dist/renderer/declarations.js +41 -56
- package/dist/renderer/declarations.js.map +1 -1
- package/dist/renderer/declare.js +4 -4
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/persist.d.ts +22 -13
- package/dist/renderer/persist.d.ts.map +1 -1
- package/dist/renderer/persist.js +40 -21
- package/dist/renderer/persist.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +4 -4
- package/dist/renderer/runtime/catalog.js +3 -3
- package/dist/renderer/runtime/components.d.ts +4 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +5 -5
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +5 -5
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +11 -5
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +3 -3
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +2 -2
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +8 -4
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/index.d.ts +1 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +1 -0
- package/dist/renderer/runtime/index.js.map +1 -1
- package/dist/renderer/runtime/locals.d.ts +57 -0
- package/dist/renderer/runtime/locals.d.ts.map +1 -0
- package/dist/renderer/runtime/locals.js +87 -0
- package/dist/renderer/runtime/locals.js.map +1 -0
- package/dist/renderer/runtime/scope.d.ts +14 -0
- package/dist/renderer/runtime/scope.d.ts.map +1 -1
- package/dist/renderer/runtime/scope.js +25 -3
- package/dist/renderer/runtime/scope.js.map +1 -1
- package/dist/renderer/runtime/tree.d.ts.map +1 -1
- package/dist/renderer/runtime/tree.js +7 -1
- package/dist/renderer/runtime/tree.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +8 -3
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/shadcn.d.ts +36 -43
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +1 -2
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +11067 -6321
- package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
- package/dist/spec/catalogs/orkestrator@1.json +10 -10
- package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
- package/dist/spec/catalogs.d.ts +4 -4
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +7 -7
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +25 -4
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +50 -5
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +58 -32
- package/dist/spec/vocabulary.json.js +58 -32
- package/package.json +1 -1
- package/src/bsx/analyze.ts +14 -12
- package/src/bsx/bsx.test.ts +4 -4
- package/src/bsx/declared.ts +346 -0
- package/src/bsx/index.ts +1 -0
- package/src/bsx/infer.test.ts +42 -32
- package/src/bsx/infer.ts +128 -71
- package/src/bsx/language.test.ts +37 -25
- package/src/bsx/language.ts +72 -25
- package/src/bsx/parse.ts +34 -3
- package/src/bsx/print.ts +3 -0
- package/src/bsx/references.test.ts +82 -81
- package/src/bsx/references.ts +313 -178
- package/src/catalogs/catalogs.test.ts +3 -2
- package/src/catalogs/index.ts +1 -1
- package/src/catalogs/logo.ts +1 -2
- package/src/catalogs/parts/logo.ts +13 -17
- package/src/catalogs/parts/scene.ts +1 -7
- package/src/logo/actionLogoSource.ts +4 -4
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.test.tsx +22 -0
- package/src/renderer/BlokRenderer.tsx +70 -20
- package/src/renderer/addBlokComponents.test.tsx +1 -1
- package/src/renderer/baseCatalog.ts +2 -2
- package/src/renderer/bloks/control.tsx +119 -16
- package/src/renderer/bloks/logo/index.tsx +2 -3
- package/src/renderer/bloks/logo/logo.fixture.json +266 -250
- package/src/renderer/bloks/logo/logo.test.tsx +18 -7
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/Scene.tsx +4 -2
- package/src/renderer/bloks/scene/host.tsx +11 -0
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- package/src/renderer/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +4 -4
- package/src/renderer/declare.ts +4 -4
- package/src/renderer/persist.test.ts +70 -49
- package/src/renderer/persist.ts +57 -34
- package/src/renderer/runtime/catalog.test.ts +2 -2
- package/src/renderer/runtime/catalog.ts +4 -4
- package/src/renderer/runtime/components.tsx +8 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +5 -5
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/shadcn.ts +1 -2
- package/src/spec/bsx_v2.json +11067 -6321
- package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/src/spec/catalogs/orkestrator@1.json +10 -10
- package/src/spec/catalogs.ts +8 -8
- package/src/spec/spec.test.ts +19 -16
- package/src/spec/vocabulary.json +58 -32
- package/src/spec/vocabulary.ts +69 -10
package/src/bsx/parse.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
BlokComponentProp,
|
|
6
6
|
BlokUtilCall,
|
|
7
7
|
} from '../renderer/runtime/types';
|
|
8
|
-
import {defaultBlokView, type BlokView} from '../spec/catalogs';
|
|
8
|
+
import {blokViewFor, defaultBlokView, type BlokView} from '../spec/catalogs';
|
|
9
9
|
import {isExplicitId, loadVocabulary, type BlokContextName} from '../spec/vocabulary';
|
|
10
10
|
import {
|
|
11
11
|
blokError,
|
|
@@ -62,6 +62,9 @@ export const FOREACH_COMPONENT = 'foreach';
|
|
|
62
62
|
export const FOREACH_LET_PROP = 'let';
|
|
63
63
|
export const FOREACH_ITEMS_PROP = 'items';
|
|
64
64
|
export const FOREACH_KEY_PROP = 'key';
|
|
65
|
+
const LOCAL_COMPONENT = 'local';
|
|
66
|
+
const LOCAL_NAME_PROP = 'name';
|
|
67
|
+
const CATALOG_ATTRIBUTE = 'catalog';
|
|
65
68
|
export const INTO_KEYWORD = 'into';
|
|
66
69
|
export const EVENT_ROOT = 'event';
|
|
67
70
|
export const REFETCH_FUNCTION = 'query.refetch';
|
|
@@ -538,6 +541,17 @@ class Lowering {
|
|
|
538
541
|
|
|
539
542
|
private prop(component: string, attribute: MarkupAttribute): BlokComponentProp {
|
|
540
543
|
const value = attribute.value;
|
|
544
|
+
if (component === LOCAL_COMPONENT && attribute.name === LOCAL_NAME_PROP) {
|
|
545
|
+
// A local declares its name, as a foreach's let does.
|
|
546
|
+
if (typeof value !== 'string' || !isLocalName(value)) {
|
|
547
|
+
throw this.fail('local.attribute', attribute.offset, {
|
|
548
|
+
name: typeof value === 'string' ? value : '{...}',
|
|
549
|
+
key: LOCAL_NAME_PROP,
|
|
550
|
+
problem: 'is not a name: write name="x", a plain identifier',
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
return {key: attribute.name, static_value: value, declares_value: value};
|
|
554
|
+
}
|
|
541
555
|
if (value === true) return {key: attribute.name, static_value: true};
|
|
542
556
|
if (typeof value === 'string') {
|
|
543
557
|
if (attribute.name === FOREACH_LET_PROP && component === FOREACH_COMPONENT) {
|
|
@@ -775,14 +789,31 @@ class Lowering {
|
|
|
775
789
|
const utf8Length = (source: string): number => new TextEncoder().encode(source).length;
|
|
776
790
|
|
|
777
791
|
/** Parse a v2 BSX source into the tree a blok stores, and where each node is. Throws a `BsxSyntaxError`. */
|
|
778
|
-
|
|
792
|
+
/** The view of the catalog a source's `<Blok catalog=...>` names: the app's own when it names none (`blokViewFor`). */
|
|
793
|
+
const rootView = (root: MarkupElement): BlokView => {
|
|
794
|
+
const catalog = root.attributes.find(attribute => attribute.name === CATALOG_ATTRIBUTE)?.value;
|
|
795
|
+
return typeof catalog === 'string' ? blokViewFor(catalog) : defaultBlokView();
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
/** The catalog a BSX source's `<Blok catalog=...>` names, read off its markup alone; null for none. Throws a `BsxSyntaxError`. */
|
|
799
|
+
export const sourceCatalog = (source: string): string | null => {
|
|
800
|
+
const locator = new Locator(source);
|
|
801
|
+
const catalog = new Markup(source, locator).document().attributes.find(attribute => attribute.name === CATALOG_ATTRIBUTE)?.value;
|
|
802
|
+
return typeof catalog === 'string' ? catalog : null;
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Parse a v2 BSX source into the tree a blok stores, and where each node is.
|
|
807
|
+
* Without a view, the one of the catalog its `<Blok catalog>` names. Throws a `BsxSyntaxError`.
|
|
808
|
+
*/
|
|
809
|
+
export const parseBsx = (source: string, view?: BlokView): {tree: BlokComponentNode; sources: BsxSourceMap} => {
|
|
779
810
|
const locator = new Locator(source);
|
|
780
811
|
if (utf8Length(source) > MAX_SOURCE_BYTES) {
|
|
781
812
|
throw blokError(locator, 'bsx.syntax', 0, {detail: `a blok's source is at most ${MAX_SOURCE_BYTES} bytes`});
|
|
782
813
|
}
|
|
783
814
|
const markup = new Markup(source, locator);
|
|
784
815
|
const root = markup.document();
|
|
785
|
-
const lowering = new Lowering(view, locator, markup);
|
|
816
|
+
const lowering = new Lowering(view ?? rootView(root), locator, markup);
|
|
786
817
|
const tree = lowering.node(root, `${root.name}[0]`, null);
|
|
787
818
|
return {tree, sources: lowering.sources};
|
|
788
819
|
};
|
package/src/bsx/print.ts
CHANGED
|
@@ -256,6 +256,9 @@ class Printer {
|
|
|
256
256
|
if (node.component === FOREACH_COMPONENT && key === FOREACH_LET_PROP && prop.static_value === prop.declares_value) {
|
|
257
257
|
return `${key}=${quoted(prop.declares_value)}`;
|
|
258
258
|
}
|
|
259
|
+
if (node.component === 'local' && key === 'name' && prop.static_value === prop.declares_value) {
|
|
260
|
+
return `${key}=${quoted(prop.declares_value)}`;
|
|
261
|
+
}
|
|
259
262
|
return refuse(`<${node.component}> (${node.id}): ${key} declares '${prop.declares_value}', which BSX cannot spell`);
|
|
260
263
|
}
|
|
261
264
|
if (prop.util_call) {
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest';
|
|
2
2
|
import corpus from '../spec/bsx_v2.json';
|
|
3
|
-
import {baseBlokView,
|
|
4
|
-
import {
|
|
3
|
+
import {baseBlokView, blokViewFor, type BlokView} from '../spec/catalogs';
|
|
4
|
+
import {blokCatalog} from './declared';
|
|
5
|
+
import {resolveLocals} from './infer';
|
|
5
6
|
import {parseBsx} from './parse';
|
|
6
|
-
import {checkBlokTree, dependencyHint,
|
|
7
|
+
import {checkBlokTree, dependencyHint, mountedBlokScope, type BlokCheckScope} from './references';
|
|
8
|
+
import type {BlokComponentNode} from '../renderer/runtime/types';
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
/** Where a corpus case is checked: the spec's `mount`, and whether a catalog is read at all. */
|
|
11
|
+
type CorpusMount = Omit<BlokCheckScope, 'catalog'> & {catalog: boolean};
|
|
12
|
+
|
|
13
|
+
const scopeOf = (mount: CorpusMount): BlokCheckScope => ({kinds: mount.kinds, dependencies: mount.dependencies, args: mount.args});
|
|
9
14
|
type CheckedCase = {
|
|
10
15
|
name: string;
|
|
11
16
|
source: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
resolved: {locals: unknown
|
|
17
|
+
mount: CorpusMount;
|
|
18
|
+
/** Each `<local>` after `resolve_locals`, by node id, kinded: nothing else is resolved. */
|
|
19
|
+
resolved: {locals: Record<string, unknown>};
|
|
15
20
|
codes: string[];
|
|
16
21
|
};
|
|
17
22
|
|
|
18
|
-
/** The view a case is checked with: none (the language alone),
|
|
19
|
-
const caseView = (
|
|
20
|
-
if (
|
|
21
|
-
|
|
23
|
+
/** The view a case is checked with: none (the language alone), else that of the catalog its <Blok> names (the base's for none). */
|
|
24
|
+
const caseView = (mount: CorpusMount, tree: BlokComponentNode): BlokView | null => {
|
|
25
|
+
if (mount.catalog === false) return null;
|
|
26
|
+
const catalog = blokCatalog(tree);
|
|
27
|
+
return catalog === null ? baseBlokView() : blokViewFor(catalog);
|
|
22
28
|
};
|
|
23
29
|
|
|
24
|
-
const caseScope = (scope: CorpusScope): BlokCheckScope => scope;
|
|
25
|
-
|
|
26
30
|
/** The wire spells "nothing" as null or leaves it out (as bsx.test.ts compares trees). */
|
|
27
31
|
const withoutNulls = (value: unknown): unknown => {
|
|
28
32
|
if (Array.isArray(value)) return value.map(withoutNulls);
|
|
@@ -32,7 +36,6 @@ const withoutNulls = (value: unknown): unknown => {
|
|
|
32
36
|
return value;
|
|
33
37
|
};
|
|
34
38
|
|
|
35
|
-
/** The fields the spec's models dump at their defaults; the resolver leaves them out. */
|
|
36
39
|
const PYDANTIC_DEFAULTS: Readonly<Record<string, unknown>> = {
|
|
37
40
|
optional: false,
|
|
38
41
|
auto_resolvable: false,
|
|
@@ -58,7 +61,7 @@ const withoutDefaults = (value: unknown): unknown => {
|
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
const checked = (corpus.cases as ReadonlyArray<Record<string, unknown>>).filter(
|
|
61
|
-
(entry): entry is CheckedCase & Record<string, unknown> => '
|
|
64
|
+
(entry): entry is CheckedCase & Record<string, unknown> => 'mount' in entry && 'codes' in entry,
|
|
62
65
|
);
|
|
63
66
|
|
|
64
67
|
describe('the validator against the corpus', () => {
|
|
@@ -68,8 +71,7 @@ describe('the validator against the corpus', () => {
|
|
|
68
71
|
|
|
69
72
|
it.each(checked.map(entry => [entry.name, entry] as const))('%s', (_name, entry) => {
|
|
70
73
|
const {tree} = parseBsx(entry.source);
|
|
71
|
-
const
|
|
72
|
-
const findings = checkBlokTree(tree, caseScope(entry.scope), view);
|
|
74
|
+
const findings = checkBlokTree(tree, scopeOf(entry.mount), caseView(entry.mount, tree));
|
|
73
75
|
expect(findings.map(found => found.code).sort()).toEqual([...entry.codes].sort());
|
|
74
76
|
});
|
|
75
77
|
});
|
|
@@ -77,50 +79,48 @@ describe('the validator against the corpus', () => {
|
|
|
77
79
|
describe('inference against the corpus', () => {
|
|
78
80
|
it.each(checked.map(entry => [entry.name, entry] as const))('%s', (_name, entry) => {
|
|
79
81
|
const {tree} = parseBsx(entry.source);
|
|
80
|
-
const resolved =
|
|
82
|
+
const resolved = resolveLocals(tree, entry.mount.dependencies, caseView(entry.mount, tree));
|
|
81
83
|
expect(Object.keys(entry.resolved)).toEqual(['locals']);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
expect(resolved.dependencies).toBe(caseScope(entry.scope).dependencies);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('is idempotent', () => {
|
|
88
|
-
for (const entry of checked) {
|
|
89
|
-
const {tree} = parseBsx(entry.source);
|
|
90
|
-
const once = resolveBlokScope(tree, caseScope(entry.scope), null);
|
|
91
|
-
const twice = resolveBlokScope(tree, once, null);
|
|
92
|
-
expect(twice).toEqual(once);
|
|
93
|
-
}
|
|
84
|
+
const locals = Object.fromEntries([...resolved].map(([node, {local}]) => [node, local]));
|
|
85
|
+
expect(withoutDefaults(locals)).toEqual(withoutDefaults(entry.resolved.locals));
|
|
94
86
|
});
|
|
95
87
|
});
|
|
96
88
|
|
|
89
|
+
/** A panel blok of `kind` around `body`. */
|
|
90
|
+
const blok = (kind: string, body: string, attributes = '') => `<Blok kind="${kind}" context="panel"${attributes}>${body}</Blok>`;
|
|
91
|
+
/** Mounted with no dependencies: every one it reads is undeclared. */
|
|
92
|
+
const mounted = mountedBlokScope();
|
|
93
|
+
|
|
97
94
|
describe('findings', () => {
|
|
98
95
|
it('name the node and prop they are about, with a filled message', () => {
|
|
99
|
-
const {tree} = parseBsx('<
|
|
100
|
-
const [found] = checkBlokTree(tree,
|
|
101
|
-
expect(found).toMatchObject({code: 'deps.unknown', level: 'error', nodeId: '
|
|
96
|
+
const {tree} = parseBsx(blok('custom', '<Card><Text text={deps.nope.x} /></Card>'));
|
|
97
|
+
const [found] = checkBlokTree(tree, mounted);
|
|
98
|
+
expect(found).toMatchObject({code: 'deps.unknown', level: 'error', nodeId: 'Blok[0]/Card[0]/Text[0]', propKey: 'text'});
|
|
102
99
|
expect(found.message).toBe(
|
|
103
100
|
'deps.nope.x: \'nope\' is not a dependency of the blok (its dependencies: none). Fix: dependencies=[AgentDependencyInput(key="nope")].',
|
|
104
101
|
);
|
|
105
102
|
});
|
|
106
103
|
|
|
107
104
|
it('hint the declaration a custom blok misses, for a read, a call and a query variable', () => {
|
|
108
|
-
const {tree} = parseBsx(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const found = checkBlokTree(tree,
|
|
105
|
+
const {tree} = parseBsx(
|
|
106
|
+
blok(
|
|
107
|
+
'custom',
|
|
108
|
+
'<query name="positions" service="mikro" document="query { positions { id } }"><var key="agent" value={deps.laser.id} /></query><Card><Text text={queries.positions.status} /><Button onClick={deps.stage.move(x: 1)} /></Card>',
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
const found = checkBlokTree(tree, mountedBlokScope([], [{key: 'robot'}])).filter(finding => finding.code === 'deps.unknown');
|
|
115
112
|
expect(found.map(finding => finding.message).sort()).toEqual([
|
|
116
|
-
'onClick of <Button> (
|
|
113
|
+
'onClick of <Button> (Blok[0]/Card[0]/Button[0]): \'stage\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="stage")].',
|
|
117
114
|
'deps.laser.id: \'laser\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="laser")].',
|
|
118
115
|
].sort());
|
|
119
116
|
});
|
|
120
117
|
|
|
118
|
+
it('take what the mount provides as written where the blok is mounted nowhere', () => {
|
|
119
|
+
expect(checkBlokTree(parseBsx(blok('custom', '<Text text={deps.nope.x} /><Button onClick={deps.stage.move(x: 1)} />')).tree)).toEqual([]);
|
|
120
|
+
});
|
|
121
|
+
|
|
121
122
|
it('hint per kind what a blok reading an undeclared dependency does about it, as the spec does', () => {
|
|
122
|
-
const
|
|
123
|
-
const message = (kind: BlokCheckScope['kind']): string => checkBlokTree(tree, emptyBlokScope(kind))[0]?.message ?? '';
|
|
123
|
+
const message = (kind: string): string => checkBlokTree(parseBsx(blok(kind, '<Text text={deps.laser.power} />')).tree, mounted)[0]?.message ?? '';
|
|
124
124
|
expect(message('custom')).toContain('Fix: dependencies=[AgentDependencyInput(key="laser")].');
|
|
125
125
|
expect(message('task')).toContain('Fix: dependencies=[AgentDependencyInput(key="laser")].');
|
|
126
126
|
expect(message('action')).toContain('Fix: add a dependency parameter `laser` to the action.');
|
|
@@ -130,93 +130,94 @@ describe('findings', () => {
|
|
|
130
130
|
|
|
131
131
|
it('scope a let to its loop and an into name to the whole tree', () => {
|
|
132
132
|
const {tree} = parseBsx(
|
|
133
|
-
'<
|
|
133
|
+
blok('agent', '<Card><foreach items={args.xs} let="p" key={p.id}><Button onClick={self.go(to: p.id) into run} /></foreach><Text text={run.status} /></Card>'),
|
|
134
134
|
);
|
|
135
|
-
expect(checkBlokTree(tree,
|
|
135
|
+
expect(checkBlokTree(tree, mounted)).toEqual([]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('scope a local to its parent\'s subtree', () => {
|
|
139
|
+
const {tree} = parseBsx(blok('agent', '<Card><local name="open" default={false} /><Switch bind={open} /></Card><Switch bind={open} />'));
|
|
140
|
+
// Outside its scope the name is neither a local to write nor a root to read (as the spec says).
|
|
141
|
+
expect(checkBlokTree(tree, mounted).map(found => [found.code, found.nodeId])).toEqual([['local.unknown', 'Blok[0]/Switch[0]'], ['roots.unknown', 'Blok[0]/Switch[0]']]);
|
|
136
142
|
});
|
|
137
143
|
|
|
138
144
|
it('fill the bind and argument kind messages', () => {
|
|
139
|
-
const {tree} = parseBsx('<
|
|
140
|
-
const scope:
|
|
141
|
-
...emptyBlokScope('agent'),
|
|
142
|
-
dependencies: [{key: 'self', action_dependencies: [{key: 'go', demand: {arg_matches: [{key: 'to', kind: 'BOOL'}]}}]}],
|
|
143
|
-
locals: [{key: 'count', kind: 'INT', default: 1}],
|
|
144
|
-
};
|
|
145
|
+
const {tree} = parseBsx(blok('agent', '<local name="count" kind="INT" default={1} /><Card><Switch bind={count} /><Button onClick={self.go(to: count)} /></Card>'));
|
|
146
|
+
const scope = mountedBlokScope([], [{key: 'self', action_dependencies: [{key: 'go', demand: {arg_matches: [{key: 'to', kind: 'BOOL'}]}}]}]);
|
|
145
147
|
const findings = checkBlokTree(tree, scope);
|
|
146
148
|
expect(findings.map(found => found.code)).toEqual(['local.bind_kind', 'local.arg_kind']);
|
|
147
|
-
expect(findings[0]).toMatchObject({nodeId: '
|
|
149
|
+
expect(findings[0]).toMatchObject({nodeId: 'Blok[0]/Card[0]/Switch[0]', propKey: 'bind'});
|
|
148
150
|
expect(findings[0].message).toBe('bind of <Switch> writes a BOOL, but count is a INT local (a BOOL control writes BOOL).');
|
|
149
151
|
expect(findings[1].message).toBe('self.go: to takes a BOOL, but count is a INT local.');
|
|
150
152
|
});
|
|
151
153
|
|
|
152
154
|
it('bind error only inside an error slot', () => {
|
|
153
|
-
const {tree} = parseBsx('<
|
|
154
|
-
expect(checkBlokTree(tree,
|
|
155
|
+
const {tree} = parseBsx(blok('agent', '<suspense><error><Alert>{error.message}</Alert></error><Text /></suspense>'));
|
|
156
|
+
expect(checkBlokTree(tree, mounted)).toEqual([]);
|
|
155
157
|
});
|
|
156
158
|
});
|
|
157
159
|
|
|
160
|
+
const codes = (source: string, scope: BlokCheckScope = mounted) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
161
|
+
|
|
158
162
|
describe('what an assign blok places and reads of the run it prepares', () => {
|
|
159
|
-
const
|
|
160
|
-
const assign = {...emptyBlokScope('assign'), args: ['image', 'exposure']};
|
|
163
|
+
const assign = mountedBlokScope([], [], ['image', 'exposure']);
|
|
161
164
|
|
|
162
165
|
it('reads assign.given.<key>, assign.missing and assign.ready', () => {
|
|
163
|
-
const source =
|
|
164
|
-
'
|
|
166
|
+
const source = blok(
|
|
167
|
+
'assign',
|
|
168
|
+
'<if when={assign.given.image}><Text text={args.image} /></if><arg key="exposure" /><args /><deps /><Button onClick={assign.start()} disabled={!assign.ready}>Run</Button>',
|
|
169
|
+
);
|
|
165
170
|
expect(codes(source, assign)).toEqual([]);
|
|
166
171
|
});
|
|
167
172
|
|
|
168
173
|
it('refuses a given flag for an argument the action has not, and a field assign has not', () => {
|
|
169
|
-
expect(codes('<
|
|
170
|
-
expect(codes('<
|
|
174
|
+
expect(codes(blok('assign', '<Text text={assign.given.nope} />'), assign)).toEqual(['args.unknown']);
|
|
175
|
+
expect(codes(blok('assign', '<Text text={assign.nope} />'), assign)).toEqual(['path.unknown']);
|
|
171
176
|
});
|
|
172
177
|
|
|
173
178
|
it('keeps <arg>, <deps>, <dep> and the assign root to an assign blok', () => {
|
|
174
|
-
|
|
175
|
-
expect(codes('<
|
|
176
|
-
expect(codes('<Html><deps /><dep key="robot" /></Html>', task)).toEqual(['catalog.kind', 'catalog.kind']);
|
|
179
|
+
expect(codes(blok('task', '<arg key="image" />'))).toEqual(['catalog.kind']);
|
|
180
|
+
expect(codes(blok('task', '<deps /><dep key="robot" />'))).toEqual(['catalog.kind', 'catalog.kind']);
|
|
177
181
|
// The language alone knows no kind of a component: that is the catalog's to say.
|
|
178
|
-
expect(checkBlokTree(parseBsx('<
|
|
179
|
-
expect(codes('<
|
|
182
|
+
expect(checkBlokTree(parseBsx(blok('task', '<arg key="image" />')).tree, mounted, null)).toEqual([]);
|
|
183
|
+
expect(codes(blok('task', '<Text text={assign.ready} />'))).toEqual(['roots.not_in_kind']);
|
|
180
184
|
});
|
|
181
185
|
});
|
|
182
186
|
|
|
183
187
|
describe('what a blok does to the task it is about', () => {
|
|
184
|
-
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
185
|
-
|
|
186
188
|
it('cancels, pauses, resumes, steps and interrupts it, and reads whether it may', () => {
|
|
187
|
-
const source =
|
|
188
|
-
'
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
const source = blok(
|
|
190
|
+
'action',
|
|
191
|
+
'<Button onClick={task.cancel()} disabled={!task.can.cancel}>Stop</Button><Button onClick={task.pause()}>Pause</Button><Button onClick={task.resume()}>Resume</Button><Button onClick={task.step()}>Step</Button><Button onClick={task.interrupt()}>Kill</Button><Text text={deps.robot.connected ? task.started_at : task.status} />',
|
|
192
|
+
);
|
|
193
|
+
expect(codes(source, mountedBlokScope([], [{key: 'robot'}]))).toEqual([]);
|
|
191
194
|
});
|
|
192
195
|
|
|
193
196
|
it('starts no run again: a rerun is the page\'s, never a blok\'s', () => {
|
|
194
|
-
expect(() => parseBsx('<
|
|
197
|
+
expect(() => parseBsx(blok('action', '<Button onClick={task.rerun()}>Again</Button>'))).toThrow(/calls nothing/);
|
|
195
198
|
});
|
|
196
199
|
|
|
197
200
|
it('refuses them where there is no task', () => {
|
|
198
|
-
expect(codes('<
|
|
201
|
+
expect(codes(blok('assign', '<Button onClick={task.cancel()}>Stop</Button>'))).toEqual(['roots.not_in_kind']);
|
|
199
202
|
});
|
|
200
203
|
});
|
|
201
204
|
|
|
202
205
|
describe('what a blok places of its task, and what it leaves the host', () => {
|
|
203
|
-
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
204
|
-
|
|
205
206
|
it('places the result, the status line and the time slider, and says how much chrome it wants', () => {
|
|
206
|
-
const source = '<
|
|
207
|
-
expect(codes(source
|
|
207
|
+
const source = blok('action', '<status /><ask /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} />', ' chrome="none"');
|
|
208
|
+
expect(codes(source)).toEqual([]);
|
|
208
209
|
});
|
|
209
210
|
|
|
210
211
|
it('warns where no chrome leaves the asks to a blok that places none, and where a part is claimed from inside a branch', () => {
|
|
211
|
-
expect(codes('<
|
|
212
|
-
expect(codes('<
|
|
212
|
+
expect(codes(blok('action', '<status />', ' chrome="none"'))).toEqual(['chrome.no_ask']);
|
|
213
|
+
expect(codes(blok('action', '<if when={task.running}><timeline /></if>'))).toEqual(['part.conditional']);
|
|
213
214
|
});
|
|
214
215
|
|
|
215
216
|
it('keeps <returns> and <status> to a blok that has a task', () => {
|
|
216
|
-
expect(codes('<
|
|
217
|
+
expect(codes(blok('assign', '<returns /><status />'))).toEqual(['catalog.kind', 'catalog.kind']);
|
|
217
218
|
});
|
|
218
219
|
|
|
219
220
|
it('reads what an assign blok knows of starting', () => {
|
|
220
|
-
expect(codes('<
|
|
221
|
+
expect(codes(blok('assign', '<Text text={assign.blocked} /><Button disabled={assign.starting} onClick={assign.start()}>Run</Button>'))).toEqual([]);
|
|
221
222
|
});
|
|
222
223
|
});
|