@tsplc/compiler 0.5.18 → 0.6.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/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.5.18",
20
+ "version": "0.6.0",
21
21
  "type": "module",
22
22
  "exports": {
23
23
  ".": {
@@ -93,17 +93,17 @@
93
93
  "bun": ">=1.4.3"
94
94
  },
95
95
  "dependencies": {
96
- "@tsplc/agent": "0.5.18",
97
- "@tsplc/build": "0.5.18",
98
- "@tsplc/config": "0.5.18",
99
- "@tsplc/debug": "0.5.18",
100
- "@tsplc/opcua": "0.5.18",
101
- "@tsplc/typegen": "0.5.18",
96
+ "@tsplc/agent": "0.6.0",
97
+ "@tsplc/build": "0.6.0",
98
+ "@tsplc/config": "0.6.0",
99
+ "@tsplc/debug": "0.6.0",
100
+ "@tsplc/opcua": "0.6.0",
101
+ "@tsplc/typegen": "0.6.0",
102
102
  "typescript": "6.0.3",
103
103
  "zod": "4.3.6",
104
104
  "@types/bun": "1.4.2",
105
- "@tsplc/server": "0.5.18",
106
- "@tsplc/iec": "0.5.18"
105
+ "@tsplc/server": "0.6.0",
106
+ "@tsplc/iec": "0.6.0"
107
107
  },
108
108
  "bin": {
109
109
  "tsplc": "./dist/cli.js"
@@ -1,5 +1,5 @@
1
1
  import { canAssign, integerType, primitiveTypes } from "@tsplc/compiler/ir";
2
- import { elementaryType } from "@tsplc/iec";
2
+ import { elementaryType, fitsNumber, isIntegerValued } from "@tsplc/iec";
3
3
  import ts from "typescript";
4
4
  import { joined, type Mapped, mapped } from "../positions";
5
5
  import { sdkModules } from "../sdk";
@@ -363,7 +363,10 @@ export class DialectText {
363
363
  left.kind === "code" ? (left.declared ?? declared) : declared,
364
364
  );
365
365
  if (left.kind !== "code" || right.kind !== "code") {
366
- return [leftText, rightText];
366
+ return [
367
+ bigintBeside(left, right, leftText),
368
+ bigintBeside(right, left, rightText),
369
+ ];
367
370
  }
368
371
  const from = left.iec ?? defaultNumericTypes.number;
369
372
  const to = right.iec ?? defaultNumericTypes.number;
@@ -388,7 +391,10 @@ export class DialectText {
388
391
  if (left.kind !== "code" || right.kind !== "code") {
389
392
  const operand = left.kind === "code" ? left : right;
390
393
  return {
391
- texts: [leftText, rightText],
394
+ texts: [
395
+ bigintBeside(left, right, leftText),
396
+ bigintBeside(right, left, rightText),
397
+ ],
392
398
  iec: operand.kind === "code" ? operand.iec : undefined,
393
399
  };
394
400
  }
@@ -408,6 +414,29 @@ export class DialectText {
408
414
  }
409
415
  }
410
416
 
417
+ /** Whether TypeScript holds an integer of this IEC width as a bigint: the 64-bit ones. */
418
+ const bigintWidth = (iec: string | undefined): boolean => {
419
+ const type = iec === undefined ? undefined : elementaryType(iec);
420
+ return isIntegerValued(type) && !fitsNumber(type);
421
+ };
422
+
423
+ /**
424
+ * A whole number constant beside a 64-bit integer, which TypeScript holds as a bigint, written as one: a widened
425
+ * difference compared with or offset by a literal would otherwise mix a bigint and a number.
426
+ */
427
+ const bigintBeside = (
428
+ value: Value,
429
+ other: Value,
430
+ text: string | Mapped,
431
+ ): string | Mapped =>
432
+ value.kind === "const" &&
433
+ typeof value.value === "number" &&
434
+ Number.isInteger(value.value) &&
435
+ other.kind === "code" &&
436
+ bigintWidth(other.iec)
437
+ ? `${value.value}n`
438
+ : text;
439
+
411
440
  /** IEC integer and bit-string types by name. */
412
441
  const integerTypes = new Map(
413
442
  primitiveTypes.filter(integerType).map((type) => [type.id, type]),
@@ -257,11 +257,22 @@ export class Storage {
257
257
  return this.layouts.enumMember(keyType, Number(key)) ?? key;
258
258
  }
259
259
 
260
- /** A record or instance root becomes its own global list, one global per field. */
260
+ /**
261
+ * A record or instance root becomes its own global list, one global per field. A table keyed by
262
+ * enum members or numbers is stored whole: its keys name no global.
263
+ */
261
264
  flattened(root: Root): boolean {
262
265
  const node = this.model.node(root.value);
266
+ if (node?.captured.kind === "instance") {
267
+ return true;
268
+ }
269
+ if (node?.captured.kind !== "object") {
270
+ return false;
271
+ }
272
+ const key = node.type && recordTypes(node.type)?.key;
263
273
  return (
264
- node?.captured.kind === "object" || node?.captured.kind === "instance"
274
+ !key ||
275
+ (key.flags & (ts.TypeFlags.EnumLike | ts.TypeFlags.NumberLike)) === 0
265
276
  );
266
277
  }
267
278