@tsplc/compiler 0.5.13 → 0.5.15
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 +33 -8
- package/dist/cli.js +794 -621
- package/dist/cli.js.map +19 -16
- package/dist/clock.js +5 -2
- package/dist/clock.js.map +5 -4
- package/dist/codesys.js +4162 -4157
- package/dist/codesys.js.map +43 -29
- package/dist/index.js +7852 -6549
- package/dist/index.js.map +53 -50
- package/dist/ir.js +2482 -2277
- package/dist/ir.js.map +28 -25
- package/dist/retain.js +3 -1
- package/dist/retain.js.map +3 -3
- package/dist/signals.js +115 -0
- package/dist/signals.js.map +10 -0
- package/dist/telemetry.js +25 -20
- package/dist/telemetry.js.map +6 -6
- package/package.json +19 -39
- package/src/codesys/config.ts +3 -3
- package/src/codesys/debug.ts +92 -108
- package/src/codesys/emit.ts +100 -88
- package/src/codesys/endpoints.ts +111 -0
- package/src/codesys/engineering.ts +30 -54
- package/src/codesys/explain/expressions.ts +445 -0
- package/src/codesys/explain/flags.ts +134 -0
- package/src/codesys/explain/parameters.ts +53 -0
- package/src/codesys/explain/rows.ts +182 -0
- package/src/codesys/explain/tables.ts +79 -0
- package/src/codesys/explain/tasks.ts +68 -0
- package/src/codesys/explain/writes.ts +497 -0
- package/src/codesys/explain.ts +85 -1401
- package/src/codesys/expressions.ts +41 -33
- package/src/codesys/global-lists.ts +114 -94
- package/src/codesys/global-names.ts +12 -14
- package/src/codesys/http.ts +428 -388
- package/src/codesys/instrumentation.ts +142 -148
- package/src/codesys/io-paths.ts +31 -23
- package/src/codesys/loops.ts +101 -0
- package/src/codesys/manifest.ts +269 -269
- package/src/codesys/names.ts +10 -33
- package/src/codesys/numeric.ts +89 -42
- package/src/codesys/plan.ts +202 -190
- package/src/codesys/programs.ts +23 -16
- package/src/codesys/publication.ts +13 -86
- package/src/codesys/required.ts +8 -0
- package/src/codesys/routines.ts +103 -489
- package/src/codesys/scheduling.ts +96 -0
- package/src/codesys/service-channels.ts +23 -0
- package/src/codesys/sources.ts +34 -28
- package/src/codesys/st-files.ts +112 -105
- package/src/codesys/statements.ts +409 -0
- package/src/codesys/storage.ts +41 -23
- package/src/codesys/symbols.ts +130 -119
- package/src/codesys/task-access.ts +65 -221
- package/src/codesys/telemetry-settings.ts +19 -0
- package/src/codesys/telemetry.ts +185 -148
- package/src/codesys/types.ts +69 -109
- package/src/codesys/vendor.ts +13 -50
- package/src/frontend/analyzer.ts +66 -111
- package/src/frontend/async.ts +316 -128
- package/src/frontend/blocks.ts +178 -154
- package/src/frontend/configuration.ts +49 -153
- package/src/frontend/const-functions.ts +50 -40
- package/src/frontend/control-flow.ts +164 -129
- package/src/frontend/cooperative.ts +17 -9
- package/src/frontend/coroutines.ts +539 -441
- package/src/frontend/dialect-names.ts +104 -0
- package/src/frontend/elaborate/array-searches.ts +77 -69
- package/src/frontend/elaborate/assignments.ts +68 -77
- package/src/frontend/elaborate/calls.ts +878 -512
- package/src/frontend/elaborate/capture-protocol.ts +118 -21
- package/src/frontend/elaborate/capture.ts +196 -109
- package/src/frontend/elaborate/declarations.ts +124 -0
- package/src/frontend/elaborate/dialect.ts +119 -46
- package/src/frontend/elaborate/expressions.ts +763 -442
- package/src/frontend/elaborate/filtered-arrays.ts +127 -91
- package/src/frontend/elaborate/frame.ts +50 -2
- package/src/frontend/elaborate/generics.ts +20 -34
- package/src/frontend/elaborate/graph.ts +13 -87
- package/src/frontend/elaborate/imports.ts +0 -5
- package/src/frontend/elaborate/index.ts +416 -169
- package/src/frontend/elaborate/initializers.ts +64 -42
- package/src/frontend/elaborate/iterators.ts +228 -364
- package/src/frontend/elaborate/layouts.ts +477 -116
- package/src/frontend/elaborate/model.ts +113 -55
- package/src/frontend/elaborate/references.ts +116 -138
- package/src/frontend/elaborate/retention.ts +137 -59
- package/src/frontend/elaborate/specialize.ts +617 -308
- package/src/frontend/elaborate/statements.ts +436 -247
- package/src/frontend/elaborate/storage.ts +280 -213
- package/src/frontend/elaborate/time-constructors.ts +34 -0
- package/src/frontend/elaborate/values.ts +77 -7
- package/src/frontend/elaborate/writes.ts +98 -84
- package/src/frontend/expressions.ts +149 -151
- package/src/frontend/generated-names.ts +3 -3
- package/src/frontend/intrinsics.ts +31 -17
- package/src/frontend/lowering-key.ts +23 -0
- package/src/frontend/module-graph.ts +105 -43
- package/src/frontend/positions.ts +43 -35
- package/src/frontend/promise-chains.ts +226 -266
- package/src/frontend/promises.ts +88 -67
- package/src/frontend/routines.ts +122 -65
- package/src/frontend/sdk.ts +104 -5
- package/src/frontend/services.ts +149 -102
- package/src/frontend/statements.ts +60 -64
- package/src/frontend/tasks.ts +151 -96
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +366 -181
- package/src/frontend/typescript.ts +239 -112
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +90 -75
- package/src/ir/allocation.ts +29 -18
- package/src/ir/conditions.ts +38 -78
- package/src/ir/core-model.ts +128 -11
- package/src/ir/declarations.ts +18 -32
- package/src/ir/diagnostics.ts +25 -18
- package/src/ir/domains.ts +26 -23
- package/src/ir/fold.ts +55 -50
- package/src/ir/identity.ts +10 -0
- package/src/ir/index.ts +31 -7
- package/src/ir/job-errors.ts +30 -8
- package/src/ir/layouts.ts +63 -34
- package/src/ir/link.ts +11 -46
- package/src/ir/model.ts +25 -6
- package/src/ir/normalize.ts +3 -28
- package/src/ir/numeric.ts +45 -18
- package/src/ir/operands.ts +102 -0
- package/src/ir/ranges.ts +242 -67
- package/src/ir/routine.ts +126 -183
- package/src/ir/scalars.ts +29 -25
- package/src/ir/share.ts +323 -343
- package/src/ir/short-circuit.ts +140 -0
- package/src/ir/tables.ts +111 -0
- package/src/ir/temporaries.ts +15 -113
- package/src/ir/types.ts +32 -8
- package/src/project/artifacts.ts +143 -71
- package/src/project/cli.ts +104 -87
- package/src/project/debugger.ts +48 -34
- package/src/project/deployments.ts +12 -68
- package/src/project/flags.ts +14 -0
- package/src/project/plant.ts +293 -225
- package/src/project/project-commands.ts +254 -192
- package/src/project/project.ts +184 -141
- package/src/project/release.ts +22 -28
- package/src/project/server.ts +22 -26
- package/src/project/terminal.ts +13 -2
- package/src/runtime/async.ts +17 -13
- package/src/runtime/launch.ts +5 -2
- package/src/runtime/main.ts +8 -3
- package/src/runtime/missing-file.ts +3 -0
- package/src/runtime/process.ts +24 -19
- package/src/runtime/program.ts +20 -53
- package/src/runtime/retain.ts +18 -10
- package/src/runtime/runtime.ts +47 -60
- package/src/runtime/settings.ts +27 -0
- package/src/runtime/storage.ts +49 -74
- package/src/runtime/symbols.ts +19 -75
- package/src/runtime/telemetry.ts +37 -14
- package/src/runtime/transport.ts +26 -30
- package/stdlib/clock.ts +4 -2
- package/stdlib/plc-time.ts +2 -0
- package/stdlib/retain.ts +2 -0
- package/stdlib/signals.ts +142 -0
- package/stdlib/telemetry.ts +5 -12
- package/types/dialect.d.ts +49 -0
- package/types/globals.d.ts +2 -42
- package/types/index.d.ts +3 -1
- package/types/retain.d.ts +8 -2
- package/types/telemetry.d.ts +3 -0
- package/dist/bun-runtime.js +0 -1472
- package/dist/bun-runtime.js.map +0 -26
- package/dist/elaborate-capture.js +0 -304
- package/dist/elaborate-capture.js.map +0 -11
- package/dist/math.js +0 -24
- package/dist/math.js.map +0 -10
- package/dist/project.js +0 -626
- package/dist/project.js.map +0 -12
- package/dist/server-check.js +0 -59
- package/dist/server-check.js.map +0 -11
- package/src/frontend/exposure.ts +0 -181
- package/src/project/index.ts +0 -6
- package/src/runtime/.runtime-65O4JH/server/router.ts +0 -17
- package/src/runtime/.runtime-65O4JH/src/cell.ts +0 -45
- package/src/runtime/.runtime-65O4JH/src/controller.ts +0 -58
- package/src/runtime/.runtime-65O4JH/src/lane.ts +0 -6
- package/src/runtime/.runtime-65O4JH/src/main.ts +0 -11
- package/src/runtime/.runtime-65O4JH/src/services.ts +0 -8
- package/src/runtime/.runtime-65O4JH/tsconfig.json +0 -13
- package/src/runtime/.runtime-65O4JH/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-Brw2kO/server/router.ts +0 -17
- package/src/runtime/.runtime-Brw2kO/src/cell.ts +0 -45
- package/src/runtime/.runtime-Brw2kO/src/controller.ts +0 -58
- package/src/runtime/.runtime-Brw2kO/src/lane.ts +0 -6
- package/src/runtime/.runtime-Brw2kO/src/main.ts +0 -11
- package/src/runtime/.runtime-Brw2kO/src/services.ts +0 -8
- package/src/runtime/.runtime-Brw2kO/tsconfig.json +0 -13
- package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-NHfu1D/server/router.ts +0 -17
- package/src/runtime/.runtime-NHfu1D/src/cell.ts +0 -45
- package/src/runtime/.runtime-NHfu1D/src/controller.ts +0 -58
- package/src/runtime/.runtime-NHfu1D/src/lane.ts +0 -6
- package/src/runtime/.runtime-NHfu1D/src/main.ts +0 -11
- package/src/runtime/.runtime-NHfu1D/src/services.ts +0 -8
- package/src/runtime/.runtime-NHfu1D/tsconfig.json +0 -13
- package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-VaUSOu/server/router.ts +0 -17
- package/src/runtime/.runtime-VaUSOu/src/cell.ts +0 -45
- package/src/runtime/.runtime-VaUSOu/src/controller.ts +0 -58
- package/src/runtime/.runtime-VaUSOu/src/lane.ts +0 -6
- package/src/runtime/.runtime-VaUSOu/src/main.ts +0 -11
- package/src/runtime/.runtime-VaUSOu/src/services.ts +0 -8
- package/src/runtime/.runtime-VaUSOu/tsconfig.json +0 -13
- package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-WbtNvR/server/router.ts +0 -17
- package/src/runtime/.runtime-WbtNvR/src/cell.ts +0 -45
- package/src/runtime/.runtime-WbtNvR/src/controller.ts +0 -58
- package/src/runtime/.runtime-WbtNvR/src/lane.ts +0 -6
- package/src/runtime/.runtime-WbtNvR/src/main.ts +0 -11
- package/src/runtime/.runtime-WbtNvR/src/services.ts +0 -8
- package/src/runtime/.runtime-WbtNvR/tsconfig.json +0 -13
- package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-ybIxYh/server/router.ts +0 -17
- package/src/runtime/.runtime-ybIxYh/src/cell.ts +0 -45
- package/src/runtime/.runtime-ybIxYh/src/controller.ts +0 -58
- package/src/runtime/.runtime-ybIxYh/src/lane.ts +0 -6
- package/src/runtime/.runtime-ybIxYh/src/main.ts +0 -11
- package/src/runtime/.runtime-ybIxYh/src/services.ts +0 -8
- package/src/runtime/.runtime-ybIxYh/tsconfig.json +0 -13
- package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +0 -31
- package/stdlib/math.ts +0 -23
- package/types/plc.d.ts +0 -4
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
1
|
import { identityDigest } from "@tsplc/compiler/ir";
|
|
3
2
|
import ts from "typescript";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { modulePath } from "../lowering-key";
|
|
4
|
+
import {
|
|
5
|
+
boundNames,
|
|
6
|
+
type CapturedGraph,
|
|
7
|
+
type CapturedNode,
|
|
8
|
+
type CapturedValue,
|
|
8
9
|
} from "./capture-protocol";
|
|
9
10
|
|
|
10
11
|
/** One step from an owner to the object it holds. */
|
|
@@ -20,16 +21,34 @@ export interface Owner {
|
|
|
20
21
|
|
|
21
22
|
/** The TypeScript path of an owned object or field, as the program names it: `program.diverters.sampleCounters[10]`. */
|
|
22
23
|
export const tsPath = (owner: Owner): string =>
|
|
23
|
-
owner.root.name + owner.steps.map(stepPath).join("");
|
|
24
|
+
owner.root.name + owner.steps.map((step) => stepPath(step, String)).join("");
|
|
24
25
|
|
|
25
|
-
/** One step of a
|
|
26
|
-
const stepPath = (step: Step): string => {
|
|
26
|
+
/** One step of a path: an index, a numeric key in brackets as `key` spells it, or a field. */
|
|
27
|
+
export const stepPath = (step: Step, key: (name: string) => string): string => {
|
|
27
28
|
if (step.kind === "index") {
|
|
28
29
|
return `[${step.index}]`;
|
|
29
30
|
}
|
|
30
|
-
return /^\d+$/.test(step.name) ? `[${step.name}]` : `.${step.name}`;
|
|
31
|
+
return /^\d+$/.test(step.name) ? `[${key(step.name)}]` : `.${step.name}`;
|
|
31
32
|
};
|
|
32
33
|
|
|
34
|
+
/** Where `holder`, owned at `owner`, puts what it holds at `step`. */
|
|
35
|
+
export const ownerAt = (owner: Owner, step: Step): Owner => ({
|
|
36
|
+
root: owner.root,
|
|
37
|
+
steps: [...owner.steps, step],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const sameStep = (left: Step, right: Step): boolean =>
|
|
41
|
+
left.kind === "index"
|
|
42
|
+
? right.kind === "index" && left.index === right.index
|
|
43
|
+
: right.kind === "field" && left.name === right.name;
|
|
44
|
+
|
|
45
|
+
/** The members of a union, or the type itself. */
|
|
46
|
+
export const unionMembers = (type: ts.Type): readonly ts.Type[] =>
|
|
47
|
+
type.isUnion() ? type.types : [type];
|
|
48
|
+
|
|
49
|
+
export const isExported = (declaration: ts.Declaration): boolean =>
|
|
50
|
+
Boolean(ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export);
|
|
51
|
+
|
|
33
52
|
/** Each step from a captured object to what it holds, with the value there. */
|
|
34
53
|
export const children = (captured: CapturedNode): [Step, CapturedValue][] => {
|
|
35
54
|
if (captured.kind === "array") {
|
|
@@ -68,7 +87,13 @@ export interface Root {
|
|
|
68
87
|
name: string;
|
|
69
88
|
/** The variable, or the element of a destructuring declaration, that names the root. */
|
|
70
89
|
declaration: ts.VariableDeclaration | ts.BindingElement;
|
|
90
|
+
/**
|
|
91
|
+
* Whether something outside the program addresses it: an export the hardware, HMI and server
|
|
92
|
+
* read, or a binding the config's `io` reaches. Every field of such a root is stored.
|
|
93
|
+
*/
|
|
71
94
|
exported: boolean;
|
|
95
|
+
/** Whether the config's `io` reaches it, so the hardware may write any field of it. */
|
|
96
|
+
bound: boolean;
|
|
72
97
|
/** What setup bound it to. */
|
|
73
98
|
value: CapturedValue;
|
|
74
99
|
}
|
|
@@ -91,6 +116,8 @@ export interface ModelNode {
|
|
|
91
116
|
export class Model {
|
|
92
117
|
readonly nodes: ModelNode[];
|
|
93
118
|
readonly roots: Root[] = [];
|
|
119
|
+
/** The paths the hardware writes every scan, with the input address of each. */
|
|
120
|
+
readonly inputs: ReadonlyMap<string, string>;
|
|
94
121
|
private readonly projectRoot: string;
|
|
95
122
|
|
|
96
123
|
constructor(
|
|
@@ -99,7 +126,17 @@ export class Model {
|
|
|
99
126
|
readonly program: ts.Program,
|
|
100
127
|
entry: string,
|
|
101
128
|
projectRoot: string,
|
|
129
|
+
{
|
|
130
|
+
bound,
|
|
131
|
+
inputs,
|
|
132
|
+
}: {
|
|
133
|
+
/** The bindings the config's `io` reaches state through. */
|
|
134
|
+
bound: ReadonlySet<string>;
|
|
135
|
+
/** The paths the config's `io` binds to inputs, with each input's address. */
|
|
136
|
+
inputs: ReadonlyMap<string, string>;
|
|
137
|
+
},
|
|
102
138
|
) {
|
|
139
|
+
this.inputs = inputs;
|
|
103
140
|
this.nodes = graph.nodes.map((captured, id) => ({
|
|
104
141
|
id,
|
|
105
142
|
reference: id,
|
|
@@ -116,9 +153,8 @@ export class Model {
|
|
|
116
153
|
file: binding.file,
|
|
117
154
|
name: binding.name,
|
|
118
155
|
declaration,
|
|
119
|
-
exported:
|
|
120
|
-
|
|
121
|
-
),
|
|
156
|
+
exported: isExported(declaration) || bound.has(binding.name),
|
|
157
|
+
bound: bound.has(binding.name),
|
|
122
158
|
value: binding.value,
|
|
123
159
|
};
|
|
124
160
|
this.roots.push(root);
|
|
@@ -137,29 +173,52 @@ export class Model {
|
|
|
137
173
|
* module and its path from there. Undefined for an object no root owns.
|
|
138
174
|
*/
|
|
139
175
|
identity(node: ModelNode): string | undefined {
|
|
176
|
+
return node.owner && this.ownerIdentity(node.owner);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private ownerIdentity(owner: Owner): string {
|
|
180
|
+
return `${modulePath(this.projectRoot, owner.root.file)}:${tsPath(owner)}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Whether `node` is owned exactly at `owner`, rather than only held there. */
|
|
184
|
+
ownsAt(node: ModelNode, owner: Owner): boolean {
|
|
185
|
+
const own = node.owner;
|
|
186
|
+
return (
|
|
187
|
+
own !== undefined &&
|
|
188
|
+
own.root === owner.root &&
|
|
189
|
+
own.steps.length === owner.steps.length &&
|
|
190
|
+
own.steps.every((step, index) => {
|
|
191
|
+
const other = owner.steps[index];
|
|
192
|
+
return other !== undefined && sameStep(step, other);
|
|
193
|
+
})
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** What setup left in a record's or instance's field: undefined when it set none. */
|
|
198
|
+
field(holder: ModelNode, name: string): CapturedValue {
|
|
140
199
|
return (
|
|
141
|
-
|
|
142
|
-
`${relative(this.projectRoot, node.owner.root.file).replace(/\\/g, "/")}:${tsPath(node.owner)}`
|
|
200
|
+
child(holder.captured, { kind: "field", name }) ?? { kind: "undefined" }
|
|
143
201
|
);
|
|
144
202
|
}
|
|
145
203
|
|
|
146
204
|
/** Gives each object setup put somewhere its reference id, from its identity. */
|
|
147
205
|
private assignReferences(): void {
|
|
148
|
-
const taken = new Map<number,
|
|
206
|
+
const taken = new Map<number, Owner>();
|
|
149
207
|
for (const node of this.nodes) {
|
|
150
|
-
const
|
|
151
|
-
if (!
|
|
208
|
+
const owner = node.owner;
|
|
209
|
+
if (!owner) {
|
|
152
210
|
continue;
|
|
153
211
|
}
|
|
154
212
|
const reference =
|
|
155
|
-
Number.parseInt(identityDigest(
|
|
213
|
+
Number.parseInt(identityDigest(this.ownerIdentity(owner)), 16) &
|
|
214
|
+
0x7fffffff;
|
|
156
215
|
const other = taken.get(reference);
|
|
157
|
-
if (other
|
|
216
|
+
if (other) {
|
|
158
217
|
throw new Error(
|
|
159
|
-
`${tsPath(other
|
|
218
|
+
`${tsPath(other)} and ${tsPath(owner)} would hold the same reference id; rename one of them.`,
|
|
160
219
|
);
|
|
161
220
|
}
|
|
162
|
-
taken.set(reference,
|
|
221
|
+
taken.set(reference, owner);
|
|
163
222
|
node.reference = reference;
|
|
164
223
|
}
|
|
165
224
|
}
|
|
@@ -182,29 +241,21 @@ export class Model {
|
|
|
182
241
|
file: string,
|
|
183
242
|
name: string,
|
|
184
243
|
): ts.VariableDeclaration | ts.BindingElement {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
for (const statement of source?.statements ?? []) {
|
|
201
|
-
if (ts.isVariableStatement(statement)) {
|
|
202
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
203
|
-
const found = named(declaration);
|
|
204
|
-
if (found) {
|
|
205
|
-
return found;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
244
|
+
const declarations = this.sourceFile(file).statements.flatMap(
|
|
245
|
+
(statement) =>
|
|
246
|
+
ts.isVariableStatement(statement)
|
|
247
|
+
? [...statement.declarationList.declarations]
|
|
248
|
+
: [],
|
|
249
|
+
);
|
|
250
|
+
for (const declaration of declarations) {
|
|
251
|
+
const named = boundNames(declaration.name).find(
|
|
252
|
+
(bound) => bound.text === name,
|
|
253
|
+
)?.parent;
|
|
254
|
+
if (
|
|
255
|
+
named &&
|
|
256
|
+
(ts.isVariableDeclaration(named) || ts.isBindingElement(named))
|
|
257
|
+
) {
|
|
258
|
+
return named;
|
|
208
259
|
}
|
|
209
260
|
}
|
|
210
261
|
throw new Error(`${file}: no module binding ${name}.`);
|
|
@@ -246,6 +297,17 @@ export class Model {
|
|
|
246
297
|
return found;
|
|
247
298
|
}
|
|
248
299
|
|
|
300
|
+
/** The nearest member of a class or the classes it extends that is `name` and passes `is`. */
|
|
301
|
+
memberNamed<T extends ts.ClassElement>(
|
|
302
|
+
declaration: ts.ClassDeclaration,
|
|
303
|
+
name: string,
|
|
304
|
+
is: (member: ts.ClassElement) => member is T,
|
|
305
|
+
): T | undefined {
|
|
306
|
+
return this.members(declaration).find(
|
|
307
|
+
(member): member is T => is(member) && member.name?.getText() === name,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
249
311
|
/** A class field's declaration: a property, or a constructor parameter property. */
|
|
250
312
|
member(
|
|
251
313
|
declaration: ts.ClassDeclaration,
|
|
@@ -319,15 +381,13 @@ export class Model {
|
|
|
319
381
|
holder: CapturedNode,
|
|
320
382
|
): ts.Type | undefined {
|
|
321
383
|
const variant = this.variant(type, holder);
|
|
322
|
-
const property =
|
|
323
|
-
variant.getProperty(name) ??
|
|
324
|
-
this.checker.getPropertyOfType(variant, name);
|
|
384
|
+
const property = variant.getProperty(name);
|
|
325
385
|
return property && this.checker.getTypeOfSymbol(property);
|
|
326
386
|
}
|
|
327
387
|
|
|
328
388
|
/** The member of a union of object types that a captured object is, by its literal fields. */
|
|
329
389
|
variant(type: ts.Type, value: CapturedNode): ts.Type {
|
|
330
|
-
const candidates = (type
|
|
390
|
+
const candidates = unionMembers(type).filter(
|
|
331
391
|
(member) => !(member.flags & ts.TypeFlags.Undefined),
|
|
332
392
|
);
|
|
333
393
|
const [first] = candidates;
|
|
@@ -355,13 +415,11 @@ export class Model {
|
|
|
355
415
|
);
|
|
356
416
|
}
|
|
357
417
|
|
|
418
|
+
/** The type of an array's or tuple's elements. */
|
|
358
419
|
elementType(type: ts.Type): ts.Type | undefined {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
(this.checker.isTupleType(target)
|
|
363
|
-
? this.checker.getTypeArguments(target as ts.TypeReference)[0]
|
|
364
|
-
: undefined)
|
|
420
|
+
return this.checker.getIndexTypeOfType(
|
|
421
|
+
this.checker.getNonNullableType(type),
|
|
422
|
+
ts.IndexKind.Number,
|
|
365
423
|
);
|
|
366
424
|
}
|
|
367
425
|
|
|
@@ -388,7 +446,7 @@ export class Model {
|
|
|
388
446
|
: undefined;
|
|
389
447
|
for (const [step, held] of children(node.captured)) {
|
|
390
448
|
queue.push({
|
|
391
|
-
owner:
|
|
449
|
+
owner: ownerAt(next.owner, step),
|
|
392
450
|
type:
|
|
393
451
|
step.kind === "index"
|
|
394
452
|
? element
|