@scriptc/compiler 0.0.22 → 0.0.23

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 (68) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +39 -3
  2. package/dist/backend/emission/emit-async.js +3 -1
  3. package/dist/backend/emission/emit-async.js.map +1 -1
  4. package/dist/backend/emission/emit-exprs.d.ts +10 -0
  5. package/dist/backend/emission/emit-exprs.js +127 -10
  6. package/dist/backend/emission/emit-exprs.js.map +1 -1
  7. package/dist/backend/emission/emit-stmts.js +13 -5
  8. package/dist/backend/emission/emit-stmts.js.map +1 -1
  9. package/dist/backend/emission/emit-types.js +4 -1
  10. package/dist/backend/emission/emit-types.js.map +1 -1
  11. package/dist/backend/emission/emitter.d.ts +11 -1
  12. package/dist/backend/emission/emitter.js +61 -1
  13. package/dist/backend/emission/emitter.js.map +1 -1
  14. package/dist/backend/llvm/emitter.js +304 -21
  15. package/dist/backend/llvm/emitter.js.map +1 -1
  16. package/dist/backend/llvm/shapes.js +3 -2
  17. package/dist/backend/llvm/shapes.js.map +1 -1
  18. package/dist/compat/fetch-profile.d.ts +10 -0
  19. package/dist/compat/fetch-profile.js +55 -6
  20. package/dist/compat/fetch-profile.js.map +1 -1
  21. package/dist/coverage/surface-manifest.js +16 -1
  22. package/dist/coverage/surface-manifest.js.map +1 -1
  23. package/dist/diagnostics/diagnostic.d.ts +10 -0
  24. package/dist/diagnostics/diagnostic.js +27 -1
  25. package/dist/diagnostics/diagnostic.js.map +1 -1
  26. package/dist/frontend/lowering/lower-builtins.d.ts +3 -7
  27. package/dist/frontend/lowering/lower-builtins.js +80 -55
  28. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  29. package/dist/frontend/lowering/lower-calls.js +1 -0
  30. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  31. package/dist/frontend/lowering/lower-classes.js +28 -8
  32. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  33. package/dist/frontend/lowering/lower-exprs.d.ts +1 -1
  34. package/dist/frontend/lowering/lower-exprs.js +25 -4
  35. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  36. package/dist/frontend/lowering/lower-generators.js +7 -1
  37. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  38. package/dist/frontend/lowering/lower-island.d.ts +21 -0
  39. package/dist/frontend/lowering/lower-island.js +284 -10
  40. package/dist/frontend/lowering/lower-island.js.map +1 -1
  41. package/dist/frontend/lowering/lower-stmts.js +8 -4
  42. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  43. package/dist/frontend/lowering/lowerer.d.ts +1 -0
  44. package/dist/frontend/lowering/lowerer.js +6 -2
  45. package/dist/frontend/lowering/lowerer.js.map +1 -1
  46. package/dist/frontend/lowering/surfaces.js +43 -12
  47. package/dist/frontend/lowering/surfaces.js.map +1 -1
  48. package/dist/frontend/program.d.ts +4 -4
  49. package/dist/frontend/program.js +264 -46
  50. package/dist/frontend/program.js.map +1 -1
  51. package/dist/frontend/resolve.d.ts +10 -0
  52. package/dist/frontend/resolve.js +37 -0
  53. package/dist/frontend/resolve.js.map +1 -1
  54. package/dist/frontend/ts7/enums.d.ts +9 -0
  55. package/dist/frontend/ts7/enums.js +8 -6
  56. package/dist/frontend/ts7/enums.js.map +1 -1
  57. package/dist/frontend/ts7/program.js +4 -1
  58. package/dist/frontend/ts7/program.js.map +1 -1
  59. package/dist/frontend/types.d.ts +4 -4
  60. package/dist/frontend/types.js +25 -8
  61. package/dist/frontend/types.js.map +1 -1
  62. package/dist/ir/nodes.d.ts +24 -11
  63. package/dist/ir/nodes.js +6 -1
  64. package/dist/ir/nodes.js.map +1 -1
  65. package/dist/ir/validate.js +45 -8
  66. package/dist/ir/validate.js.map +1 -1
  67. package/package.json +2 -2
  68. package/surface-manifest.json +137 -28
