@tsplc/compiler 0.4.4 → 0.5.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/dist/codesys.js +2 -2
- package/dist/codesys.js.map +1 -1
- package/dist/index.js +13 -7
- package/dist/index.js.map +3 -3
- package/package.json +9 -9
- package/src/frontend/statements.ts +23 -6
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"url": "git+https://github.com/rip-technologies/tsplc.git",
|
|
18
18
|
"directory": "packages/compiler"
|
|
19
19
|
},
|
|
20
|
-
"version": "0.
|
|
20
|
+
"version": "0.5.0",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
@@ -101,17 +101,17 @@
|
|
|
101
101
|
"bun": ">=1.4.3"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@tsplc/agent": "0.
|
|
105
|
-
"@tsplc/build": "0.
|
|
106
|
-
"@tsplc/config": "0.
|
|
107
|
-
"@tsplc/debug": "0.
|
|
108
|
-
"@tsplc/opcua": "0.
|
|
109
|
-
"@tsplc/typegen": "0.
|
|
104
|
+
"@tsplc/agent": "0.5.0",
|
|
105
|
+
"@tsplc/build": "0.5.0",
|
|
106
|
+
"@tsplc/config": "0.5.0",
|
|
107
|
+
"@tsplc/debug": "0.5.0",
|
|
108
|
+
"@tsplc/opcua": "0.5.0",
|
|
109
|
+
"@tsplc/typegen": "0.5.0",
|
|
110
110
|
"typescript": "6.0.3",
|
|
111
111
|
"zod": "4.3.6",
|
|
112
112
|
"@types/bun": "1.4.2",
|
|
113
|
-
"@tsplc/server": "0.
|
|
114
|
-
"@tsplc/iec": "0.
|
|
113
|
+
"@tsplc/server": "0.5.0",
|
|
114
|
+
"@tsplc/iec": "0.5.0"
|
|
115
115
|
},
|
|
116
116
|
"bin": {
|
|
117
117
|
"tsplc": "./dist/cli.js"
|
|
@@ -29,6 +29,19 @@ interface LoopHeader {
|
|
|
29
29
|
existing: boolean;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* A case's statements, out of the braces that scope its declarations, as elaboration writes every case: they end where the
|
|
34
|
+
* braces do, and blocks lower without a scope of their own.
|
|
35
|
+
*/
|
|
36
|
+
const unbraced = (
|
|
37
|
+
statements: readonly ts.Statement[],
|
|
38
|
+
): readonly ts.Statement[] => {
|
|
39
|
+
const [only] = statements;
|
|
40
|
+
return statements.length === 1 && only && ts.isBlock(only)
|
|
41
|
+
? unbraced(only.statements)
|
|
42
|
+
: statements;
|
|
43
|
+
};
|
|
44
|
+
|
|
32
45
|
/**
|
|
33
46
|
* Lowers one routine's statements. Expressions, and the scope facts that
|
|
34
47
|
* declarations, branches and loops establish, go through its ExpressionLowering.
|
|
@@ -235,10 +248,11 @@ export class StatementLowering {
|
|
|
235
248
|
} else {
|
|
236
249
|
labels.push(this.caseValue(clause, value.type));
|
|
237
250
|
}
|
|
238
|
-
|
|
251
|
+
const statements = unbraced(clause.statements);
|
|
252
|
+
if (!statements.length) {
|
|
239
253
|
continue;
|
|
240
254
|
}
|
|
241
|
-
const body = this.caseBody(clause);
|
|
255
|
+
const body = this.caseBody(clause, statements);
|
|
242
256
|
if (labels.length) {
|
|
243
257
|
cases.push({ values: labels.splice(0), body });
|
|
244
258
|
}
|
|
@@ -271,10 +285,13 @@ export class StatementLowering {
|
|
|
271
285
|
}
|
|
272
286
|
|
|
273
287
|
/** A case's statements without the break that ends it. */
|
|
274
|
-
private caseBody(
|
|
275
|
-
|
|
288
|
+
private caseBody(
|
|
289
|
+
clause: ts.CaseOrDefaultClause,
|
|
290
|
+
statements: readonly ts.Statement[],
|
|
291
|
+
): Statement[] {
|
|
292
|
+
const last = statements.at(-1);
|
|
276
293
|
if (last && ts.isBreakStatement(last) && !last.label) {
|
|
277
|
-
return this.statements(
|
|
294
|
+
return this.statements(statements.slice(0, -1));
|
|
278
295
|
}
|
|
279
296
|
if (!(last && ts.isReturnStatement(last))) {
|
|
280
297
|
this.fail(
|
|
@@ -283,7 +300,7 @@ export class StatementLowering {
|
|
|
283
300
|
"Switch cases must end with break or return; fallthrough is prohibited.",
|
|
284
301
|
);
|
|
285
302
|
}
|
|
286
|
-
return this.statements(
|
|
303
|
+
return this.statements(statements);
|
|
287
304
|
}
|
|
288
305
|
|
|
289
306
|
private localDeclarations(node: ts.VariableStatement): Statement[] {
|