@scriptc/compiler 0.0.10 → 0.0.12

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 (111) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +63 -15
  2. package/ambient/scriptc.d.ts +2 -2
  3. package/dist/backend/cc.d.ts +2 -2
  4. package/dist/backend/emission/emit-async.js +1 -1
  5. package/dist/backend/emission/emit-exprs.js +131 -54
  6. package/dist/backend/emission/emit-exprs.js.map +1 -1
  7. package/dist/backend/emission/emit-island.js +1 -1
  8. package/dist/backend/emission/emit-shapes.js +1 -1
  9. package/dist/backend/emission/emit-walkers.d.ts +14 -14
  10. package/dist/backend/emission/emit-walkers.js +44 -44
  11. package/dist/backend/emission/emit-walkers.js.map +1 -1
  12. package/dist/backend/emission/emitter.d.ts +3 -3
  13. package/dist/backend/emission/emitter.js +33 -9
  14. package/dist/backend/emission/emitter.js.map +1 -1
  15. package/dist/backend/emission/may-throw.js +1 -1
  16. package/dist/backend/llvm/dyn.d.ts +10 -10
  17. package/dist/backend/llvm/dyn.js +26 -26
  18. package/dist/backend/llvm/dyn.js.map +1 -1
  19. package/dist/backend/llvm/emitter.js +156 -47
  20. package/dist/backend/llvm/emitter.js.map +1 -1
  21. package/dist/backend/llvm/shapes.js +1 -1
  22. package/dist/backend/llvm/walkers.js +2 -2
  23. package/dist/backend/llvm/walkers.js.map +1 -1
  24. package/dist/coverage/surface-manifest.js +16 -2
  25. package/dist/coverage/surface-manifest.js.map +1 -1
  26. package/dist/diagnostics/diagnostic.d.ts +21 -8
  27. package/dist/diagnostics/diagnostic.js +48 -14
  28. package/dist/diagnostics/diagnostic.js.map +1 -1
  29. package/dist/frontend/lowering/lib-boundary.js +5 -5
  30. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  31. package/dist/frontend/lowering/lower-assert.js +12 -12
  32. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  33. package/dist/frontend/lowering/lower-builtins.d.ts +63 -7
  34. package/dist/frontend/lowering/lower-builtins.js +327 -35
  35. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  36. package/dist/frontend/lowering/lower-calls.d.ts +4 -4
  37. package/dist/frontend/lowering/lower-calls.js +104 -70
  38. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  39. package/dist/frontend/lowering/lower-classes.d.ts +7 -0
  40. package/dist/frontend/lowering/lower-classes.js +82 -6
  41. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  42. package/dist/frontend/lowering/lower-containers.d.ts +9 -5
  43. package/dist/frontend/lowering/lower-containers.js +88 -26
  44. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  45. package/dist/frontend/lowering/lower-emitter.d.ts +70 -3
  46. package/dist/frontend/lowering/lower-emitter.js +438 -31
  47. package/dist/frontend/lowering/lower-emitter.js.map +1 -1
  48. package/dist/frontend/lowering/lower-exprs.d.ts +87 -12
  49. package/dist/frontend/lowering/lower-exprs.js +630 -125
  50. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  51. package/dist/frontend/lowering/lower-inspect.js +5 -5
  52. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  53. package/dist/frontend/lowering/lower-island.js +12 -3
  54. package/dist/frontend/lowering/lower-island.js.map +1 -1
  55. package/dist/frontend/lowering/lower-modules.d.ts +8 -5
  56. package/dist/frontend/lowering/lower-modules.js +157 -63
  57. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  58. package/dist/frontend/lowering/lower-namespaces.d.ts +24 -0
  59. package/dist/frontend/lowering/lower-namespaces.js +158 -16
  60. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  61. package/dist/frontend/lowering/lower-server.js +11 -11
  62. package/dist/frontend/lowering/lower-server.js.map +1 -1
  63. package/dist/frontend/lowering/lower-stmts.d.ts +1 -1
  64. package/dist/frontend/lowering/lower-stmts.js +271 -36
  65. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  66. package/dist/frontend/lowering/lower-stream.js +171 -20
  67. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  68. package/dist/frontend/lowering/lowerer.d.ts +27 -10
  69. package/dist/frontend/lowering/lowerer.js +156 -54
  70. package/dist/frontend/lowering/lowerer.js.map +1 -1
  71. package/dist/frontend/lowering/surfaces.d.ts +44 -0
  72. package/dist/frontend/lowering/surfaces.js +236 -5
  73. package/dist/frontend/lowering/surfaces.js.map +1 -1
  74. package/dist/frontend/npm.d.ts +12 -0
  75. package/dist/frontend/npm.js +30 -0
  76. package/dist/frontend/npm.js.map +1 -1
  77. package/dist/frontend/program.d.ts +25 -0
  78. package/dist/frontend/program.js +145 -136
  79. package/dist/frontend/program.js.map +1 -1
  80. package/dist/frontend/shared.d.ts +1 -1
  81. package/dist/frontend/shared.js +8 -8
  82. package/dist/frontend/shared.js.map +1 -1
  83. package/dist/frontend/types.d.ts +2 -2
  84. package/dist/frontend/types.js +15 -15
  85. package/dist/frontend/types.js.map +1 -1
  86. package/dist/index.d.ts +2 -1
  87. package/dist/index.js +169 -5
  88. package/dist/index.js.map +1 -1
  89. package/dist/ir/nodes.d.ts +174 -106
  90. package/dist/ir/nodes.js +69 -24
  91. package/dist/ir/nodes.js.map +1 -1
  92. package/dist/ir/validate.js +55 -36
  93. package/dist/ir/validate.js.map +1 -1
  94. package/dist/library/fence-eval.js +12 -2
  95. package/dist/library/fence-eval.js.map +1 -1
  96. package/dist/library/int-infer.d.ts +119 -0
  97. package/dist/library/int-infer.js +1314 -0
  98. package/dist/library/int-infer.js.map +1 -0
  99. package/dist/library/int-infer.test.d.ts +1 -0
  100. package/dist/library/int-infer.test.js +279 -0
  101. package/dist/library/int-infer.test.js.map +1 -0
  102. package/dist/library/profile.d.ts +34 -5
  103. package/dist/library/profile.js +77 -13
  104. package/dist/library/profile.js.map +1 -1
  105. package/dist/library/sidecar-validate.js +1 -1
  106. package/dist/library/sidecar-validate.js.map +1 -1
  107. package/dist/library/sidecar.d.ts +24 -1
  108. package/dist/library/sidecar.js +163 -16
  109. package/dist/library/sidecar.js.map +1 -1
  110. package/package.json +2 -2
  111. package/surface-manifest.json +210 -12
