@scriptc/compiler 0.0.8 → 0.0.9

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 (66) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +13 -0
  2. package/dist/backend/cc.js +14 -0
  3. package/dist/backend/cc.js.map +1 -1
  4. package/dist/backend/emission/emit-exprs.js +108 -5
  5. package/dist/backend/emission/emit-exprs.js.map +1 -1
  6. package/dist/backend/emission/emit-types.d.ts +3 -0
  7. package/dist/backend/emission/emit-types.js +12 -0
  8. package/dist/backend/emission/emit-types.js.map +1 -1
  9. package/dist/backend/emission/emit-walkers.d.ts +7 -5
  10. package/dist/backend/emission/emit-walkers.js +23 -10
  11. package/dist/backend/emission/emit-walkers.js.map +1 -1
  12. package/dist/backend/emission/emitter.d.ts +1 -1
  13. package/dist/backend/emission/emitter.js +30 -9
  14. package/dist/backend/emission/emitter.js.map +1 -1
  15. package/dist/backend/llvm/emitter.js +206 -11
  16. package/dist/backend/llvm/emitter.js.map +1 -1
  17. package/dist/diagnostics/diagnostic.d.ts +55 -10
  18. package/dist/diagnostics/diagnostic.js +82 -20
  19. package/dist/diagnostics/diagnostic.js.map +1 -1
  20. package/dist/frontend/lowering/lower-assert.js +16 -0
  21. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  22. package/dist/frontend/lowering/lower-builtins.d.ts +11 -0
  23. package/dist/frontend/lowering/lower-builtins.js +111 -3
  24. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  25. package/dist/frontend/lowering/lower-calls.d.ts +30 -11
  26. package/dist/frontend/lowering/lower-calls.js +418 -8
  27. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  28. package/dist/frontend/lowering/lower-classes.js +27 -1
  29. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  30. package/dist/frontend/lowering/lower-containers.d.ts +4 -2
  31. package/dist/frontend/lowering/lower-containers.js +193 -43
  32. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  33. package/dist/frontend/lowering/lower-emitter.js +54 -0
  34. package/dist/frontend/lowering/lower-emitter.js.map +1 -1
  35. package/dist/frontend/lowering/lower-exprs.js +52 -7
  36. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  37. package/dist/frontend/lowering/lower-stmts.js +445 -13
  38. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  39. package/dist/frontend/lowering/lower-stream.js +28 -2
  40. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  41. package/dist/frontend/lowering/lowerer.d.ts +66 -14
  42. package/dist/frontend/lowering/lowerer.js +273 -28
  43. package/dist/frontend/lowering/lowerer.js.map +1 -1
  44. package/dist/frontend/lowering/surfaces.js +20 -3
  45. package/dist/frontend/lowering/surfaces.js.map +1 -1
  46. package/dist/frontend/npm-static-rewrite.d.ts +7 -2
  47. package/dist/frontend/npm-static-rewrite.js +566 -138
  48. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  49. package/dist/frontend/npm-static.js +11 -2
  50. package/dist/frontend/npm-static.js.map +1 -1
  51. package/dist/frontend/program.js +5 -5
  52. package/dist/frontend/program.js.map +1 -1
  53. package/dist/frontend/shared.d.ts +6 -1
  54. package/dist/frontend/shared.js +46 -1
  55. package/dist/frontend/shared.js.map +1 -1
  56. package/dist/frontend/types.js +4 -2
  57. package/dist/frontend/types.js.map +1 -1
  58. package/dist/index.js +150 -25
  59. package/dist/index.js.map +1 -1
  60. package/dist/ir/nodes.d.ts +131 -7
  61. package/dist/ir/nodes.js +41 -3
  62. package/dist/ir/nodes.js.map +1 -1
  63. package/dist/ir/validate.js +58 -8
  64. package/dist/ir/validate.js.map +1 -1
  65. package/package.json +2 -2
  66. package/surface-manifest.json +10 -3
@@ -4,10 +4,10 @@
4
4
  * process.env access, and console.log detection. */
5
5
  import { builtinModules } from "node:module";
6
6
  import * as ts from "../ts7/adapter.js";
7
- import { dynUndefinedExpr, own } from "./lowerer.js";
7
+ import { dynUndefinedExpr, nodeThrowExpr, own } from "./lowerer.js";
8
8
  import { canonicalBuiltinModule, isJsSourceFile, locOf, requireSpecOf } from "../program.js";
