@unframework.dev/target-angular 0.0.0-stage → 0.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 +426 -2
- package/dist/composable.js +239 -0
- package/dist/composition.js +214 -0
- package/dist/directives.js +82 -0
- package/dist/effects.js +187 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +559 -0
- package/dist/listeners.js +547 -0
- package/dist/members.js +462 -0
- package/dist/models.js +308 -0
- package/dist/modules.js +54 -0
- package/dist/narrowing.js +157 -0
- package/dist/outputs.js +190 -0
- package/dist/plan.js +558 -0
- package/dist/rules.js +332 -0
- package/dist/seeded.js +284 -0
- package/dist/statements.js +213 -0
- package/dist/template.js +243 -0
- package/dist/toolchain/check.js +91 -0
- package/dist/toolchain/client.d.ts +10 -0
- package/dist/toolchain/client.js +79 -0
- package/dist/toolchain/component.js +20 -0
- package/dist/toolchain/index.d.ts +4 -0
- package/dist/toolchain/index.js +15 -0
- package/dist/toolchain/linker.js +57 -0
- package/dist/toolchain/ngtsc-virtual.js +238 -0
- package/dist/toolchain/ngtsc-worker.d.ts +1 -0
- package/dist/toolchain/ngtsc-worker.js +104 -0
- package/dist/toolchain/ngtsc.js +187 -0
- package/dist/toolchain/server.d.ts +8 -0
- package/dist/toolchain/server.js +31 -0
- package/dist/toolchain/tools.js +82 -0
- package/dist/toolchain/vite.js +103 -0
- package/dist/types.js +262 -0
- package/package.json +67 -3
package/dist/plan.js
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
import { assertedSetup } from "./narrowing.js";
|
|
2
|
+
import { outputName } from "./outputs.js";
|
|
3
|
+
import { ImportSet, NameScope, addPassThroughImports, codeKind, codeNames, passThroughImports, sourceNames } from "@unframework.dev/codegen";
|
|
4
|
+
import { summarizeCode, walk } from "@unframework.dev/ir";
|
|
5
|
+
/** The names Angular gives a component class's own members: no binding may take them. */
|
|
6
|
+
const ANGULAR_MEMBERS = [
|
|
7
|
+
"constructor",
|
|
8
|
+
"ngOnInit",
|
|
9
|
+
"ngOnDestroy",
|
|
10
|
+
"ngOnChanges",
|
|
11
|
+
"ngDoCheck"
|
|
12
|
+
];
|
|
13
|
+
/** Every name the output may import from Angular: no local the emitter declares takes one. */
|
|
14
|
+
const ANGULAR_IMPORTS = [
|
|
15
|
+
"Component",
|
|
16
|
+
"AfterRenderRef",
|
|
17
|
+
"ApplicationRef",
|
|
18
|
+
"DestroyRef",
|
|
19
|
+
"Directive",
|
|
20
|
+
"EffectRef",
|
|
21
|
+
"ElementRef",
|
|
22
|
+
"Injector",
|
|
23
|
+
"OnDestroy",
|
|
24
|
+
"OnInit",
|
|
25
|
+
"PLATFORM_ID",
|
|
26
|
+
"Renderer2",
|
|
27
|
+
"Signal",
|
|
28
|
+
"InjectionToken",
|
|
29
|
+
"NgTemplateOutlet",
|
|
30
|
+
"TemplateRef",
|
|
31
|
+
"WritableSignal",
|
|
32
|
+
"afterNextRender",
|
|
33
|
+
"afterRenderEffect",
|
|
34
|
+
"computed",
|
|
35
|
+
"contentChild",
|
|
36
|
+
"effect",
|
|
37
|
+
"inject",
|
|
38
|
+
"input",
|
|
39
|
+
"isPlatformBrowser",
|
|
40
|
+
"isPlatformServer",
|
|
41
|
+
"linkedSignal",
|
|
42
|
+
"model",
|
|
43
|
+
"output",
|
|
44
|
+
"runInInjectionContext",
|
|
45
|
+
"signal",
|
|
46
|
+
"untracked",
|
|
47
|
+
"viewChild"
|
|
48
|
+
];
|
|
49
|
+
/**
|
|
50
|
+
* Plans a component's members: how each binding is declared, and the names in use. The plan's
|
|
51
|
+
* component is the source's, with each setup binding an event shares its name with renamed
|
|
52
|
+
* (`withOutputNames`) and each narrowed member path of the setup asserted (./narrowing.ts).
|
|
53
|
+
*/
|
|
54
|
+
function planComponent(declared, module) {
|
|
55
|
+
const component = assertedSetup(withOutputNames(declared, module));
|
|
56
|
+
const source = sourceNames(component, module);
|
|
57
|
+
const imports = new ImportSet(new NameScope([...source].filter((name) => name !== component.name)));
|
|
58
|
+
addPassThroughImports(component, module, imports);
|
|
59
|
+
const events = new Map(component.emits?.events.map((event) => [event.name, event]) ?? []);
|
|
60
|
+
const memberNames = [
|
|
61
|
+
...ANGULAR_MEMBERS,
|
|
62
|
+
...component.props.map(({ name }) => name),
|
|
63
|
+
...component.bindings.filter(({ kind }) => !isLoopVariable(kind)).map(({ name }) => name),
|
|
64
|
+
...[...events.keys()].map(outputName)
|
|
65
|
+
];
|
|
66
|
+
const members = new NameScope(memberNames);
|
|
67
|
+
const loopNames = new Set(component.bindings.filter(({ kind }) => isLoopVariable(kind)).map(({ name }) => name));
|
|
68
|
+
const composition = new NameScope([
|
|
69
|
+
...memberNames,
|
|
70
|
+
"class",
|
|
71
|
+
"style",
|
|
72
|
+
...component.slots?.slots.map(({ name }) => slotQuery(name)) ?? []
|
|
73
|
+
]);
|
|
74
|
+
const recipes = /* @__PURE__ */ new Map();
|
|
75
|
+
for (const { names } of passThroughImports(component, module)) for (const { local } of names) {
|
|
76
|
+
let member = composition.claim(local);
|
|
77
|
+
while (loopNames.has(member)) member = composition.claim(local);
|
|
78
|
+
members.reserve(member);
|
|
79
|
+
recipes.set(local, member);
|
|
80
|
+
}
|
|
81
|
+
const claimMember = (name) => {
|
|
82
|
+
let member = composition.claim(name);
|
|
83
|
+
while (loopNames.has(member)) member = composition.claim(name);
|
|
84
|
+
members.reserve(member);
|
|
85
|
+
return member;
|
|
86
|
+
};
|
|
87
|
+
const declaredMembers = /* @__PURE__ */ new Set([
|
|
88
|
+
...[...events.keys()].map(outputName),
|
|
89
|
+
"class",
|
|
90
|
+
"style",
|
|
91
|
+
...component.slots?.slots.map(({ name }) => slotQuery(name)) ?? []
|
|
92
|
+
]);
|
|
93
|
+
const moduleMembers = new Map(component.bindings.filter(({ kind, name }) => isModuleBinding(kind) && declaredMembers.has(name)).map(({ id, name, kind }) => [id, claimMember(outputSafeName(name, kind))]));
|
|
94
|
+
const bindingNames = new Set(component.bindings.map(({ name }) => name));
|
|
95
|
+
const { forms, seeded, placements, late } = formsOf(component);
|
|
96
|
+
const calls = component.setup.flatMap((item) => {
|
|
97
|
+
if (item.kind !== "Use") return [];
|
|
98
|
+
const holder = claimMember(holderName(item.composable));
|
|
99
|
+
const injector = item.hasEffects ? claimMember(`${holderName(item.composable)}Injector`) : void 0;
|
|
100
|
+
return [{
|
|
101
|
+
item,
|
|
102
|
+
holder,
|
|
103
|
+
placement: placements.get(item),
|
|
104
|
+
...injector === void 0 ? {} : { injector }
|
|
105
|
+
}];
|
|
106
|
+
});
|
|
107
|
+
const results = new Map(calls.flatMap(({ item, holder }) => item.members.map(({ member, binding }) => [binding, `${holder}.${member}`])));
|
|
108
|
+
return {
|
|
109
|
+
component,
|
|
110
|
+
module,
|
|
111
|
+
imports,
|
|
112
|
+
members,
|
|
113
|
+
locals: new NameScope([
|
|
114
|
+
...[...source].filter((name) => !bindingNames.has(name)),
|
|
115
|
+
...component.bindings.filter(({ kind }) => isModuleBinding(kind)).map(({ name }) => name),
|
|
116
|
+
...ANGULAR_IMPORTS,
|
|
117
|
+
"Object"
|
|
118
|
+
]),
|
|
119
|
+
reserved: (fn) => [
|
|
120
|
+
...codeNames(fn.body.code, codeKind(fn.body, component)),
|
|
121
|
+
...fn.parameters.flatMap((parameter) => parameter.name === void 0 ? parameter.pattern?.names ?? [] : [parameter.name]),
|
|
122
|
+
...ANGULAR_IMPORTS,
|
|
123
|
+
"Object"
|
|
124
|
+
],
|
|
125
|
+
forms,
|
|
126
|
+
seeded,
|
|
127
|
+
events,
|
|
128
|
+
loopNames,
|
|
129
|
+
recipes,
|
|
130
|
+
calls,
|
|
131
|
+
results,
|
|
132
|
+
moduleMembers,
|
|
133
|
+
late
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** A module's constant or a value imported from a `.ts` module (ADR-0070). */
|
|
137
|
+
function isModuleBinding(kind) {
|
|
138
|
+
return kind === "moduleConst" || kind === "import";
|
|
139
|
+
}
|
|
140
|
+
/** The member the template reads a module's value through (ADR-0070). */
|
|
141
|
+
function moduleMember(plan, binding) {
|
|
142
|
+
return plan.moduleMembers.get(binding.id) ?? binding.name;
|
|
143
|
+
}
|
|
144
|
+
/** The member a composable's call is held by: its name without `use`, `toggle` for `useToggle`. */
|
|
145
|
+
function holderName(composable) {
|
|
146
|
+
const name = composable.replace(/^use(?=[A-Z])/, "");
|
|
147
|
+
return `${name.charAt(0).toLowerCase()}${name.slice(1)}`;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The component with each setup binding whose name an event takes renamed (ADR-0047): the class
|
|
151
|
+
* declares a member for both, and the output keeps the event's name, which is the component's API
|
|
152
|
+
* (angular-eslint's `no-output-rename` rules out an alias). The binding is the class's own, so it
|
|
153
|
+
* takes another name: a local function `onSave`, as Angular names a method that handles and emits,
|
|
154
|
+
* a template ref `fieldElement`, any other value `currentPage`. Every read and write of a binding is
|
|
155
|
+
* a reference the rules spell by its binding's name, so the new name reaches each one. A binding
|
|
156
|
+
* named like a member composition declares (the `class` and `style` inputs, a slot's query) is
|
|
157
|
+
* renamed the same way.
|
|
158
|
+
*/
|
|
159
|
+
function withOutputNames(component, module) {
|
|
160
|
+
const events = new Set(component.emits?.events.map(({ name }) => outputName(name)) ?? []);
|
|
161
|
+
const declared = /* @__PURE__ */ new Set([
|
|
162
|
+
"class",
|
|
163
|
+
"style",
|
|
164
|
+
...component.slots?.slots.map(({ name }) => slotQuery(name)) ?? []
|
|
165
|
+
]);
|
|
166
|
+
const clashing = component.bindings.filter(({ name, kind }) => (events.has(name) || declared.has(name)) && kind !== "prop" && kind !== "emit" && !isModuleBinding(kind) && !isLoopVariable(kind));
|
|
167
|
+
if (clashing.length === 0) return component;
|
|
168
|
+
const taken = new NameScope([
|
|
169
|
+
...sourceNames(component, module),
|
|
170
|
+
...events,
|
|
171
|
+
...declared,
|
|
172
|
+
...ANGULAR_MEMBERS,
|
|
173
|
+
...ANGULAR_IMPORTS
|
|
174
|
+
]);
|
|
175
|
+
const renamed = new Map(clashing.map(({ id, name, kind }) => [id, taken.claim(outputSafeName(name, kind))]));
|
|
176
|
+
return {
|
|
177
|
+
...component,
|
|
178
|
+
bindings: component.bindings.map((binding) => {
|
|
179
|
+
const name = renamed.get(binding.id);
|
|
180
|
+
return name === void 0 ? binding : {
|
|
181
|
+
...binding,
|
|
182
|
+
name
|
|
183
|
+
};
|
|
184
|
+
})
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** The member that queries a slot's template, `titleTemplate` (`angularDialect`'s outlet). */
|
|
188
|
+
function slotQuery(slot) {
|
|
189
|
+
return `${slot}Template`;
|
|
190
|
+
}
|
|
191
|
+
/** The name a binding takes beside an event or a declared member of its own name. */
|
|
192
|
+
function outputSafeName(name, kind) {
|
|
193
|
+
const pascal = `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
194
|
+
switch (kind) {
|
|
195
|
+
case "localFn": return `on${pascal}`;
|
|
196
|
+
case "templateRef": return `${name}Element`;
|
|
197
|
+
case "state":
|
|
198
|
+
case "derived":
|
|
199
|
+
case "localConst":
|
|
200
|
+
case "localVar":
|
|
201
|
+
case "prop":
|
|
202
|
+
case "loopVar":
|
|
203
|
+
case "emit":
|
|
204
|
+
case "model":
|
|
205
|
+
case "slots":
|
|
206
|
+
case "slotScope":
|
|
207
|
+
case "context":
|
|
208
|
+
case "component":
|
|
209
|
+
case "moduleConst":
|
|
210
|
+
case "import":
|
|
211
|
+
case "argument":
|
|
212
|
+
case "usedState":
|
|
213
|
+
case "usedDerived":
|
|
214
|
+
case "usedFn":
|
|
215
|
+
case "usedConst": return `current${pascal}`;
|
|
216
|
+
default: return unreachable(kind);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Each binding's form, and the setup `let`s seeded once the inputs are set: setup items in source
|
|
221
|
+
* order, as a later item may read an earlier one.
|
|
222
|
+
*/
|
|
223
|
+
function formsOf(component) {
|
|
224
|
+
const forms = /* @__PURE__ */ new Map();
|
|
225
|
+
const seeded = /* @__PURE__ */ new Set();
|
|
226
|
+
const placements = /* @__PURE__ */ new Map();
|
|
227
|
+
const kinds = new Map(component.bindings.map((binding) => [binding.id, binding.kind]));
|
|
228
|
+
const lazy = /* @__PURE__ */ new Set();
|
|
229
|
+
const readsLazily = (code) => [...summarizeCode(code, component).reads].some((id) => {
|
|
230
|
+
const kind = kinds.get(id);
|
|
231
|
+
return lazy.has(id) || kind !== void 0 && readLazily(kind);
|
|
232
|
+
});
|
|
233
|
+
for (const binding of component.bindings) switch (binding.kind) {
|
|
234
|
+
case "prop":
|
|
235
|
+
forms.set(binding.id, "input");
|
|
236
|
+
lazy.add(binding.id);
|
|
237
|
+
break;
|
|
238
|
+
case "loopVar":
|
|
239
|
+
forms.set(binding.id, "loop");
|
|
240
|
+
break;
|
|
241
|
+
case "emit":
|
|
242
|
+
forms.set(binding.id, "emit");
|
|
243
|
+
break;
|
|
244
|
+
case "state":
|
|
245
|
+
case "derived":
|
|
246
|
+
case "templateRef":
|
|
247
|
+
case "localConst":
|
|
248
|
+
case "localFn":
|
|
249
|
+
case "localVar": break;
|
|
250
|
+
case "slotScope":
|
|
251
|
+
forms.set(binding.id, "loop");
|
|
252
|
+
break;
|
|
253
|
+
case "context":
|
|
254
|
+
forms.set(binding.id, "context");
|
|
255
|
+
break;
|
|
256
|
+
case "component":
|
|
257
|
+
forms.set(binding.id, "component");
|
|
258
|
+
break;
|
|
259
|
+
case "moduleConst":
|
|
260
|
+
case "import":
|
|
261
|
+
forms.set(binding.id, "module");
|
|
262
|
+
break;
|
|
263
|
+
case "usedState":
|
|
264
|
+
case "usedDerived":
|
|
265
|
+
case "usedFn":
|
|
266
|
+
case "usedConst":
|
|
267
|
+
case "model":
|
|
268
|
+
case "slots":
|
|
269
|
+
case "argument": break;
|
|
270
|
+
default: unreachable(binding.kind);
|
|
271
|
+
}
|
|
272
|
+
const instances = componentRefs(component);
|
|
273
|
+
const escaping = escapingFunctions(component);
|
|
274
|
+
let constructs = false;
|
|
275
|
+
let watches = false;
|
|
276
|
+
let defers = false;
|
|
277
|
+
const late = /* @__PURE__ */ new Set();
|
|
278
|
+
for (const item of component.setup) switch (item.kind) {
|
|
279
|
+
case "State": {
|
|
280
|
+
const linked = item.initial !== void 0 && readsLazily(item.initial);
|
|
281
|
+
forms.set(item.binding, linked ? "linked" : "signal");
|
|
282
|
+
if (linked) lazy.add(item.binding);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case "Derived":
|
|
286
|
+
forms.set(item.binding, "computed");
|
|
287
|
+
break;
|
|
288
|
+
case "TemplateRef":
|
|
289
|
+
forms.set(item.binding, instances.has(item.binding) ? "instance" : "query");
|
|
290
|
+
break;
|
|
291
|
+
case "Model":
|
|
292
|
+
forms.set(item.binding, "model");
|
|
293
|
+
break;
|
|
294
|
+
case "Id":
|
|
295
|
+
forms.set(item.binding, "value");
|
|
296
|
+
break;
|
|
297
|
+
case "Const": {
|
|
298
|
+
const once = readsLazily(item.value);
|
|
299
|
+
forms.set(item.binding, once ? "once" : "value");
|
|
300
|
+
if (once) lazy.add(item.binding);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
case "Variable":
|
|
304
|
+
forms.set(item.binding, "field");
|
|
305
|
+
if (item.initial !== void 0 && readsLazily(item.initial)) {
|
|
306
|
+
seeded.add(item.binding);
|
|
307
|
+
lazy.add(item.binding);
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
case "Function":
|
|
311
|
+
forms.set(item.binding, escaping.has(item.binding) ? "arrow" : "method");
|
|
312
|
+
break;
|
|
313
|
+
case "WatchEffect":
|
|
314
|
+
if (defers) late.add(item);
|
|
315
|
+
else constructs = true;
|
|
316
|
+
break;
|
|
317
|
+
case "Lifecycle":
|
|
318
|
+
if (item.hook !== "mounted") break;
|
|
319
|
+
if (defers) late.add(item);
|
|
320
|
+
else constructs = true;
|
|
321
|
+
break;
|
|
322
|
+
case "Watch":
|
|
323
|
+
watches = true;
|
|
324
|
+
break;
|
|
325
|
+
case "Provide":
|
|
326
|
+
case "Inject": break;
|
|
327
|
+
case "Use": {
|
|
328
|
+
const placement = item.arguments.flatMap((argument) => {
|
|
329
|
+
switch (argument.kind) {
|
|
330
|
+
case "Value": return [argument.value];
|
|
331
|
+
case "Getter": return [argument.getter.body];
|
|
332
|
+
case "Callback": return [];
|
|
333
|
+
default: return unreachable(argument);
|
|
334
|
+
}
|
|
335
|
+
}).some(readsLazily) || item.hasEffects && (watches || defers) ? "init" : item.hasEffects && constructs ? "constructor" : "field";
|
|
336
|
+
placements.set(item, placement);
|
|
337
|
+
if (placement === "constructor") constructs = true;
|
|
338
|
+
if (placement === "init" && item.hasEffects) defers = true;
|
|
339
|
+
for (const { binding } of item.members) {
|
|
340
|
+
const kind = kinds.get(binding);
|
|
341
|
+
forms.set(binding, kind === "usedState" || kind === "usedDerived" ? "result" : "resultValue");
|
|
342
|
+
if (placement === "constructor" || placement === "init" || kind === "usedDerived") lazy.add(binding);
|
|
343
|
+
}
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
default: unreachable(item);
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
forms,
|
|
350
|
+
seeded,
|
|
351
|
+
placements,
|
|
352
|
+
late
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/** The template refs a `ref` on a component holds, which hold its instance (ADR-0054). */
|
|
356
|
+
function componentRefs(component) {
|
|
357
|
+
const found = /* @__PURE__ */ new Set();
|
|
358
|
+
walk(component.render, { enter(node) {
|
|
359
|
+
if (node.kind !== "Component" && node.kind !== "Dynamic") return;
|
|
360
|
+
for (const attribute of node.attributes) if (attribute.kind === "Ref") found.add(attribute.binding);
|
|
361
|
+
} });
|
|
362
|
+
return found;
|
|
363
|
+
}
|
|
364
|
+
/** The local functions code passes as a value (`setTimeout(tick, 100)`), which run later. */
|
|
365
|
+
function escapingFunctions(component) {
|
|
366
|
+
const escaping = /* @__PURE__ */ new Set();
|
|
367
|
+
const functions = new Set(component.bindings.filter(({ kind }) => isFunction(kind)).map(({ id }) => id));
|
|
368
|
+
const visit = (code) => {
|
|
369
|
+
for (const reference of code.refs) if (reference.kind === "Binding" && !reference.call && functions.has(reference.binding)) escaping.add(reference.binding);
|
|
370
|
+
};
|
|
371
|
+
for (const item of component.setup) switch (item.kind) {
|
|
372
|
+
case "State":
|
|
373
|
+
case "Variable":
|
|
374
|
+
if (item.initial) visit(item.initial);
|
|
375
|
+
break;
|
|
376
|
+
case "Const":
|
|
377
|
+
visit(item.value);
|
|
378
|
+
break;
|
|
379
|
+
case "Derived":
|
|
380
|
+
visit(item.getter.body);
|
|
381
|
+
break;
|
|
382
|
+
case "Function":
|
|
383
|
+
visit(item.function.body);
|
|
384
|
+
break;
|
|
385
|
+
case "Watch":
|
|
386
|
+
for (const source of item.sources) if (source.kind === "Getter") visit(source.getter.body);
|
|
387
|
+
visit(item.callback.body);
|
|
388
|
+
break;
|
|
389
|
+
case "WatchEffect":
|
|
390
|
+
visit(item.effect.body);
|
|
391
|
+
break;
|
|
392
|
+
case "Lifecycle":
|
|
393
|
+
visit(item.callback.body);
|
|
394
|
+
break;
|
|
395
|
+
case "Provide":
|
|
396
|
+
visit(item.value);
|
|
397
|
+
break;
|
|
398
|
+
case "Inject":
|
|
399
|
+
if (item.fallback) visit(item.fallback);
|
|
400
|
+
break;
|
|
401
|
+
case "Use":
|
|
402
|
+
for (const argument of item.arguments) if (argument.kind === "Value") visit(argument.value);
|
|
403
|
+
else visit((argument.kind === "Getter" ? argument.getter : argument.callback).body);
|
|
404
|
+
break;
|
|
405
|
+
case "TemplateRef":
|
|
406
|
+
case "Id":
|
|
407
|
+
case "Model": break;
|
|
408
|
+
default: unreachable(item);
|
|
409
|
+
}
|
|
410
|
+
return escaping;
|
|
411
|
+
}
|
|
412
|
+
/** Whether a binding is a list's item or index, which the `@for` declares: no member. */
|
|
413
|
+
function isLoopVariable(kind) {
|
|
414
|
+
switch (kind) {
|
|
415
|
+
case "loopVar": return true;
|
|
416
|
+
case "prop":
|
|
417
|
+
case "state":
|
|
418
|
+
case "derived":
|
|
419
|
+
case "templateRef":
|
|
420
|
+
case "localConst":
|
|
421
|
+
case "localFn":
|
|
422
|
+
case "localVar":
|
|
423
|
+
case "emit":
|
|
424
|
+
case "model":
|
|
425
|
+
case "slots":
|
|
426
|
+
case "slotScope":
|
|
427
|
+
case "context":
|
|
428
|
+
case "component":
|
|
429
|
+
case "moduleConst":
|
|
430
|
+
case "import":
|
|
431
|
+
case "argument":
|
|
432
|
+
case "usedState":
|
|
433
|
+
case "usedDerived":
|
|
434
|
+
case "usedFn":
|
|
435
|
+
case "usedConst": return false;
|
|
436
|
+
default: return unreachable(kind);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/** Whether a binding is a local function. */
|
|
440
|
+
function isFunction(kind) {
|
|
441
|
+
switch (kind) {
|
|
442
|
+
case "localFn": return true;
|
|
443
|
+
case "prop":
|
|
444
|
+
case "loopVar":
|
|
445
|
+
case "state":
|
|
446
|
+
case "derived":
|
|
447
|
+
case "templateRef":
|
|
448
|
+
case "localConst":
|
|
449
|
+
case "localVar":
|
|
450
|
+
case "emit":
|
|
451
|
+
case "model":
|
|
452
|
+
case "slots":
|
|
453
|
+
case "slotScope":
|
|
454
|
+
case "context":
|
|
455
|
+
case "component":
|
|
456
|
+
case "moduleConst":
|
|
457
|
+
case "import":
|
|
458
|
+
case "argument":
|
|
459
|
+
case "usedState":
|
|
460
|
+
case "usedDerived":
|
|
461
|
+
case "usedFn":
|
|
462
|
+
case "usedConst": return false;
|
|
463
|
+
default: return unreachable(kind);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Whether a binding of this kind is read lazily whatever its item: an input (unset while the
|
|
468
|
+
* class constructs) or a derived value (a `computed` that may read one). A state or a constant
|
|
469
|
+
* is lazy when its own value reads one (`formsOf`).
|
|
470
|
+
*/
|
|
471
|
+
function readLazily(kind) {
|
|
472
|
+
switch (kind) {
|
|
473
|
+
case "prop":
|
|
474
|
+
case "model":
|
|
475
|
+
case "derived":
|
|
476
|
+
case "context": return true;
|
|
477
|
+
case "loopVar":
|
|
478
|
+
case "state":
|
|
479
|
+
case "templateRef":
|
|
480
|
+
case "localConst":
|
|
481
|
+
case "localFn":
|
|
482
|
+
case "localVar":
|
|
483
|
+
case "emit":
|
|
484
|
+
case "slots":
|
|
485
|
+
case "slotScope":
|
|
486
|
+
case "component":
|
|
487
|
+
case "moduleConst":
|
|
488
|
+
case "import":
|
|
489
|
+
case "argument":
|
|
490
|
+
case "usedState":
|
|
491
|
+
case "usedDerived":
|
|
492
|
+
case "usedFn":
|
|
493
|
+
case "usedConst": return false;
|
|
494
|
+
default: return unreachable(kind);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/** The binding a component declares under `id`. */
|
|
498
|
+
function bindingById(plan, id) {
|
|
499
|
+
const binding = plan.component.bindings.find((each) => each.id === id);
|
|
500
|
+
if (!binding) throw new Error(`Component ${plan.component.name} declares no binding ${id}.`);
|
|
501
|
+
return binding;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* The member a class reads a binding through: its own, or for a composable's result the holder's
|
|
505
|
+
* member (`toggle_1.on`).
|
|
506
|
+
*/
|
|
507
|
+
function memberOf(plan, binding) {
|
|
508
|
+
return plan.results.get(binding.id) ?? binding.name;
|
|
509
|
+
}
|
|
510
|
+
/** What a composable's API says of a member a `Use` item destructures (ADR-0069). */
|
|
511
|
+
function resultApi(plan, id) {
|
|
512
|
+
for (const { item } of plan.calls) {
|
|
513
|
+
const used = item.members.find(({ binding }) => binding === id);
|
|
514
|
+
if (used === void 0) continue;
|
|
515
|
+
for (const entry of plan.module.imports ?? []) {
|
|
516
|
+
const name = entry.names.find((each) => each.kind === "Composable" && each.local === item.composable);
|
|
517
|
+
const member = (name && entry.api.composables?.find((each) => each.name === name.imported))?.members.find((each) => each.name === used.member);
|
|
518
|
+
if (member) return member;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
throw new Error(`No composable's API declares the member ${id} reads.`);
|
|
522
|
+
}
|
|
523
|
+
/** A binding's form. */
|
|
524
|
+
function formOf(plan, binding) {
|
|
525
|
+
const form = plan.forms.get(binding.id);
|
|
526
|
+
if (form === void 0) throw new Error(`No form for the binding ${binding.id}.`);
|
|
527
|
+
return form;
|
|
528
|
+
}
|
|
529
|
+
/** Whether a form is a signal, read by calling it. */
|
|
530
|
+
function isSignal(form) {
|
|
531
|
+
switch (form) {
|
|
532
|
+
case "input":
|
|
533
|
+
case "signal":
|
|
534
|
+
case "linked":
|
|
535
|
+
case "computed":
|
|
536
|
+
case "once": return true;
|
|
537
|
+
case "value":
|
|
538
|
+
case "query":
|
|
539
|
+
case "method":
|
|
540
|
+
case "arrow":
|
|
541
|
+
case "field":
|
|
542
|
+
case "loop":
|
|
543
|
+
case "emit":
|
|
544
|
+
case "instance":
|
|
545
|
+
case "component":
|
|
546
|
+
case "module":
|
|
547
|
+
case "resultValue": return false;
|
|
548
|
+
case "model":
|
|
549
|
+
case "context":
|
|
550
|
+
case "result": return true;
|
|
551
|
+
default: return unreachable(form);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
/** The `never` default of an exhaustive switch: a kind added to a union fails type checking. */
|
|
555
|
+
function unreachable(value) {
|
|
556
|
+
throw new Error(`Unexpected value: ${JSON.stringify(value)}`);
|
|
557
|
+
}
|
|
558
|
+
export { ANGULAR_IMPORTS, ANGULAR_MEMBERS, bindingById, formOf, isLoopVariable, isSignal, memberOf, moduleMember, planComponent, resultApi, slotQuery, unreachable };
|