@scriptc/compiler 0.0.10 → 0.0.11

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 (78) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +54 -9
  2. package/dist/backend/emission/emit-exprs.js +34 -2
  3. package/dist/backend/emission/emit-exprs.js.map +1 -1
  4. package/dist/backend/emission/emitter.js +25 -1
  5. package/dist/backend/emission/emitter.js.map +1 -1
  6. package/dist/backend/llvm/emitter.js +59 -4
  7. package/dist/backend/llvm/emitter.js.map +1 -1
  8. package/dist/coverage/surface-manifest.js +16 -2
  9. package/dist/coverage/surface-manifest.js.map +1 -1
  10. package/dist/diagnostics/diagnostic.d.ts +20 -7
  11. package/dist/diagnostics/diagnostic.js +44 -11
  12. package/dist/diagnostics/diagnostic.js.map +1 -1
  13. package/dist/frontend/lowering/lower-builtins.d.ts +56 -0
  14. package/dist/frontend/lowering/lower-builtins.js +235 -4
  15. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  16. package/dist/frontend/lowering/lower-calls.js +38 -4
  17. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  18. package/dist/frontend/lowering/lower-classes.d.ts +7 -0
  19. package/dist/frontend/lowering/lower-classes.js +51 -1
  20. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  21. package/dist/frontend/lowering/lower-containers.d.ts +4 -0
  22. package/dist/frontend/lowering/lower-containers.js +69 -7
  23. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  24. package/dist/frontend/lowering/lower-emitter.d.ts +70 -3
  25. package/dist/frontend/lowering/lower-emitter.js +436 -29
  26. package/dist/frontend/lowering/lower-emitter.js.map +1 -1
  27. package/dist/frontend/lowering/lower-exprs.d.ts +80 -5
  28. package/dist/frontend/lowering/lower-exprs.js +472 -13
  29. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  30. package/dist/frontend/lowering/lower-modules.d.ts +8 -5
  31. package/dist/frontend/lowering/lower-modules.js +141 -47
  32. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  33. package/dist/frontend/lowering/lower-namespaces.d.ts +14 -0
  34. package/dist/frontend/lowering/lower-namespaces.js +122 -15
  35. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  36. package/dist/frontend/lowering/lower-stmts.js +80 -6
  37. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  38. package/dist/frontend/lowering/lower-stream.js +113 -6
  39. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  40. package/dist/frontend/lowering/lowerer.d.ts +17 -0
  41. package/dist/frontend/lowering/lowerer.js +105 -17
  42. package/dist/frontend/lowering/lowerer.js.map +1 -1
  43. package/dist/frontend/lowering/surfaces.d.ts +44 -0
  44. package/dist/frontend/lowering/surfaces.js +234 -3
  45. package/dist/frontend/lowering/surfaces.js.map +1 -1
  46. package/dist/frontend/npm.d.ts +12 -0
  47. package/dist/frontend/npm.js +30 -0
  48. package/dist/frontend/npm.js.map +1 -1
  49. package/dist/frontend/program.d.ts +25 -0
  50. package/dist/frontend/program.js +144 -135
  51. package/dist/frontend/program.js.map +1 -1
  52. package/dist/frontend/shared.d.ts +1 -1
  53. package/dist/frontend/shared.js +1 -1
  54. package/dist/frontend/shared.js.map +1 -1
  55. package/dist/index.d.ts +2 -1
  56. package/dist/index.js +137 -4
  57. package/dist/index.js.map +1 -1
  58. package/dist/ir/nodes.d.ts +64 -8
  59. package/dist/ir/nodes.js +21 -3
  60. package/dist/ir/nodes.js.map +1 -1
  61. package/dist/ir/validate.js +11 -2
  62. package/dist/ir/validate.js.map +1 -1
  63. package/dist/library/fence-eval.js +12 -2
  64. package/dist/library/fence-eval.js.map +1 -1
  65. package/dist/library/int-infer.d.ts +119 -0
  66. package/dist/library/int-infer.js +1301 -0
  67. package/dist/library/int-infer.js.map +1 -0
  68. package/dist/library/int-infer.test.d.ts +1 -0
  69. package/dist/library/int-infer.test.js +279 -0
  70. package/dist/library/int-infer.test.js.map +1 -0
  71. package/dist/library/profile.d.ts +32 -5
  72. package/dist/library/profile.js +77 -13
  73. package/dist/library/profile.js.map +1 -1
  74. package/dist/library/sidecar.d.ts +23 -0
  75. package/dist/library/sidecar.js +150 -16
  76. package/dist/library/sidecar.js.map +1 -1
  77. package/package.json +2 -2
  78. package/surface-manifest.json +208 -10