9
9
  import { builtinModuleFnOf, FS_READDIR_DOCUMENTED_OPTIONS, FS_WATCH_DOCUMENTED_OPTIONS, FS_WRITE_FILE_DOCUMENTED_OPTIONS, QS_PARSE_DOCUMENTED_OPTIONS, QS_STRINGIFY_DOCUMENTED_OPTIONS, READLINE_DOCUMENTED_OPTIONS, builtinConstLit, fenceOrDropOptionKey, isChildSurfaceMember, } from "./surfaces.js";
10
- import { conditionalSpreadOf } from "./lower-exprs.js";
10
+ import { conditionalSpreadOf, lowerDynObjectLiteral } from "./lower-exprs.js";
11
11
  import { HTTP2_CONSTANTS } from "./http2-constants.js";
12
12
  import { timerStyleCallback } from "./lower-calls.js";
13
13
  import { registerHttpClientFnBinding } from "./lower-server.js";
@@ -352,6 +352,25 @@ function optionMember(p) {
352
352
  * arguments into a single array-literal argument; `defaults` complete
353
353
  * omitted trailing arguments. fs.readFileSync keeps its historical
354
354
  * per-site checks (the encoding must be the literal "utf8"). */
355
+ /** fs._toUnixTimestamp — the (underscore-stable) seconds coercion the
356
+ * utimes family runs on its time arguments: finite numbers pass
357
+ * (negatives answer now/1000, Node's shape), numeric STRINGS coerce
358
+ * through ToNumber's loose-equality gate, everything else throws
359
+ * Node's exact ERR_INVALID_ARG_TYPE. The argument crosses as a DOM
360
+ * value so the runtime renders the Received tail. Null when this is
361
+ * not that call (the table fence stays for other shapes). */
362
+ export function lowerFsToUnixTimestampCall(L, expr, bi, loc) {
363
+ if (bi.module !== "fs" || bi.member !== "_toUnixTimestamp")
364
+ return null;
365
+ if (expr.arguments.length !== 1 || ts.isSpreadElement(expr.arguments[0]))
366
+ return null;
367
+ const raw = L.lowerExpr(expr.arguments[0]);
368
+ if (raw.type.kind === "dyn" || raw.kind === "unitLit" || L.dynConvertible(raw.type)) {
369
+ const arg = raw.type.kind === "dyn" ? raw : { kind: "dynFrom", value: raw, type: DYN, loc };
370
+ return { kind: "libCall", fn: "fs.toUnixTimestamp", args: [arg], type: F64, loc };
371
+ }
372
+ return null;
373
+ }
355
374
  export function lowerBuiltinModuleCall(L, expr, bi, fn, loc) {
356
375
  const name = expr.expression.getText();
357
376
  if (bi.module === "child_process" && bi.member === "spawnSync") {
@@ -2970,7 +2989,96 @@ export function lowerSearchParamsMethodCall(L, call, access) {
2970
2989
  const name = access.name.text;
2971
2990
  const loc = locOf(call);
2972
2991
  const args = call.arguments;
2973
- const strArg = (i) => L.lowerExprExpecting(args[i], STRING);
2992
+ // The WHATWG arity ladder: too few arguments throw Node's
2993
+ // ERR_MISSING_ARGS before any conversion (the invalid-input probes'
2994
+ // `params.get()`). Claimed for effect-free receivers only — the
2995
+ // throw replaces the whole call, so an effectful receiver expression
2996
+ // keeps the fence below.
2997
+ const required = {
2998
+ get: [1, 'The "name" argument must be specified'],
2999
+ getAll: [1, 'The "name" argument must be specified'],
3000
+ has: [1, 'The "name" argument must be specified'],
3001
+ delete: [1, 'The "name" argument must be specified'],
3002
+ append: [2, 'The "name" and "value" arguments must be specified'],
3003
+ set: [2, 'The "name" and "value" arguments must be specified'],
3004
+ };
3005
+ const req = own(required, name);
3006
+ if (req && args.length < req[0] && ts.isIdentifier(access.expression)) {
3007
+ // The present-but-short forms still convert nothing in Node — the
3008
+ // arity check runs first; present arguments are identifierish
3009
+ // probes ('a') whose evaluation is pure in every suite shape, and
3010
+ // effectful ones would land here too (statement-coarsening, the
3011
+ // runtimeFence precedent).
3012
+ return nodeThrowExpr(1, "ERR_MISSING_ARGS", req[1], L.mapTypeOf(L.typeOf(call)) ?? VOID, loc);
3013
+ }
3014
+ // One name/value slot, WHATWG USVString rules: statically-string
3015
+ // arguments lower directly; a symbol can never convert (V8's
3016
+ // TypeError, statically decided); everything else crosses into the
3017
+ // DOM and coerces at runtime with the object protocol (a user
3018
+ // toString/valueOf runs and its throw propagates).
3019
+ const strArg = (i) => {
3020
+ const node = args[i];
3021
+ const t = L.mapTypeOf(L.typeOf(node));
3022
+ if (t?.kind === "string")
3023
+ return L.lowerExprExpecting(node, STRING);
3024
+ if (t?.kind === "symbol") {
3025
+ return nodeThrowExpr(1, "", "Cannot convert a Symbol value to a string", STRING, loc);
3026
+ }
3027
+ let v;
3028
+ if (ts.isObjectLiteralExpression(node)) {
3029
+ // Object literals take the DOM literal path directly (method
3030
+ // members box as dyn functions — the typed record fence never
3031
+ // applies to the coercion probes).
3032
+ v = lowerDynObjectLiteral(L, node);
3033
+ }
3034
+ else {
3035
+ const raw = L.lowerExpr(node);
3036
+ if (raw.type.kind === "dyn")
3037
+ v = raw;
3038
+ else if (raw.kind === "unitLit" || L.dynConvertible(raw.type)) {
3039
+ v = { kind: "dynFrom", value: raw, type: DYN, loc: raw.loc };
3040
+ }
3041
+ else if (raw.type.kind === "record") {
3042
+ // A RECORD-represented value that cannot cross into the DOM (a
3043
+ // func-carrying shape — the throwing-toString probes): run
3044
+ // ToPrimitive's string hint STATICALLY. A zero-parameter
3045
+ // toString func member is called (its throw propagates); a
3046
+ // string answer is the conversion, and a void/never-typed one
3047
+ // (the always-throwing probe shape, or a bare undefined return)
3048
+ // stringifies as ToString(undefined). Other shapes keep the
3049
+ // fence — honesty over coverage.
3050
+ const shape = L.shapes.get(raw.type.shapeId);
3051
+ const tsMember = shape?.fields.find((f) => f.name === "toString");
3052
+ if (shape &&
3053
+ tsMember &&
3054
+ tsMember.type.kind === "func" &&
3055
+ tsMember.type.params.length === 0 &&
3056
+ L.dynConvertible(tsMember.type)) {
3057
+ // Box just the toString member into a fresh DOM carrier and
3058
+ // run the protocol at runtime — the boxed call propagates its
3059
+ // throw, string answers convert, and a bare (void) return is
3060
+ // ToString(undefined), all through one path.
3061
+ const member = { kind: "recordGet", obj: raw, shapeId: raw.type.shapeId, field: "toString", type: tsMember.type, loc };
3062
+ v = {
3063
+ kind: "dynObjLit",
3064
+ fields: [{
3065
+ key: { kind: "strLit", value: "toString", type: STRING, loc },
3066
+ value: { kind: "dynFrom", value: member, type: DYN, loc },
3067
+ }],
3068
+ type: DYN,
3069
+ loc,
3070
+ };
3071
+ }
3072
+ else {
3073
+ L.noLowering(`URLSearchParams.${name} with a '${L.fmt(raw.type)}' argument`, node, "string arguments are the lowered shape (other values coerce through the DOM — narrow unions first)");
3074
+ }
3075
+ }
3076
+ else {
3077
+ L.noLowering(`URLSearchParams.${name} with a '${L.fmt(raw.type)}' argument`, node, "string arguments are the lowered shape (other values coerce through the DOM — narrow unions first)");
3078
+ }
3079
+ }
3080
+ return { kind: "libCall", fn: "dyn.toStringCoerce", args: [v], type: STRING, loc };
3081
+ };
2974
3082
  // has/delete's OPTIONAL value argument: absent, or an explicitly
2975
3083
  // undefined-typed expression (Node treats explicit undefined as the
2976
3084
  // name-only form). A `string | undefined` union has two behaviors in