@arkitektio/bsx 4.3.0 → 5.0.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 +39 -18
- package/dist/bsx/parse.d.ts +13 -7
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +18 -57
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +22 -35
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +5 -5
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +106 -33
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +1 -1
- package/dist/catalogs/html.d.ts.map +1 -1
- package/dist/catalogs/html.js +3 -3
- package/dist/catalogs/html.js.map +1 -1
- package/dist/catalogs/index.d.ts +126 -112
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +6 -2
- package/dist/catalogs/index.js.map +1 -1
- package/dist/catalogs/logo.d.ts +5 -5
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +3 -3
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +5 -5
- package/dist/catalogs/parts/feedback.d.ts +12 -12
- package/dist/catalogs/parts/forms.d.ts +20 -20
- package/dist/catalogs/parts/html.d.ts +1 -1
- package/dist/catalogs/parts/html.d.ts.map +1 -1
- package/dist/catalogs/parts/html.js +1 -1
- package/dist/catalogs/parts/html.js.map +1 -1
- package/dist/catalogs/parts/icons.d.ts +9 -9
- package/dist/catalogs/parts/icons.js +1 -1
- package/dist/catalogs/parts/index.d.ts +120 -110
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.d.ts +11 -1
- package/dist/catalogs/parts/layout.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.js +9 -0
- package/dist/catalogs/parts/layout.js.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +8 -8
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +2 -2
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +16 -16
- package/dist/catalogs/parts/overlays.d.ts +44 -44
- package/dist/catalogs/parts/run.d.ts +5 -5
- package/dist/catalogs/parts/run.js +1 -1
- package/dist/catalogs/parts/scene.d.ts +4 -4
- package/dist/catalogs/parts/structure.js +2 -2
- package/dist/catalogs/parts/toast.js +1 -1
- package/dist/catalogs/parts/toast.js.map +1 -1
- package/dist/catalogs/parts/typography.js +1 -1
- package/dist/catalogs/parts/typography.js.map +1 -1
- package/dist/catalogs/props.d.ts +2 -2
- package/dist/catalogs/scene.d.ts +5 -5
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/scene.js +3 -3
- package/dist/catalogs/scene.js.map +1 -1
- package/dist/catalogs/shadcn.d.ts +47 -47
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +4 -4
- package/dist/catalogs/shadcn.js.map +1 -1
- package/dist/catalogs/structure.d.ts +1 -1
- package/dist/catalogs/structure.d.ts.map +1 -1
- package/dist/catalogs/structure.js +3 -3
- package/dist/catalogs/structure.js.map +1 -1
- package/dist/catalogs/ui.d.ts +67 -57
- package/dist/catalogs/ui.d.ts.map +1 -1
- package/dist/catalogs/ui.js +4 -3
- package/dist/catalogs/ui.js.map +1 -1
- package/dist/catalogs.d.ts +1 -1
- package/dist/catalogs.d.ts.map +1 -1
- package/dist/catalogs.js +2 -2
- package/dist/catalogs.js.map +1 -1
- package/dist/ports.js +1 -1
- package/dist/ports.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +8 -6
- package/dist/renderer/baseCatalog.d.ts.map +1 -1
- package/dist/renderer/baseCatalog.js +7 -5
- package/dist/renderer/baseCatalog.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +2 -0
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +13 -1
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +5 -5
- package/dist/renderer/bloks/feedback.d.ts +12 -12
- package/dist/renderer/bloks/forms.d.ts +20 -20
- package/dist/renderer/bloks/html.js +2 -2
- package/dist/renderer/bloks/icons.d.ts +4 -4
- package/dist/renderer/bloks/index.d.ts +115 -107
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/index.js +1 -1
- package/dist/renderer/bloks/layout.d.ts +9 -1
- package/dist/renderer/bloks/layout.d.ts.map +1 -1
- package/dist/renderer/bloks/layout.js +15 -0
- package/dist/renderer/bloks/layout.js.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +5 -5
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +2 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/navigation.d.ts +16 -16
- package/dist/renderer/bloks/overlays.d.ts +44 -44
- package/dist/renderer/bloks/run/components.d.ts +2 -2
- package/dist/renderer/bloks/run/components.js +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +2 -2
- package/dist/renderer/bloks/toast.d.ts +1 -1
- package/dist/renderer/bloks/typography.js +1 -1
- package/dist/renderer/catalog.d.ts +4 -7
- package/dist/renderer/catalog.d.ts.map +1 -1
- package/dist/renderer/catalog.js +7 -31
- package/dist/renderer/catalog.js.map +1 -1
- package/dist/renderer/declare.d.ts +31 -19
- package/dist/renderer/declare.d.ts.map +1 -1
- package/dist/renderer/declare.js +44 -18
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +27 -7
- package/dist/renderer/runtime/catalog.d.ts.map +1 -1
- package/dist/renderer/runtime/catalog.js +30 -3
- package/dist/renderer/runtime/catalog.js.map +1 -1
- package/dist/renderer/runtime/components.d.ts +7 -1
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +3 -0
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +14 -4
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +3 -0
- package/dist/renderer/runtime/describe.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/preflight.d.ts.map +1 -1
- package/dist/renderer/runtime/preflight.js +5 -2
- package/dist/renderer/runtime/preflight.js.map +1 -1
- package/dist/renderer/runtime/text.d.ts +28 -0
- package/dist/renderer/runtime/text.d.ts.map +1 -0
- package/dist/renderer/runtime/text.js +82 -0
- package/dist/renderer/runtime/text.js.map +1 -0
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +0 -1
- package/dist/runtime.js.map +1 -1
- package/dist/scene.d.ts +1 -1
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +2 -2
- package/dist/scene.js.map +1 -1
- package/dist/shadcn.d.ts +118 -110
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +6 -5
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +3080 -2436
- package/dist/spec/catalogs/base@3.json +13029 -0
- package/dist/spec/catalogs/base@3.json.js +13029 -0
- package/dist/spec/catalogs/orkestrator@1.json +489 -0
- package/dist/spec/catalogs/orkestrator@1.json.js +489 -0
- package/dist/spec/catalogs.d.ts +109 -46
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +241 -73
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +19 -3
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +15 -2
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +30 -16
- package/dist/spec/vocabulary.json.js +30 -16
- package/dist/vendor/core/ui/button-group.d.ts +1 -1
- package/dist/vendor/core/ui/button.d.ts +1 -1
- package/dist/vendor/core/ui/field.d.ts +1 -1
- package/package.json +1 -1
- package/src/bsx/infer.test.ts +18 -26
- package/src/bsx/language.test.ts +1 -1
- package/src/bsx/parse.ts +18 -62
- package/src/bsx/partial.test.ts +1 -1
- package/src/bsx/print.ts +24 -34
- package/src/bsx/references.test.ts +16 -14
- package/src/bsx/references.ts +96 -38
- package/src/catalogs/catalogs.test.ts +45 -14
- package/src/catalogs/html.ts +3 -3
- package/src/catalogs/index.ts +6 -2
- package/src/catalogs/logo.ts +3 -3
- package/src/catalogs/parts/html.ts +1 -1
- package/src/catalogs/parts/icons.ts +1 -1
- package/src/catalogs/parts/layout.ts +11 -0
- package/src/catalogs/parts/logo.ts +2 -2
- package/src/catalogs/parts/run.ts +1 -1
- package/src/catalogs/parts/structure.ts +2 -2
- package/src/catalogs/parts/toast.ts +1 -1
- package/src/catalogs/parts/typography.ts +1 -1
- package/src/catalogs/scene.ts +3 -3
- package/src/catalogs/shadcn.ts +4 -4
- package/src/catalogs/structure.ts +3 -3
- package/src/catalogs/ui.ts +4 -3
- package/src/catalogs.ts +9 -2
- package/src/ports.ts +1 -1
- package/src/renderer/addBlokComponents.test.tsx +8 -22
- package/src/renderer/baseCatalog.ts +7 -5
- package/src/renderer/bloks/components.test.tsx +2 -2
- package/src/renderer/bloks/control.tsx +17 -1
- package/src/renderer/bloks/flow.test.tsx +1 -1
- package/src/renderer/bloks/html.tsx +2 -2
- package/src/renderer/bloks/index.ts +1 -1
- package/src/renderer/bloks/layout.tsx +28 -0
- package/src/renderer/bloks/logo/index.tsx +2 -2
- package/src/renderer/bloks/run/components.tsx +1 -1
- package/src/renderer/bloks/time.test.tsx +1 -1
- package/src/renderer/bloks/toast.tsx +1 -1
- package/src/renderer/bloks/typography.tsx +1 -1
- package/src/renderer/catalog.tsx +7 -31
- package/src/renderer/declare.test.ts +41 -0
- package/src/renderer/declare.ts +70 -32
- package/src/renderer/runtime/catalog.ts +35 -10
- package/src/renderer/runtime/components.tsx +10 -1
- package/src/renderer/runtime/describe.ts +17 -4
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/preflight.ts +5 -2
- package/src/renderer/runtime/text.test.tsx +65 -0
- package/src/renderer/runtime/text.ts +88 -0
- package/src/runtime.ts +0 -1
- package/src/scene.ts +2 -2
- package/src/shadcn.ts +6 -5
- package/src/spec/bsx_v2.json +3080 -2436
- package/src/spec/catalogs/base@3.json +13029 -0
- package/src/spec/catalogs/orkestrator@1.json +489 -0
- package/src/spec/catalogs.ts +257 -101
- package/src/spec/spec.test.ts +87 -21
- package/src/spec/vocabulary.json +30 -16
- package/src/spec/vocabulary.ts +33 -7
- package/dist/renderer/modules.d.ts +0 -4
- package/dist/renderer/modules.d.ts.map +0 -1
- package/dist/renderer/modules.js +0 -11
- package/dist/renderer/modules.js.map +0 -1
- package/dist/spec/catalogs/base@2.json +0 -355
- package/dist/spec/catalogs/base@2.json.js +0 -355
- package/dist/spec/catalogs/html@1.json +0 -308
- package/dist/spec/catalogs/html@1.json.js +0 -308
- package/dist/spec/catalogs/logo@1.json +0 -1687
- package/dist/spec/catalogs/logo@1.json.js +0 -1687
- package/dist/spec/catalogs/scene@1.json +0 -878
- package/dist/spec/catalogs/scene@1.json.js +0 -878
- package/dist/spec/catalogs/shadcn@1.json +0 -4002
- package/dist/spec/catalogs/shadcn@1.json.js +0 -4002
- package/dist/spec/catalogs/structure@1.json +0 -185
- package/dist/spec/catalogs/structure@1.json.js +0 -185
- package/dist/spec/catalogs/ui@1.json +0 -5349
- package/dist/spec/catalogs/ui@1.json.js +0 -5349
- package/src/renderer/modules.ts +0 -12
- package/src/spec/catalogs/base@2.json +0 -355
- package/src/spec/catalogs/html@1.json +0 -308
- package/src/spec/catalogs/logo@1.json +0 -1687
- package/src/spec/catalogs/scene@1.json +0 -878
- package/src/spec/catalogs/shadcn@1.json +0 -4002
- package/src/spec/catalogs/structure@1.json +0 -185
- package/src/spec/catalogs/ui@1.json +0 -5349
package/src/bsx/infer.test.ts
CHANGED
|
@@ -104,29 +104,20 @@ describe('new warnings', () => {
|
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
describe('
|
|
108
|
-
it(
|
|
109
|
-
|
|
107
|
+
describe('a catalog only adds', () => {
|
|
108
|
+
it('refuses one that redefines a component of the base catalog, the language included', () => {
|
|
109
|
+
const redefining = (name: string) => parseSpecCatalog({name: 'mine', components: [{name, context: 'HTML', props: [{key: 'bind', kind: 'STRING'}]}]}, 'mine');
|
|
110
|
+
expect(() => blokView(redefining('Slider'))).toThrow(/redefines <Slider> of base@3: a catalog only adds/);
|
|
111
|
+
expect(() => blokView(redefining('foreach'))).toThrow(/redefines <foreach>/);
|
|
110
112
|
});
|
|
111
113
|
|
|
112
|
-
it(
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
],
|
|
120
|
-
},
|
|
121
|
-
'mine',
|
|
122
|
-
);
|
|
123
|
-
const view = blokView([module]);
|
|
124
|
-
expect(view.components.get('Slider')?.catalog).toBe('mine');
|
|
125
|
-
expect(view.shadows.get('Slider')).toEqual({component: 'Slider', catalog: 'ui@1', module: 'mine', winner: 'mine'});
|
|
126
|
-
expect(view.components.get('foreach')?.catalog).toMatch(/^base@/);
|
|
127
|
-
expect(view.shadows.get('foreach')?.winner).toMatch(/^base@/);
|
|
128
|
-
const found = checkBlokTree(parseBsx('<Html><Card><Slider bind={l} /><Slider bind={l} /></Card></Html>').tree, {...emptyBlokScope('agent'), locals: [{key: 'l', kind: 'STRING'}]}, view);
|
|
129
|
-
expect(found.map(finding => finding.code)).toEqual(['catalog.shadow']);
|
|
114
|
+
it('draws what it adds on top of the base', () => {
|
|
115
|
+
const view = blokView(parseSpecCatalog({name: 'mine', components: [{name: 'Gauge', context: 'HTML', props: []}]}, 'mine'));
|
|
116
|
+
expect(view.components.get('Gauge')?.catalog).toBe('mine');
|
|
117
|
+
expect(view.components.get('Slider')?.catalog).toBe('base@3');
|
|
118
|
+
expect(view.label).toBe('base@3 + mine');
|
|
119
|
+
const found = checkBlokTree(parseBsx('<Html><Card><Gauge /></Card></Html>').tree, emptyBlokScope('agent'), view);
|
|
120
|
+
expect(found).toEqual([]);
|
|
130
121
|
});
|
|
131
122
|
});
|
|
132
123
|
|
|
@@ -137,13 +128,14 @@ describe('??', () => {
|
|
|
137
128
|
operation: 'logic.coalesce',
|
|
138
129
|
arguments: [{key: 'values', value_list: [{value_path: 'a'}, {value_path: 'b'}, {value_path: 'c'}]}],
|
|
139
130
|
});
|
|
140
|
-
expect(printBsx(tree)).toBe('<Text
|
|
131
|
+
expect(printBsx(tree)).toBe('<Text text={a ?? b ?? c} />');
|
|
132
|
+
expect(printBsx(parseBsx('<Text>{a ?? b ?? c}</Text>').tree)).toBe('<Text>{a ?? b ?? c}</Text>');
|
|
141
133
|
});
|
|
142
134
|
|
|
143
135
|
it('binds looser than || and tighter than a ternary', () => {
|
|
144
|
-
expect(printBsx(parseBsx('<Text
|
|
145
|
-
expect(printBsx(parseBsx('<Text
|
|
146
|
-
expect(printBsx(parseBsx('<Text
|
|
147
|
-
expect(printBsx(parseBsx('<Text
|
|
136
|
+
expect(printBsx(parseBsx('<Text>{(a || b) ?? c}</Text>').tree)).toBe('<Text>{a || b ?? c}</Text>');
|
|
137
|
+
expect(printBsx(parseBsx('<Text>{a || (b ?? c)}</Text>').tree)).toBe('<Text>{a || (b ?? c)}</Text>');
|
|
138
|
+
expect(printBsx(parseBsx('<Text>{(a ?? b) ? x : y}</Text>').tree)).toBe('<Text>{a ?? b ? x : y}</Text>');
|
|
139
|
+
expect(printBsx(parseBsx('<Text>{(a ?? b) ?? c}</Text>').tree)).toBe('<Text>{(a ?? b) ?? c}</Text>');
|
|
148
140
|
});
|
|
149
141
|
});
|
package/src/bsx/language.test.ts
CHANGED
|
@@ -162,7 +162,7 @@ describe('hover and signatures', () => {
|
|
|
162
162
|
const source = '<Text text={str.upper(deps.stage.id)} />';
|
|
163
163
|
expect(hoverBsx(source, source.indexOf('upper') + 1, env())?.contents).toContain('str.upper(value)');
|
|
164
164
|
expect(hoverBsx(source, source.indexOf('deps') + 1, env())?.contents).toContain('**deps**');
|
|
165
|
-
expect(hoverBsx('<Time value={then} relative />', 2, env())?.contents).toContain('
|
|
165
|
+
expect(hoverBsx('<Time value={then} relative />', 2, env())?.contents).toContain('base@3');
|
|
166
166
|
const then = '<Time value={then} />';
|
|
167
167
|
expect(hoverBsx(then, then.indexOf('then') + 1, env())?.contents).toContain('**then**');
|
|
168
168
|
});
|
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,
|
|
8
|
+
import {defaultBlokView, type BlokView} from '../spec/catalogs';
|
|
9
9
|
import {isExplicitId, loadVocabulary, type BlokContextName} from '../spec/vocabulary';
|
|
10
10
|
import {
|
|
11
11
|
blokError,
|
|
@@ -30,8 +30,10 @@ import {BsxSyntaxError, type BsxRange} from './source';
|
|
|
30
30
|
*
|
|
31
31
|
* - `attr="..."` is always a literal string, `attr={...}` an expression, a bare
|
|
32
32
|
* `attr` is `true`.
|
|
33
|
-
* - Text
|
|
34
|
-
*
|
|
33
|
+
* - Text is a child like any other: each run of text between elements is
|
|
34
|
+
* stored as a `#text` node holding its `value`. What a component does with
|
|
35
|
+
* it (a `Button` makes it its label) is its renderer's to say, so no catalog
|
|
36
|
+
* is needed to parse. Several parts of one run desugar to `str.template`.
|
|
35
37
|
* Whitespace follows JSX.
|
|
36
38
|
* - `className={[...]}` and `className={{...}}` desugar to `str.classes`.
|
|
37
39
|
* - Operators desugar to `cmp.*` / `logic.*` calls; a callback holds one task
|
|
@@ -42,11 +44,15 @@ import {BsxSyntaxError, type BsxRange} from './source';
|
|
|
42
44
|
*/
|
|
43
45
|
|
|
44
46
|
export const MAX_SOURCE_BYTES = 256 * 1024;
|
|
45
|
-
/** The
|
|
46
|
-
export const
|
|
47
|
-
/**
|
|
48
|
-
export const
|
|
49
|
-
|
|
47
|
+
/** The node a run of text is stored as: no element can be called this, so only text makes one. */
|
|
48
|
+
export const TEXT_NODE = '#text';
|
|
49
|
+
/** The prop of a text node that holds its text: a literal, or an expression. */
|
|
50
|
+
export const TEXT_VALUE = 'value';
|
|
51
|
+
/**
|
|
52
|
+
* The components text between elements was stored as before it was a node of
|
|
53
|
+
* its own: a tree stored then still prints as text, and still renders.
|
|
54
|
+
*/
|
|
55
|
+
export const LEGACY_IMPLICIT_TEXTS: readonly string[] = ['Text', 'span'];
|
|
50
56
|
export const CLASS_NAME = 'className';
|
|
51
57
|
export const CLASSES_FUNCTION = 'str.classes';
|
|
52
58
|
export const TEMPLATE_FUNCTION = 'str.template';
|
|
@@ -378,24 +384,7 @@ class Lowering {
|
|
|
378
384
|
return blokError(this.locator, code, offset, fields);
|
|
379
385
|
}
|
|
380
386
|
|
|
381
|
-
node(
|
|
382
|
-
element: MarkupElement,
|
|
383
|
-
derivedId: string,
|
|
384
|
-
context: BlokContextName,
|
|
385
|
-
parent: string | null,
|
|
386
|
-
inheritedLooseText: string = IMPLICIT_TEXT,
|
|
387
|
-
): BlokComponentNode {
|
|
388
|
-
const spec = this.view.components.get(element.name);
|
|
389
|
-
// the component loose text becomes here, from the nearest non-language ancestor
|
|
390
|
-
const catalog = spec?.catalog;
|
|
391
|
-
const looseText =
|
|
392
|
-
spec === undefined
|
|
393
|
-
? inheritedLooseText
|
|
394
|
-
: catalog?.startsWith('html@')
|
|
395
|
-
? IMPLICIT_HTML_TEXT
|
|
396
|
-
: catalog?.startsWith('base@')
|
|
397
|
-
? inheritedLooseText
|
|
398
|
-
: IMPLICIT_TEXT;
|
|
387
|
+
node(element: MarkupElement, derivedId: string, parent: string | null): BlokComponentNode {
|
|
399
388
|
if (element.name === ELSE_COMPONENT && parent !== IF_COMPONENT) throw this.fail('bsx.else_outside_if', element.offset);
|
|
400
389
|
let nodeId = derivedId;
|
|
401
390
|
const explicit = element.attributes.find(attribute => attribute.name === 'id');
|
|
@@ -411,31 +400,15 @@ class Lowering {
|
|
|
411
400
|
const props = element.attributes.filter(attribute => attribute.name !== 'id').map(attribute => this.prop(element.name, attribute));
|
|
412
401
|
if (element.name === FOREACH_COMPONENT) this.checkForeach(element);
|
|
413
402
|
|
|
414
|
-
const inner = spec ? innerContext(spec, context) : context;
|
|
415
|
-
|
|
416
403
|
const children: BlokComponentNode[] = [];
|
|
417
404
|
const runs = this.runs(element);
|
|
418
|
-
const hasElements = element.children.some(child => child.kind === 'element');
|
|
419
|
-
const textRuns = runs.filter(isTextRun);
|
|
420
|
-
let implicitText = false;
|
|
421
|
-
if (textRuns.length > 0) {
|
|
422
|
-
const textProp = this.textTarget(element, inner, textRuns, hasElements);
|
|
423
|
-
implicitText = textProp === null;
|
|
424
|
-
if (textProp !== null) {
|
|
425
|
-
if (props.some(prop => prop.key === textProp)) {
|
|
426
|
-
throw this.fail('bsx.text_and_prop', element.offset, {component: element.name, key: textProp});
|
|
427
|
-
}
|
|
428
|
-
props.push(this.textProp(textProp, textRuns[0], element.offset));
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
405
|
let implicit = 0;
|
|
432
406
|
const counts = new Map<string, number>();
|
|
433
407
|
let seenElse = false;
|
|
434
408
|
for (const run of runs) {
|
|
435
409
|
if (isTextRun(run)) {
|
|
436
|
-
if (!implicitText) continue;
|
|
437
410
|
if (seenElse) throw this.fail('bsx.else_order', element.offset);
|
|
438
|
-
children.push({id: `${nodeId}/#${implicit}`, component:
|
|
411
|
+
children.push({id: `${nodeId}/#${implicit}`, component: TEXT_NODE, props: [this.textProp(TEXT_VALUE, run, element.offset)]});
|
|
439
412
|
implicit += 1;
|
|
440
413
|
continue;
|
|
441
414
|
}
|
|
@@ -446,7 +419,7 @@ class Lowering {
|
|
|
446
419
|
}
|
|
447
420
|
const index = counts.get(child.name) ?? 0;
|
|
448
421
|
counts.set(child.name, index + 1);
|
|
449
|
-
children.push(this.node(child, `${nodeId}/${child.name}[${index}]`,
|
|
422
|
+
children.push(this.node(child, `${nodeId}/${child.name}[${index}]`, element.name));
|
|
450
423
|
}
|
|
451
424
|
if (element.name === IF_COMPONENT) {
|
|
452
425
|
const elses = element.children.filter((child): child is MarkupElement => child.kind === 'element' && child.name === ELSE_COMPONENT);
|
|
@@ -535,23 +508,6 @@ class Lowering {
|
|
|
535
508
|
return runs;
|
|
536
509
|
}
|
|
537
510
|
|
|
538
|
-
/** Where text goes: the text_prop (returned), implicit Text nodes (null), or refused. */
|
|
539
|
-
private textTarget(element: MarkupElement, context: BlokContextName, runs: Part[][], hasElements: boolean): string | null {
|
|
540
|
-
const component = this.view.components.get(element.name);
|
|
541
|
-
const sample = runs[0].map(part => (typeof part === 'string' ? part : '{...}')).join('').slice(0, 60);
|
|
542
|
-
if (!component) throw this.fail('bsx.text_unknown_component', element.offset, {component: element.name, text: sample});
|
|
543
|
-
const drawsText = this.vocabulary.contexts[context];
|
|
544
|
-
if (drawsText && !drawsText.text) {
|
|
545
|
-
throw this.fail('bsx.text_in_context', element.offset, {component: element.name, context, text: sample});
|
|
546
|
-
}
|
|
547
|
-
if (component.textProp !== null && !hasElements) {
|
|
548
|
-
if (runs.length > 1) throw this.fail('bsx.text_not_accepted', element.offset, {component: element.name, text: sample});
|
|
549
|
-
return component.textProp;
|
|
550
|
-
}
|
|
551
|
-
if (component.textProp !== null || isLanguageContainer(component)) return null;
|
|
552
|
-
throw this.fail('bsx.text_not_accepted', element.offset, {component: element.name, text: sample});
|
|
553
|
-
}
|
|
554
|
-
|
|
555
511
|
private textProp(key: string, parts: Part[], offset: number): BlokComponentProp {
|
|
556
512
|
if (parts.length === 1) {
|
|
557
513
|
const only = parts[0];
|
|
@@ -827,7 +783,7 @@ export const parseBsx = (source: string, view: BlokView = defaultBlokView()): {t
|
|
|
827
783
|
const markup = new Markup(source, locator);
|
|
828
784
|
const root = markup.document();
|
|
829
785
|
const lowering = new Lowering(view, locator, markup);
|
|
830
|
-
const tree = lowering.node(root, `${root.name}[0]`,
|
|
786
|
+
const tree = lowering.node(root, `${root.name}[0]`, null);
|
|
831
787
|
return {tree, sources: lowering.sources};
|
|
832
788
|
};
|
|
833
789
|
|
package/src/bsx/partial.test.ts
CHANGED
|
@@ -60,7 +60,7 @@ describe('parseBsxPartial', () => {
|
|
|
60
60
|
const result = parseBsxPartial('<Html><Card><Text>Hel');
|
|
61
61
|
expect(result.complete).toBe(false);
|
|
62
62
|
expect(result.error?.code).toBe('bsx.unclosed');
|
|
63
|
-
expect(result.tree && [...ids(result.tree)]).toEqual(['Html[0]', 'Html[0]/Card[0]', 'Html[0]/Card[0]/Text[0]']);
|
|
63
|
+
expect(result.tree && [...ids(result.tree)]).toEqual(['Html[0]', 'Html[0]/Card[0]', 'Html[0]/Card[0]/Text[0]', 'Html[0]/Card[0]/Text[0]/#0']);
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it('drops a tag that cannot draw until its attributes arrive', () => {
|
package/src/bsx/print.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
BlokComponentProp,
|
|
6
6
|
BlokUtilCall,
|
|
7
7
|
} from '../renderer/runtime/types';
|
|
8
|
-
import {defaultBlokView,
|
|
8
|
+
import {defaultBlokView, type BlokView} from '../spec/catalogs';
|
|
9
9
|
import {isExplicitId, loadVocabulary, type BlokContextName} from '../spec/vocabulary';
|
|
10
10
|
import {
|
|
11
11
|
CLASS_NAME,
|
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
FETCH_MORE_FUNCTION,
|
|
14
14
|
FOREACH_COMPONENT,
|
|
15
15
|
FOREACH_LET_PROP,
|
|
16
|
-
|
|
16
|
+
LEGACY_IMPLICIT_TEXTS,
|
|
17
|
+
TEXT_NODE,
|
|
18
|
+
TEXT_VALUE,
|
|
17
19
|
REFETCH_FUNCTION,
|
|
18
20
|
TEMPLATE_FUNCTION,
|
|
19
21
|
} from './parse';
|
|
@@ -157,10 +159,8 @@ class Printer {
|
|
|
157
159
|
this.indent = indent;
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
node(node: BlokComponentNode, derived: string, depth: number,
|
|
162
|
+
node(node: BlokComponentNode, derived: string, depth: number, lines: string[]): void {
|
|
161
163
|
const pad = ' '.repeat(this.indent * depth);
|
|
162
|
-
const spec = this.view.components.get(node.component);
|
|
163
|
-
const inner = spec ? innerContext(spec, context) : context;
|
|
164
164
|
const attributes: string[] = [];
|
|
165
165
|
if (node.id !== derived) {
|
|
166
166
|
if (!isExplicitId(node.id)) {
|
|
@@ -169,23 +169,9 @@ class Printer {
|
|
|
169
169
|
attributes.push(`id=${quoted(node.id)}`);
|
|
170
170
|
}
|
|
171
171
|
const children = node.children ?? [];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const drawsText = this.vocabulary.contexts[inner]?.text ?? true;
|
|
176
|
-
const props = node.props ?? [];
|
|
177
|
-
props.forEach((prop, position) => {
|
|
178
|
-
// The parser puts the prop text children fill last, so only the last is spelled as text.
|
|
179
|
-
const last = position === props.length - 1;
|
|
180
|
-
if (textProp !== null && prop.key === textProp && last && children.length === 0 && drawsText) {
|
|
181
|
-
const printed = this.textOf(prop, node, true);
|
|
182
|
-
if (printed !== null) {
|
|
183
|
-
textChild = printed;
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
attributes.push(this.attribute(node, prop));
|
|
188
|
-
});
|
|
172
|
+
// Its one child a text node: spelled on the line of its tags.
|
|
173
|
+
const textChild = children.length === 1 && Printer.isImplicit(children[0], node.id) ? this.textNode(children[0], true) : null;
|
|
174
|
+
for (const prop of node.props ?? []) attributes.push(this.attribute(node, prop));
|
|
189
175
|
let head = `<${node.component}${attributes.map(attribute => ` ${attribute}`).join('')}`;
|
|
190
176
|
const wrapped = pad.length + head.length > LINE_WIDTH && attributes.length > 1;
|
|
191
177
|
if (wrapped) {
|
|
@@ -204,27 +190,32 @@ class Printer {
|
|
|
204
190
|
let implicit = 0;
|
|
205
191
|
for (const child of children) {
|
|
206
192
|
if (Printer.isImplicit(child, node.id)) {
|
|
207
|
-
if (
|
|
208
|
-
refuse(`<${node.component}> (${node.id}) holds implicit Text with no element beside it`);
|
|
209
|
-
}
|
|
210
|
-
if (child.id !== `${node.id}/#${implicit}`) refuse(`<${node.component}> (${node.id}): implicit Text '${child.id}' is out of order`);
|
|
193
|
+
if (child.id !== `${node.id}/#${implicit}`) refuse(`<${node.component}> (${node.id}): the text node '${child.id}' is out of order`);
|
|
211
194
|
implicit += 1;
|
|
212
|
-
|
|
213
|
-
const text = only ? this.textOf(only, child, false) : null;
|
|
214
|
-
if (text === null) refuse(`implicit Text '${child.id}' cannot be spelled as text`);
|
|
215
|
-
lines.push(`${pad}${' '.repeat(this.indent)}${text}`);
|
|
195
|
+
lines.push(`${pad}${' '.repeat(this.indent)}${this.textNode(child, false)}`);
|
|
216
196
|
continue;
|
|
217
197
|
}
|
|
218
198
|
const index = counts.get(child.component) ?? 0;
|
|
219
199
|
counts.set(child.component, index + 1);
|
|
220
|
-
this.node(child, `${node.id}/${child.component}[${index}]`, depth + 1,
|
|
200
|
+
this.node(child, `${node.id}/${child.component}[${index}]`, depth + 1, lines);
|
|
221
201
|
}
|
|
222
202
|
lines.push(`${pad}</${node.component}>`);
|
|
223
203
|
}
|
|
224
204
|
|
|
205
|
+
/** Whether `child` is a run of text of `parent`: a text node, or what one was stored as before. */
|
|
225
206
|
static isImplicit(child: BlokComponentNode, parent: string): boolean {
|
|
226
207
|
const match = IMPLICIT.exec(child.id);
|
|
227
|
-
return match !== null && match.groups?.parent === parent &&
|
|
208
|
+
return match !== null && match.groups?.parent === parent && (child.component === TEXT_NODE || LEGACY_IMPLICIT_TEXTS.includes(child.component));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** A text node as the text it was parsed from; refuses one that holds anything but its one value. */
|
|
212
|
+
private textNode(child: BlokComponentNode, inline: boolean): string {
|
|
213
|
+
const key = child.component === TEXT_NODE ? TEXT_VALUE : 'text';
|
|
214
|
+
const props = child.props ?? [];
|
|
215
|
+
const only = props.length === 1 && props[0].key === key && !(child.children && child.children.length > 0) ? props[0] : null;
|
|
216
|
+
const text = only ? this.textOf(only, child, inline) : null;
|
|
217
|
+
if (text === null) return refuse(`the text node '${child.id}' cannot be spelled as text`);
|
|
218
|
+
return text;
|
|
228
219
|
}
|
|
229
220
|
|
|
230
221
|
/**
|
|
@@ -233,7 +224,6 @@ class Printer {
|
|
|
233
224
|
* its ends; on a line of its own they are trimmed, so they are spelled as strings.
|
|
234
225
|
*/
|
|
235
226
|
private textOf(prop: BlokComponentProp, node: BlokComponentNode, inline: boolean): string | null {
|
|
236
|
-
if (prop.key !== 'text' && IMPLICIT_TEXTS.includes(node.component)) return null;
|
|
237
227
|
if (prop.declares_value || prop.agent_call) return null;
|
|
238
228
|
if (typeof prop.static_value === 'string') return textLiteral(prop.static_value, !inline);
|
|
239
229
|
if (prop.dynamic_value) {
|
|
@@ -406,7 +396,7 @@ class Printer {
|
|
|
406
396
|
/** Print `node` as v2 BSX that `parseBsx` (with the same view) reads back into it. Throws a `BsxPrintError`. */
|
|
407
397
|
export const printBsx = (node: BlokComponentNode, options: {view?: BlokView; indent?: number} = {}): string => {
|
|
408
398
|
const lines: string[] = [];
|
|
409
|
-
new Printer(options.view ?? defaultBlokView(), options.indent ?? 2).node(node, `${node.component}[0]`, 0,
|
|
399
|
+
new Printer(options.view ?? defaultBlokView(), options.indent ?? 2).node(node, `${node.component}[0]`, 0, lines);
|
|
410
400
|
return lines.join('\n');
|
|
411
401
|
};
|
|
412
402
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest';
|
|
2
2
|
import corpus from '../spec/bsx_v2.json';
|
|
3
|
-
import {
|
|
3
|
+
import {baseBlokView, blokView, type BlokView} from '../spec/catalogs';
|
|
4
4
|
import {resolveBlokScope} from './infer';
|
|
5
5
|
import {parseBsx} from './parse';
|
|
6
6
|
import {checkBlokTree, dependencyHint, emptyBlokScope, type BlokCheckScope} from './references';
|
|
7
7
|
|
|
8
|
-
type CorpusScope =
|
|
8
|
+
type CorpusScope = BlokCheckScope & {catalog?: boolean};
|
|
9
9
|
type CheckedCase = {
|
|
10
10
|
name: string;
|
|
11
11
|
source: string;
|
|
@@ -15,18 +15,13 @@ type CheckedCase = {
|
|
|
15
15
|
codes: string[];
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
/** The view a case is checked with: none, the
|
|
18
|
+
/** The view a case is checked with: none (the language alone), the base catalog's, or that of the catalog it is written for. */
|
|
19
19
|
const caseView = (scope: CorpusScope): BlokView | null => {
|
|
20
20
|
if (scope.catalog === false) return null;
|
|
21
|
-
|
|
22
|
-
return blokView([parseSpecCatalog(scope.module, 'module')]);
|
|
21
|
+
return scope.target == null ? baseBlokView() : blokView(scope.target);
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
const caseScope = (scope: CorpusScope): BlokCheckScope =>
|
|
26
|
-
const {module} = scope;
|
|
27
|
-
const named = typeof module === 'object' && module !== null && 'name' in module && typeof module.name === 'string' ? module.name : null;
|
|
28
|
-
return {...scope, module: named};
|
|
29
|
-
};
|
|
24
|
+
const caseScope = (scope: CorpusScope): BlokCheckScope => scope;
|
|
30
25
|
|
|
31
26
|
/** The wire spells "nothing" as null or leaves it out (as bsx.test.ts compares trees). */
|
|
32
27
|
const withoutNulls = (value: unknown): unknown => {
|
|
@@ -177,8 +172,10 @@ describe('what an assign blok places and reads of the run it prepares', () => {
|
|
|
177
172
|
|
|
178
173
|
it('keeps <arg>, <deps>, <dep> and the assign root to an assign blok', () => {
|
|
179
174
|
const task = emptyBlokScope('task');
|
|
180
|
-
expect(codes('<Html><arg key="image" /></Html>', task)).toEqual(['
|
|
181
|
-
expect(codes('<Html><deps /><dep key="robot" /></Html>', task)).toEqual(['
|
|
175
|
+
expect(codes('<Html><arg key="image" /></Html>', task)).toEqual(['catalog.kind']);
|
|
176
|
+
expect(codes('<Html><deps /><dep key="robot" /></Html>', task)).toEqual(['catalog.kind', 'catalog.kind']);
|
|
177
|
+
// The language alone knows no kind of a component: that is the catalog's to say.
|
|
178
|
+
expect(checkBlokTree(parseBsx('<Html><arg key="image" /></Html>').tree, task, null)).toEqual([]);
|
|
182
179
|
expect(codes('<Html><Text text={assign.ready} /></Html>', task)).toEqual(['roots.not_in_kind']);
|
|
183
180
|
});
|
|
184
181
|
});
|
|
@@ -206,12 +203,17 @@ describe('what a blok places of its task, and what it leaves the host', () => {
|
|
|
206
203
|
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
207
204
|
|
|
208
205
|
it('places the result, the status line and the time slider, and says how much chrome it wants', () => {
|
|
209
|
-
const source = '<Html chrome="none"><status /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} /></Html>';
|
|
206
|
+
const source = '<Html chrome="none"><status /><ask /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} /></Html>';
|
|
210
207
|
expect(codes(source, emptyBlokScope('action'))).toEqual([]);
|
|
211
208
|
});
|
|
212
209
|
|
|
210
|
+
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('<Html chrome="none"><status /></Html>', emptyBlokScope('action'))).toEqual(['chrome.no_ask']);
|
|
212
|
+
expect(codes('<Html><if when={task.running}><timeline /></if></Html>', emptyBlokScope('action'))).toEqual(['part.conditional']);
|
|
213
|
+
});
|
|
214
|
+
|
|
213
215
|
it('keeps <returns> and <status> to a blok that has a task', () => {
|
|
214
|
-
expect(codes('<Html><returns /><status /></Html>', emptyBlokScope('assign'))).toEqual(['
|
|
216
|
+
expect(codes('<Html><returns /><status /></Html>', emptyBlokScope('assign'))).toEqual(['catalog.kind', 'catalog.kind']);
|
|
215
217
|
});
|
|
216
218
|
|
|
217
219
|
it('reads what an assign blok knows of starting', () => {
|
package/src/bsx/references.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
BlokUtilCall,
|
|
7
7
|
} from '../renderer/runtime/types';
|
|
8
8
|
import {defaultBlokView, type BlokView, type SpecComponent} from '../spec/catalogs';
|
|
9
|
+
import {TEXT_NODE} from './parse';
|
|
9
10
|
import {valueFitsPort} from '../spec/locals';
|
|
10
11
|
import {LOCAL_ANY, resolveBlokScope} from './infer';
|
|
11
12
|
import {
|
|
@@ -107,6 +108,43 @@ export type BlokScopeSubscription = {
|
|
|
107
108
|
history?: string | null;
|
|
108
109
|
};
|
|
109
110
|
|
|
111
|
+
/** A class at its variant colons, those inside brackets left alone (`[&>*]:p-2`). */
|
|
112
|
+
const splitClass = (token: string): string[] => {
|
|
113
|
+
const parts: string[] = [];
|
|
114
|
+
let depth = 0;
|
|
115
|
+
let current = '';
|
|
116
|
+
for (const character of token) {
|
|
117
|
+
if (character === '[') depth += 1;
|
|
118
|
+
else if (character === ']') depth = Math.max(0, depth - 1);
|
|
119
|
+
if (character === ':' && depth === 0) {
|
|
120
|
+
parts.push(current);
|
|
121
|
+
current = '';
|
|
122
|
+
} else current += character;
|
|
123
|
+
}
|
|
124
|
+
parts.push(current);
|
|
125
|
+
return parts;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** What of the class `token` is outside the portable subset (`the before variant`), or null. */
|
|
129
|
+
export const unportableClass = (token: string, vocabulary: BlokVocabulary): string | null => {
|
|
130
|
+
const parts = splitClass(token);
|
|
131
|
+
const utility = (parts.pop() ?? '').replace(/^[!-]+/, '');
|
|
132
|
+
for (const variant of parts) {
|
|
133
|
+
if (variant.startsWith('[')) return 'an arbitrary variant';
|
|
134
|
+
const name = variant.split('/')[0];
|
|
135
|
+
if (vocabulary.unportableVariants.has(name) || vocabulary.unportableVariants.has(name.split('-[')[0])) return `the ${name} variant`;
|
|
136
|
+
}
|
|
137
|
+
if (utility.startsWith('[')) return 'an arbitrary property';
|
|
138
|
+
if (utility.includes('[')) {
|
|
139
|
+
const prefix = utility.split('-[')[0];
|
|
140
|
+
return vocabulary.arbitraryValues.has(prefix) ? null : `an arbitrary value of ${prefix}`;
|
|
141
|
+
}
|
|
142
|
+
for (const prefix of vocabulary.unportableUtilities) {
|
|
143
|
+
if (utility === prefix || utility.startsWith(`${prefix}-`)) return `the ${prefix} utility`;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
};
|
|
147
|
+
|
|
110
148
|
/** What a blok declares beside its tree; the corpus' `scope` verbatim. */
|
|
111
149
|
export type BlokCheckScope = {
|
|
112
150
|
kind: BlokKind;
|
|
@@ -118,10 +156,8 @@ export type BlokCheckScope = {
|
|
|
118
156
|
subscriptions: readonly BlokScopeSubscription[];
|
|
119
157
|
/** The keys `args.<key>` may read; null reads any. */
|
|
120
158
|
args: readonly string[] | null;
|
|
121
|
-
/** The
|
|
122
|
-
|
|
123
|
-
/** The module (an app's own extras) the blok names, if any. */
|
|
124
|
-
module?: string | null;
|
|
159
|
+
/** The id of the catalog the blok is written for; null (or absent): the base catalog. The corpus' `target`. */
|
|
160
|
+
target?: string | null;
|
|
125
161
|
/** Per declared query, the shape of its value when its service's schema is known. */
|
|
126
162
|
query_values?: Readonly<Record<string, BlokPortMatch>>;
|
|
127
163
|
/** The assets `self.assets.<name>` may name; null (or absent) names any. */
|
|
@@ -141,7 +177,6 @@ export const emptyBlokScope = (kind: BlokKind = 'agent', context = 'HTML'): Blok
|
|
|
141
177
|
queries: [],
|
|
142
178
|
subscriptions: [],
|
|
143
179
|
args: null,
|
|
144
|
-
catalogs: [],
|
|
145
180
|
});
|
|
146
181
|
|
|
147
182
|
const ACTION_LOGO = 'ACTION_LOGO';
|
|
@@ -173,10 +208,11 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
|
|
|
173
208
|
/** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
|
|
174
209
|
const RUN_KINDS: readonly string[] = ['action', 'assign'];
|
|
175
210
|
const ASSIGN_KIND = 'assign';
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
211
|
+
const ASK_COMPONENT = 'ask';
|
|
212
|
+
const CHROME_PROP = 'chrome';
|
|
213
|
+
const CHROME_NONE = 'none';
|
|
214
|
+
/** The language's elements whose children do not always show: a host part inside one still claims its slot. */
|
|
215
|
+
const CONDITIONAL_COMPONENTS: ReadonlySet<string> = new Set(['if', 'else', 'match', 'case', 'default', 'foreach', 'suspense', 'fallback', 'error']);
|
|
180
216
|
/** The one field of an agent that is not text. */
|
|
181
217
|
const AGENT_CONNECTED = 'connected';
|
|
182
218
|
/** Where an assign blok reads which arguments the caller decided. */
|
|
@@ -409,7 +445,9 @@ class Checker {
|
|
|
409
445
|
private readonly subscriptions: Map<string, BlokScopeSubscription>;
|
|
410
446
|
private readonly boundLocals = new Set<string>();
|
|
411
447
|
private readonly into = new Set<string>();
|
|
412
|
-
private
|
|
448
|
+
private asks = false;
|
|
449
|
+
/** The id of the root that says `chrome="none"`, when it does. */
|
|
450
|
+
private chromeless: string | null = null;
|
|
413
451
|
private readonly colour: RegExp;
|
|
414
452
|
|
|
415
453
|
readonly scope: ResolvedBlokScope;
|
|
@@ -516,6 +554,7 @@ class Checker {
|
|
|
516
554
|
for (const local of this.scope.locals) {
|
|
517
555
|
if (local.persist && !this.boundLocals.has(local.key)) this.add('local.unused_persist', `locals.${local.key}`, {name: local.key});
|
|
518
556
|
}
|
|
557
|
+
if (this.chromeless !== null && this.kind.roots.includes('task') && !this.asks) this.add('chrome.no_ask', this.chromeless);
|
|
519
558
|
}
|
|
520
559
|
|
|
521
560
|
/* -- the walk -- */
|
|
@@ -572,28 +611,36 @@ class Checker {
|
|
|
572
611
|
|
|
573
612
|
private visitComponent(node: BlokComponentNode, ancestors: readonly BlokComponentNode[]): void {
|
|
574
613
|
const spec = this.view?.components.get(node.component);
|
|
575
|
-
if (this.view && !spec
|
|
576
|
-
this.
|
|
614
|
+
if (this.view && !spec) {
|
|
615
|
+
const foreign = this.view.foreign.get(node.component);
|
|
616
|
+
if (foreign !== undefined) {
|
|
617
|
+
this.add('catalog.target', node.id, {component: node.component, catalog: foreign, target: this.view.target ?? this.view.label});
|
|
618
|
+
} else if (this.view.complete) {
|
|
619
|
+
this.add('catalog.unknown_component', node.id, {component: node.component, catalogs: this.view.label});
|
|
620
|
+
}
|
|
577
621
|
}
|
|
578
622
|
if (spec) this.checkCatalog(node, spec, ancestors);
|
|
579
|
-
|
|
580
|
-
if (shadow && !this.shadowed.has(node.component)) {
|
|
581
|
-
this.shadowed.add(node.component);
|
|
582
|
-
this.add('catalog.shadow', node.id, {component: node.component, catalog: shadow.catalog, module: shadow.module, winner: shadow.winner});
|
|
583
|
-
}
|
|
584
|
-
if (TASK_COMPONENTS.has(node.component) && !this.kind.roots.includes('task')) {
|
|
585
|
-
this.notInKind(node.id, `<${node.component}>`, 'task');
|
|
586
|
-
}
|
|
587
|
-
if (ASSIGN_COMPONENTS.has(node.component) && this.scope.kind !== ASSIGN_KIND) {
|
|
588
|
-
this.add('assign.kind', node.id, {what: `<${node.component}>`, n: article(this.scope.kind), kind: this.scope.kind});
|
|
589
|
-
}
|
|
623
|
+
this.checkHostPart(node, ancestors);
|
|
590
624
|
for (const prop of node.props ?? []) this.checkProp(node, prop, spec);
|
|
591
625
|
}
|
|
592
626
|
|
|
593
627
|
private checkCatalog(node: BlokComponentNode, spec: SpecComponent, ancestors: readonly BlokComponentNode[]): void {
|
|
594
628
|
const view = this.view;
|
|
595
629
|
if (!view) return;
|
|
596
|
-
|
|
630
|
+
const texts = (node.children ?? []).filter(child => child.component === TEXT_NODE);
|
|
631
|
+
const elements = (node.children ?? []).length - texts.length;
|
|
632
|
+
if (elements && !spec.acceptsChildren) this.add('catalog.children', node.id, {component: node.component});
|
|
633
|
+
if (texts.length) {
|
|
634
|
+
// Text is a child like any other; what takes it is the catalog's to say.
|
|
635
|
+
const textProp = spec.textProp;
|
|
636
|
+
if (textProp === null && !spec.acceptsChildren) {
|
|
637
|
+
this.add('catalog.text', node.id, {component: node.component, detail: 'takes no text'});
|
|
638
|
+
} else if (textProp !== null && (node.props ?? []).some(prop => prop.key === textProp)) {
|
|
639
|
+
this.add('catalog.text', node.id, {component: node.component, detail: `sets ${textProp} as an attribute and as its text`});
|
|
640
|
+
} else if (textProp !== null && !spec.acceptsChildren && (elements || texts.length > 1)) {
|
|
641
|
+
this.add('catalog.text', node.id, {component: node.component, detail: `takes one run of text as its ${textProp}, and no elements beside it`});
|
|
642
|
+
}
|
|
643
|
+
}
|
|
597
644
|
const present = new Set((node.props ?? []).map(prop => prop.key));
|
|
598
645
|
const known = new Set([...spec.props.map(prop => prop.key), WHEN_PROP]);
|
|
599
646
|
const unknown = [...present].filter(key => !known.has(key)).sort();
|
|
@@ -619,20 +666,31 @@ class Checker {
|
|
|
619
666
|
if (forbidden.length) {
|
|
620
667
|
this.add('catalog.placement', node.id, {component: node.component, detail: `must not be inside [${forbidden.map(pythonRepr).join(', ')}]`});
|
|
621
668
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
669
|
+
if (spec.kinds.length && !spec.kinds.includes(this.scope.kind)) {
|
|
670
|
+
this.add('catalog.kind', node.id, {component: node.component, kinds: spec.kinds.join(' and '), n: article(this.scope.kind), kind: this.scope.kind});
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* What the language itself says of the host's parts, whatever catalog draws
|
|
676
|
+
* them: a part placed anywhere claims its slot, and a root without chrome
|
|
677
|
+
* leaves the asks to the blok.
|
|
678
|
+
*/
|
|
679
|
+
private checkHostPart(node: BlokComponentNode, ancestors: readonly BlokComponentNode[]): void {
|
|
680
|
+
if (node.component === ASK_COMPONENT) this.asks = true;
|
|
681
|
+
if (ancestors.length === 0 && (node.props ?? []).some(prop => prop.key === CHROME_PROP && prop.static_value === CHROME_NONE)) {
|
|
682
|
+
this.chromeless = node.id;
|
|
683
|
+
}
|
|
684
|
+
if (this.vocabulary.hostParts.includes(node.component)) {
|
|
685
|
+
const inside = [...ancestors].reverse().find(ancestor => CONDITIONAL_COMPONENTS.has(ancestor.component));
|
|
686
|
+
if (inside) this.add('part.conditional', node.id, {component: node.component, inside: inside.component});
|
|
627
687
|
}
|
|
628
688
|
}
|
|
629
689
|
|
|
630
690
|
/** A ``Placed dep`` or ``Route through`` names dependencies of the blok, written out as keys. */
|
|
631
691
|
private checkDependencyKeys(node: BlokComponentNode, prop: BlokComponentProp): void {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
692
|
+
// catalog.kind says it: a Space and its parts belong to an action's own blok.
|
|
693
|
+
if (!RUN_KINDS.includes(this.scope.kind)) return;
|
|
636
694
|
const path = `${node.component}.${prop.key}`;
|
|
637
695
|
const value = prop.static_value;
|
|
638
696
|
const keys = typeof value === 'string' ? [value] : Array.isArray(value) ? value.filter((key): key is string => typeof key === 'string') : [];
|
|
@@ -678,7 +736,7 @@ class Checker {
|
|
|
678
736
|
}
|
|
679
737
|
// `task.answer(...)`, `task.cancel()` and their kin act on the task the blok is about.
|
|
680
738
|
const effect = prop.util_call?.operation;
|
|
681
|
-
if (effect
|
|
739
|
+
if (effect !== undefined && vocabulary.functions.get(effect)?.taskOperation && !this.kind.roots.includes('task')) {
|
|
682
740
|
this.notInKind(node.id, effect, 'task', prop.key);
|
|
683
741
|
}
|
|
684
742
|
if (prop.key === BIND_PROP) {
|
|
@@ -698,10 +756,6 @@ class Checker {
|
|
|
698
756
|
this.add('assign.kind', node.id, {what: 'assign.start()', n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
|
|
699
757
|
}
|
|
700
758
|
if (DEPENDENCY_KEY_PROPS.has(`${node.component}.${prop.key}`)) this.checkDependencyKeys(node, prop);
|
|
701
|
-
if (node.component === 'Space' && prop.key === 'room' && !RUN_KINDS.includes(this.scope.kind)) {
|
|
702
|
-
// A Space places the run's dependencies: only an action's own blok (for a run, or for starting one) has them.
|
|
703
|
-
this.add('space.kind', node.id, {component: node.component, n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
|
|
704
|
-
}
|
|
705
759
|
if (node.component === TOAST_COMPONENT && prop.key === TOAST_TASK_PROP) {
|
|
706
760
|
const path = prop.dynamic_value?.path ?? null;
|
|
707
761
|
if (path === null || (path !== 'task' && !this.into.has(path))) this.add('toast.task', node.id, {what: path ?? what(prop)}, prop.key);
|
|
@@ -749,7 +803,11 @@ class Checker {
|
|
|
749
803
|
{token, suggestion: `${arbitrary.groups.utility}-<role> (${this.vocabulary.theme.colourRoles.slice(0, 6).join(', ')}, ...)`},
|
|
750
804
|
propKey,
|
|
751
805
|
);
|
|
806
|
+
continue;
|
|
752
807
|
}
|
|
808
|
+
// A colour that is no role is told as that; anything else outside the portable subset as this.
|
|
809
|
+
const unportable = unportableClass(token, this.vocabulary);
|
|
810
|
+
if (unportable !== null) this.add('class.not_portable', owner, {token, what: unportable}, propKey);
|
|
753
811
|
}
|
|
754
812
|
}
|
|
755
813
|
|