@tsplc/compiler 0.2.17 → 0.2.18
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/cli.js +920 -943
- package/dist/cli.js.map +13 -10
- package/dist/codesys.js +3893 -3352
- package/dist/codesys.js.map +29 -20
- package/dist/elaborate-capture.js +33 -17
- package/dist/elaborate-capture.js.map +3 -3
- package/dist/index.js +8787 -6855
- package/dist/index.js.map +40 -20
- package/dist/ir.js +1575 -1072
- package/dist/ir.js.map +21 -17
- package/dist/math.js.map +2 -2
- package/dist/project.js +154 -60
- package/dist/project.js.map +5 -5
- package/dist/telemetry.js +27 -9
- package/dist/telemetry.js.map +5 -5
- package/package.json +112 -112
- package/src/codesys/config.ts +50 -0
- package/src/codesys/debug.ts +670 -0
- package/src/codesys/emit.ts +142 -0
- package/src/codesys/engineering.ts +109 -0
- package/src/codesys/expressions.ts +92 -0
- package/src/codesys/global-lists.ts +250 -0
- package/src/codesys/global-names.ts +68 -0
- package/src/codesys/http.ts +890 -0
- package/src/codesys/index.ts +30 -0
- package/src/codesys/instrumentation.ts +430 -0
- package/src/codesys/io-paths.ts +140 -0
- package/src/codesys/manifest.ts +643 -0
- package/src/codesys/names.ts +81 -0
- package/src/codesys/numeric.ts +409 -0
- package/src/codesys/operands.ts +62 -0
- package/src/codesys/plan.ts +605 -0
- package/src/codesys/programs.ts +53 -0
- package/src/codesys/publication.ts +171 -0
- package/src/codesys/routines.ts +603 -0
- package/src/codesys/sources.ts +71 -0
- package/src/codesys/st-files.ts +115 -0
- package/src/codesys/storage.ts +97 -0
- package/src/codesys/symbols.ts +220 -0
- package/src/codesys/task-access.ts +320 -0
- package/src/codesys/telemetry.ts +732 -0
- package/src/codesys/types.ts +250 -0
- package/src/codesys/vendor.ts +150 -0
- package/src/frontend/analyzer.ts +794 -0
- package/src/frontend/async.ts +317 -1137
- package/src/frontend/blocks.ts +537 -403
- package/src/frontend/configuration.ts +176 -144
- package/src/frontend/const-functions.ts +183 -148
- package/src/frontend/cooperative.ts +73 -43
- package/src/frontend/coroutines.ts +1032 -0
- package/src/frontend/elaborate/calls.ts +535 -0
- package/src/frontend/elaborate/capture.ts +157 -101
- package/src/frontend/elaborate/dialect.ts +257 -0
- package/src/frontend/elaborate/expressions.ts +992 -0
- package/src/frontend/elaborate/frame.ts +53 -0
- package/src/frontend/elaborate/graph.ts +116 -71
- package/src/frontend/elaborate/imports.ts +70 -0
- package/src/frontend/elaborate/index.ts +435 -331
- package/src/frontend/elaborate/initializers.ts +198 -0
- package/src/frontend/elaborate/layouts.ts +591 -384
- package/src/frontend/elaborate/model.ts +264 -169
- package/src/frontend/elaborate/specialize.ts +343 -2586
- package/src/frontend/elaborate/statements.ts +606 -0
- package/src/frontend/elaborate/storage.ts +546 -0
- package/src/frontend/elaborate/values.ts +58 -0
- package/src/frontend/elaborate/writes.ts +100 -0
- package/src/frontend/exposure.ts +172 -140
- package/src/frontend/expressions.ts +1383 -0
- package/src/frontend/intrinsics.ts +337 -0
- package/src/frontend/module-graph.ts +89 -59
- package/src/frontend/positions.ts +271 -200
- package/src/frontend/promise-chains.ts +897 -0
- package/src/frontend/promises.ts +390 -747
- package/src/frontend/routines.ts +181 -0
- package/src/frontend/sdk.ts +82 -0
- package/src/frontend/services.ts +506 -372
- package/src/frontend/statements.ts +855 -0
- package/src/frontend/tasks.ts +471 -0
- package/src/frontend/telemetry.ts +174 -0
- package/src/frontend/types.ts +845 -551
- package/src/frontend/typescript.ts +323 -2543
- package/src/index.ts +5 -5
- package/src/ir/aggregates.ts +275 -0
- package/src/ir/allocation.ts +84 -0
- package/src/ir/core-model.ts +146 -0
- package/src/ir/declarations.ts +295 -0
- package/src/ir/diagnostics.ts +61 -0
- package/src/ir/domains.ts +152 -0
- package/src/ir/fold.ts +342 -0
- package/src/ir/index.ts +90 -0
- package/{ir/errors.ts → src/ir/job-errors.ts} +12 -10
- package/src/ir/layouts.ts +181 -0
- package/src/ir/link.ts +354 -0
- package/src/ir/model.ts +386 -0
- package/{ir → src/ir}/normalization-error.ts +4 -4
- package/src/ir/normalize.ts +70 -0
- package/src/ir/numeric.ts +171 -0
- package/src/ir/ranges.ts +256 -0
- package/src/ir/routine.ts +1163 -0
- package/src/ir/scalars.ts +321 -0
- package/src/ir/types.ts +127 -0
- package/src/project/artifacts.ts +342 -0
- package/src/project/cli.ts +177 -0
- package/src/project/debugger.ts +82 -0
- package/src/project/index.ts +6 -0
- package/src/project/plant.ts +467 -0
- package/src/project/project-commands.ts +372 -0
- package/src/project/project.ts +457 -0
- package/src/project/release.ts +153 -0
- package/src/project/server.ts +150 -0
- package/src/project/terminal.ts +32 -0
- package/stdlib/math.ts +14 -10
- package/stdlib/telemetry.ts +71 -47
- package/types/async.d.ts +46 -40
- package/types/data-types.d.ts +26 -26
- package/types/globals.d.ts +41 -38
- package/types/index.d.ts +96 -51
- package/types/plc.d.ts +3 -4
- package/types/telemetry.d.ts +14 -14
- package/backends/codesys/config.ts +0 -54
- package/backends/codesys/debug.ts +0 -509
- package/backends/codesys/emit.ts +0 -1738
- package/backends/codesys/engineering.ts +0 -88
- package/backends/codesys/global-names.ts +0 -49
- package/backends/codesys/http.ts +0 -675
- package/backends/codesys/index.ts +0 -13
- package/backends/codesys/io-paths.ts +0 -105
- package/backends/codesys/manifest.ts +0 -312
- package/backends/codesys/names.ts +0 -76
- package/backends/codesys/numeric.ts +0 -356
- package/backends/codesys/plan.ts +0 -457
- package/backends/codesys/publication.ts +0 -59
- package/backends/codesys/storage.ts +0 -70
- package/backends/codesys/task-access.ts +0 -293
- package/backends/codesys/telemetry.ts +0 -593
- package/backends/codesys/types.ts +0 -179
- package/backends/codesys/vendor.ts +0 -108
- package/ir/aggregates.ts +0 -333
- package/ir/allocation.ts +0 -74
- package/ir/core-model.ts +0 -129
- package/ir/core.ts +0 -64
- package/ir/declarations.ts +0 -208
- package/ir/diagnostics.ts +0 -43
- package/ir/domains.ts +0 -96
- package/ir/index.ts +0 -8
- package/ir/link.ts +0 -185
- package/ir/model.ts +0 -346
- package/ir/routine.ts +0 -859
- package/ir/scalars.ts +0 -675
- package/ir/types.ts +0 -76
- package/project/artifacts.ts +0 -277
- package/project/cli.ts +0 -395
- package/project/index.ts +0 -1
- package/project/plant.ts +0 -509
- package/project/project.ts +0 -358
- package/project/server.ts +0 -113
|
@@ -2,189 +2,284 @@ import ts from "typescript";
|
|
|
2
2
|
import type { CapturedGraph, CapturedNode, CapturedValue } from "./graph.ts";
|
|
3
3
|
|
|
4
4
|
/** One step from an owner to the object it holds. */
|
|
5
|
-
export type Step =
|
|
5
|
+
export type Step =
|
|
6
|
+
{ kind: "field"; name: string } | { kind: "index"; index: number };
|
|
6
7
|
|
|
7
8
|
/** Where a captured object is stored: a root binding and the steps to it. */
|
|
8
9
|
export interface Owner {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
root: Root;
|
|
11
|
+
steps: readonly Step[];
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
/** The TypeScript path of an owned object or field, as the program names it: `program.diverters.binTrackers[10]`. */
|
|
14
15
|
export const tsPath = (owner: Owner): string =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
owner.root.name + owner.steps.map(stepPath).join("");
|
|
17
|
+
|
|
18
|
+
/** One step of a TypeScript path: an index, a numeric key, or a property. */
|
|
19
|
+
const stepPath = (step: Step): string => {
|
|
20
|
+
if (step.kind === "index") {
|
|
21
|
+
return `[${step.index}]`;
|
|
22
|
+
}
|
|
23
|
+
return /^\d+$/.test(step.name) ? `[${step.name}]` : `.${step.name}`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Each step from a captured object to what it holds, with the value there. */
|
|
27
|
+
export const children = (captured: CapturedNode): [Step, CapturedValue][] => {
|
|
28
|
+
if (captured.kind === "array") {
|
|
29
|
+
return captured.items.map((item, index) => [
|
|
30
|
+
{ kind: "index", index },
|
|
31
|
+
item,
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
if (captured.kind === "object" || captured.kind === "instance") {
|
|
35
|
+
return Object.entries(captured.fields).map(([name, field]) => [
|
|
36
|
+
{ kind: "field", name },
|
|
37
|
+
field,
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
return [];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** The value one step down from a captured object, when it has one there. */
|
|
44
|
+
const child = (
|
|
45
|
+
captured: CapturedNode,
|
|
46
|
+
step: Step,
|
|
47
|
+
): CapturedValue | undefined => {
|
|
48
|
+
if (step.kind === "index") {
|
|
49
|
+
return captured.kind === "array" ? captured.items[step.index] : undefined;
|
|
50
|
+
}
|
|
51
|
+
return captured.kind === "object" || captured.kind === "instance"
|
|
52
|
+
? captured.fields[step.name]
|
|
53
|
+
: undefined;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** A field a class declares: a property, or a constructor parameter property. */
|
|
57
|
+
type ClassField = ts.PropertyDeclaration | ts.ParameterPropertyDeclaration;
|
|
25
58
|
|
|
26
59
|
export interface Root {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
60
|
+
file: string;
|
|
61
|
+
name: string;
|
|
62
|
+
declaration: ts.VariableDeclaration;
|
|
63
|
+
exported: boolean;
|
|
64
|
+
/** What setup bound it to. */
|
|
65
|
+
value: CapturedValue;
|
|
31
66
|
}
|
|
32
67
|
|
|
33
68
|
export interface ModelNode {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
id: number;
|
|
70
|
+
captured: CapturedNode;
|
|
71
|
+
/** The declared type where the object is stored; undefined for functions and services. */
|
|
72
|
+
type?: ts.Type;
|
|
73
|
+
/** The first place setup reached it. Every other place holding it refers to this one. */
|
|
74
|
+
owner?: Owner;
|
|
40
75
|
}
|
|
41
76
|
|
|
42
77
|
/** The captured setup graph with each object's owner and declared type. */
|
|
43
78
|
export class Model {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
79
|
+
readonly nodes: ModelNode[];
|
|
80
|
+
readonly roots: Root[] = [];
|
|
81
|
+
|
|
82
|
+
constructor(
|
|
83
|
+
readonly graph: CapturedGraph,
|
|
84
|
+
readonly checker: ts.TypeChecker,
|
|
85
|
+
readonly program: ts.Program,
|
|
86
|
+
entry: string,
|
|
87
|
+
) {
|
|
88
|
+
this.nodes = graph.nodes.map((captured, id) => ({ id, captured }));
|
|
89
|
+
// Dependencies own what they build before the entry module's instances refer to it.
|
|
90
|
+
const ordered = [
|
|
91
|
+
...graph.bindings.filter((binding) => binding.file !== entry),
|
|
92
|
+
...graph.bindings.filter((binding) => binding.file === entry),
|
|
93
|
+
];
|
|
94
|
+
for (const binding of ordered) {
|
|
95
|
+
const declaration = this.binding(binding.file, binding.name);
|
|
96
|
+
const root: Root = {
|
|
97
|
+
file: binding.file,
|
|
98
|
+
name: binding.name,
|
|
99
|
+
declaration,
|
|
100
|
+
exported: Boolean(
|
|
101
|
+
ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export,
|
|
102
|
+
),
|
|
103
|
+
value: binding.value,
|
|
104
|
+
};
|
|
105
|
+
this.roots.push(root);
|
|
106
|
+
this.own(
|
|
107
|
+
binding.value,
|
|
108
|
+
{ root, steps: [] },
|
|
109
|
+
checker.getTypeAtLocation(declaration.name),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The object a captured value refers to; undefined for a primitive. */
|
|
115
|
+
node(value: Extract<CapturedValue, { kind: "node" }>): ModelNode;
|
|
116
|
+
node(value: CapturedValue): ModelNode | undefined;
|
|
117
|
+
node(value: CapturedValue): ModelNode | undefined {
|
|
118
|
+
if (value.kind !== "node") {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const node = this.nodes[value.id];
|
|
122
|
+
if (!node) {
|
|
123
|
+
throw new Error(`The setup graph has no object ${value.id}.`);
|
|
124
|
+
}
|
|
125
|
+
return node;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private binding(file: string, name: string): ts.VariableDeclaration {
|
|
129
|
+
const source = this.program.getSourceFile(file);
|
|
130
|
+
for (const statement of source?.statements ?? []) {
|
|
131
|
+
if (ts.isVariableStatement(statement)) {
|
|
132
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
133
|
+
if (
|
|
134
|
+
ts.isIdentifier(declaration.name) &&
|
|
135
|
+
declaration.name.text === name
|
|
136
|
+
) {
|
|
137
|
+
return declaration;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
throw new Error(`${file}: no module binding ${name}.`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The node at a path from a root, following captured values. */
|
|
146
|
+
at(root: Root, steps: readonly Step[]): ModelNode | undefined {
|
|
147
|
+
const value = steps.reduce<CapturedValue | undefined>((current, step) => {
|
|
148
|
+
const node = current && this.node(current);
|
|
149
|
+
return node && child(node.captured, step);
|
|
150
|
+
}, root.value);
|
|
151
|
+
return value && this.node(value);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** The class a captured instance belongs to. */
|
|
155
|
+
classOf(node: ModelNode): ts.ClassDeclaration {
|
|
156
|
+
const captured = node.captured;
|
|
157
|
+
if (captured.kind !== "instance") {
|
|
158
|
+
throw new Error("Not a class instance.");
|
|
159
|
+
}
|
|
160
|
+
const source = this.program.getSourceFile(captured.file);
|
|
161
|
+
const found = source?.statements.find(
|
|
162
|
+
(statement): statement is ts.ClassDeclaration =>
|
|
163
|
+
ts.isClassDeclaration(statement) &&
|
|
164
|
+
statement.name?.text === captured.name,
|
|
165
|
+
);
|
|
166
|
+
if (!found) {
|
|
167
|
+
throw new Error(`${captured.file}: no class ${captured.name}.`);
|
|
168
|
+
}
|
|
169
|
+
return found;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A class field's declaration: a property, or a constructor parameter property. */
|
|
173
|
+
member(
|
|
174
|
+
declaration: ts.ClassDeclaration,
|
|
175
|
+
name: string,
|
|
176
|
+
): ClassField | undefined {
|
|
177
|
+
return this.fields(declaration).find(
|
|
178
|
+
(field) => field.name.getText() === name,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** A class's fields in declaration order: properties and constructor parameter properties. */
|
|
183
|
+
fields(declaration: ts.ClassDeclaration): ClassField[] {
|
|
184
|
+
return declaration.members.flatMap((member): ClassField[] => {
|
|
185
|
+
if (ts.isPropertyDeclaration(member)) {
|
|
186
|
+
return [member];
|
|
187
|
+
}
|
|
188
|
+
if (ts.isConstructorDeclaration(member)) {
|
|
189
|
+
return member.parameters.filter(
|
|
190
|
+
(parameter): parameter is ts.ParameterPropertyDeclaration =>
|
|
191
|
+
ts.isParameterPropertyDeclaration(parameter, member),
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return [];
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The declared type of a field of a captured instance or record. */
|
|
199
|
+
capturedFieldType(holder: ModelNode, name: string): ts.Type | undefined {
|
|
200
|
+
if (holder.captured.kind === "instance") {
|
|
201
|
+
const member = this.member(this.classOf(holder), name);
|
|
202
|
+
return member && this.checker.getTypeAtLocation(member.name);
|
|
203
|
+
}
|
|
204
|
+
return holder.type && this.fieldType(holder.type, name, holder.captured);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The declared type of a field of `type` holding `value`, choosing the union member it matches. */
|
|
208
|
+
fieldType(
|
|
209
|
+
type: ts.Type,
|
|
210
|
+
name: string,
|
|
211
|
+
holder: CapturedNode,
|
|
212
|
+
): ts.Type | undefined {
|
|
213
|
+
const variant = this.variant(type, holder);
|
|
214
|
+
const property =
|
|
215
|
+
variant.getProperty(name) ??
|
|
216
|
+
this.checker.getPropertyOfType(variant, name);
|
|
217
|
+
return property && this.checker.getTypeOfSymbol(property);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The member of a union of object types that a captured object is, by its literal fields. */
|
|
221
|
+
variant(type: ts.Type, value: CapturedNode): ts.Type {
|
|
222
|
+
const candidates = (type.isUnion() ? type.types : [type]).filter(
|
|
223
|
+
(member) => !(member.flags & ts.TypeFlags.Undefined),
|
|
224
|
+
);
|
|
225
|
+
const [first] = candidates;
|
|
226
|
+
if (!first) {
|
|
227
|
+
return type;
|
|
228
|
+
}
|
|
229
|
+
if (candidates.length === 1 || value.kind !== "object") {
|
|
230
|
+
return first;
|
|
231
|
+
}
|
|
232
|
+
return (
|
|
233
|
+
candidates.find((candidate) =>
|
|
234
|
+
Object.entries(value.fields).every(([name, field]) => {
|
|
235
|
+
const property = candidate.getProperty(name);
|
|
236
|
+
if (!property) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
const fieldType = this.checker.getTypeOfSymbol(property);
|
|
240
|
+
return (
|
|
241
|
+
!fieldType.isLiteral() ||
|
|
242
|
+
field.kind !== "string" ||
|
|
243
|
+
fieldType.value === field.value
|
|
244
|
+
);
|
|
245
|
+
}),
|
|
246
|
+
) ?? first
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
elementType(type: ts.Type): ts.Type | undefined {
|
|
251
|
+
const target = this.checker.getNonNullableType(type);
|
|
252
|
+
return (
|
|
253
|
+
this.checker.getIndexTypeOfType(target, ts.IndexKind.Number) ??
|
|
254
|
+
(this.checker.isTupleType(target)
|
|
255
|
+
? this.checker.getTypeArguments(target as ts.TypeReference)[0]
|
|
256
|
+
: undefined)
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private own(
|
|
261
|
+
value: CapturedValue,
|
|
262
|
+
owner: Owner,
|
|
263
|
+
type: ts.Type | undefined,
|
|
264
|
+
): void {
|
|
265
|
+
const node = this.node(value);
|
|
266
|
+
if (!node || node.owner) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
node.owner = owner;
|
|
270
|
+
node.type = type;
|
|
271
|
+
const element =
|
|
272
|
+
node.captured.kind === "array" && type
|
|
273
|
+
? this.elementType(type)
|
|
274
|
+
: undefined;
|
|
275
|
+
for (const [step, held] of children(node.captured)) {
|
|
276
|
+
this.own(
|
|
277
|
+
held,
|
|
278
|
+
{ root: owner.root, steps: [...owner.steps, step] },
|
|
279
|
+
step.kind === "index"
|
|
280
|
+
? element
|
|
281
|
+
: this.capturedFieldType(node, step.name),
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
190
285
|
}
|