@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.
Files changed (263) hide show
  1. package/README.md +33 -8
  2. package/dist/cli.js +794 -621
  3. package/dist/cli.js.map +19 -16
  4. package/dist/clock.js +5 -2
  5. package/dist/clock.js.map +5 -4
  6. package/dist/codesys.js +4162 -4157
  7. package/dist/codesys.js.map +43 -29
  8. package/dist/index.js +7852 -6549
  9. package/dist/index.js.map +53 -50
  10. package/dist/ir.js +2482 -2277
  11. package/dist/ir.js.map +28 -25
  12. package/dist/retain.js +3 -1
  13. package/dist/retain.js.map +3 -3
  14. package/dist/signals.js +115 -0
  15. package/dist/signals.js.map +10 -0
  16. package/dist/telemetry.js +25 -20
  17. package/dist/telemetry.js.map +6 -6
  18. package/package.json +19 -39
  19. package/src/codesys/config.ts +3 -3
  20. package/src/codesys/debug.ts +92 -108
  21. package/src/codesys/emit.ts +100 -88
  22. package/src/codesys/endpoints.ts +111 -0
  23. package/src/codesys/engineering.ts +30 -54
  24. package/src/codesys/explain/expressions.ts +445 -0
  25. package/src/codesys/explain/flags.ts +134 -0
  26. package/src/codesys/explain/parameters.ts +53 -0
  27. package/src/codesys/explain/rows.ts +182 -0
  28. package/src/codesys/explain/tables.ts +79 -0
  29. package/src/codesys/explain/tasks.ts +68 -0
  30. package/src/codesys/explain/writes.ts +497 -0
  31. package/src/codesys/explain.ts +85 -1401
  32. package/src/codesys/expressions.ts +41 -33
  33. package/src/codesys/global-lists.ts +114 -94
  34. package/src/codesys/global-names.ts +12 -14
  35. package/src/codesys/http.ts +428 -388
  36. package/src/codesys/instrumentation.ts +142 -148
  37. package/src/codesys/io-paths.ts +31 -23
  38. package/src/codesys/loops.ts +101 -0
  39. package/src/codesys/manifest.ts +269 -269
  40. package/src/codesys/names.ts +10 -33
  41. package/src/codesys/numeric.ts +89 -42
  42. package/src/codesys/plan.ts +202 -190
  43. package/src/codesys/programs.ts +23 -16
  44. package/src/codesys/publication.ts +13 -86
  45. package/src/codesys/required.ts +8 -0
  46. package/src/codesys/routines.ts +103 -489
  47. package/src/codesys/scheduling.ts +96 -0
  48. package/src/codesys/service-channels.ts +23 -0
  49. package/src/codesys/sources.ts +34 -28
  50. package/src/codesys/st-files.ts +112 -105
  51. package/src/codesys/statements.ts +409 -0
  52. package/src/codesys/storage.ts +41 -23
  53. package/src/codesys/symbols.ts +130 -119
  54. package/src/codesys/task-access.ts +65 -221
  55. package/src/codesys/telemetry-settings.ts +19 -0
  56. package/src/codesys/telemetry.ts +185 -148
  57. package/src/codesys/types.ts +69 -109
  58. package/src/codesys/vendor.ts +13 -50
  59. package/src/frontend/analyzer.ts +66 -111
  60. package/src/frontend/async.ts +316 -128
  61. package/src/frontend/blocks.ts +178 -154
  62. package/src/frontend/configuration.ts +49 -153
  63. package/src/frontend/const-functions.ts +50 -40
  64. package/src/frontend/control-flow.ts +164 -129
  65. package/src/frontend/cooperative.ts +17 -9
  66. package/src/frontend/coroutines.ts +539 -441
  67. package/src/frontend/dialect-names.ts +104 -0
  68. package/src/frontend/elaborate/array-searches.ts +77 -69
  69. package/src/frontend/elaborate/assignments.ts +68 -77
  70. package/src/frontend/elaborate/calls.ts +878 -512
  71. package/src/frontend/elaborate/capture-protocol.ts +118 -21
  72. package/src/frontend/elaborate/capture.ts +196 -109
  73. package/src/frontend/elaborate/declarations.ts +124 -0
  74. package/src/frontend/elaborate/dialect.ts +119 -46
  75. package/src/frontend/elaborate/expressions.ts +763 -442
  76. package/src/frontend/elaborate/filtered-arrays.ts +127 -91
  77. package/src/frontend/elaborate/frame.ts +50 -2
  78. package/src/frontend/elaborate/generics.ts +20 -34
  79. package/src/frontend/elaborate/graph.ts +13 -87
  80. package/src/frontend/elaborate/imports.ts +0 -5
  81. package/src/frontend/elaborate/index.ts +416 -169
  82. package/src/frontend/elaborate/initializers.ts +64 -42
  83. package/src/frontend/elaborate/iterators.ts +228 -364
  84. package/src/frontend/elaborate/layouts.ts +477 -116
  85. package/src/frontend/elaborate/model.ts +113 -55
  86. package/src/frontend/elaborate/references.ts +116 -138
  87. package/src/frontend/elaborate/retention.ts +137 -59
  88. package/src/frontend/elaborate/specialize.ts +617 -308
  89. package/src/frontend/elaborate/statements.ts +436 -247
  90. package/src/frontend/elaborate/storage.ts +280 -213
  91. package/src/frontend/elaborate/time-constructors.ts +34 -0
  92. package/src/frontend/elaborate/values.ts +77 -7
  93. package/src/frontend/elaborate/writes.ts +98 -84
  94. package/src/frontend/expressions.ts +149 -151
  95. package/src/frontend/generated-names.ts +3 -3
  96. package/src/frontend/intrinsics.ts +31 -17
  97. package/src/frontend/lowering-key.ts +23 -0
  98. package/src/frontend/module-graph.ts +105 -43
  99. package/src/frontend/positions.ts +43 -35
  100. package/src/frontend/promise-chains.ts +226 -266
  101. package/src/frontend/promises.ts +88 -67
  102. package/src/frontend/routines.ts +122 -65
  103. package/src/frontend/sdk.ts +104 -5
  104. package/src/frontend/services.ts +149 -102
  105. package/src/frontend/statements.ts +60 -64
  106. package/src/frontend/tasks.ts +151 -96
  107. package/src/frontend/telemetry.ts +1 -1
  108. package/src/frontend/types.ts +366 -181
  109. package/src/frontend/typescript.ts +239 -112
  110. package/src/index.ts +2 -1
  111. package/src/ir/aggregates.ts +90 -75
  112. package/src/ir/allocation.ts +29 -18
  113. package/src/ir/conditions.ts +38 -78
  114. package/src/ir/core-model.ts +128 -11
  115. package/src/ir/declarations.ts +18 -32
  116. package/src/ir/diagnostics.ts +25 -18
  117. package/src/ir/domains.ts +26 -23
  118. package/src/ir/fold.ts +55 -50
  119. package/src/ir/identity.ts +10 -0
  120. package/src/ir/index.ts +31 -7
  121. package/src/ir/job-errors.ts +30 -8
  122. package/src/ir/layouts.ts +63 -34
  123. package/src/ir/link.ts +11 -46
  124. package/src/ir/model.ts +25 -6
  125. package/src/ir/normalize.ts +3 -28
  126. package/src/ir/numeric.ts +45 -18
  127. package/src/ir/operands.ts +102 -0
  128. package/src/ir/ranges.ts +242 -67
  129. package/src/ir/routine.ts +126 -183
  130. package/src/ir/scalars.ts +29 -25
  131. package/src/ir/share.ts +323 -343
  132. package/src/ir/short-circuit.ts +140 -0
  133. package/src/ir/tables.ts +111 -0
  134. package/src/ir/temporaries.ts +15 -113
  135. package/src/ir/types.ts +32 -8
  136. package/src/project/artifacts.ts +143 -71
  137. package/src/project/cli.ts +104 -87
  138. package/src/project/debugger.ts +48 -34
  139. package/src/project/deployments.ts +12 -68
  140. package/src/project/flags.ts +14 -0
  141. package/src/project/plant.ts +293 -225
  142. package/src/project/project-commands.ts +254 -192
  143. package/src/project/project.ts +184 -141
  144. package/src/project/release.ts +22 -28
  145. package/src/project/server.ts +22 -26
  146. package/src/project/terminal.ts +13 -2
  147. package/src/runtime/async.ts +17 -13
  148. package/src/runtime/launch.ts +5 -2
  149. package/src/runtime/main.ts +8 -3
  150. package/src/runtime/missing-file.ts +3 -0
  151. package/src/runtime/process.ts +24 -19
  152. package/src/runtime/program.ts +20 -53
  153. package/src/runtime/retain.ts +18 -10
  154. package/src/runtime/runtime.ts +47 -60
  155. package/src/runtime/settings.ts +27 -0
  156. package/src/runtime/storage.ts +49 -74
  157. package/src/runtime/symbols.ts +19 -75
  158. package/src/runtime/telemetry.ts +37 -14
  159. package/src/runtime/transport.ts +26 -30
  160. package/stdlib/clock.ts +4 -2
  161. package/stdlib/plc-time.ts +2 -0
  162. package/stdlib/retain.ts +2 -0
  163. package/stdlib/signals.ts +142 -0
  164. package/stdlib/telemetry.ts +5 -12
  165. package/types/dialect.d.ts +49 -0
  166. package/types/globals.d.ts +2 -42
  167. package/types/index.d.ts +3 -1
  168. package/types/retain.d.ts +8 -2
  169. package/types/telemetry.d.ts +3 -0
  170. package/dist/bun-runtime.js +0 -1472
  171. package/dist/bun-runtime.js.map +0 -26
  172. package/dist/elaborate-capture.js +0 -304
  173. package/dist/elaborate-capture.js.map +0 -11
  174. package/dist/math.js +0 -24
  175. package/dist/math.js.map +0 -10
  176. package/dist/project.js +0 -626
  177. package/dist/project.js.map +0 -12
  178. package/dist/server-check.js +0 -59
  179. package/dist/server-check.js.map +0 -11
  180. package/src/frontend/exposure.ts +0 -181
  181. package/src/project/index.ts +0 -6
  182. package/src/runtime/.runtime-65O4JH/server/router.ts +0 -17
  183. package/src/runtime/.runtime-65O4JH/src/cell.ts +0 -45
  184. package/src/runtime/.runtime-65O4JH/src/controller.ts +0 -58
  185. package/src/runtime/.runtime-65O4JH/src/lane.ts +0 -6
  186. package/src/runtime/.runtime-65O4JH/src/main.ts +0 -11
  187. package/src/runtime/.runtime-65O4JH/src/services.ts +0 -8
  188. package/src/runtime/.runtime-65O4JH/tsconfig.json +0 -13
  189. package/src/runtime/.runtime-65O4JH/tsplc.config.ts +0 -31
  190. package/src/runtime/.runtime-Brw2kO/server/router.ts +0 -17
  191. package/src/runtime/.runtime-Brw2kO/src/cell.ts +0 -45
  192. package/src/runtime/.runtime-Brw2kO/src/controller.ts +0 -58
  193. package/src/runtime/.runtime-Brw2kO/src/lane.ts +0 -6
  194. package/src/runtime/.runtime-Brw2kO/src/main.ts +0 -11
  195. package/src/runtime/.runtime-Brw2kO/src/services.ts +0 -8
  196. package/src/runtime/.runtime-Brw2kO/tsconfig.json +0 -13
  197. package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +0 -31
  198. package/src/runtime/.runtime-NHfu1D/server/router.ts +0 -17
  199. package/src/runtime/.runtime-NHfu1D/src/cell.ts +0 -45
  200. package/src/runtime/.runtime-NHfu1D/src/controller.ts +0 -58
  201. package/src/runtime/.runtime-NHfu1D/src/lane.ts +0 -6
  202. package/src/runtime/.runtime-NHfu1D/src/main.ts +0 -11
  203. package/src/runtime/.runtime-NHfu1D/src/services.ts +0 -8
  204. package/src/runtime/.runtime-NHfu1D/tsconfig.json +0 -13
  205. package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +0 -31
  206. package/src/runtime/.runtime-VaUSOu/server/router.ts +0 -17
  207. package/src/runtime/.runtime-VaUSOu/src/cell.ts +0 -45
  208. package/src/runtime/.runtime-VaUSOu/src/controller.ts +0 -58
  209. package/src/runtime/.runtime-VaUSOu/src/lane.ts +0 -6
  210. package/src/runtime/.runtime-VaUSOu/src/main.ts +0 -11
  211. package/src/runtime/.runtime-VaUSOu/src/services.ts +0 -8
  212. package/src/runtime/.runtime-VaUSOu/tsconfig.json +0 -13
  213. package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +0 -31
  214. package/src/runtime/.runtime-WbtNvR/server/router.ts +0 -17
  215. package/src/runtime/.runtime-WbtNvR/src/cell.ts +0 -45
  216. package/src/runtime/.runtime-WbtNvR/src/controller.ts +0 -58
  217. package/src/runtime/.runtime-WbtNvR/src/lane.ts +0 -6
  218. package/src/runtime/.runtime-WbtNvR/src/main.ts +0 -11
  219. package/src/runtime/.runtime-WbtNvR/src/services.ts +0 -8
  220. package/src/runtime/.runtime-WbtNvR/tsconfig.json +0 -13
  221. package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +0 -31
  222. package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +0 -17
  223. package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +0 -45
  224. package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +0 -58
  225. package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +0 -6
  226. package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +0 -11
  227. package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +0 -8
  228. package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +0 -13
  229. package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +0 -31
  230. package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +0 -17
  231. package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +0 -45
  232. package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +0 -58
  233. package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +0 -6
  234. package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +0 -11
  235. package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +0 -8
  236. package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +0 -13
  237. package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +0 -31
  238. package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +0 -17
  239. package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +0 -45
  240. package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +0 -58
  241. package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +0 -6
  242. package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +0 -11
  243. package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +0 -8
  244. package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +0 -13
  245. package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +0 -31
  246. package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +0 -17
  247. package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +0 -45
  248. package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +0 -58
  249. package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +0 -6
  250. package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +0 -11
  251. package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +0 -8
  252. package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +0 -13
  253. package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +0 -31
  254. package/src/runtime/.runtime-ybIxYh/server/router.ts +0 -17
  255. package/src/runtime/.runtime-ybIxYh/src/cell.ts +0 -45
  256. package/src/runtime/.runtime-ybIxYh/src/controller.ts +0 -58
  257. package/src/runtime/.runtime-ybIxYh/src/lane.ts +0 -6
  258. package/src/runtime/.runtime-ybIxYh/src/main.ts +0 -11
  259. package/src/runtime/.runtime-ybIxYh/src/services.ts +0 -8
  260. package/src/runtime/.runtime-ybIxYh/tsconfig.json +0 -13
  261. package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +0 -31
  262. package/stdlib/math.ts +0 -23
  263. package/types/plc.d.ts +0 -4
