@arkitektio/bsx 5.0.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 +2 -2
- package/dist/bsx/analyze.d.ts +6 -5
- package/dist/bsx/analyze.d.ts.map +1 -1
- package/dist/bsx/analyze.js +12 -10
- package/dist/bsx/analyze.js.map +1 -1
- package/dist/bsx/declared.d.ts +111 -0
- package/dist/bsx/declared.d.ts.map +1 -0
- package/dist/bsx/declared.js +311 -0
- package/dist/bsx/declared.js.map +1 -0
- package/dist/bsx/index.d.ts +1 -0
- package/dist/bsx/index.d.ts.map +1 -1
- package/dist/bsx/index.js +1 -0
- package/dist/bsx/index.js.map +1 -1
- package/dist/bsx/infer.d.ts +40 -17
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +105 -49
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts +6 -2
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +65 -21
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +6 -1
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +32 -3
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +3 -0
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +45 -51
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +265 -138
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +2 -2
- package/dist/catalogs/index.d.ts +49 -71
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +1 -1
- package/dist/catalogs/logo.d.ts +14 -28
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +1 -2
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +1 -1
- package/dist/catalogs/parts/feedback.d.ts +3 -3
- package/dist/catalogs/parts/forms.d.ts +4 -4
- package/dist/catalogs/parts/html.d.ts +2 -2
- package/dist/catalogs/parts/icons.d.ts +2 -2
- package/dist/catalogs/parts/index.d.ts +35 -57
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +10 -25
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +12 -14
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +4 -4
- package/dist/catalogs/parts/overlays.d.ts +11 -11
- package/dist/catalogs/parts/run.d.ts +2 -10
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.d.ts +7 -15
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +1 -5
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/typography.d.ts +3 -3
- package/dist/catalogs/props.d.ts +2 -2
- package/dist/catalogs/scene.d.ts +5 -13
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/shadcn.d.ts +11 -11
- package/dist/catalogs/ui.d.ts +16 -16
- package/dist/logo/actionLogoSource.d.ts +3 -3
- package/dist/logo/actionLogoSource.d.ts.map +1 -1
- package/dist/logo/actionLogoSource.js +4 -4
- package/dist/logo/actionLogoSource.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +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 +3 -3
- package/dist/renderer/baseCatalog.js +2 -2
- package/dist/renderer/bloks/control.d.ts +18 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +85 -14
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +1 -1
- package/dist/renderer/bloks/feedback.d.ts +3 -3
- package/dist/renderer/bloks/forms.d.ts +4 -4
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/icons.d.ts +1 -1
- package/dist/renderer/bloks/index.d.ts +30 -37
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +1 -8
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +1 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
- package/dist/renderer/bloks/navigation.d.ts +4 -4
- package/dist/renderer/bloks/overlays.d.ts +11 -11
- package/dist/renderer/bloks/run/components.d.ts +1 -5
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +4 -8
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.js +3 -2
- package/dist/renderer/bloks/scene/interaction.js.map +1 -1
- package/dist/renderer/bloks/shared/props.d.ts +2 -2
- package/dist/renderer/bloks/typography.d.ts +3 -3
- package/dist/renderer/declarations.d.ts +40 -33
- package/dist/renderer/declarations.d.ts.map +1 -1
- package/dist/renderer/declarations.js +41 -56
- package/dist/renderer/declarations.js.map +1 -1
- package/dist/renderer/declare.js +4 -4
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/persist.d.ts +22 -13
- package/dist/renderer/persist.d.ts.map +1 -1
- package/dist/renderer/persist.js +40 -21
- package/dist/renderer/persist.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +4 -4
- package/dist/renderer/runtime/catalog.js +3 -3
- package/dist/renderer/runtime/components.d.ts +4 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +5 -5
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +5 -5
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +11 -5
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +3 -3
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +2 -2
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +8 -4
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/index.d.ts +1 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +1 -0
- package/dist/renderer/runtime/index.js.map +1 -1
- package/dist/renderer/runtime/locals.d.ts +57 -0
- package/dist/renderer/runtime/locals.d.ts.map +1 -0
- package/dist/renderer/runtime/locals.js +87 -0
- package/dist/renderer/runtime/locals.js.map +1 -0
- package/dist/renderer/runtime/scope.d.ts +14 -0
- package/dist/renderer/runtime/scope.d.ts.map +1 -1
- package/dist/renderer/runtime/scope.js +25 -3
- package/dist/renderer/runtime/scope.js.map +1 -1
- package/dist/renderer/runtime/tree.d.ts.map +1 -1
- package/dist/renderer/runtime/tree.js +7 -1
- package/dist/renderer/runtime/tree.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +8 -3
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/shadcn.d.ts +36 -43
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +1 -2
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +11067 -6321
- package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
- package/dist/spec/catalogs/orkestrator@1.json +10 -10
- package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
- package/dist/spec/catalogs.d.ts +4 -4
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +7 -7
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +25 -4
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +50 -5
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +58 -32
- package/dist/spec/vocabulary.json.js +58 -32
- package/package.json +1 -1
- package/src/bsx/analyze.ts +14 -12
- package/src/bsx/bsx.test.ts +4 -4
- package/src/bsx/declared.ts +346 -0
- package/src/bsx/index.ts +1 -0
- package/src/bsx/infer.test.ts +42 -32
- package/src/bsx/infer.ts +128 -71
- package/src/bsx/language.test.ts +37 -25
- package/src/bsx/language.ts +72 -25
- package/src/bsx/parse.ts +34 -3
- package/src/bsx/print.ts +3 -0
- package/src/bsx/references.test.ts +82 -81
- package/src/bsx/references.ts +313 -178
- package/src/catalogs/catalogs.test.ts +3 -2
- package/src/catalogs/index.ts +1 -1
- package/src/catalogs/logo.ts +1 -2
- package/src/catalogs/parts/logo.ts +13 -17
- package/src/catalogs/parts/scene.ts +1 -7
- package/src/logo/actionLogoSource.ts +4 -4
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.tsx +46 -14
- package/src/renderer/addBlokComponents.test.tsx +1 -1
- package/src/renderer/baseCatalog.ts +2 -2
- package/src/renderer/bloks/control.tsx +119 -16
- package/src/renderer/bloks/logo/index.tsx +2 -3
- package/src/renderer/bloks/logo/logo.fixture.json +266 -250
- package/src/renderer/bloks/logo/logo.test.tsx +18 -7
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- package/src/renderer/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +4 -4
- package/src/renderer/declare.ts +4 -4
- package/src/renderer/persist.test.ts +70 -49
- package/src/renderer/persist.ts +57 -34
- package/src/renderer/runtime/catalog.test.ts +2 -2
- package/src/renderer/runtime/catalog.ts +4 -4
- package/src/renderer/runtime/components.tsx +8 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +5 -5
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/shadcn.ts +1 -2
- package/src/spec/bsx_v2.json +11067 -6321
- package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/src/spec/catalogs/orkestrator@1.json +10 -10
- package/src/spec/catalogs.ts +8 -8
- package/src/spec/spec.test.ts +19 -16
- package/src/spec/vocabulary.json +58 -32
- package/src/spec/vocabulary.ts +69 -10
package/dist/bsx/references.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { defaultBlokView } from '../spec/catalogs.js';
|
|
1
|
+
import { blokViewFor, defaultBlokView } from '../spec/catalogs.js';
|
|
2
2
|
import { TEXT_NODE } from './parse.js';
|
|
3
3
|
import { valueFitsPort } from '../spec/locals.js';
|
|
4
|
-
import { LOCAL_ANY,
|
|
5
|
-
import {
|
|
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';
|
|
6
7
|
/** A class at its variant colons, those inside brackets left alone (`[&>*]:p-2`). */
|
|
7
8
|
const splitClass = (token) => {
|
|
8
9
|
const parts = [];
|
|
@@ -46,28 +47,15 @@ export const unportableClass = (token, vocabulary) => {
|
|
|
46
47
|
}
|
|
47
48
|
return null;
|
|
48
49
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
locals: [],
|
|
54
|
-
queries: [],
|
|
55
|
-
subscriptions: [],
|
|
56
|
-
args: null,
|
|
57
|
-
});
|
|
58
|
-
const ACTION_LOGO = 'ACTION_LOGO';
|
|
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 });
|
|
59
54
|
const LOGO = 'LOGO';
|
|
60
55
|
const SCENE = 'SCENE';
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export const blokRootsOf = (context) => Object.entries(loadVocabulary().blokRoots)
|
|
65
|
-
.filter(([, named]) => named === context)
|
|
66
|
-
.map(([root]) => root);
|
|
67
|
-
/** The root a new blok of ``context`` starts with: the first it may start with (`SCENE` → `Scene`). */
|
|
68
|
-
export const blokRootOf = (context) => blokRootsOf(context)[0] ?? null;
|
|
69
|
-
/** The blok context a root component names (`Space` → `SCENE`), or null when it names none. */
|
|
70
|
-
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();
|
|
71
59
|
/* -------------------------------------------------------------------------- */
|
|
72
60
|
/* Matches */
|
|
73
61
|
/* -------------------------------------------------------------------------- */
|
|
@@ -77,7 +65,6 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
|
|
|
77
65
|
const RUN_KINDS = ['action', 'assign'];
|
|
78
66
|
const ASSIGN_KIND = 'assign';
|
|
79
67
|
const ASK_COMPONENT = 'ask';
|
|
80
|
-
const CHROME_PROP = 'chrome';
|
|
81
68
|
const CHROME_NONE = 'none';
|
|
82
69
|
/** The language's elements whose children do not always show: a host part inside one still claims its slot. */
|
|
83
70
|
const CONDITIONAL_COMPONENTS = new Set(['if', 'else', 'match', 'case', 'default', 'foreach', 'suspense', 'fallback', 'error']);
|
|
@@ -166,19 +153,23 @@ export const foreachLet = (node) => {
|
|
|
166
153
|
return null;
|
|
167
154
|
return node.props?.find(prop => prop.key === FOREACH_LET && prop.declares_value)?.declares_value ?? null;
|
|
168
155
|
};
|
|
169
|
-
const
|
|
170
|
-
/**
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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] ?? '';
|
|
182
173
|
};
|
|
183
174
|
/* -------------------------------------------------------------------------- */
|
|
184
175
|
/* The checker */
|
|
@@ -199,7 +190,7 @@ const DIGITS = /^[0-9]+$/;
|
|
|
199
190
|
* - an agent blok has none: ``agent bloks read only `self` ``.
|
|
200
191
|
*/
|
|
201
192
|
export const dependencyHint = (key, kind) => {
|
|
202
|
-
if (kind === 'action' || kind === 'assign'
|
|
193
|
+
if (kind === 'action' || kind === 'assign')
|
|
203
194
|
return `add a dependency parameter \`${key}\` to the action`;
|
|
204
195
|
if (kind === 'agent')
|
|
205
196
|
return 'agent bloks read only `self`';
|
|
@@ -285,27 +276,37 @@ const argumentWhat = (argument) => {
|
|
|
285
276
|
class Checker {
|
|
286
277
|
findings = [];
|
|
287
278
|
vocabulary = loadVocabulary();
|
|
279
|
+
/** The kind's row in the blok's context (an action's logo reads only `task`). */
|
|
288
280
|
kind;
|
|
281
|
+
kindName;
|
|
282
|
+
context;
|
|
283
|
+
mounted;
|
|
289
284
|
dependencies;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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. */
|
|
293
290
|
boundLocals = new Set();
|
|
294
291
|
into = new Set();
|
|
295
292
|
asks = false;
|
|
296
293
|
/** The id of the root that says `chrome="none"`, when it does. */
|
|
297
|
-
chromeless
|
|
294
|
+
chromeless;
|
|
298
295
|
colour;
|
|
296
|
+
header;
|
|
299
297
|
scope;
|
|
300
298
|
view;
|
|
301
|
-
constructor(scope, view) {
|
|
299
|
+
constructor(header, scope, view, resolved) {
|
|
300
|
+
this.header = header;
|
|
302
301
|
this.scope = scope;
|
|
303
302
|
this.view = view;
|
|
304
|
-
this.
|
|
305
|
-
this.
|
|
306
|
-
this.
|
|
307
|
-
this.
|
|
308
|
-
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;
|
|
309
310
|
this.colour = colourPattern(this.vocabulary);
|
|
310
311
|
}
|
|
311
312
|
add(code, nodeId, fields = {}, propKey) {
|
|
@@ -315,76 +316,166 @@ class Checker {
|
|
|
315
316
|
return [...this.kind.roots].sort().join(', ');
|
|
316
317
|
}
|
|
317
318
|
notInKind(nodeId, path, root, propKey) {
|
|
318
|
-
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);
|
|
319
320
|
}
|
|
320
321
|
/* -- declarations -- */
|
|
321
322
|
checkDeclarations(tree) {
|
|
322
|
-
const { vocabulary,
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
this.add('
|
|
332
|
-
}
|
|
333
|
-
if (
|
|
334
|
-
this.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
+
}
|
|
339
343
|
}
|
|
344
|
+
this.checkLocalPositions(tree);
|
|
345
|
+
this.checkQueries(tree);
|
|
340
346
|
for (const [name, sites] of intoSites(tree)) {
|
|
341
347
|
this.into.add(name);
|
|
342
348
|
if (vocabulary.reserved.has(name))
|
|
343
349
|
this.add('roots.reserved', sites[0].site, { name });
|
|
344
|
-
if (this.locals.has(name))
|
|
345
|
-
this.add('roots.shadow', sites[0].site, { name, first: 'a local', second: `the record of ${sites[0].site}` });
|
|
346
350
|
if (sites.length > 1)
|
|
347
351
|
this.add('into.twice', sites[1].site, { name, first: sites[0].site, second: sites[1].site });
|
|
348
352
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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>" });
|
|
379
|
+
continue;
|
|
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 });
|
|
407
|
+
}
|
|
408
|
+
}
|
|
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);
|
|
352
425
|
continue;
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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' });
|
|
361
452
|
}
|
|
362
453
|
}
|
|
363
|
-
for (const query of
|
|
364
|
-
|
|
365
|
-
this.
|
|
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
|
+
}
|
|
366
458
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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()) {
|
|
370
462
|
if (subscription.history != null && !this.queries.has(subscription.history)) {
|
|
371
463
|
this.add('query.history', `subscriptions.${subscription.key}`, { name: subscription.key, history: subscription.history });
|
|
372
464
|
}
|
|
373
465
|
}
|
|
374
466
|
}
|
|
375
467
|
/** A local's default fits its port: a number for a number, a list for a list, one of its choices. */
|
|
376
|
-
checkLocalDefault(local) {
|
|
468
|
+
checkLocalDefault(nodeId, local) {
|
|
377
469
|
if (local.kind === LOCAL_ANY)
|
|
378
470
|
return;
|
|
379
471
|
if (!valueFitsPort(local.default, local)) {
|
|
380
|
-
this.add('local.default',
|
|
472
|
+
this.add('local.default', nodeId, { name: local.key, default: local.default, kind: local.kind });
|
|
381
473
|
}
|
|
382
474
|
}
|
|
383
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). */
|
|
384
|
-
localPort(path) {
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
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;
|
|
388
479
|
for (const part of rest) {
|
|
389
480
|
if (port === null)
|
|
390
481
|
return null;
|
|
@@ -397,9 +488,9 @@ class Checker {
|
|
|
397
488
|
return port;
|
|
398
489
|
}
|
|
399
490
|
finish() {
|
|
400
|
-
for (const
|
|
401
|
-
if (local.persist && !this.boundLocals.has(
|
|
402
|
-
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 });
|
|
403
494
|
}
|
|
404
495
|
if (this.chromeless !== null && this.kind.roots.includes('task') && !this.asks)
|
|
405
496
|
this.add('chrome.no_ask', this.chromeless);
|
|
@@ -412,7 +503,7 @@ class Checker {
|
|
|
412
503
|
this.walkNode(tree, scope, [], false);
|
|
413
504
|
}
|
|
414
505
|
walkNode(node, scope, ancestors, inError) {
|
|
415
|
-
this.visitComponent(node, ancestors);
|
|
506
|
+
this.visitComponent(node, ancestors, scope);
|
|
416
507
|
const inner = new Map(scope);
|
|
417
508
|
const declared = foreachLet(node);
|
|
418
509
|
if (declared !== null) {
|
|
@@ -425,7 +516,14 @@ class Checker {
|
|
|
425
516
|
this.walkProp(node, prop, propScope, inError);
|
|
426
517
|
}
|
|
427
518
|
const inSlot = inError || (node.component === ERROR_SLOT && ancestors.length > 0 && ancestors[ancestors.length - 1].component === SUSPENSE);
|
|
428
|
-
|
|
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)
|
|
429
527
|
this.walkNode(child, inner, [...ancestors, node], inSlot);
|
|
430
528
|
}
|
|
431
529
|
walkProp(node, prop, scope, inError) {
|
|
@@ -455,7 +553,7 @@ class Checker {
|
|
|
455
553
|
[...(argument.value_list ?? []), ...(argument.value_dict ?? [])].forEach(nested => this.walkArgument(nested, scope, where));
|
|
456
554
|
}
|
|
457
555
|
/* -- components and props -- */
|
|
458
|
-
visitComponent(node, ancestors) {
|
|
556
|
+
visitComponent(node, ancestors, scope) {
|
|
459
557
|
const spec = this.view?.components.get(node.component);
|
|
460
558
|
if (this.view && !spec) {
|
|
461
559
|
const foreign = this.view.foreign.get(node.component);
|
|
@@ -470,14 +568,14 @@ class Checker {
|
|
|
470
568
|
this.checkCatalog(node, spec, ancestors);
|
|
471
569
|
this.checkHostPart(node, ancestors);
|
|
472
570
|
for (const prop of node.props ?? [])
|
|
473
|
-
this.checkProp(node, prop, spec);
|
|
571
|
+
this.checkProp(node, prop, spec, scope);
|
|
474
572
|
}
|
|
475
573
|
checkCatalog(node, spec, ancestors) {
|
|
476
574
|
const view = this.view;
|
|
477
575
|
if (!view)
|
|
478
576
|
return;
|
|
479
577
|
const texts = (node.children ?? []).filter(child => child.component === TEXT_NODE);
|
|
480
|
-
const elements = (node.children ?? []).
|
|
578
|
+
const elements = (node.children ?? []).filter(child => child.component !== TEXT_NODE && !isDeclaration(child)).length;
|
|
481
579
|
if (elements && !spec.acceptsChildren)
|
|
482
580
|
this.add('catalog.children', node.id, { component: node.component });
|
|
483
581
|
if (texts.length) {
|
|
@@ -501,7 +599,7 @@ class Checker {
|
|
|
501
599
|
const missing = spec.props.filter(prop => prop.required && !present.has(prop.key)).map(prop => prop.key).sort();
|
|
502
600
|
if (missing.length)
|
|
503
601
|
this.add('catalog.props', node.id, { component: node.component, detail: `requires props [${missing.map(pythonRepr).join(', ')}]` });
|
|
504
|
-
let context =
|
|
602
|
+
let context = PANEL;
|
|
505
603
|
for (const ancestor of ancestors) {
|
|
506
604
|
const above = view.components.get(ancestor.component);
|
|
507
605
|
if (above && !above.inheritsContext)
|
|
@@ -521,21 +619,18 @@ class Checker {
|
|
|
521
619
|
if (forbidden.length) {
|
|
522
620
|
this.add('catalog.placement', node.id, { component: node.component, detail: `must not be inside [${forbidden.map(pythonRepr).join(', ')}]` });
|
|
523
621
|
}
|
|
524
|
-
if (spec.kinds.length && !spec.kinds.includes(this.
|
|
525
|
-
this.add('catalog.kind', node.id, { component: node.component, kinds: spec.kinds.join(' and '), n: article(this.
|
|
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 });
|
|
526
624
|
}
|
|
527
625
|
}
|
|
528
626
|
/**
|
|
529
627
|
* What the language itself says of the host's parts, whatever catalog draws
|
|
530
|
-
* them: a part placed anywhere claims its slot
|
|
531
|
-
* leaves the asks to
|
|
628
|
+
* them: a part placed anywhere claims its slot (a blok without chrome
|
|
629
|
+
* leaves the asks to itself: `finish`).
|
|
532
630
|
*/
|
|
533
631
|
checkHostPart(node, ancestors) {
|
|
534
632
|
if (node.component === ASK_COMPONENT)
|
|
535
633
|
this.asks = true;
|
|
536
|
-
if (ancestors.length === 0 && (node.props ?? []).some(prop => prop.key === CHROME_PROP && prop.static_value === CHROME_NONE)) {
|
|
537
|
-
this.chromeless = node.id;
|
|
538
|
-
}
|
|
539
634
|
if (this.vocabulary.hostParts.includes(node.component)) {
|
|
540
635
|
const inside = [...ancestors].reverse().find(ancestor => CONDITIONAL_COMPONENTS.has(ancestor.component));
|
|
541
636
|
if (inside)
|
|
@@ -544,19 +639,19 @@ class Checker {
|
|
|
544
639
|
}
|
|
545
640
|
/** A ``Placed dep`` or ``Route through`` names dependencies of the blok, written out as keys. */
|
|
546
641
|
checkDependencyKeys(node, prop) {
|
|
547
|
-
// catalog.kind says it: a Space and its parts belong to an action's own blok.
|
|
548
|
-
if (!RUN_KINDS.includes(this.
|
|
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)
|
|
549
644
|
return;
|
|
550
645
|
const path = `${node.component}.${prop.key}`;
|
|
551
646
|
const value = prop.static_value;
|
|
552
647
|
const keys = typeof value === 'string' ? [value] : Array.isArray(value) ? value.filter((key) => typeof key === 'string') : [];
|
|
553
648
|
for (const key of keys) {
|
|
554
649
|
if (!this.dependencies.has(key)) {
|
|
555
|
-
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);
|
|
556
651
|
}
|
|
557
652
|
}
|
|
558
653
|
}
|
|
559
|
-
checkProp(node, prop, spec) {
|
|
654
|
+
checkProp(node, prop, spec, scope) {
|
|
560
655
|
const { vocabulary } = this;
|
|
561
656
|
const propSpec = spec?.props.find(candidate => candidate.key === prop.key);
|
|
562
657
|
const holds = isCallbackValue(prop);
|
|
@@ -591,17 +686,18 @@ class Checker {
|
|
|
591
686
|
}
|
|
592
687
|
else {
|
|
593
688
|
const root = path.split('.')[0];
|
|
594
|
-
|
|
689
|
+
const binding = scope.get(root);
|
|
690
|
+
if (!isLocalBinding(binding))
|
|
595
691
|
this.add('local.unknown', node.id, { path, root }, prop.key);
|
|
596
692
|
else {
|
|
597
|
-
this.boundLocals.add(
|
|
693
|
+
this.boundLocals.add(binding.node);
|
|
598
694
|
if (propSpec)
|
|
599
|
-
this.checkBindKind(node, propSpec.kind, path);
|
|
695
|
+
this.checkBindKind(node, propSpec.kind, binding, path);
|
|
600
696
|
}
|
|
601
697
|
}
|
|
602
698
|
}
|
|
603
|
-
if (prop.util_call?.operation === START_EFFECT && this.
|
|
604
|
-
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);
|
|
605
701
|
}
|
|
606
702
|
if (DEPENDENCY_KEY_PROPS.has(`${node.component}.${prop.key}`))
|
|
607
703
|
this.checkDependencyKeys(node, prop);
|
|
@@ -613,7 +709,7 @@ class Checker {
|
|
|
613
709
|
if (typeof prop.static_value === 'string') {
|
|
614
710
|
if (prop.key === CLASS_NAME)
|
|
615
711
|
this.checkClasses(prop.static_value, node.id, prop.key);
|
|
616
|
-
if (
|
|
712
|
+
if (this.context === LOGO && vocabulary.theme.logoPaintProps.includes(prop.key))
|
|
617
713
|
this.checkPaint(node, prop.key, prop.static_value);
|
|
618
714
|
if (spec?.context === SCENE && vocabulary.theme.scenePaintProps.includes(prop.key))
|
|
619
715
|
this.checkSceneColour(node, prop.key, prop.static_value);
|
|
@@ -624,9 +720,9 @@ class Checker {
|
|
|
624
720
|
}
|
|
625
721
|
}
|
|
626
722
|
/** The local a control writes is of a kind the control writes (`Slider`: FLOAT or INT). */
|
|
627
|
-
checkBindKind(node, propKind, path) {
|
|
723
|
+
checkBindKind(node, propKind, binding, path) {
|
|
628
724
|
const allowed = this.vocabulary.locals.bindKinds[propKind];
|
|
629
|
-
const port = this.localPort(path);
|
|
725
|
+
const port = this.localPort(binding, path);
|
|
630
726
|
if (!allowed || port === null)
|
|
631
727
|
return;
|
|
632
728
|
if (!allowed.includes(port.kind)) {
|
|
@@ -683,8 +779,8 @@ class Checker {
|
|
|
683
779
|
}
|
|
684
780
|
const dependency = this.dependencies.get(call.dependency);
|
|
685
781
|
if (!dependency) {
|
|
686
|
-
if (call.dependency !== 'self') {
|
|
687
|
-
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);
|
|
688
784
|
}
|
|
689
785
|
return;
|
|
690
786
|
}
|
|
@@ -706,10 +802,10 @@ class Checker {
|
|
|
706
802
|
const match = ports.get(argument.key ?? '');
|
|
707
803
|
if (path == null || !match || match.kind == null)
|
|
708
804
|
continue;
|
|
709
|
-
const
|
|
710
|
-
if (
|
|
805
|
+
const binding = scope.get(path.split('.')[0]);
|
|
806
|
+
if (!isLocalBinding(binding))
|
|
711
807
|
continue;
|
|
712
|
-
const port = this.localPort(path);
|
|
808
|
+
const port = this.localPort(binding, path);
|
|
713
809
|
if (port === null)
|
|
714
810
|
continue;
|
|
715
811
|
const target = { kind: match.kind, identifier: match.identifier ?? null };
|
|
@@ -775,6 +871,11 @@ class Checker {
|
|
|
775
871
|
this.add('query.fetch_more', where.node.id, { path, name }, where.key);
|
|
776
872
|
}
|
|
777
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
|
+
}
|
|
778
879
|
const keyed = (where.node.props ?? []).some(prop => prop.key === FOREACH_KEY);
|
|
779
880
|
const literal = items?.static_value;
|
|
780
881
|
if (!keyed && Array.isArray(literal) && literal.some(item => typeof item === 'object' && item !== null)) {
|
|
@@ -799,6 +900,15 @@ class Checker {
|
|
|
799
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);
|
|
800
901
|
return openMatch(name);
|
|
801
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
|
+
}
|
|
802
912
|
bindInto(call) {
|
|
803
913
|
const dependency = this.dependencies.get(call.dependency);
|
|
804
914
|
const action = actionKeyFor(call);
|
|
@@ -824,15 +934,16 @@ class Checker {
|
|
|
824
934
|
const [root, ...rest] = parts;
|
|
825
935
|
const report = (code, fields) => this.add(code, nodeId, fields, propKey);
|
|
826
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
|
+
}
|
|
827
944
|
if (this.into.has(root))
|
|
828
945
|
this.checkReturns(path, rest, nodeId, propKey);
|
|
829
|
-
return this.descend(
|
|
830
|
-
}
|
|
831
|
-
const local = this.locals.get(root);
|
|
832
|
-
if (local) {
|
|
833
|
-
if (local.kind === LOCAL_ANY || OPAQUE_KINDS.has(local.kind))
|
|
834
|
-
return openMatch(root);
|
|
835
|
-
return this.descend({ ...portMatch(local), key: root }, rest, path, nodeId, propKey);
|
|
946
|
+
return this.descend(binding, rest, path, nodeId, propKey);
|
|
836
947
|
}
|
|
837
948
|
if (root === 'event') {
|
|
838
949
|
if (!where || !where.callback) {
|
|
@@ -871,7 +982,9 @@ class Checker {
|
|
|
871
982
|
}
|
|
872
983
|
const dependency = this.dependencies.get(rest[0]);
|
|
873
984
|
if (!dependency) {
|
|
874
|
-
|
|
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) });
|
|
875
988
|
return null;
|
|
876
989
|
}
|
|
877
990
|
return this.agent(dependency, rest[0], rest.slice(1), path, nodeId, propKey);
|
|
@@ -1090,15 +1203,29 @@ export const checkLogo = (tree, demo) => {
|
|
|
1090
1203
|
return findings;
|
|
1091
1204
|
};
|
|
1092
1205
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
* 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.
|
|
1096
1219
|
*/
|
|
1097
|
-
export const checkBlokTree = (tree, scope, view =
|
|
1098
|
-
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));
|
|
1099
1226
|
checker.checkDeclarations(tree);
|
|
1100
1227
|
checker.walk(tree);
|
|
1101
|
-
if (
|
|
1228
|
+
if (header.context === LOGO)
|
|
1102
1229
|
checker.findings.push(...checkLogo(tree, scope.demo));
|
|
1103
1230
|
checker.finish();
|
|
1104
1231
|
return checker.findings;
|