@arkitektio/bsx 4.3.0 → 6.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/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 +19 -8
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +49 -59
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +25 -35
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +48 -54
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +359 -159
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +3 -3
- 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 +172 -180
- 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 +19 -33
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +4 -5
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +6 -6
- package/dist/catalogs/parts/feedback.d.ts +15 -15
- package/dist/catalogs/parts/forms.d.ts +24 -24
- package/dist/catalogs/parts/html.d.ts +3 -3
- 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 +11 -11
- package/dist/catalogs/parts/icons.js +1 -1
- package/dist/catalogs/parts/index.d.ts +153 -165
- 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 +17 -32
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +13 -15
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +20 -20
- package/dist/catalogs/parts/overlays.d.ts +55 -55
- package/dist/catalogs/parts/run.d.ts +5 -13
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/run.js +1 -1
- package/dist/catalogs/parts/scene.d.ts +9 -17
- 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/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.d.ts +3 -3
- package/dist/catalogs/parts/typography.js +1 -1
- package/dist/catalogs/parts/typography.js.map +1 -1
- package/dist/catalogs/props.d.ts +4 -4
- package/dist/catalogs/scene.d.ts +8 -16
- 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 +58 -58
- 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 +83 -73
- 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/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/ports.js +1 -1
- package/dist/ports.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +10 -6
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +23 -9
- package/dist/renderer/BlokRenderer.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 +20 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +98 -15
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +6 -6
- package/dist/renderer/bloks/feedback.d.ts +15 -15
- package/dist/renderer/bloks/forms.d.ts +24 -24
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/html.js +2 -2
- package/dist/renderer/bloks/icons.d.ts +5 -5
- package/dist/renderer/bloks/index.d.ts +145 -144
- 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 +6 -13
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +3 -4
- 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 +20 -20
- package/dist/renderer/bloks/overlays.d.ts +55 -55
- package/dist/renderer/bloks/run/components.d.ts +2 -6
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/components.js +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +5 -9
- 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/toast.d.ts +1 -1
- package/dist/renderer/bloks/typography.d.ts +3 -3
- 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/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.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/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 +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 +10 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +8 -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 +16 -6
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +5 -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 +2 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +2 -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/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/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/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/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/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 +154 -153
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +7 -7
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +12324 -6934
- package/dist/spec/catalogs/base@4.json +13175 -0
- package/dist/spec/catalogs/base@4.json.js +13175 -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 +243 -75
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +44 -7
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +65 -7
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +83 -43
- package/dist/spec/vocabulary.json.js +83 -43
- 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/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 +54 -52
- 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 +51 -64
- package/src/bsx/partial.test.ts +1 -1
- package/src/bsx/print.ts +27 -34
- package/src/bsx/references.test.ts +86 -83
- package/src/bsx/references.ts +391 -198
- package/src/catalogs/catalogs.test.ts +46 -14
- package/src/catalogs/html.ts +3 -3
- package/src/catalogs/index.ts +6 -2
- package/src/catalogs/logo.ts +4 -5
- 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 +14 -18
- package/src/catalogs/parts/run.ts +1 -1
- package/src/catalogs/parts/scene.ts +1 -7
- 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/logo/actionLogoSource.ts +4 -4
- package/src/ports.ts +1 -1
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.tsx +46 -14
- 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 +136 -17
- 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 +4 -5
- 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/components.tsx +1 -1
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- 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/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +41 -0
- package/src/renderer/declare.ts +70 -32
- 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 +35 -10
- package/src/renderer/runtime/components.tsx +17 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +21 -8
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +2 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/preflight.ts +5 -2
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/text.test.tsx +65 -0
- package/src/renderer/runtime/text.ts +88 -0
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/runtime.ts +0 -1
- package/src/scene.ts +2 -2
- package/src/shadcn.ts +7 -7
- package/src/spec/bsx_v2.json +12324 -6934
- package/src/spec/catalogs/base@4.json +13175 -0
- package/src/spec/catalogs/orkestrator@1.json +489 -0
- package/src/spec/catalogs.ts +259 -103
- package/src/spec/spec.test.ts +93 -24
- package/src/spec/vocabulary.json +83 -43
- package/src/spec/vocabulary.ts +102 -17
- 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/dist/bsx/references.js
CHANGED
|
@@ -1,30 +1,61 @@
|
|
|
1
|
-
import { defaultBlokView } from '../spec/catalogs.js';
|
|
1
|
+
import { blokViewFor, defaultBlokView } from '../spec/catalogs.js';
|
|
2
|
+
import { TEXT_NODE } from './parse.js';
|
|
2
3
|
import { valueFitsPort } from '../spec/locals.js';
|
|
3
|
-
import { LOCAL_ANY,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
import { LOCAL_ANY, localDeclared, resolveLocals } from './infer.js';
|
|
5
|
+
import { blokCatalog, blokHeader, content, declarationProblem, declaredQueries, declaredSubscriptions, headerProblem, isDeclaration, iterWithParents, LIKE_PROP, LOCAL_COMPONENT, localName, localProblem, QUERY_COMPONENT, SUBSCRIPTION_COMPONENT, VAR_COMPONENT, } from './declared.js';
|
|
6
|
+
import { argFits, finding, kindIn, loadVocabulary, } from '../spec/vocabulary.js';
|
|
7
|
+
/** A class at its variant colons, those inside brackets left alone (`[&>*]:p-2`). */
|
|
8
|
+
const splitClass = (token) => {
|
|
9
|
+
const parts = [];
|
|
10
|
+
let depth = 0;
|
|
11
|
+
let current = '';
|
|
12
|
+
for (const character of token) {
|
|
13
|
+
if (character === '[')
|
|
14
|
+
depth += 1;
|
|
15
|
+
else if (character === ']')
|
|
16
|
+
depth = Math.max(0, depth - 1);
|
|
17
|
+
if (character === ':' && depth === 0) {
|
|
18
|
+
parts.push(current);
|
|
19
|
+
current = '';
|
|
20
|
+
}
|
|
21
|
+
else
|
|
22
|
+
current += character;
|
|
23
|
+
}
|
|
24
|
+
parts.push(current);
|
|
25
|
+
return parts;
|
|
26
|
+
};
|
|
27
|
+
/** What of the class `token` is outside the portable subset (`the before variant`), or null. */
|
|
28
|
+
export const unportableClass = (token, vocabulary) => {
|
|
29
|
+
const parts = splitClass(token);
|
|
30
|
+
const utility = (parts.pop() ?? '').replace(/^[!-]+/, '');
|
|
31
|
+
for (const variant of parts) {
|
|
32
|
+
if (variant.startsWith('['))
|
|
33
|
+
return 'an arbitrary variant';
|
|
34
|
+
const name = variant.split('/')[0];
|
|
35
|
+
if (vocabulary.unportableVariants.has(name) || vocabulary.unportableVariants.has(name.split('-[')[0]))
|
|
36
|
+
return `the ${name} variant`;
|
|
37
|
+
}
|
|
38
|
+
if (utility.startsWith('['))
|
|
39
|
+
return 'an arbitrary property';
|
|
40
|
+
if (utility.includes('[')) {
|
|
41
|
+
const prefix = utility.split('-[')[0];
|
|
42
|
+
return vocabulary.arbitraryValues.has(prefix) ? null : `an arbitrary value of ${prefix}`;
|
|
43
|
+
}
|
|
44
|
+
for (const prefix of vocabulary.unportableUtilities) {
|
|
45
|
+
if (utility === prefix || utility.startsWith(`${prefix}-`))
|
|
46
|
+
return `the ${prefix} utility`;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
/** A blok checked on its own, mounted nowhere: what an editor checks from the source alone. */
|
|
51
|
+
export const unmountedBlokScope = () => ({ kinds: [], dependencies: null, args: null });
|
|
52
|
+
/** A blok mounted where `kinds` go, with `dependencies` (none by default): every agent it reads must be one of them. */
|
|
53
|
+
export const mountedBlokScope = (kinds = [], dependencies = [], args = null) => ({ kinds, dependencies, args });
|
|
16
54
|
const LOGO = 'LOGO';
|
|
17
55
|
const SCENE = 'SCENE';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export const blokRootsOf = (context) => Object.entries(loadVocabulary().blokRoots)
|
|
22
|
-
.filter(([, named]) => named === context)
|
|
23
|
-
.map(([root]) => root);
|
|
24
|
-
/** The root a new blok of ``context`` starts with: the first it may start with (`SCENE` → `Scene`). */
|
|
25
|
-
export const blokRootOf = (context) => blokRootsOf(context)[0] ?? null;
|
|
26
|
-
/** The blok context a root component names (`Space` → `SCENE`), or null when it names none. */
|
|
27
|
-
export const blokContextOf = (component) => loadVocabulary().blokRoots[component] ?? null;
|
|
56
|
+
const PANEL = 'PANEL';
|
|
57
|
+
/** A context as a `<Blok context>` spells it (`PANEL` → `panel`). */
|
|
58
|
+
export const spelledContext = (context) => context.toLowerCase();
|
|
28
59
|
/* -------------------------------------------------------------------------- */
|
|
29
60
|
/* Matches */
|
|
30
61
|
/* -------------------------------------------------------------------------- */
|
|
@@ -33,10 +64,10 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
|
|
|
33
64
|
/** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
|
|
34
65
|
const RUN_KINDS = ['action', 'assign'];
|
|
35
66
|
const ASSIGN_KIND = 'assign';
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
/**
|
|
39
|
-
const
|
|
67
|
+
const ASK_COMPONENT = 'ask';
|
|
68
|
+
const CHROME_NONE = 'none';
|
|
69
|
+
/** The language's elements whose children do not always show: a host part inside one still claims its slot. */
|
|
70
|
+
const CONDITIONAL_COMPONENTS = new Set(['if', 'else', 'match', 'case', 'default', 'foreach', 'suspense', 'fallback', 'error']);
|
|
40
71
|
/** The one field of an agent that is not text. */
|
|
41
72
|
const AGENT_CONNECTED = 'connected';
|
|
42
73
|
/** Where an assign blok reads which arguments the caller decided. */
|
|
@@ -122,19 +153,23 @@ export const foreachLet = (node) => {
|
|
|
122
153
|
return null;
|
|
123
154
|
return node.props?.find(prop => prop.key === FOREACH_LET && prop.declares_value)?.declares_value ?? null;
|
|
124
155
|
};
|
|
125
|
-
const
|
|
126
|
-
/**
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
156
|
+
const isLocalBinding = (binding) => binding !== null && binding !== undefined && binding.local === true;
|
|
157
|
+
/** What a name in scope is, for `roots.shadow`. */
|
|
158
|
+
const bindingWhat = (name, binding, into) => {
|
|
159
|
+
if (isLocalBinding(binding))
|
|
160
|
+
return `the local ${binding.node}`;
|
|
161
|
+
if (into.has(name))
|
|
162
|
+
return "a call's record";
|
|
163
|
+
return 'a let';
|
|
164
|
+
};
|
|
165
|
+
const LOCAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
166
|
+
const FIELD_PATH = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
167
|
+
/** The kind of a GraphQL document's first operation: `query` (also for `{ ... }`), `mutation`, `subscription`, `fragment`. */
|
|
168
|
+
export const operationKeyword = (document) => {
|
|
169
|
+
const text = document.replace(/#[^\n]*/g, '').trimStart();
|
|
170
|
+
if (text.startsWith('{'))
|
|
171
|
+
return 'query';
|
|
172
|
+
return /^[A-Za-z_]+/.exec(text)?.[0] ?? '';
|
|
138
173
|
};
|
|
139
174
|
/* -------------------------------------------------------------------------- */
|
|
140
175
|
/* The checker */
|
|
@@ -155,7 +190,7 @@ const DIGITS = /^[0-9]+$/;
|
|
|
155
190
|
* - an agent blok has none: ``agent bloks read only `self` ``.
|
|
156
191
|
*/
|
|
157
192
|
export const dependencyHint = (key, kind) => {
|
|
158
|
-
if (kind === 'action' || kind === 'assign'
|
|
193
|
+
if (kind === 'action' || kind === 'assign')
|
|
159
194
|
return `add a dependency parameter \`${key}\` to the action`;
|
|
160
195
|
if (kind === 'agent')
|
|
161
196
|
return 'agent bloks read only `self`';
|
|
@@ -241,25 +276,37 @@ const argumentWhat = (argument) => {
|
|
|
241
276
|
class Checker {
|
|
242
277
|
findings = [];
|
|
243
278
|
vocabulary = loadVocabulary();
|
|
279
|
+
/** The kind's row in the blok's context (an action's logo reads only `task`). */
|
|
244
280
|
kind;
|
|
281
|
+
kindName;
|
|
282
|
+
context;
|
|
283
|
+
mounted;
|
|
245
284
|
dependencies;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
285
|
+
/** Per `<local>` node id, its port with its kind resolved. */
|
|
286
|
+
resolved;
|
|
287
|
+
queries = new Map();
|
|
288
|
+
subscriptions = new Map();
|
|
289
|
+
/** The node ids of the locals a control binds. */
|
|
249
290
|
boundLocals = new Set();
|
|
250
291
|
into = new Set();
|
|
251
|
-
|
|
292
|
+
asks = false;
|
|
293
|
+
/** The id of the root that says `chrome="none"`, when it does. */
|
|
294
|
+
chromeless;
|
|
252
295
|
colour;
|
|
296
|
+
header;
|
|
253
297
|
scope;
|
|
254
298
|
view;
|
|
255
|
-
constructor(scope, view) {
|
|
299
|
+
constructor(header, scope, view, resolved) {
|
|
300
|
+
this.header = header;
|
|
256
301
|
this.scope = scope;
|
|
257
302
|
this.view = view;
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
262
|
-
this.
|
|
303
|
+
this.kindName = header.kind;
|
|
304
|
+
this.context = header.context;
|
|
305
|
+
this.kind = kindIn(this.vocabulary.kinds[header.kind], header.context);
|
|
306
|
+
this.mounted = scope.dependencies !== null;
|
|
307
|
+
this.dependencies = new Map((scope.dependencies ?? []).map(dependency => [dependency.key, dependency]));
|
|
308
|
+
this.resolved = resolved;
|
|
309
|
+
this.chromeless = header.chrome === CHROME_NONE ? header.node : null;
|
|
263
310
|
this.colour = colourPattern(this.vocabulary);
|
|
264
311
|
}
|
|
265
312
|
add(code, nodeId, fields = {}, propKey) {
|
|
@@ -269,76 +316,166 @@ class Checker {
|
|
|
269
316
|
return [...this.kind.roots].sort().join(', ');
|
|
270
317
|
}
|
|
271
318
|
notInKind(nodeId, path, root, propKey) {
|
|
272
|
-
this.add('roots.not_in_kind', nodeId, { path, n: article(this.
|
|
319
|
+
this.add('roots.not_in_kind', nodeId, { path, n: article(this.kindName), kind: this.kindName, root, roots: this.rootsText() }, propKey);
|
|
273
320
|
}
|
|
274
321
|
/* -- declarations -- */
|
|
275
322
|
checkDeclarations(tree) {
|
|
276
|
-
const { vocabulary,
|
|
277
|
-
const
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
this.add('
|
|
286
|
-
}
|
|
287
|
-
if (
|
|
288
|
-
this.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
323
|
+
const { vocabulary, header } = this;
|
|
324
|
+
const kind = this.kindName;
|
|
325
|
+
const row = vocabulary.kinds[kind];
|
|
326
|
+
const contextName = spelledContext(header.context);
|
|
327
|
+
if (!row.contexts.includes(header.context)) {
|
|
328
|
+
this.add('context.kind', tree.id, { n: article(kind), kind, contexts: row.contexts.map(spelledContext).join(', '), context: contextName });
|
|
329
|
+
}
|
|
330
|
+
const kinds = this.scope.kinds ?? [];
|
|
331
|
+
if (kinds.length && !kinds.includes(kind)) {
|
|
332
|
+
this.add('kind.placement', tree.id, { n: article(kind), kind, m: article(kinds[0]), expected: kinds.join(' or '), where: this.scope.mount || 'here' });
|
|
333
|
+
}
|
|
334
|
+
if (header.chrome !== null && !vocabulary.blok.chrome.includes(header.context))
|
|
335
|
+
this.add('chrome.context', tree.id, { context: contextName });
|
|
336
|
+
const allowed = vocabulary.blok.content[header.context];
|
|
337
|
+
if (allowed) {
|
|
338
|
+
const drawn = content(tree);
|
|
339
|
+
if (drawn.length !== 1 || !allowed.includes(drawn[0].component)) {
|
|
340
|
+
const found = drawn.map(node => (node.component === TEXT_NODE ? 'text' : `<${node.component}>`)).join(', ') || 'nothing';
|
|
341
|
+
this.add('blok.content', tree.id, { context: contextName, expected: allowed.map(name => `one <${name}>`).join(' or '), found });
|
|
342
|
+
}
|
|
293
343
|
}
|
|
344
|
+
this.checkLocalPositions(tree);
|
|
345
|
+
this.checkQueries(tree);
|
|
294
346
|
for (const [name, sites] of intoSites(tree)) {
|
|
295
347
|
this.into.add(name);
|
|
296
348
|
if (vocabulary.reserved.has(name))
|
|
297
349
|
this.add('roots.reserved', sites[0].site, { name });
|
|
298
|
-
if (this.locals.has(name))
|
|
299
|
-
this.add('roots.shadow', sites[0].site, { name, first: 'a local', second: `the record of ${sites[0].site}` });
|
|
300
350
|
if (sites.length > 1)
|
|
301
351
|
this.add('into.twice', sites[1].site, { name, first: sites[0].site, second: sites[1].site });
|
|
302
352
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Each `<local>` reads, comes first among its parent's children, inside an
|
|
356
|
+
* element that takes children, in a kind that has locals; a persisted one
|
|
357
|
+
* inside a keyless foreach is a warning.
|
|
358
|
+
*/
|
|
359
|
+
checkLocalPositions(tree) {
|
|
360
|
+
for (const [node, ancestors] of iterWithParents(tree)) {
|
|
361
|
+
const parent = ancestors.length ? ancestors[ancestors.length - 1] : null;
|
|
362
|
+
if (node.component === VAR_COMPONENT && (parent === null || (parent.component !== QUERY_COMPONENT && parent.component !== SUBSCRIPTION_COMPONENT))) {
|
|
363
|
+
this.add('query.declaration', node.id, { component: 'var', problem: 'belongs inside a <query> or <subscription>' });
|
|
364
|
+
}
|
|
365
|
+
if (node.component !== LOCAL_COMPONENT)
|
|
366
|
+
continue;
|
|
367
|
+
const name = localName(node) ?? '?';
|
|
368
|
+
const problem = localProblem(node);
|
|
369
|
+
if (problem !== null) {
|
|
370
|
+
this.findings.push(problem);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (!this.kind.locals)
|
|
374
|
+
this.notInKind(node.id, `<local name='${name}'>`, 'locals');
|
|
375
|
+
if (this.vocabulary.reserved.has(name))
|
|
376
|
+
this.add('roots.reserved', node.id, { name });
|
|
377
|
+
if (parent === null) {
|
|
378
|
+
this.add('local.position', node.id, { name, problem: "is a blok's root; a blok is a <Blok>" });
|
|
306
379
|
continue;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
380
|
+
}
|
|
381
|
+
const siblings = parent.children ?? [];
|
|
382
|
+
const other = siblings.slice(0, siblings.indexOf(node)).find(sibling => sibling.component !== LOCAL_COMPONENT);
|
|
383
|
+
if (other) {
|
|
384
|
+
const shown = other.component === TEXT_NODE ? 'text' : `<${other.component}>`;
|
|
385
|
+
this.add('local.position', node.id, { name, problem: `comes after ${shown} (${other.id}); locals come first among their parent's children` });
|
|
386
|
+
}
|
|
387
|
+
if ([QUERY_COMPONENT, SUBSCRIPTION_COMPONENT, LOCAL_COMPONENT, VAR_COMPONENT].includes(parent.component)) {
|
|
388
|
+
this.add('local.position', node.id, { name, problem: `is inside <${parent.component}>, which declares, and draws nothing` });
|
|
389
|
+
}
|
|
390
|
+
else if (this.view) {
|
|
391
|
+
const spec = this.view.components.get(parent.component);
|
|
392
|
+
if (spec && !spec.acceptsChildren)
|
|
393
|
+
this.add('local.position', node.id, { name, problem: `is inside <${parent.component}>, which takes no children` });
|
|
394
|
+
}
|
|
395
|
+
const resolved = this.resolved.get(node.id);
|
|
396
|
+
if (!resolved)
|
|
397
|
+
continue;
|
|
398
|
+
if (resolved.likeProblem !== null) {
|
|
399
|
+
const like = node.props?.find(prop => prop.key === LIKE_PROP)?.static_value ?? null;
|
|
400
|
+
this.add('local.like', node.id, { name, like, problem: resolved.likeProblem });
|
|
401
|
+
}
|
|
402
|
+
this.checkLocalDefault(node.id, resolved.local);
|
|
403
|
+
if (resolved.local.persist) {
|
|
404
|
+
const loop = [...ancestors].reverse().find(ancestor => ancestor.component === FOREACH);
|
|
405
|
+
if (loop && !(loop.props ?? []).some(prop => prop.key === FOREACH_KEY))
|
|
406
|
+
this.add('local.persist_id', node.id, { name });
|
|
315
407
|
}
|
|
316
408
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
409
|
+
}
|
|
410
|
+
/** Queries and subscriptions are children of the `<Blok>`, each declared once and readable. */
|
|
411
|
+
checkQueries(tree) {
|
|
412
|
+
const first = new Map();
|
|
413
|
+
for (const [node, ancestors] of iterWithParents(tree)) {
|
|
414
|
+
if (node.component !== QUERY_COMPONENT && node.component !== SUBSCRIPTION_COMPONENT)
|
|
415
|
+
continue;
|
|
416
|
+
const named = node.props?.find(prop => prop.key === 'name')?.static_value;
|
|
417
|
+
const name = typeof named === 'string' ? named : '?';
|
|
418
|
+
if (ancestors.length !== 1) {
|
|
419
|
+
const at = ancestors.length ? ancestors[ancestors.length - 1].id : 'the root';
|
|
420
|
+
this.add('query.position', node.id, { component: node.component, name, at });
|
|
421
|
+
}
|
|
422
|
+
const problem = declarationProblem(node);
|
|
423
|
+
if (problem !== null) {
|
|
424
|
+
this.findings.push(problem);
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const key = `${node.component}\u0000${name}`;
|
|
428
|
+
const seen = first.get(key);
|
|
429
|
+
if (seen !== undefined)
|
|
430
|
+
this.add('query.duplicate', node.id, { what: node.component, name, first: seen, second: node.id });
|
|
431
|
+
else
|
|
432
|
+
first.set(key, node.id);
|
|
433
|
+
}
|
|
434
|
+
this.queries = new Map(declaredQueries(tree).map(query => [query.key, query]));
|
|
435
|
+
this.subscriptions = new Map(declaredSubscriptions(tree).map(subscription => [subscription.key, subscription]));
|
|
436
|
+
const declared = [
|
|
437
|
+
...[...this.queries.values()].map(query => ['query', query]),
|
|
438
|
+
...[...this.subscriptions.values()].map(subscription => ['subscription', subscription]),
|
|
439
|
+
];
|
|
440
|
+
for (const [what, each] of declared) {
|
|
441
|
+
const at = `${what === 'query' ? 'queries' : 'subscriptions'}.${each.key}`;
|
|
442
|
+
if (!LOCAL_NAME.test(each.key))
|
|
443
|
+
this.add('manifest.name', at, { what, key: each.key });
|
|
444
|
+
if (this.vocabulary.reserved.has(each.key))
|
|
445
|
+
this.add('roots.reserved', at, { name: each.key });
|
|
446
|
+
const operation = operationKeyword(each.document);
|
|
447
|
+
if (operation === 'mutation') {
|
|
448
|
+
this.add('query.read_only', at, { kind: what, name: each.key, problem: 'is a mutation: a blok reads, and writes only through a task' });
|
|
449
|
+
}
|
|
450
|
+
else if (operation !== what) {
|
|
451
|
+
this.add('query.kind', at, { kind: what, name: each.key, operation: operation || 'document without an operation' });
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
for (const query of this.queries.values()) {
|
|
455
|
+
if (query.more != null && !FIELD_PATH.test(query.more)) {
|
|
456
|
+
this.add('query.more', `queries.${query.key}`, { name: query.key, more: query.more, problem: 'is not a field path into its data (positions, images.items)' });
|
|
457
|
+
}
|
|
320
458
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
459
|
+
if (this.kindName === 'action' && this.context === LOGO && this.dependencies.size)
|
|
460
|
+
this.add('manifest.action_logo', this.header.node);
|
|
461
|
+
for (const subscription of this.subscriptions.values()) {
|
|
324
462
|
if (subscription.history != null && !this.queries.has(subscription.history)) {
|
|
325
463
|
this.add('query.history', `subscriptions.${subscription.key}`, { name: subscription.key, history: subscription.history });
|
|
326
464
|
}
|
|
327
465
|
}
|
|
328
466
|
}
|
|
329
467
|
/** A local's default fits its port: a number for a number, a list for a list, one of its choices. */
|
|
330
|
-
checkLocalDefault(local) {
|
|
468
|
+
checkLocalDefault(nodeId, local) {
|
|
331
469
|
if (local.kind === LOCAL_ANY)
|
|
332
470
|
return;
|
|
333
471
|
if (!valueFitsPort(local.default, local)) {
|
|
334
|
-
this.add('local.default',
|
|
472
|
+
this.add('local.default', nodeId, { name: local.key, default: local.default, kind: local.kind });
|
|
335
473
|
}
|
|
336
474
|
}
|
|
337
475
|
/** The port a path into a local names (the local, or a field of it), or null when its shape does not say (an ANY local). */
|
|
338
|
-
localPort(path) {
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
let port = local !== null && local.kind !== LOCAL_ANY ? local : null;
|
|
476
|
+
localPort(binding, path) {
|
|
477
|
+
const rest = path.split('.').slice(1);
|
|
478
|
+
let port = binding.port.kind !== LOCAL_ANY ? binding.port : null;
|
|
342
479
|
for (const part of rest) {
|
|
343
480
|
if (port === null)
|
|
344
481
|
return null;
|
|
@@ -351,10 +488,12 @@ class Checker {
|
|
|
351
488
|
return port;
|
|
352
489
|
}
|
|
353
490
|
finish() {
|
|
354
|
-
for (const
|
|
355
|
-
if (local.persist && !this.boundLocals.has(
|
|
356
|
-
this.add('local.unused_persist',
|
|
491
|
+
for (const [nodeId, resolved] of this.resolved) {
|
|
492
|
+
if (resolved.local.persist && !this.boundLocals.has(nodeId))
|
|
493
|
+
this.add('local.unused_persist', nodeId, { name: resolved.local.key });
|
|
357
494
|
}
|
|
495
|
+
if (this.chromeless !== null && this.kind.roots.includes('task') && !this.asks)
|
|
496
|
+
this.add('chrome.no_ask', this.chromeless);
|
|
358
497
|
}
|
|
359
498
|
/* -- the walk -- */
|
|
360
499
|
walk(tree) {
|
|
@@ -364,7 +503,7 @@ class Checker {
|
|
|
364
503
|
this.walkNode(tree, scope, [], false);
|
|
365
504
|
}
|
|
366
505
|
walkNode(node, scope, ancestors, inError) {
|
|
367
|
-
this.visitComponent(node, ancestors);
|
|
506
|
+
this.visitComponent(node, ancestors, scope);
|
|
368
507
|
const inner = new Map(scope);
|
|
369
508
|
const declared = foreachLet(node);
|
|
370
509
|
if (declared !== null) {
|
|
@@ -377,7 +516,14 @@ class Checker {
|
|
|
377
516
|
this.walkProp(node, prop, propScope, inError);
|
|
378
517
|
}
|
|
379
518
|
const inSlot = inError || (node.component === ERROR_SLOT && ancestors.length > 0 && ancestors[ancestors.length - 1].component === SUSPENSE);
|
|
380
|
-
|
|
519
|
+
// Every local of a node is bound before any of its children is walked, in order: a second local of one name sees the first.
|
|
520
|
+
const children = node.children ?? [];
|
|
521
|
+
for (const child of children) {
|
|
522
|
+
const name = localDeclared(child);
|
|
523
|
+
if (name !== null)
|
|
524
|
+
inner.set(name, this.bindLocal(name, child, new Map(inner)));
|
|
525
|
+
}
|
|
526
|
+
for (const child of children)
|
|
381
527
|
this.walkNode(child, inner, [...ancestors, node], inSlot);
|
|
382
528
|
}
|
|
383
529
|
walkProp(node, prop, scope, inError) {
|
|
@@ -407,33 +553,44 @@ class Checker {
|
|
|
407
553
|
[...(argument.value_list ?? []), ...(argument.value_dict ?? [])].forEach(nested => this.walkArgument(nested, scope, where));
|
|
408
554
|
}
|
|
409
555
|
/* -- components and props -- */
|
|
410
|
-
visitComponent(node, ancestors) {
|
|
556
|
+
visitComponent(node, ancestors, scope) {
|
|
411
557
|
const spec = this.view?.components.get(node.component);
|
|
412
|
-
if (this.view && !spec
|
|
413
|
-
this.
|
|
558
|
+
if (this.view && !spec) {
|
|
559
|
+
const foreign = this.view.foreign.get(node.component);
|
|
560
|
+
if (foreign !== undefined) {
|
|
561
|
+
this.add('catalog.target', node.id, { component: node.component, catalog: foreign, target: this.view.target ?? this.view.label });
|
|
562
|
+
}
|
|
563
|
+
else if (this.view.complete) {
|
|
564
|
+
this.add('catalog.unknown_component', node.id, { component: node.component, catalogs: this.view.label });
|
|
565
|
+
}
|
|
414
566
|
}
|
|
415
567
|
if (spec)
|
|
416
568
|
this.checkCatalog(node, spec, ancestors);
|
|
417
|
-
|
|
418
|
-
if (shadow && !this.shadowed.has(node.component)) {
|
|
419
|
-
this.shadowed.add(node.component);
|
|
420
|
-
this.add('catalog.shadow', node.id, { component: node.component, catalog: shadow.catalog, module: shadow.module, winner: shadow.winner });
|
|
421
|
-
}
|
|
422
|
-
if (TASK_COMPONENTS.has(node.component) && !this.kind.roots.includes('task')) {
|
|
423
|
-
this.notInKind(node.id, `<${node.component}>`, 'task');
|
|
424
|
-
}
|
|
425
|
-
if (ASSIGN_COMPONENTS.has(node.component) && this.scope.kind !== ASSIGN_KIND) {
|
|
426
|
-
this.add('assign.kind', node.id, { what: `<${node.component}>`, n: article(this.scope.kind), kind: this.scope.kind });
|
|
427
|
-
}
|
|
569
|
+
this.checkHostPart(node, ancestors);
|
|
428
570
|
for (const prop of node.props ?? [])
|
|
429
|
-
this.checkProp(node, prop, spec);
|
|
571
|
+
this.checkProp(node, prop, spec, scope);
|
|
430
572
|
}
|
|
431
573
|
checkCatalog(node, spec, ancestors) {
|
|
432
574
|
const view = this.view;
|
|
433
575
|
if (!view)
|
|
434
576
|
return;
|
|
435
|
-
|
|
577
|
+
const texts = (node.children ?? []).filter(child => child.component === TEXT_NODE);
|
|
578
|
+
const elements = (node.children ?? []).filter(child => child.component !== TEXT_NODE && !isDeclaration(child)).length;
|
|
579
|
+
if (elements && !spec.acceptsChildren)
|
|
436
580
|
this.add('catalog.children', node.id, { component: node.component });
|
|
581
|
+
if (texts.length) {
|
|
582
|
+
// Text is a child like any other; what takes it is the catalog's to say.
|
|
583
|
+
const textProp = spec.textProp;
|
|
584
|
+
if (textProp === null && !spec.acceptsChildren) {
|
|
585
|
+
this.add('catalog.text', node.id, { component: node.component, detail: 'takes no text' });
|
|
586
|
+
}
|
|
587
|
+
else if (textProp !== null && (node.props ?? []).some(prop => prop.key === textProp)) {
|
|
588
|
+
this.add('catalog.text', node.id, { component: node.component, detail: `sets ${textProp} as an attribute and as its text` });
|
|
589
|
+
}
|
|
590
|
+
else if (textProp !== null && !spec.acceptsChildren && (elements || texts.length > 1)) {
|
|
591
|
+
this.add('catalog.text', node.id, { component: node.component, detail: `takes one run of text as its ${textProp}, and no elements beside it` });
|
|
592
|
+
}
|
|
593
|
+
}
|
|
437
594
|
const present = new Set((node.props ?? []).map(prop => prop.key));
|
|
438
595
|
const known = new Set([...spec.props.map(prop => prop.key), WHEN_PROP]);
|
|
439
596
|
const unknown = [...present].filter(key => !known.has(key)).sort();
|
|
@@ -442,7 +599,7 @@ class Checker {
|
|
|
442
599
|
const missing = spec.props.filter(prop => prop.required && !present.has(prop.key)).map(prop => prop.key).sort();
|
|
443
600
|
if (missing.length)
|
|
444
601
|
this.add('catalog.props', node.id, { component: node.component, detail: `requires props [${missing.map(pythonRepr).join(', ')}]` });
|
|
445
|
-
let context =
|
|
602
|
+
let context = PANEL;
|
|
446
603
|
for (const ancestor of ancestors) {
|
|
447
604
|
const above = view.components.get(ancestor.component);
|
|
448
605
|
if (above && !above.inheritsContext)
|
|
@@ -462,29 +619,39 @@ class Checker {
|
|
|
462
619
|
if (forbidden.length) {
|
|
463
620
|
this.add('catalog.placement', node.id, { component: node.component, detail: `must not be inside [${forbidden.map(pythonRepr).join(', ')}]` });
|
|
464
621
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
622
|
+
if (spec.kinds.length && !spec.kinds.includes(this.kindName)) {
|
|
623
|
+
this.add('catalog.kind', node.id, { component: node.component, kinds: spec.kinds.join(' and '), n: article(this.kindName), kind: this.kindName });
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* What the language itself says of the host's parts, whatever catalog draws
|
|
628
|
+
* them: a part placed anywhere claims its slot (a blok without chrome
|
|
629
|
+
* leaves the asks to itself: `finish`).
|
|
630
|
+
*/
|
|
631
|
+
checkHostPart(node, ancestors) {
|
|
632
|
+
if (node.component === ASK_COMPONENT)
|
|
633
|
+
this.asks = true;
|
|
634
|
+
if (this.vocabulary.hostParts.includes(node.component)) {
|
|
635
|
+
const inside = [...ancestors].reverse().find(ancestor => CONDITIONAL_COMPONENTS.has(ancestor.component));
|
|
636
|
+
if (inside)
|
|
637
|
+
this.add('part.conditional', node.id, { component: node.component, inside: inside.component });
|
|
470
638
|
}
|
|
471
639
|
}
|
|
472
640
|
/** A ``Placed dep`` or ``Route through`` names dependencies of the blok, written out as keys. */
|
|
473
641
|
checkDependencyKeys(node, prop) {
|
|
474
|
-
|
|
475
|
-
|
|
642
|
+
// catalog.kind says it: a Space and its parts belong to an action's own blok. Unmounted, its keys are taken as written.
|
|
643
|
+
if (!RUN_KINDS.includes(this.kindName) || !this.mounted)
|
|
476
644
|
return;
|
|
477
|
-
}
|
|
478
645
|
const path = `${node.component}.${prop.key}`;
|
|
479
646
|
const value = prop.static_value;
|
|
480
647
|
const keys = typeof value === 'string' ? [value] : Array.isArray(value) ? value.filter((key) => typeof key === 'string') : [];
|
|
481
648
|
for (const key of keys) {
|
|
482
649
|
if (!this.dependencies.has(key)) {
|
|
483
|
-
this.add('deps.unknown', node.id, { path, key, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(key, this.
|
|
650
|
+
this.add('deps.unknown', node.id, { path, key, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(key, this.kindName) }, prop.key);
|
|
484
651
|
}
|
|
485
652
|
}
|
|
486
653
|
}
|
|
487
|
-
checkProp(node, prop, spec) {
|
|
654
|
+
checkProp(node, prop, spec, scope) {
|
|
488
655
|
const { vocabulary } = this;
|
|
489
656
|
const propSpec = spec?.props.find(candidate => candidate.key === prop.key);
|
|
490
657
|
const holds = isCallbackValue(prop);
|
|
@@ -509,7 +676,7 @@ class Checker {
|
|
|
509
676
|
}
|
|
510
677
|
// `task.answer(...)`, `task.cancel()` and their kin act on the task the blok is about.
|
|
511
678
|
const effect = prop.util_call?.operation;
|
|
512
|
-
if (effect
|
|
679
|
+
if (effect !== undefined && vocabulary.functions.get(effect)?.taskOperation && !this.kind.roots.includes('task')) {
|
|
513
680
|
this.notInKind(node.id, effect, 'task', prop.key);
|
|
514
681
|
}
|
|
515
682
|
if (prop.key === BIND_PROP) {
|
|
@@ -519,24 +686,21 @@ class Checker {
|
|
|
519
686
|
}
|
|
520
687
|
else {
|
|
521
688
|
const root = path.split('.')[0];
|
|
522
|
-
|
|
689
|
+
const binding = scope.get(root);
|
|
690
|
+
if (!isLocalBinding(binding))
|
|
523
691
|
this.add('local.unknown', node.id, { path, root }, prop.key);
|
|
524
692
|
else {
|
|
525
|
-
this.boundLocals.add(
|
|
693
|
+
this.boundLocals.add(binding.node);
|
|
526
694
|
if (propSpec)
|
|
527
|
-
this.checkBindKind(node, propSpec.kind, path);
|
|
695
|
+
this.checkBindKind(node, propSpec.kind, binding, path);
|
|
528
696
|
}
|
|
529
697
|
}
|
|
530
698
|
}
|
|
531
|
-
if (prop.util_call?.operation === START_EFFECT && this.
|
|
532
|
-
this.add('assign.kind', node.id, { what: 'assign.start()', n: article(this.
|
|
699
|
+
if (prop.util_call?.operation === START_EFFECT && this.kindName !== ASSIGN_KIND) {
|
|
700
|
+
this.add('assign.kind', node.id, { what: 'assign.start()', n: article(this.kindName), kind: this.kindName }, prop.key);
|
|
533
701
|
}
|
|
534
702
|
if (DEPENDENCY_KEY_PROPS.has(`${node.component}.${prop.key}`))
|
|
535
703
|
this.checkDependencyKeys(node, prop);
|
|
536
|
-
if (node.component === 'Space' && prop.key === 'room' && !RUN_KINDS.includes(this.scope.kind)) {
|
|
537
|
-
// A Space places the run's dependencies: only an action's own blok (for a run, or for starting one) has them.
|
|
538
|
-
this.add('space.kind', node.id, { component: node.component, n: article(this.scope.kind), kind: this.scope.kind }, prop.key);
|
|
539
|
-
}
|
|
540
704
|
if (node.component === TOAST_COMPONENT && prop.key === TOAST_TASK_PROP) {
|
|
541
705
|
const path = prop.dynamic_value?.path ?? null;
|
|
542
706
|
if (path === null || (path !== 'task' && !this.into.has(path)))
|
|
@@ -545,7 +709,7 @@ class Checker {
|
|
|
545
709
|
if (typeof prop.static_value === 'string') {
|
|
546
710
|
if (prop.key === CLASS_NAME)
|
|
547
711
|
this.checkClasses(prop.static_value, node.id, prop.key);
|
|
548
|
-
if (
|
|
712
|
+
if (this.context === LOGO && vocabulary.theme.logoPaintProps.includes(prop.key))
|
|
549
713
|
this.checkPaint(node, prop.key, prop.static_value);
|
|
550
714
|
if (spec?.context === SCENE && vocabulary.theme.scenePaintProps.includes(prop.key))
|
|
551
715
|
this.checkSceneColour(node, prop.key, prop.static_value);
|
|
@@ -556,9 +720,9 @@ class Checker {
|
|
|
556
720
|
}
|
|
557
721
|
}
|
|
558
722
|
/** The local a control writes is of a kind the control writes (`Slider`: FLOAT or INT). */
|
|
559
|
-
checkBindKind(node, propKind, path) {
|
|
723
|
+
checkBindKind(node, propKind, binding, path) {
|
|
560
724
|
const allowed = this.vocabulary.locals.bindKinds[propKind];
|
|
561
|
-
const port = this.localPort(path);
|
|
725
|
+
const port = this.localPort(binding, path);
|
|
562
726
|
if (!allowed || port === null)
|
|
563
727
|
return;
|
|
564
728
|
if (!allowed.includes(port.kind)) {
|
|
@@ -578,7 +742,12 @@ class Checker {
|
|
|
578
742
|
const arbitrary = ARBITRARY_COLOUR.exec(base);
|
|
579
743
|
if (arbitrary?.groups) {
|
|
580
744
|
this.add('palette.raw_colour', owner, { token, suggestion: `${arbitrary.groups.utility}-<role> (${this.vocabulary.theme.colourRoles.slice(0, 6).join(', ')}, ...)` }, propKey);
|
|
745
|
+
continue;
|
|
581
746
|
}
|
|
747
|
+
// A colour that is no role is told as that; anything else outside the portable subset as this.
|
|
748
|
+
const unportable = unportableClass(token, this.vocabulary);
|
|
749
|
+
if (unportable !== null)
|
|
750
|
+
this.add('class.not_portable', owner, { token, what: unportable }, propKey);
|
|
582
751
|
}
|
|
583
752
|
}
|
|
584
753
|
checkPaint(node, key, value) {
|
|
@@ -610,8 +779,8 @@ class Checker {
|
|
|
610
779
|
}
|
|
611
780
|
const dependency = this.dependencies.get(call.dependency);
|
|
612
781
|
if (!dependency) {
|
|
613
|
-
if (call.dependency !== 'self') {
|
|
614
|
-
this.add('deps.unknown', where.node.id, { path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.
|
|
782
|
+
if (call.dependency !== 'self' && this.mounted) {
|
|
783
|
+
this.add('deps.unknown', where.node.id, { path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.kindName) }, where.key);
|
|
615
784
|
}
|
|
616
785
|
return;
|
|
617
786
|
}
|
|
@@ -633,10 +802,10 @@ class Checker {
|
|
|
633
802
|
const match = ports.get(argument.key ?? '');
|
|
634
803
|
if (path == null || !match || match.kind == null)
|
|
635
804
|
continue;
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
805
|
+
const binding = scope.get(path.split('.')[0]);
|
|
806
|
+
if (!isLocalBinding(binding))
|
|
638
807
|
continue;
|
|
639
|
-
const port = this.localPort(path);
|
|
808
|
+
const port = this.localPort(binding, path);
|
|
640
809
|
if (port === null)
|
|
641
810
|
continue;
|
|
642
811
|
const target = { kind: match.kind, identifier: match.identifier ?? null };
|
|
@@ -702,6 +871,11 @@ class Checker {
|
|
|
702
871
|
this.add('query.fetch_more', where.node.id, { path, name }, where.key);
|
|
703
872
|
}
|
|
704
873
|
bindLet(name, items, where, scope) {
|
|
874
|
+
if (this.vocabulary.reserved.has(name))
|
|
875
|
+
this.add('roots.reserved', where.node.id, { name });
|
|
876
|
+
else if (scope.has(name)) {
|
|
877
|
+
this.add('roots.shadow', where.node.id, { name, first: bindingWhat(name, scope.get(name), this.into), second: `the let of <foreach> (${where.node.id})` });
|
|
878
|
+
}
|
|
705
879
|
const keyed = (where.node.props ?? []).some(prop => prop.key === FOREACH_KEY);
|
|
706
880
|
const literal = items?.static_value;
|
|
707
881
|
if (!keyed && Array.isArray(literal) && literal.some(item => typeof item === 'object' && item !== null)) {
|
|
@@ -726,6 +900,15 @@ class Checker {
|
|
|
726
900
|
this.add('path.unknown', where.node.id, { path, detail: `${FOREACH_ITEMS} of a foreach reads a list, not this ${resolved.kind.toLowerCase()}` }, FOREACH_ITEMS);
|
|
727
901
|
return openMatch(name);
|
|
728
902
|
}
|
|
903
|
+
bindLocal(name, node, scope) {
|
|
904
|
+
if (scope.has(name) && !this.vocabulary.reserved.has(name)) {
|
|
905
|
+
this.add('roots.shadow', node.id, { name, first: bindingWhat(name, scope.get(name), this.into), second: `the local ${node.id}` });
|
|
906
|
+
}
|
|
907
|
+
const resolved = this.resolved.get(node.id);
|
|
908
|
+
if (!resolved)
|
|
909
|
+
return openMatch(name);
|
|
910
|
+
return { local: true, node: node.id, name, port: resolved.local };
|
|
911
|
+
}
|
|
729
912
|
bindInto(call) {
|
|
730
913
|
const dependency = this.dependencies.get(call.dependency);
|
|
731
914
|
const action = actionKeyFor(call);
|
|
@@ -751,15 +934,16 @@ class Checker {
|
|
|
751
934
|
const [root, ...rest] = parts;
|
|
752
935
|
const report = (code, fields) => this.add(code, nodeId, fields, propKey);
|
|
753
936
|
if (scope.has(root)) {
|
|
937
|
+
const binding = scope.get(root) ?? null;
|
|
938
|
+
if (isLocalBinding(binding)) {
|
|
939
|
+
const local = binding.port;
|
|
940
|
+
if (local.kind === LOCAL_ANY || OPAQUE_KINDS.has(local.kind))
|
|
941
|
+
return openMatch(root);
|
|
942
|
+
return this.descend({ ...portMatch(local), key: root }, rest, path, nodeId, propKey);
|
|
943
|
+
}
|
|
754
944
|
if (this.into.has(root))
|
|
755
945
|
this.checkReturns(path, rest, nodeId, propKey);
|
|
756
|
-
return this.descend(
|
|
757
|
-
}
|
|
758
|
-
const local = this.locals.get(root);
|
|
759
|
-
if (local) {
|
|
760
|
-
if (local.kind === LOCAL_ANY || OPAQUE_KINDS.has(local.kind))
|
|
761
|
-
return openMatch(root);
|
|
762
|
-
return this.descend({ ...portMatch(local), key: root }, rest, path, nodeId, propKey);
|
|
946
|
+
return this.descend(binding, rest, path, nodeId, propKey);
|
|
763
947
|
}
|
|
764
948
|
if (root === 'event') {
|
|
765
949
|
if (!where || !where.callback) {
|
|
@@ -798,7 +982,9 @@ class Checker {
|
|
|
798
982
|
}
|
|
799
983
|
const dependency = this.dependencies.get(rest[0]);
|
|
800
984
|
if (!dependency) {
|
|
801
|
-
|
|
985
|
+
if (!this.mounted)
|
|
986
|
+
return openMatch(path);
|
|
987
|
+
report('deps.unknown', { path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.kindName) });
|
|
802
988
|
return null;
|
|
803
989
|
}
|
|
804
990
|
return this.agent(dependency, rest[0], rest.slice(1), path, nodeId, propKey);
|
|
@@ -1017,15 +1203,29 @@ export const checkLogo = (tree, demo) => {
|
|
|
1017
1203
|
return findings;
|
|
1018
1204
|
};
|
|
1019
1205
|
/**
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1022
|
-
* and
|
|
1206
|
+
* The view a blok is checked with when none is given: that of the catalog its
|
|
1207
|
+
* `<Blok catalog>` names when it is known here, the app's own when it names
|
|
1208
|
+
* none, and an incomplete base view (nothing reported unknown) otherwise.
|
|
1209
|
+
*/
|
|
1210
|
+
export const viewForTree = (tree) => {
|
|
1211
|
+
const catalog = blokCatalog(tree);
|
|
1212
|
+
return catalog === null ? defaultBlokView() : blokViewFor(catalog);
|
|
1213
|
+
};
|
|
1214
|
+
/**
|
|
1215
|
+
* Every finding of `tree` mounted as `scope` says (unmounted by default),
|
|
1216
|
+
* against `view`: errors and warnings, in tree order. A root that is no
|
|
1217
|
+
* readable `<Blok>` is the one finding. `view` defaults to that of the catalog
|
|
1218
|
+
* the blok names (`viewForTree`); `null` skips every catalog rule.
|
|
1023
1219
|
*/
|
|
1024
|
-
export const checkBlokTree = (tree, scope, view =
|
|
1025
|
-
const
|
|
1220
|
+
export const checkBlokTree = (tree, scope = unmountedBlokScope(), view = viewForTree(tree)) => {
|
|
1221
|
+
const problem = headerProblem(tree);
|
|
1222
|
+
if (problem !== null)
|
|
1223
|
+
return [problem];
|
|
1224
|
+
const header = blokHeader(tree);
|
|
1225
|
+
const checker = new Checker(header, scope, view, resolveLocals(tree, scope.dependencies, view));
|
|
1026
1226
|
checker.checkDeclarations(tree);
|
|
1027
1227
|
checker.walk(tree);
|
|
1028
|
-
if (
|
|
1228
|
+
if (header.context === LOGO)
|
|
1029
1229
|
checker.findings.push(...checkLogo(tree, scope.demo));
|
|
1030
1230
|
checker.finish();
|
|
1031
1231
|
return checker.findings;
|