@@ -2,6 +2,7 @@ import * as ts from "../ts7/adapter.js";
2
2
  import type { Lowerer } from "./lowerer.js";
3
3
  import { IrClassDef, IrExpr, IrFunction, IrLocal, IrStmt, IrType, SrcLoc } from "../../ir/nodes.js";
4
4
  import { type GenericFnInfo, type ParamShape } from "./lower-calls.js";
5
+ import { type EmitOverrideRec } from "./lower-emitter.js";
5
6
  import { type MixinInstanceInfo } from "./lower-mixins.js";
6
7
  export interface ClassInfo {
7
8
  def: IrClassDef;
@@ -81,6 +82,12 @@ export interface ClassInfo {
81
82
  * the base chain. The value names which SIDES the class carries. User
82
83
  * `extends` of these classes is fenced at the declaration (phase 1). */
83
84
  builtinStream?: "r" | "w" | "rw";
85
+ /** This class's own `emit` override in the FORWARDING SHAPE (the one
86
+ * EventEmitter member a subclass may re-declare): never in `methods` —
87
+ * emit calls keep routing through the emitter spoke, which lowers the
88
+ * body once per event name as the specialization method `emit:<event>`
89
+ * (lower-emitter.ts's emit-overrides block has the whole story). */
90
+ emitOverride?: EmitOverrideRec;
84
91
  ctor: ts.ConstructorDeclaration | null;
85
92
  /** PARAMETER PROPERTIES (`constructor(public x: number)`), in parameter
86
93
  * order: each declares a field (placed BEFORE the class's declared
@@ -14,6 +14,7 @@ import { pureReemittable } from "./lower-exprs.js";
14
14
  import { lowerSearchParamsNew } from "./lower-builtins.js";
15
15
  import { requiresDynamicPackageDiag, unsupportedDiag } from "../../diagnostics/diagnostic.js";
16
16
  import { STREAM_API_MEMBERS, STREAM_PROP_MEMBERS, UNDERSCORE_METHODS, lowerStreamNew, lowerStreamSuperCall, streamCtorShape } from "./lower-stream.js";
17
+ import { emitOverrideShapeReason, emitSpecSuperForward, emitterRooted, lowerEmitterSuperCall } from "./lower-emitter.js";
17
18
  import { declSymbolOf } from "./lower-modules.js";
18
19
  import { uniqueSymbolKeyOf } from "./lower-exprs.js";
19
20
  import { lowerHttpServerNew } from "./lower-server.js";
@@ -473,6 +474,32 @@ export function collectClassShape(L, decl) {
473
474
  }
474
475
  }
475
476
  }
477
+ // A poisoned BASE this class EXTENDS must report EAGERLY for the same
478
+ // reason: the derived statement evaluates its heritage when module
479
+ // init reaches it (these are top-level declarations), and the base's
480
+ // fence is the COMPILER's, not Node's — Node defines the base fine and
481
+ // runs on — so a deferred trap there is a manufactured divergence, not
482
+ // the Node-parity deferral is licensed by (classFieldSuperAccessibleJs2:
483
+ // the binary refused at `class D extends C` where Node prints five
484
+ // lines). Leaf poisoned classes stay deferred — only the extends edge
485
+ // reports. Resolution runs under the collect pass's guard (this is
486
+ // collectProgram), so the lookup neither flushes nor fences.
487
+ {
488
+ const baseIdent = decl.heritageClauses
489
+ ?.find((h) => h.token === ts.SyntaxKind.ExtendsKeyword)
490
+ ?.types.map((t) => t.expression)
491
+ .filter(ts.isIdentifier)[0];
492
+ const baseSym = baseIdent ? L.resolveValueSymbol(baseIdent) : null;
493
+ const baseDiags = baseSym ? L.deferredDiags.get(baseSym) : undefined;
494
+ if (baseSym && baseDiags) {
495
+ L.deferredDiags.delete(baseSym);
496
+ if (!L.alreadyFlushed.has(baseSym)) {
497
+ L.flushedSymbols.add(baseSym);
498
+ for (const d of baseDiags)
499
+ L.pushDiag(d);
500
+ }
501
+ }
502
+ }
476
503
  }
477
504
  export function collectClassShapeInner(L, decl, jsNameOverride, inst,
478
505
  /** MIXIN instantiation mode (lower-mixins.ts): the class inside a
@@ -814,6 +841,10 @@ mixin) {
814
841
  * symbol-slot refinement retries them after the constructor scan
815
842
  * declares this class's OWN symbol-keyed slots. */
816
843
  const dynRetMethods = new Map();
844
+ /** The class's own `emit` override in the forwarding shape (emitter-
845
+ * rooted classes only) — recorded here, NEVER in `methods`, so emit
846
+ * calls keep routing through the emitter spoke's dispatch. */
847
+ let emitOverride;
817
848
  let ctor = null;
818
849
  /** Initializer-less fields whose type cannot hold undefined and whose
819
850
  * definite assignment tsc did NOT verify (a `!` assertion, or
@@ -1011,7 +1042,13 @@ mixin) {
1011
1042
  // The EventEmitter API surface is runtime-provided: a subclass
1012
1043
  // member with one of its names would shadow behavior the runtime
1013
1044
  // dispatches internally (meta events, once removal), so the
1014
- // override is fenced rather than silently split-brained.
1045
+ // override is fenced rather than silently split-brained — with ONE
1046
+ // exception: `emit` in the forwarding shape on a plain (non-
1047
+ // stream) emitter-rooted class monomorphizes per event name
1048
+ // (lower-emitter.ts's emit-overrides block). Stream-rooted classes
1049
+ // keep the fence for emit too: the runtime stream machinery emits
1050
+ // 'data'/'end'/... internally, which could never route through
1051
+ // the override.
1015
1052
  if (memberName && ts.isIdentifier(memberName) &&
1016
1053
  EMITTER_API_MEMBERS.has(memberName.text) &&
1017
1054
  (() => {
@@ -1020,6 +1057,26 @@ mixin) {
1020
1057
  return true;
1021
1058
  return false;
1022
1059
  })()) {
1060
+ const streamRooted = (() => {
1061
+ for (let c = base; c; c = c.base)
1062
+ if (c.builtinStream !== undefined)
1063
+ return true;
1064
+ return false;
1065
+ })();
1066
+ if (memberName.text === "emit" && !streamRooted && !inst && !mixin &&
1067
+ ts.isMethodDeclaration(member) &&
1068
+ !member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword)) {
1069
+ const reason = emitOverrideShapeReason(L, member);
1070
+ if (reason === null) {
1071
+ const eventSym = L.checker.getSymbolAtLocation(member.parameters[0].name);
1072
+ const restSym = L.checker.getSymbolAtLocation(member.parameters[1].name);
1073
+ if (eventSym && restSym) {
1074
+ emitOverride = { decl: member, eventSym, restSym };
1075
+ continue;
1076
+ }
1077
+ }
1078
+ L.unsupported("SC1090", memberName, `overriding EventEmitter's 'emit' outside the forwarding shape (${reason ?? "its parameters do not resolve statically"}; the compiled form is \`emit(event: string, ...args: unknown[]): boolean\`)`);
1079
+ }
1023
1080
  L.unsupported("SC1090", memberName, `overriding the EventEmitter member '${memberName.text}' (the runtime owns the emitter surface)`);
1024
1081
  }
1025
1082
  // The stream surface is likewise runtime-provided on stream-rooted
@@ -1838,6 +1895,7 @@ mixin) {
1838
1895
  fieldOrder,
1839
1896
  methods,
1840
1897
  decl,
1898
+ ...(emitOverride !== undefined ? { emitOverride } : {}),
1841
1899
  ctor,
1842
1900
  ctorParams,
1843
1901
  ...(paramProps.length > 0 ? { paramProps } : {}),
@@ -3925,6 +3983,13 @@ export function lowerSuperMethodCall(L, call, access) {
3925
3983
  // tsc rejects super outside derived-class bodies first; defensive.
3926
3984
  L.unsupported("SC1090", access, "'super' outside a derived class");
3927
3985
  }
3986
+ // An emit-override SPECIALIZATION body's forward — `super.emit(event,
3987
+ // ...args)` — carries no literal event name; the specialization's own
3988
+ // context answers it (matched before any lookup: neither identifier
3989
+ // resolves through the ordinary lowering).
3990
+ const forward = emitSpecSuperForward(L, call, access);
3991
+ if (forward)
3992
+ return forward;
3928
3993
  const found = L.findMethodOn(cls.base, access.name.text);
3929
3994
  if (!found) {
3930
3995
  // `super.m(...)` of a GENERIC method: super dispatch is static in JS
@@ -3947,6 +4012,17 @@ export function lowerSuperMethodCall(L, call, access) {
3947
4012
  loc,
3948
4013
  };
3949
4014
  }
4015
+ // The runtime-provided emitter surface through `super` —
4016
+ // `super.emit('x', v)`, `super.on(...)`: Node's prototype-chain rule
4017
+ // is STATIC dispatch above the lexical class, which the emitter
4018
+ // spoke lowers with this method's own `this` as the receiver (an
4019
+ // emit override at-or-below `cls` never answers; the nearest one
4020
+ // strictly above does).
4021
+ if (EMITTER_API_MEMBERS.has(access.name.text) && emitterRooted(L, cls.base)) {
4022
+ const viaEmitter = lowerEmitterSuperCall(L, call, access, cls);
4023
+ if (viaEmitter)
4024
+ return viaEmitter;
4025
+ }
3950
4026
  L.unsupported("SC1090", access, `'super.${access.name.text}' (no base class declares it)`);
3951
4027
  }
3952
4028
  // tsc rejects super-access of abstract members (TS2513); defensive —
@@ -4312,7 +4388,7 @@ export function lowerNew(L, expr) {
4312
4388
  // like Node's message property default.
4313
4389
  const errInfo = L.builtinErrorInfoOf(symbol);
4314
4390
  // `new DOMException(message?, nameOrOptions?)`: both arguments cross
4315
- // as DOM values (absent → the DOM undefined), and the runtime owns
4391
+ // as dyn values (absent → the dyn undefined), and the runtime owns
4316
4392
  // WebIDL's resolution — ToString of the message ("" for undefined),
4317
4393
  // name from a string / an options object's `name` member (with the
4318
4394
  // `cause` own-property record) / "Error" for absent, and the legacy
@@ -4573,7 +4649,7 @@ export function lowerNew(L, expr) {
4573
4649
  const targs = L.checker.getTypeArguments(tsType);
4574
4650
  // JAVASCRIPT `new Map()` whose arguments never resolved past
4575
4651
  // Map<any, any> (no annotation, no contextual type, no seed): the
4576
- // WeakMap stance below — the VALUE lowers as an opaque DOM object
4652
+ // WeakMap stance below — the VALUE lowers as an opaque dyn object
4577
4653
  // (identity and truthiness are real), and every reached METHOD use
4578
4654
  // meets its own per-site fence at runtime. The formatter's
4579
4655
  // config-cache shape: module init constructs the caches
@@ -4606,7 +4682,7 @@ export function lowerNew(L, expr) {
4606
4682
  // `new WeakMap()` / `new WeakSet()` in JAVASCRIPT sources: no weak
4607
4683
  // container exists in the value model, but harness code constructs
4608
4684
  // one unconditionally and touches it only on paths tests don't
4609
- // reach — the value lowers as an opaque DOM object (identity only;
4685
+ // reach — the value lowers as an opaque dyn object (identity only;
4610
4686
  // every reached METHOD use meets its own per-site fence → runtime
4611
4687
  // fence). TypeScript keeps the compile fence.
4612
4688
  if ((symbol?.name === "WeakMap" || symbol?.name === "WeakSet") &&
@@ -4706,14 +4782,14 @@ export function lowerNew(L, expr) {
4706
4782
  // `new Promise(setImmediate)` (the Node-suite early-exit shape):
4707
4783
  // the executor IS the stdlib setImmediate, so resolve rides the
4708
4784
  // immediate queue — a dedicated runtime constructor arms an
4709
- // immediate that fulfills with the undefined DOM value.
4785
+ // immediate that fulfills with the undefined dyn value.
4710
4786
  {
4711
4787
  const a0 = args[0];
4712
4788
  if (ts.isIdentifier(a0) && a0.text === "setImmediate") {
4713
4789
  const sym = L.checker.getSymbolAtLocation(a0);
4714
4790
  const decls = sym ? L.checker.declarationsOf(sym) : [];
4715
4791
  if (decls.length > 0 && decls.every((d) => L.isStdlibFile(d.getSourceFile()))) {
4716
- // The settled value is the undefined DOM value — the result
4792
+ // The settled value is the undefined dyn value — the result
4717
4793
  // is promise<dyn> whatever T the checker inferred for the
4718
4794
  // unusual executor (Promise<unknown> in the suite's shape).
4719
4795
  return {