@@ -1,4 +1,4 @@
1
- import { dirname, join, relative, resolve } from "node:path";
1
+ import { dirname, join, resolve } from "node:path";
2
2
  import {
3
3
  type Constant,
4
4
  type Diagnostic,
@@ -10,7 +10,8 @@ import {
10
10
  } from "@tsplc/compiler/ir";
11
11
  import { generatedDirectory } from "@tsplc/config/project-files";
12
12
  import ts from "typescript";
13
- import { runtimeSources } from "../module-graph";
13
+ import { modulePath } from "../lowering-key";
14
+ import { plcSources } from "../module-graph";
14
15
  import {
15
16
  copied,
16
17
  from,
@@ -18,28 +19,42 @@ import {
18
19
  type Mapped,
19
20
  type Positions,
20
21
  } from "../positions";
21
- import { inSdk, namesSdk } from "../sdk";
22
- import type { CompileDebug } from "../typescript";
22
+ import { inSdk, namesSdk, sdkModules, unaliased } from "../sdk";
23
+ import { defaultNumericTypes } from "../types";
24
+ import type { BoundPath, CompileDebug } from "../typescript";
23
25
  import type { CapturedValue } from "./capture-protocol";
24
26
  import { GenericTypes } from "./generics";
25
27
  import { captureGraph } from "./graph";
26
28
  import { importPath } from "./imports";
29
+ import { stringEnums, type TypeDeclarations } from "./layouts";
27
30
  import { Model, type Root } from "./model";
28
- import { Retention, retainedDeclarations } from "./retention";
31
+ import { Retention, retentionDeclarations } from "./retention";
29
32
  import { closingBrace, Specializer } from "./specialize";
30
- import { setterName } from "./storage";
31
33
  import { SpecializeError } from "./values";
32
34
 
33
35
  /**
34
- * A module the compiled program keeps as written: only types, enums, constants and the service
35
- * client. Everything else is plain TypeScript that elaboration compiles from its setup graph.
36
+ * A module the compiled program keeps as written: only types, enums, constants, tasks and the
37
+ * service client. Everything else is plain TypeScript that elaboration compiles from its setup graph.
38
+ * A const that scan code writes through, or that `io` binds the hardware to, is state, not a constant.
36
39
  */
37
40
  const keptModule = (
38
41
  source: ts.SourceFile,
39
42
  checker: ts.TypeChecker,
40
43
  sdk: string,
41
- ): boolean =>
42
- source.statements.every((statement) => {
44
+ {
45
+ written,
46
+ bound,
47
+ }: { written: ReadonlySet<ts.Symbol>; bound: ReadonlySet<string> },
48
+ ): boolean => {
49
+ const work = taskWork(source, checker, sdk);
50
+ return source.statements.every((statement) => {
51
+ if (
52
+ ts.isFunctionDeclaration(statement) &&
53
+ statement.name &&
54
+ work.has(statement.name.text)
55
+ ) {
56
+ return true;
57
+ }
43
58
  if (
44
59
  ts.isImportDeclaration(statement) ||
45
60
  ts.isExportDeclaration(statement) ||
@@ -52,12 +67,123 @@ const keptModule = (
52
67
  if (!ts.isVariableStatement(statement)) {
53
68
  return false;
54
69
  }
55
- return statement.declarationList.declarations.every(
56
- (declaration) =>
70
+ return statement.declarationList.declarations.every((declaration) => {
71
+ const symbol = checker.getSymbolAtLocation(declaration.name);
72
+ return (
57
73
  declaration.initializer &&
58
- constantInitializer(declaration.initializer, checker, sdk),
59
- );
74
+ constantInitializer(declaration.initializer, checker, sdk) &&
75
+ !(symbol && written.has(symbol)) &&
76
+ !(ts.isIdentifier(declaration.name) && bound.has(declaration.name.text))
77
+ );
78
+ });
60
79
  });
80
+ };
81
+
82
+ /** The identifier a place is reached from: `a` of `a.b[i].c`. */
83
+ const placeRoot = (node: ts.Expression): ts.Identifier | undefined => {
84
+ if (ts.isIdentifier(node)) {
85
+ return node;
86
+ }
87
+ if (
88
+ ts.isPropertyAccessExpression(node) ||
89
+ ts.isElementAccessExpression(node) ||
90
+ ts.isParenthesizedExpression(node) ||
91
+ ts.isNonNullExpression(node)
92
+ ) {
93
+ return placeRoot(node.expression);
94
+ }
95
+ return undefined;
96
+ };
97
+
98
+ /** The bindings `sources` assign, or assign a field or element of, through any import of them. */
99
+ const writtenBindings = (
100
+ sources: readonly ts.SourceFile[],
101
+ checker: ts.TypeChecker,
102
+ ): Set<ts.Symbol> => {
103
+ const written = new Set<ts.Symbol>();
104
+ const note = (target: ts.Expression) => {
105
+ const root = placeRoot(target);
106
+ const symbol = root && checker.getSymbolAtLocation(root);
107
+ if (symbol) {
108
+ written.add(unaliased(checker, symbol));
109
+ }
110
+ };
111
+ const visit = (node: ts.Node): void => {
112
+ if (
113
+ ts.isBinaryExpression(node) &&
114
+ node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
115
+ node.operatorToken.kind <= ts.SyntaxKind.LastAssignment
116
+ ) {
117
+ note(node.left);
118
+ }
119
+ if (
120
+ (ts.isPrefixUnaryExpression(node) || ts.isPostfixUnaryExpression(node)) &&
121
+ (node.operator === ts.SyntaxKind.PlusPlusToken ||
122
+ node.operator === ts.SyntaxKind.MinusMinusToken)
123
+ ) {
124
+ note(node.operand);
125
+ }
126
+ ts.forEachChild(node, visit);
127
+ };
128
+ for (const source of sources) {
129
+ visit(source);
130
+ }
131
+ return written;
132
+ };
133
+
134
+ /**
135
+ * The functions a module's tasks run: the names its module-level `define` calls pass as their work,
136
+ * and the module's functions those call, which run in the task too.
137
+ */
138
+ const taskWork = (
139
+ source: ts.SourceFile,
140
+ checker: ts.TypeChecker,
141
+ sdk: string,
142
+ ): Set<string> => {
143
+ const functions = new Map(
144
+ source.statements.flatMap((statement) =>
145
+ ts.isFunctionDeclaration(statement) && statement.name
146
+ ? [[statement.name.text, statement] as const]
147
+ : [],
148
+ ),
149
+ );
150
+ const work = new Set<string>();
151
+ const add = (name: string): void => {
152
+ const declaration = functions.get(name);
153
+ if (!declaration || work.has(name)) {
154
+ return;
155
+ }
156
+ work.add(name);
157
+ const visit = (node: ts.Node): void => {
158
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
159
+ const called = checker
160
+ .getSymbolAtLocation(node.expression)
161
+ ?.declarations?.find(ts.isFunctionDeclaration);
162
+ if (called?.name && called.parent === source) {
163
+ add(called.name.text);
164
+ }
165
+ }
166
+ ts.forEachChild(node, visit);
167
+ };
168
+ ts.forEachChild(declaration, visit);
169
+ };
170
+ for (const statement of source.statements) {
171
+ if (!ts.isVariableStatement(statement)) {
172
+ continue;
173
+ }
174
+ for (const declaration of statement.declarationList.declarations) {
175
+ const call = declaration.initializer;
176
+ const argument =
177
+ call && ts.isCallExpression(call) && definesTask(call, checker, sdk)
178
+ ? call.arguments[0]
179
+ : undefined;
180
+ if (argument && ts.isIdentifier(argument)) {
181
+ add(argument.text);
182
+ }
183
+ }
184
+ }
185
+ return work;
186
+ };
61
187
 
62
188
  const constantInitializer = (
63
189
  node: ts.Expression,
@@ -104,11 +230,25 @@ const constantInitializer = (
104
230
  );
105
231
  }
106
232
  if (ts.isCallExpression(node)) {
107
- return namesSdk(checker, sdk, node.expression, "createServiceClient");
233
+ return (
234
+ namesSdk(checker, sdk, node.expression, "createServiceClient") ||
235
+ definesTask(node, checker, sdk)
236
+ );
108
237
  }
109
238
  return false;
110
239
  };
111
240
 
241
+ /** Whether `call` is `tasks.define(...)` or `backgroundTasks.define(...)`, which the async lowering compiles as written. */
242
+ const definesTask = (
243
+ call: ts.CallExpression,
244
+ checker: ts.TypeChecker,
245
+ sdk: string,
246
+ ): boolean =>
247
+ ts.isPropertyAccessExpression(call.expression) &&
248
+ call.expression.name.text === "define" &&
249
+ (namesSdk(checker, sdk, call.expression.expression, "tasks") ||
250
+ namesSdk(checker, sdk, call.expression.expression, "backgroundTasks"));
251
+
112
252
  /**
113
253
  * Whether the program is plain TypeScript: it declares a class that is not a function block, one
114
254
  * extending the SDK's `FunctionBlock` however the module names it.
@@ -144,7 +284,7 @@ interface Folded {
144
284
  * A folded primitive as a PLC constant, with its scalar type: the IEC width its declaration
145
285
  * names, or the one a TypeScript number of that value gets. Strings, often enum members, have none.
146
286
  */
147
- const constant = (
287
+ const foldedConstant = (
148
288
  value: CapturedValue,
149
289
  iec: string | undefined,
150
290
  ): Pick<Folded, "value" | "type"> | undefined => {
@@ -153,16 +293,16 @@ const constant = (
153
293
  return Number.isInteger(value.value)
154
294
  ? {
155
295
  value: { kind: "integer", value: String(value.value) },
156
- type: iec ?? "DINT",
296
+ type: iec ?? defaultNumericTypes.number,
157
297
  }
158
298
  : {
159
299
  value: { kind: "float", value: value.value },
160
- type: iec ?? "LREAL",
300
+ type: iec ?? defaultNumericTypes.float,
161
301
  };
162
302
  case "bigint":
163
303
  return {
164
304
  value: { kind: "integer", value: value.value },
165
- type: iec ?? "LINT",
305
+ type: iec ?? defaultNumericTypes.bigint,
166
306
  };
167
307
  case "boolean":
168
308
  return { value: { kind: "bool", value: value.value }, type: "BOOL" };
@@ -183,7 +323,20 @@ export const lowerElaboration = (
183
323
  entries: Readonly<Record<string, { module: string; export: string }>>,
184
324
  root: string,
185
325
  positions: Positions,
186
- debug: Pick<CompileDebug, "stackTraces">,
326
+ {
327
+ debug,
328
+ configuration,
329
+ always,
330
+ io,
331
+ }: {
332
+ debug: Pick<CompileDebug, "stackTraces">;
333
+ /** The environment values the program's `env()` calls read, by name, which setup returns. */
334
+ configuration: Readonly<Record<string, string>>;
335
+ /** Whether every program is plain TypeScript, or only one that declares a plain class. */
336
+ always: boolean;
337
+ /** The state paths the config's `io` binds. */
338
+ io: readonly BoundPath[];
339
+ },
187
340
  ): {
188
341
  sources: Map<string, Mapped>;
189
342
  diagnostics: Diagnostic[];
@@ -210,27 +363,44 @@ export const lowerElaboration = (
210
363
  literals,
211
364
  references: { objects: references, fields: referenceFields },
212
365
  };
213
- const runtime = runtimeSources(program).filter(
214
- (source) => !source.isDeclarationFile && !inSdk(sdk, source.fileName),
366
+ const runtime = plcSources(program).filter(
367
+ (source) => !inSdk(sdk, source.fileName),
215
368
  );
216
369
  const checker = program.getTypeChecker();
370
+ // The bindings `io` reaches state through, which are never constants.
371
+ const bound = new Set(io.map(({ path }) => path.split(/[.[]/)[0] ?? path));
372
+ const inputs = new Map(
373
+ io.flatMap(({ path, input }) => (input === null ? [] : [[path, input]])),
374
+ );
375
+ const written = writtenBindings(runtime, checker);
217
376
  const kept = new Set(
218
377
  runtime
219
- .filter((source) => keptModule(source, checker, sdk))
378
+ .filter((source) => keptModule(source, checker, sdk, { written, bound }))
220
379
  .map((source) => source.fileName),
221
380
  );
222
381
  const isKept = (file: string) => kept.has(file);
223
- if (!needsElaboration(runtime, isKept, checker, sdk)) {
382
+ if (!always && !needsElaboration(runtime, isKept, checker, sdk)) {
224
383
  return result;
225
384
  }
226
- const [entry, ...otherEntries] = Object.values(entries);
227
- if (!entry || otherEntries.length) {
385
+ const scanFunctions = [
386
+ ...new Set(Object.values(entries).map((item) => item.export)),
387
+ ];
388
+ const modules = new Set(
389
+ Object.values(entries).map((item) =>
390
+ resolve(root, item.module).replace(/\\/g, "/"),
391
+ ),
392
+ );
393
+ const [entryFile, ...otherModules] = modules;
394
+ const [entry] = Object.values(entries);
395
+ if (!entry || !entryFile || otherModules.length) {
228
396
  diagnostics.push(
229
- error("PLC1001", "A plain TypeScript program has one entry function."),
397
+ error(
398
+ "PLC1001",
399
+ "A plain TypeScript program exports all its scan functions from one module.",
400
+ ),
230
401
  );
231
402
  return result;
232
403
  }
233
- const entryFile = resolve(root, entry.module).replace(/\\/g, "/");
234
404
  const entrySource = program.getSourceFile(entryFile);
235
405
  if (!entrySource) {
236
406
  diagnostics.push(
@@ -242,27 +412,45 @@ export const lowerElaboration = (
242
412
  /\\/g,
243
413
  "/",
244
414
  );
245
- // Failures statements recorded before one escaped: often its cause, as a skipped declaration's name is then unknown.
246
- let recorded = (): readonly SpecializeError[] => [];
247
-
248
415
  try {
249
- const declarations = retainedDeclarations(runtime, checker, sdk);
250
- const graph = captureGraph(entryFile, runtime, checker);
416
+ const refused = stringEnums(runtime, checker);
417
+ if (refused.length) {
418
+ throw new AggregateError(refused);
419
+ }
420
+ const declarations = retentionDeclarations(runtime, checker, sdk);
421
+ const graph = captureGraph(entryFile, runtime, checker, configuration);
251
422
  // Generic classes specialize per instance, through a checker that knows each one's type arguments.
252
423
  const generics = new GenericTypes(checker);
253
- const model = new Model(graph, generics.checker, program, entryFile, root);
254
- const rootModule = rootModules(model.roots, directory, root);
424
+ const model = new Model(graph, generics.checker, program, entryFile, root, {
425
+ bound,
426
+ inputs,
427
+ });
428
+ const rootModule = rootModules(model.roots, { directory, root, bound });
429
+ // A module that also holds state keeps its client and types, which a reply's type may need: the
430
+ // router's types have no layout of their own.
431
+ const named = (source: ts.SourceFile) =>
432
+ isKept(source.fileName) ||
433
+ serviceClients(source, checker, sdk).length > 0;
255
434
  const specializer = new Specializer(
256
435
  model,
257
436
  generics,
258
437
  sdk,
259
438
  runtime,
260
- isKept,
439
+ { kept: isKept, named },
261
440
  rootModule,
262
441
  );
263
- recorded = () => specializer.failures;
264
- const main = findEntry(entrySource, entry.export);
265
- const body = specializer.entry(main);
442
+ const scans = scanFunctions.map((name) => {
443
+ const declaration = findEntry(entrySource, name);
444
+ return {
445
+ name,
446
+ declaration,
447
+ body: specializedEntry(specializer, declaration),
448
+ };
449
+ });
450
+ const [main] = scans.map((scan) => scan.declaration);
451
+ if (!main) {
452
+ throw new Error("A plain TypeScript program needs a scan function.");
453
+ }
266
454
  if (specializer.failures.length) {
267
455
  diagnostics.push(
268
456
  ...specializer.failures.map((cause) =>
@@ -272,53 +460,42 @@ export const lowerElaboration = (
272
460
  return result;
273
461
  }
274
462
 
275
- // Exported data the hardware, HMI and server address is stored whether or not code reads it.
463
+ // Exported data the hardware, HMI and server address, and any object io binds the hardware
464
+ // to, is stored whether or not code reads it.
276
465
  for (const item of model.roots) {
277
- if (item.exported && !isKept(item.file) && item.file === entryFile) {
466
+ const addressed =
467
+ (item.exported && item.file === entryFile) || bound.has(item.name);
468
+ if (addressed && !isKept(item.file)) {
278
469
  specializer.storage.use(item);
279
470
  }
280
471
  }
281
472
 
282
- // Writing the globals declares the types they use, so they come before the types module.
283
- const retention = new Retention(model, specializer.storage, declarations);
284
- const globals = new Map<Root, Mapped[]>();
285
- for (const item of specializer.storage.roots) {
286
- globals.set(item, storageGlobals(specializer, retention, item));
473
+ for (const name of specializer.initializers.takeSdkCalls()) {
474
+ specializer.imports.addSdk(sdkModules.types, name);
287
475
  }
288
- const [unretained] = retention.unclaimed();
476
+ const retention = new Retention(model, specializer.storage, declarations);
477
+ const globals = new Map(
478
+ [...specializer.storage.roots].map((item) => [
479
+ item,
480
+ storageGlobals(specializer, retention, item),
481
+ ]),
482
+ );
483
+ const unretained = retention.unclaimed();
289
484
  if (unretained) {
290
485
  throw unretained;
291
486
  }
487
+ // Writing the globals declared the types they use.
488
+ const types = specializer.layouts.snapshot();
292
489
  const typesFile = `${directory}/types.ts`;
293
490
  const typeImports = (file: string) => [
294
491
  ...specializer.layouts.imports.lines(file, "import"),
295
492
  ...specializer.layouts.typeImports.lines(file, "import type"),
296
493
  ];
297
- const enums = specializer.layouts.enumNames;
298
- const interfaces = [...specializer.layouts.declarations.keys()].filter(
299
- (name) => !enums.includes(name),
300
- );
301
- const importTypes = (file: string) => [
302
- ...(enums.length
303
- ? [
304
- `import { ${enums.join(", ")} } from "${importPath(file, typesFile)}";`,
305
- ]
306
- : []),
307
- ...(interfaces.length
308
- ? [
309
- `import type { ${interfaces.join(", ")} } from "${importPath(file, typesFile)}";`,
310
- ]
311
- : []),
312
- ];
494
+ const importTypes = (file: string) =>
495
+ typesModuleImports(types, importPath(file, typesFile));
313
496
  sources.set(
314
497
  typesFile,
315
- joined(
316
- [
317
- ...typeImports(typesFile),
318
- ...specializer.layouts.declarations.values(),
319
- ],
320
- "\n",
321
- ),
498
+ joined([...typeImports(typesFile), ...types.declarations.values()], "\n"),
322
499
  );
323
500
  for (const [item, lines] of globals) {
324
501
  const file = rootModule(item);
@@ -344,9 +521,11 @@ export const lowerElaboration = (
344
521
  ...header.map((line) => from(main, line)),
345
522
  ...specializer.expressions.tableDeclarations,
346
523
  ...specializer.routines,
347
- from(main, `export function ${entry.export}(): void {`),
348
- ...body,
349
- from(closingBrace(main), "}"),
524
+ ...scans.flatMap(({ name, declaration, body }) => [
525
+ from(declaration, `export function ${name}(): void {`),
526
+ ...body,
527
+ from(closingBrace(declaration), "}"),
528
+ ]),
350
529
  ],
351
530
  "\n",
352
531
  ),
@@ -361,7 +540,7 @@ export const lowerElaboration = (
361
540
  references.push(...table.references);
362
541
  referenceFields.push(...table.referenceFields);
363
542
  for (const item of specializer.storage.folded()) {
364
- const known = constant(item.value, item.iec);
543
+ const known = foldedConstant(item.value, item.iec);
365
544
  if (known) {
366
545
  folded.push({
367
546
  path: item.path,
@@ -373,21 +552,54 @@ export const lowerElaboration = (
373
552
  // The plain modules now live in the generated code; keep only their types for type importers.
374
553
  for (const source of runtime) {
375
554
  if (source.fileName !== entryFile && !isKept(source.fileName)) {
376
- sources.set(source.fileName, typesOnly(source));
555
+ sources.set(source.fileName, typesOnly(source, checker, sdk));
377
556
  }
378
557
  }
379
558
  } catch (cause) {
559
+ const causes = cause instanceof AggregateError ? cause.errors : [cause];
380
560
  diagnostics.push(
381
- ...recorded().map((earlier) => failure(earlier, positions, debug)),
382
- failure(cause, positions, debug),
561
+ ...causes.map((reported) => failure(reported, positions, debug)),
383
562
  );
384
563
  }
385
564
  return result;
386
565
  };
387
566
 
567
+ /**
568
+ * The entry's specialized body. When specializing fails, the failures statements recorded before
569
+ * escape with the cause: often they are its cause, as a skipped declaration's name is then unknown.
570
+ */
571
+ const specializedEntry = (
572
+ specializer: Specializer,
573
+ main: ts.FunctionDeclaration | ts.ArrowFunction,
574
+ ): Mapped[] => {
575
+ try {
576
+ return specializer.entry(main);
577
+ } catch (cause) {
578
+ throw new AggregateError([...specializer.failures, cause]);
579
+ }
580
+ };
581
+
582
+ /** The imports of what the types module declares, from a module that reaches it at `path`. */
583
+ const typesModuleImports = (
584
+ types: TypeDeclarations,
585
+ path: string,
586
+ ): string[] => {
587
+ const interfaces = [...types.declarations.keys()].filter(
588
+ (name) => !types.enums.includes(name),
589
+ );
590
+ return [
591
+ ...(types.enums.length
592
+ ? [`import { ${types.enums.join(", ")} } from "${path}";`]
593
+ : []),
594
+ ...(interfaces.length
595
+ ? [`import type { ${interfaces.join(", ")} } from "${path}";`]
596
+ : []),
597
+ ];
598
+ };
599
+
388
600
  /**
389
601
  * The globals of a root's storage module: one per stored field of a record or instance, or the
390
- * root itself. Other modules can't assign an imported binding, so each global comes with a setter.
602
+ * root itself. The entry module assigns them through its namespace import of this module.
391
603
  */
392
604
  const storageGlobals = (
393
605
  specializer: Specializer,
@@ -396,104 +608,80 @@ const storageGlobals = (
396
608
  ): Mapped[] => {
397
609
  const { model, checker, layouts, storage, initializers } = specializer;
398
610
  const lines: Mapped[] = [];
399
- const retained: string[] = [];
400
- const global = (
401
- name: string,
402
- layout: string,
403
- initial: string,
404
- declaration: ts.Node | undefined,
405
- ) => {
611
+ /** The SDK calls the globals' initializers are wrapped in, `retain` or `persist`. */
612
+ const kept = new Set<string>();
613
+ const global = ({
614
+ name,
615
+ layout,
616
+ initial,
617
+ declaration,
618
+ }: {
619
+ name: string;
620
+ layout: string;
621
+ initial: string;
622
+ declaration: ts.Node | undefined;
623
+ }) => {
406
624
  const origin = declaration ?? item.declaration;
407
- const kept = retention.global(item, storage.flattened(item) ? name : null);
408
- if (kept) {
409
- retained.push(name);
625
+ const keeps = retention.global(item, storage.flattened(item) ? name : null);
626
+ if (keeps !== "none") {
627
+ kept.add(keeps);
410
628
  }
411
- const value = kept ? `retain(${initial})` : initial;
412
- lines.push(
413
- from(origin, `export let ${name}: ${layout} = ${value};`),
414
- from(
415
- origin,
416
- `export function ${setterName(name)}(value: ${layout}): void { ${name} = value; }`,
417
- ),
418
- );
629
+ const value = keeps === "none" ? initial : `${keeps}(${initial})`;
630
+ lines.push(from(origin, `export let ${name}: ${layout} = ${value};`));
419
631
  };
420
632
  const node = model.node(item.value);
633
+ const sdkImports = (): Mapped[] => {
634
+ const calls = [...[...kept].sort(), ...initializers.takeSdkCalls()];
635
+ return calls.length
636
+ ? [
637
+ from(
638
+ item.declaration,
639
+ `import { ${calls.join(", ")} } from "${sdkModules.types}";`,
640
+ ),
641
+ ]
642
+ : [];
643
+ };
421
644
  if (!node || !storage.flattened(item)) {
422
645
  const declared = checker.getTypeAtLocation(item.declaration.name);
423
- // An array of instances stores each instance's state, not its class.
424
- const instances =
425
- node?.captured.kind === "array" &&
426
- node.captured.items.some(
427
- (value) => model.node(value)?.captured.kind === "instance",
428
- );
429
- const layout =
430
- (instances && node && storage.storageType(node)) ||
431
- layouts.declaredText(item.declaration, declared, item.value);
432
- global(
433
- item.name,
646
+ const layout = layouts.declaredText(item.declaration, declared, item.value);
647
+ global({
648
+ name: item.name,
434
649
  layout,
435
- initializers.valueText(item.value, declared, layout),
436
- item.declaration,
437
- );
438
- return lines;
650
+ initial: initializers.valueText(item.value, declared, layout),
651
+ declaration: item.declaration,
652
+ });
653
+ return [...sdkImports(), ...lines];
439
654
  }
440
- const captured = node.captured;
441
- if (captured.kind === "instance") {
442
- const declaration = model.classOf(node);
443
- for (const [name, layout] of storage.instanceFields(node)) {
444
- global(
445
- name,
446
- layout,
447
- initializers.instanceFieldInitializer(node, name, layout),
448
- model.member(declaration, name),
449
- );
655
+ const fieldInitializer = (name: string, layout: string): string => {
656
+ if (node.captured.kind === "instance") {
657
+ return initializers.instanceFieldInitializer(node, name, layout);
450
658
  }
451
- } else if (captured.kind === "object") {
452
- for (const [name, field] of Object.entries(captured.fields)) {
453
- const inner = model.node(field);
454
- const declared = model.capturedFieldType(node, name);
455
- if (!declared) {
456
- continue;
457
- }
458
- const stored = item.exported || storage.stored(node, name);
459
- if (!stored && !inner) {
460
- continue;
461
- }
462
- const property = node.type?.getProperty(name)?.valueDeclaration;
463
- const layout =
464
- inner && !item.exported
465
- ? storage.storageType(inner)
466
- : layouts.declaredText(
467
- property,
468
- declared,
469
- field,
470
- name.charAt(0).toUpperCase() + name.slice(1),
471
- );
472
- if (!layout) {
473
- continue;
474
- }
475
- global(
476
- name,
477
- layout,
478
- initializers.valueText(field, declared, layout),
479
- property,
480
- );
659
+ const declared = model.capturedFieldType(node, name);
660
+ if (!declared) {
661
+ throw new Error(`${item.name}.${name} has no declared type.`);
481
662
  }
663
+ return initializers.valueText(model.field(node, name), declared, layout);
664
+ };
665
+ for (const field of storage.rootFields(item)) {
666
+ global({
667
+ ...field,
668
+ initial: fieldInitializer(field.name, field.layout),
669
+ });
482
670
  }
483
- return retained.length
484
- ? [
485
- from(
486
- item.declaration,
487
- 'import { retain } from "@tsplc/compiler/types";',
488
- ),
489
- ...lines,
490
- ]
491
- : lines;
671
+ return [...sdkImports(), ...lines];
492
672
  };
493
673
 
494
- /** A plain module reduced to the types other modules may import from it. */
495
- const typesOnly = (source: ts.SourceFile): Mapped =>
496
- joined(
674
+ /**
675
+ * A plain module reduced to the types other modules may import from it, and the service client it
676
+ * creates, which scan code calls through this module as it does through a module of constants.
677
+ */
678
+ const typesOnly = (
679
+ source: ts.SourceFile,
680
+ checker: ts.TypeChecker,
681
+ sdk: string,
682
+ ): Mapped => {
683
+ const clients = serviceClients(source, checker, sdk);
684
+ return joined(
497
685
  [
498
686
  ...source.statements
499
687
  .filter(
@@ -501,13 +689,47 @@ const typesOnly = (source: ts.SourceFile): Mapped =>
501
689
  ts.isInterfaceDeclaration(statement) ||
502
690
  ts.isTypeAliasDeclaration(statement) ||
503
691
  (ts.isImportDeclaration(statement) &&
504
- statement.importClause?.isTypeOnly),
692
+ (statement.importClause?.isTypeOnly ||
693
+ (clients.length > 0 && importsSdk(statement)))) ||
694
+ clients.includes(statement),
505
695
  )
506
696
  .map(copied),
507
697
  "export {};",
508
698
  ],
509
699
  "\n",
510
700
  );
701
+ };
702
+
703
+ /** A module's statements that create the service client. */
704
+ const serviceClients = (
705
+ source: ts.SourceFile,
706
+ checker: ts.TypeChecker,
707
+ sdk: string,
708
+ ): ts.Statement[] =>
709
+ source.statements.filter(
710
+ (statement) =>
711
+ ts.isVariableStatement(statement) &&
712
+ statement.declarationList.declarations.every(
713
+ (declaration) =>
714
+ declaration.initializer &&
715
+ ts.isCallExpression(declaration.initializer) &&
716
+ namesSdk(
717
+ checker,
718
+ sdk,
719
+ declaration.initializer.expression,
720
+ "createServiceClient",
721
+ ),
722
+ ),
723
+ );
724
+
725
+ /** Whether an import names one of the SDK's modules, which every module can import. */
726
+ const importsSdk = (statement: ts.ImportDeclaration): boolean => {
727
+ const specifier = statement.moduleSpecifier;
728
+ return (
729
+ ts.isStringLiteral(specifier) &&
730
+ Object.values(sdkModules).some((module) => module === specifier.text)
731
+ );
732
+ };
511
733
 
512
734
  /** An elaboration failure as a diagnostic, at the node specialization stopped at when it knows one. */
513
735
  const failure = (
@@ -557,22 +779,47 @@ const findEntry = (
557
779
 
558
780
  /**
559
781
  * Each root's storage module. Roots in different modules can share a name, up to case, and would
560
- * then share one module and its list; each of them is qualified by its own module instead.
782
+ * then share one module and its list; each of them is qualified by its own module instead. The
783
+ * config's `io` names a root by its binding name, which then names none of them, so that is refused.
561
784
  */
562
785
  const rootModules = (
563
786
  roots: readonly Root[],
564
- directory: string,
565
- projectRoot: string,
787
+ {
788
+ directory,
789
+ root: projectRoot,
790
+ bound,
791
+ }: { directory: string; root: string; bound: ReadonlySet<string> },
566
792
  ): ((item: Root) => string) => {
567
793
  const counts = new Map<string, number>();
568
794
  for (const item of roots) {
569
795
  const key = item.name.toLowerCase();
570
796
  counts.set(key, (counts.get(key) ?? 0) + 1);
571
797
  }
798
+ const shareName = (item: Root) =>
799
+ roots.filter(
800
+ (other) => other.name.toLowerCase() === item.name.toLowerCase(),
801
+ );
802
+ const ambiguous = roots.filter(
803
+ (item) => bound.has(item.name) && shareName(item).length > 1,
804
+ );
805
+ if (ambiguous.length) {
806
+ throw new AggregateError(
807
+ ambiguous.map((item) => {
808
+ const modules = shareName(item).map((other) =>
809
+ modulePath(projectRoot, other.file),
810
+ );
811
+ return new SpecializeError(
812
+ item.declaration,
813
+ `The config's io names this root ${item.name}, which roots in ${modules.join(" and ")} share: rename one of them.`,
814
+ );
815
+ }),
816
+ );
817
+ }
572
818
  return (item) => {
573
819
  const shared = (counts.get(item.name.toLowerCase()) ?? 0) > 1;
574
- const module = relative(projectRoot, item.file).replace(/\\/g, "/");
575
- const name = shared ? `${item.name}_${identityDigest(module)}` : item.name;
820
+ const name = shared
821
+ ? `${item.name}_${identityDigest(modulePath(projectRoot, item.file))}`
822
+ : item.name;
576
823
  return `${directory}/${name}.ts`;
577
824
  };
578
825
  };