@@ -785,6 +785,41 @@ export function lowerBuiltinModuleCall(L, expr, bi, fn, loc) {
785
785
  if (bi.module === "fs" && bi.member === "watch") {
786
786
  return lowerFsWatchCall(L, expr, loc);
787
787
  }
788
+ // fs.readSync(fd, buffer, offset, length[, position]) — normalize the
789
+ // current-offset forms to Node/libuv's -1 sentinel so the IR and native
790
+ // ABI stay fixed-width. A real numeric position is a positioned read
791
+ // and therefore must not advance the descriptor. Literal null is the
792
+ // documented current-offset spelling; richer nullable expressions must
793
+ // narrow first so no effectful evaluation is silently discarded.
794
+ if (bi.module === "fs" && bi.member === "readSync") {
795
+ const supported = "use readSync(fd, buffer, offset, length[, position]) with a numeric position or literal null; options objects and bigint positions have no lowering";
796
+ if ((expr.arguments.length !== 4 && expr.arguments.length !== 5) ||
797
+ expr.arguments.some(ts.isSpreadElement)) {
798
+ L.noLowering(`readSync with ${expr.arguments.length} argument${expr.arguments.length === 1 ? "" : "s"}`, expr, supported);
799
+ }
800
+ const args = [
801
+ L.lowerExprExpecting(expr.arguments[0], F64),
802
+ L.lowerExprExpecting(expr.arguments[1], BYTES_U8),
803
+ L.lowerExprExpecting(expr.arguments[2], F64),
804
+ L.lowerExprExpecting(expr.arguments[3], F64),
805
+ ];
806
+ const positionNode = expr.arguments[4];
807
+ let positionValueNode = positionNode;
808
+ while (positionValueNode && ts.isParenthesizedExpression(positionValueNode)) {
809
+ positionValueNode = positionValueNode.expression;
810
+ }
811
+ if (positionNode === undefined || positionValueNode.kind === ts.SyntaxKind.NullKeyword) {
812
+ args.push({ kind: "numLit", value: -1, type: F64, loc });
813
+ }
814
+ else {
815
+ const positionType = L.mapTypeOf(L.typeOf(positionNode));
816
+ if (positionType?.kind !== "f64") {
817
+ L.noLowering(`readSync with a '${positionType ? L.fmt(positionType) : L.checker.typeToString(L.typeOf(positionNode))}' position`, positionNode, supported);
818
+ }
819
+ args.push(L.lowerExprExpecting(positionNode, F64));
820
+ }
821
+ return { kind: "libCall", fn: "fs.readSync", args, type: F64, loc };
822
+ }
788
823
  if (bi.module === "child_process" &&
789
824
  (bi.member === "execFileSync" || bi.member === "execSync")) {
790
825
  return L.lowerExecSyncCall(expr, bi.member === "execSync", loc);
@@ -5326,13 +5361,29 @@ export function lowerNumberStaticCall(L, call, access) {
5326
5361
  }
5327
5362
  return null; // other Number statics land on the member fence
5328
5363
  }
5329
- /** The Date slice: `Date.now()` and the COMPOSED
5330
- * `new Date(ms?).toISOString()` — the Date object between the two calls
5331
- * never exists (the crypto randomBytes(n).toString(enc) precedent). An
5332
- * omitted constructor argument completes with date.now; a one-argument
5333
- * form takes the milliseconds. String parsing, Y/M/D fields (local-time
5334
- * semantics), and Date VALUES stay fenced — lowerNew carries the hint.
5335
- * Null when this is neither form. */
5364
+ const DATE_GETTER_FNS = {
5365
+ getFullYear: "date.getFullYear",
5366
+ getUTCFullYear: "date.getUTCFullYear",
5367
+ getMonth: "date.getMonth",
5368
+ getUTCMonth: "date.getUTCMonth",
5369
+ getDate: "date.getDate",
5370
+ getUTCDate: "date.getUTCDate",
5371
+ getDay: "date.getDay",
5372
+ getUTCDay: "date.getUTCDay",
5373
+ getHours: "date.getHours",
5374
+ getUTCHours: "date.getUTCHours",
5375
+ getMinutes: "date.getMinutes",
5376
+ getUTCMinutes: "date.getUTCMinutes",
5377
+ getSeconds: "date.getSeconds",
5378
+ getUTCSeconds: "date.getUTCSeconds",
5379
+ getMilliseconds: "date.getMilliseconds",
5380
+ getUTCMilliseconds: "date.getUTCMilliseconds",
5381
+ getTimezoneOffset: "date.getTimezoneOffset",
5382
+ };
5383
+ const DATE_METHOD_HINT = "getTime(), valueOf(), toISOString(), the local/UTC calendar getters, and getTimezoneOffset() are supported; Date setters and locale/string formatters have no lowering";
5384
+ /** The Date slice: statics plus read-only Date values backed by one
5385
+ * TimeClip'd millisecond scalar. Construction lives in lowerNew;
5386
+ * identity and mutating methods remain fenced. */
5336
5387
  export function lowerDateCall(L, call, access) {
5337
5388
  if (call.questionDotToken || access.questionDotToken)
5338
5389
  return null;
@@ -5363,60 +5414,34 @@ export function lowerDateCall(L, call, access) {
5363
5414
  }
5364
5415
  return { kind: "libCall", fn: "date.utc", args, type: F64, loc };
5365
5416
  }
5366
- if (access.name.text !== "toISOString" && access.name.text !== "getTime")
5417
+ if (L.mapTypeOf(L.typeOf(access.expression))?.kind !== "date")
5367
5418
  return null;
5368
- const recv = access.expression;
5369
- if (!ts.isNewExpression(recv) || !ts.isIdentifier(recv.expression))
5370
- return null;
5371
- const sym = L.resolveValueSymbol(recv.expression);
5372
- if (!sym || sym.name !== "Date" || !L.isStdlibSymbol(sym))
5373
- return null;
5374
- if (access.name.text === "getTime") {
5375
- // The composed `new Date(x).getTime()` read — the Date value
5376
- // between the two never materializes (the toISOString precedent).
5377
- // new Date().getTime() IS Date.now(); the STRING form parses the
5378
- // bounded date-string grammar (the X509 validity shape portless's
5379
- // cert-expiry check reads, plus ECMA's own date-time format) and
5380
- // answers NaN elsewhere — a documented divergence from V8's wider
5381
- // parser. The ms form is pointless composition; the fence points at
5382
- // the value.
5383
- if (call.arguments.length !== 0) {
5384
- L.noLowering("getTime with arguments", call);
5385
- }
5386
- const ctorArgs = recv.arguments ?? [];
5387
- if (ctorArgs.length === 0) {
5388
- return { kind: "libCall", fn: "date.now", args: [], type: F64, loc };
5389
- }
5390
- if (ctorArgs.length !== 1) {
5391
- L.noLowering("new Date with year/month/day arguments", recv, "the field constructor is local-time; only new Date() and new Date(dateString) compose with .getTime()");
5392
- }
5393
- const arg = L.lowerExpr(ctorArgs[0]);
5394
- if (arg.type.kind !== "string") {
5395
- L.noLowering(`new Date of '${L.fmt(arg.type)}' values composed with .getTime()`, ctorArgs[0], arg.type.kind === "f64"
5396
- ? "new Date(ms).getTime() is the ms value — use it directly (or Date.now())"
5397
- : "the composed form parses date STRINGS — narrow unions first");
5398
- }
5399
- return { kind: "libCall", fn: "date.parseGetTime", args: [arg], type: F64, loc };
5400
- }
5419
+ if (!L.isStdlibMember(access))
5420
+ return null;
5421
+ const name = access.name.text;
5401
5422
  if (call.arguments.length !== 0) {
5402
- L.noLowering("toISOString with arguments", call);
5423
+ L.noLowering(`Date.prototype.${name} with arguments`, call, DATE_METHOD_HINT);
5403
5424
  }
5404
- const ctorArgs = recv.arguments ?? [];
5405
- let ms;
5406
- if (ctorArgs.length === 0) {
5407
- ms = { kind: "libCall", fn: "date.now", args: [], type: F64, loc };
5425
+ const receiver = L.lowerExpr(access.expression);
5426
+ if (receiver.type.kind !== "date")
5427
+ L.badType(access.expression, L.typeOf(access.expression));
5428
+ if (name === "getTime" || name === "valueOf") {
5429
+ return {
5430
+ kind: "libCall",
5431
+ fn: name === "getTime" ? "date.getTime" : "date.valueOf",
5432
+ args: [receiver],
5433
+ type: F64,
5434
+ loc,
5435
+ };
5408
5436
  }
5409
- else if (ctorArgs.length === 1) {
5410
- const arg = L.lowerExpr(ctorArgs[0]);
5411
- if (arg.type.kind !== "f64") {
5412
- L.noLowering(`new Date of '${L.fmt(arg.type)}' values`, ctorArgs[0], "only the milliseconds form composes — new Date(ms).toISOString(); date-string parsing has no lowering");
5413
- }
5414
- ms = arg;
5437
+ if (name === "toISOString") {
5438
+ return { kind: "libCall", fn: "date.toISOStringValue", args: [receiver], type: STRING, loc };
5415
5439
  }
5416
- else {
5417
- L.noLowering("new Date with year/month/day arguments", recv, "the field constructor is local-time; only new Date() and new Date(ms) compose with .toISOString()");
5440
+ const fn = DATE_GETTER_FNS[name];
5441
+ if (fn !== undefined) {
5442
+ return { kind: "libCall", fn, args: [receiver], type: F64, loc };
5418
5443
  }
5419
- return { kind: "libCall", fn: "date.toISOString", args: [ms], type: STRING, loc };
5444
+ L.noLowering(`Date.prototype.${name}`, call, DATE_METHOD_HINT, L.checker.getSymbolAtLocation(access.name));
5420
5445
  }
5421
5446
  /** A direct construction of THE stdlib TextEncoder/TextDecoder, through
5422
5447
  * type-only wrappers. Name alone is never enough: a user class with the