@@ -344,6 +344,10 @@ export declare function lowerBytesNew(L: Lowerer, expr: ts.NewExpression, symbol
344
344
  * else the lib declares (fill, indexOf, reverse, ...) falls through to
345
345
  * the SC2020 member fence. Null when this isn't a bytes method call. */
346
346
  export declare function lowerBytesMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
347
+ /** A literal encoding's canonical name, or undefined for a spelling Node
348
+ * does not know — the ladder callers (stream options) turn unknown
349
+ * literals into Node's runtime ERR_UNKNOWN_ENCODING throw. */
350
+ export declare function knownBufEncoding(name: string): string | undefined;
347
351
  /** The literal encoding argument of a Buffer surface, normalized — or a
348
352
  * fence when it isn't a literal alias Node knows. */
349
353
  export declare function bufEncoding(L: Lowerer, what: string, encNode: ts.Expression): string;
@@ -4004,9 +4004,26 @@ export function lowerRegexMethodCall(L, call, access, dynReceiver) {
4004
4004
  // [whole match, ...captures] or the null arm. The g-flag match returns
4005
4005
  // EVERY match (a different shape) and /y is stateful — both fence at
4006
4006
  // compile time on literal arguments (values reaching the runtime with
4007
- // those flags abort, the test() stance). `.index`/`.input`/`.groups`
4008
- // reads on the result fence per member (array-typed value).
4009
- if (receiverKind === "string" && name === "match") {
4007
+ // those flags abort, the test() stance). `.index`/`.input` reads on
4008
+ // the result fence per member (array-typed value); `.groups` reads
4009
+ // desugar at their access sites when the regex is statically known
4010
+ // (lowerMatchGroupsRead).
4011
+ // `s.match(re)` also claims a NULLABLE string receiver (string + unit
4012
+ // arms — `process.versions.openssl.match(...)`, the Dict<string>
4013
+ // member the node suite's crypto helper reads): the checked
4014
+ // extraction narrows to the string arm and a unit value throws the
4015
+ // catchable TypeError at the read, where Node's own member read
4016
+ // throws — tsc only admits the spelling in JS sources.
4017
+ const nullableStringRecv = receiverKind === "union" &&
4018
+ name === "match" &&
4019
+ (() => {
4020
+ const t = L.mapTypeOf(L.typeOf(access.expression));
4021
+ if (t?.kind !== "union")
4022
+ return false;
4023
+ const arms = L.unions.get(t.unionId)?.arms ?? [];
4024
+ return arms.some((a) => a.kind === "string") && arms.every((a) => a.kind === "string" || isUnitType(a));
4025
+ })();
4026
+ if ((receiverKind === "string" || nullableStringRecv) && name === "match") {
4010
4027
  const arg0 = call.arguments[0];
4011
4028
  if (!arg0 || L.mapTypeOf(L.typeOf(arg0))?.kind !== "regex")
4012
4029
  return null; // string-pattern match: the SC2020 fence
@@ -4021,7 +4038,7 @@ export function lowerRegexMethodCall(L, call, access, dynReceiver) {
4021
4038
  L.unsupported("SC1120", call, "'.match()' with the 'g' or 'y' flag (an every-match array is a different shape — use replaceAll/split, or test() per position)");
4022
4039
  }
4023
4040
  }
4024
- const receiver = lowerReceiver();
4041
+ const receiver = nullableStringRecv ? L.lowerExprExpecting(access.expression, STRING) : lowerReceiver();
4025
4042
  const re = L.lowerExpr(arg0);
4026
4043
  // RegExpMatchArray | null maps to the string[] | null union by
4027
4044
  // itself; intern it directly when the checker's spelling doesn't —
@@ -4395,8 +4412,30 @@ export function lowerBytesMethodCall(L, call, access) {
4395
4412
  }
4396
4413
  const receiver = L.lowerExpr(access.expression);
4397
4414
  const args = call.arguments.map((a) => L.lowerExprExpecting(a, F64));
4398
- // subarray COPIES here (no views exist) — SEMANTICS.md documents it.
4399
- return { kind: "bytesIntrinsic", method: "slice", receiver, args, type: receiverIr, loc };
4415
+ // subarray is a VIEW (TypedArray.prototype.subarray aliases), and
4416
+ // Buffer's slice() is subarray's deprecated Node alias — resolved by
4417
+ // where the member is declared, the toString discipline below. Only
4418
+ // the plain typed arrays' slice() copies (JS-exact).
4419
+ const declaredOnBuffer = name === "slice" &&
4420
+ (() => {
4421
+ const nameSym = L.checker.getSymbolAtLocation(access.name);
4422
+ return nameSym !== undefined && L.checker.declarationsOf(nameSym).some((d) => ts.isInterfaceDeclaration(d.parent) && d.parent.name.text === "Buffer");
4423
+ })();
4424
+ const method = name === "subarray" || declaredOnBuffer ? "subarray" : "slice";
4425
+ return { kind: "bytesIntrinsic", method, receiver, args, type: receiverIr, loc };
4426
+ }
4427
+ if (name === "fill" && receiverIr.elem !== "u8") {
4428
+ // TypedArray.prototype.fill on the non-u8 kinds: per-element value
4429
+ // coercion, slice-clamped relative indices, never throws. u8
4430
+ // receivers keep the Buffer fill family (string patterns, throwing
4431
+ // offset validation) — lowerBufferInstanceMethod's surface.
4432
+ if (nArgs < 1 || nArgs > 3) {
4433
+ L.noLowering(`.fill with ${nArgs} arguments on typed arrays`, call);
4434
+ }
4435
+ const receiver = L.lowerExpr(access.expression);
4436
+ const v = L.lowerExprExpecting(call.arguments[0], F64);
4437
+ const idx = call.arguments.slice(1).map((a) => L.lowerExprExpecting(a, F64));
4438
+ return { kind: "bytesIntrinsic", method: "fillElem", receiver, args: [v, ...idx], type: receiverIr, loc };
4400
4439
  }
4401
4440
  if (name === "set") {
4402
4441
  if (nArgs < 1 || nArgs > 2) {
@@ -4571,6 +4610,12 @@ const BUF_ENCODINGS = {
4571
4610
  ucs2: "utf16le",
4572
4611
  "ucs-2": "utf16le",
4573
4612
  };
4613
+ /** A literal encoding's canonical name, or undefined for a spelling Node
4614
+ * does not know — the ladder callers (stream options) turn unknown
4615
+ * literals into Node's runtime ERR_UNKNOWN_ENCODING throw. */
4616
+ export function knownBufEncoding(name) {
4617
+ return own(BUF_ENCODINGS, name);
4618
+ }
4574
4619
  /** The literal encoding argument of a Buffer surface, normalized — or a
4575
4620
  * fence when it isn't a literal alias Node knows. */
4576
4621
  export function bufEncoding(L, what, encNode) {
@@ -4853,6 +4898,22 @@ export function lowerBufferStaticCall(L, call, access) {
4853
4898
  const loc = locOf(call);
4854
4899
  const args = call.arguments;
4855
4900
  if (member === "from") {
4901
+ // Buffer.from(x.buffer[, byteOffset[, length]]): a u8 VIEW sharing
4902
+ // x's storage (Node shares the ArrayBuffer; length is in BYTES).
4903
+ // The first argument must be the SYNTACTIC `.buffer` of a typed
4904
+ // array — the DataView peel — and the construction rides the same
4905
+ // dataViewNew intrinsic (offset/length validation throws Node's
4906
+ // DataView-shaped RangeErrors; valid indices behave exactly).
4907
+ if (args.length >= 1 && args.length <= 3 && !args.some(ts.isSpreadElement) &&
4908
+ ts.isPropertyAccessExpression(args[0]) && args[0].name.text === "buffer") {
4909
+ const srcNode = args[0].expression;
4910
+ const srcIr = L.mapTypeOf(L.typeOf(srcNode));
4911
+ if (srcIr?.kind === "bytes") {
4912
+ const receiver = L.lowerExpr(srcNode);
4913
+ const idxArgs = args.slice(1).map((a) => L.lowerExprExpecting(a, F64));
4914
+ return { kind: "bytesIntrinsic", method: "dataViewNew", receiver, args: idxArgs, type: BYTES_U8, loc };
4915
+ }
4916
+ }
4856
4917
  if (args.length >= 1 && args.length <= 2 && !ts.isSpreadElement(args[0])) {
4857
4918
  const argNode = args[0];
4858
4919
  if (ts.isArrayLiteralExpression(argNode) && !argNode.elements.some(ts.isSpreadElement)) {
@@ -4882,7 +4943,8 @@ export function lowerBufferStaticCall(L, call, access) {
4882
4943
  }
4883
4944
  }
4884
4945
  L.noLowering("Buffer.from with this argument shape", call, "supported: Buffer.from(string, encoding?) with a literal encoding, Buffer.from(u8Array) — a copy — " +
4885
- "or Buffer.from(number[]); ArrayBuffers do not exist here (narrow unions first)");
4946
+ "Buffer.from(number[]), or Buffer.from(x.buffer, byteOffset?, length?) — a view sharing x's " +
4947
+ "storage (no free-standing ArrayBuffer value exists; narrow unions first)");
4886
4948
  }
4887
4949
  if (member === "alloc" || member === "allocUnsafe") {
4888
4950
  const maxArgs = member === "alloc" ? 3 : 1;