@scriptc/compiler 0.0.22 → 0.0.24

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 (93) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +139 -14
  2. package/dist/backend/cc.d.ts +13 -0
  3. package/dist/backend/cc.js +11 -0
  4. package/dist/backend/cc.js.map +1 -1
  5. package/dist/backend/emission/emit-async.d.ts +4 -0
  6. package/dist/backend/emission/emit-async.js +34 -2
  7. package/dist/backend/emission/emit-async.js.map +1 -1
  8. package/dist/backend/emission/emit-exprs.d.ts +10 -0
  9. package/dist/backend/emission/emit-exprs.js +272 -22
  10. package/dist/backend/emission/emit-exprs.js.map +1 -1
  11. package/dist/backend/emission/emit-shapes.js +1 -0
  12. package/dist/backend/emission/emit-shapes.js.map +1 -1
  13. package/dist/backend/emission/emit-stmts.js +36 -9
  14. package/dist/backend/emission/emit-stmts.js.map +1 -1
  15. package/dist/backend/emission/emit-types.js +14 -1
  16. package/dist/backend/emission/emit-types.js.map +1 -1
  17. package/dist/backend/emission/emitter.d.ts +19 -1
  18. package/dist/backend/emission/emitter.js +81 -2
  19. package/dist/backend/emission/emitter.js.map +1 -1
  20. package/dist/backend/llvm/emitter.js +578 -36
  21. package/dist/backend/llvm/emitter.js.map +1 -1
  22. package/dist/backend/llvm/shapes.js +12 -3
  23. package/dist/backend/llvm/shapes.js.map +1 -1
  24. package/dist/backend/mangle.d.ts +3 -0
  25. package/dist/backend/mangle.js +5 -0
  26. package/dist/backend/mangle.js.map +1 -1
  27. package/dist/compat/fetch-profile.d.ts +10 -0
  28. package/dist/compat/fetch-profile.js +55 -6
  29. package/dist/compat/fetch-profile.js.map +1 -1
  30. package/dist/coverage/surface-manifest.js +16 -1
  31. package/dist/coverage/surface-manifest.js.map +1 -1
  32. package/dist/diagnostics/diagnostic.d.ts +10 -0
  33. package/dist/diagnostics/diagnostic.js +27 -1
  34. package/dist/diagnostics/diagnostic.js.map +1 -1
  35. package/dist/frontend/lowering/lower-builtins.d.ts +17 -16
  36. package/dist/frontend/lowering/lower-builtins.js +817 -117
  37. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  38. package/dist/frontend/lowering/lower-calls.js +3 -1
  39. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  40. package/dist/frontend/lowering/lower-classes.js +28 -8
  41. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  42. package/dist/frontend/lowering/lower-containers.d.ts +2 -1
  43. package/dist/frontend/lowering/lower-containers.js +99 -32
  44. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  45. package/dist/frontend/lowering/lower-exprs.d.ts +1 -1
  46. package/dist/frontend/lowering/lower-exprs.js +78 -6
  47. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  48. package/dist/frontend/lowering/lower-generators.js +7 -1
  49. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  50. package/dist/frontend/lowering/lower-inspect.js +59 -1
  51. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  52. package/dist/frontend/lowering/lower-island.d.ts +21 -0
  53. package/dist/frontend/lowering/lower-island.js +284 -10
  54. package/dist/frontend/lowering/lower-island.js.map +1 -1
  55. package/dist/frontend/lowering/lower-server.d.ts +5 -0
  56. package/dist/frontend/lowering/lower-server.js +1 -1
  57. package/dist/frontend/lowering/lower-server.js.map +1 -1
  58. package/dist/frontend/lowering/lower-stmts.d.ts +6 -2
  59. package/dist/frontend/lowering/lower-stmts.js +53 -14
  60. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  61. package/dist/frontend/lowering/lowerer.d.ts +3 -2
  62. package/dist/frontend/lowering/lowerer.js +17 -8
  63. package/dist/frontend/lowering/lowerer.js.map +1 -1
  64. package/dist/frontend/lowering/surfaces.js +108 -25
  65. package/dist/frontend/lowering/surfaces.js.map +1 -1
  66. package/dist/frontend/program.d.ts +4 -4
  67. package/dist/frontend/program.js +264 -46
  68. package/dist/frontend/program.js.map +1 -1
  69. package/dist/frontend/resolve.d.ts +10 -0
  70. package/dist/frontend/resolve.js +37 -0
  71. package/dist/frontend/resolve.js.map +1 -1
  72. package/dist/frontend/ts7/enums.d.ts +9 -0
  73. package/dist/frontend/ts7/enums.js +8 -6
  74. package/dist/frontend/ts7/enums.js.map +1 -1
  75. package/dist/frontend/ts7/program.js +4 -1
  76. package/dist/frontend/ts7/program.js.map +1 -1
  77. package/dist/frontend/types.d.ts +7 -4
  78. package/dist/frontend/types.js +103 -8
  79. package/dist/frontend/types.js.map +1 -1
  80. package/dist/index.js +8 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/ir/integer-loops.d.ts +23 -0
  83. package/dist/ir/integer-loops.js +82 -0
  84. package/dist/ir/integer-loops.js.map +1 -0
  85. package/dist/ir/nodes.d.ts +104 -28
  86. package/dist/ir/nodes.js +89 -1
  87. package/dist/ir/nodes.js.map +1 -1
  88. package/dist/ir/validate.js +136 -25
  89. package/dist/ir/validate.js.map +1 -1
  90. package/dist/library/fence-eval.js +4 -3
  91. package/dist/library/fence-eval.js.map +1 -1
  92. package/package.json +2 -2
  93. package/surface-manifest.json +186 -29
@@ -165,6 +165,10 @@ export declare function lowerVarStatement(L: Lowerer, stmt: ts.VariableStatement
165
165
  * object: it has observable mutable protocol state, represented by
166
166
  * hidden locals only while a stored binding stays in one function. */
167
167
  export declare function numericIteratorSourceOf(L: Lowerer, expr: ts.Expression | undefined): ts.Expression | null;
168
+ /** Whether a checker type belongs to node:util.parseArgs's dyn-backed
169
+ * declaration family. Module ancestry disambiguates short private helper
170
+ * names such as `Token` from names in other standard-library modules. */
171
+ export declare function isParseArgsDynCheckerType(L: Lowerer, type: ts.Type): boolean;
168
172
  /** Destructuring declarations, desugared as sugar over indexed/field
169
173
  * reads: the initializer evaluates ONCE into a hidden temp, then each
170
174
  * bound name declares (or assigns its pre-registered module global) from
@@ -178,7 +182,7 @@ export declare function numericIteratorSourceOf(L: Lowerer, expr: ts.Expression
178
182
  export declare function lowerDestructuringDecl(L: Lowerer, decl: ts.VariableDeclaration, isLet: boolean): IrStmt[];
179
183
  /** One pattern level: emits a declaration (or global assignment) per
180
184
  * bound name, recursing through hidden temps for nested patterns. */
181
- export declare function lowerBindingPattern(L: Lowerer, pattern: ts.ArrayBindingPattern | ts.ObjectBindingPattern, srcRef: () => IrExpr, srcType: IrType, isLet: boolean, out: IrStmt[], dynSpell?: string): void;
185
+ export declare function lowerBindingPattern(L: Lowerer, pattern: ts.ArrayBindingPattern | ts.ObjectBindingPattern, srcRef: () => IrExpr, srcType: IrType, isLet: boolean, out: IrStmt[], dynSpell?: string, allowDynObject?: boolean): void;
182
186
  /** The STATIC property name of a destructuring key: identifiers spell
183
187
  * themselves, string/numeric-literal keys and COMPUTED keys fold through
184
188
  * foldedStringKeyOf — pure single-name expressions only (`{ [k]: v }`
@@ -217,7 +221,7 @@ export declare function enginePatternSpec(L: Lowerer, pattern: ts.ArrayBindingPa
217
221
  * exit), rest, and transportable defaults all ride. False when the
218
222
  * pattern has no engine form (the caller fences). */
219
223
  export declare function lowerJsvalBindingPattern(L: Lowerer, pattern: ts.ArrayBindingPattern | ts.ObjectBindingPattern, srcRef: () => IrExpr, isLet: boolean, out: IrStmt[]): boolean;
220
- export declare function bindPatternTarget(L: Lowerer, name: ts.BindingName, value: IrExpr, isLet: boolean, out: IrStmt[]): void;
224
+ export declare function bindPatternTarget(L: Lowerer, name: ts.BindingName, value: IrExpr, isLet: boolean, out: IrStmt[], allowDynObject?: boolean): void;
221
225
  /** For-loop initializers. let/const stay restricted to ONE declarator (JS
222
226
  * per-iteration binding copies for several captured loop variables are
223
227
  * not modeled yet); `var` initializers take any number — a `var` is ONE
@@ -22,7 +22,7 @@ import { builtinMemberRequireDecl, builtinNamespaceDestructureModuleOf, createRe
22
22
  import { lowerEnumDeclaration } from "./lower-enums.js";
23
23
  import { abstractPropertyDeclOf, aliasTypeofNarrows, isMatchSliceType, lowerGroupsProjection, matchResultNamedGroupsOf, probeLower, pureReemittable, symbolFieldInfo } from "./lower-exprs.js";
24
24
  import { checkerPanicDiag, isCheckerPanic, requiresDynamicDiag } from "../../diagnostics/diagnostic.js";
25
- import { isUnitOnlyTsType, unitOnlyUnion } from "../types.js";
25
+ import { isParseArgsDynTypeName, isUnitOnlyTsType, unitOnlyUnion } from "../types.js";
26
26
  import { canonicalBuiltinModule, isRelativeSpecifier } from "../shared.js";
27
27
  import { probeNodeRequireRefusal } from "../npm.js";
28
28
  /** `const X = /* @__PURE__ *\/ makeX()` at a module's top level: every
@@ -813,12 +813,16 @@ export function lowerStmt(L, stmt) {
813
813
  if (caughtLocal) {
814
814
  return { kind: "rethrow", localId: caughtLocal.id, loc: locOf(stmt) };
815
815
  }
816
- // Any supported value type can be thrown; ownership moves into the
817
- // runtime's exception cell. `throw f()` of a void call has no value —
818
- // rejected via the type fence.
816
+ // Exception-representable values move into the runtime's exception
817
+ // cell. `throw f()` of a void call has no value; Date has numeric
818
+ // storage internally, but cannot preserve its object kind through the
819
+ // untyped catch boundary. Reject both rather than changing JS identity.
819
820
  const value = L.lowerExpr(stmt.expression);
820
821
  if (value.type.kind === "void")
821
822
  L.badType(stmt.expression, L.typeOf(stmt.expression));
823
+ if (value.type.kind === "date") {
824
+ L.unsupported("SC1090", stmt.expression, "throwing Date values (catch bindings cannot preserve Date's object kind; throw an Error or primitive instead)");
825
+ }
822
826
  // A dyn throw rides the REF cell arm (scr_throw_ref over the checked-dynamic tree
823
827
  // node — identity preserved through catch bindings, caughtToDyn
824
828
  // passes it back by reference). The JS-lane traced-call shape:
@@ -1072,6 +1076,36 @@ function lowerMatchAllDrainDecl(L, decl, isConst) {
1072
1076
  },
1073
1077
  ];
1074
1078
  }
1079
+ /** Whether a checker type belongs to node:util.parseArgs's dyn-backed
1080
+ * declaration family. Module ancestry disambiguates short private helper
1081
+ * names such as `Token` from names in other standard-library modules. */
1082
+ export function isParseArgsDynCheckerType(L, type) {
1083
+ const widened = L.checker.getBaseTypeOfLiteralType(type);
1084
+ const declarationBelongs = (d) => {
1085
+ if (!L.isStdlibFile(d.getSourceFile()))
1086
+ return false;
1087
+ let inParseArgsType = false;
1088
+ for (let node = d.parent; node; node = node.parent) {
1089
+ if ((ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) &&
1090
+ isParseArgsDynTypeName(node.name.text)) {
1091
+ inParseArgsType = true;
1092
+ }
1093
+ if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) {
1094
+ return inParseArgsType && (node.name.text === "util" || node.name.text === "node:util");
1095
+ }
1096
+ }
1097
+ return false;
1098
+ };
1099
+ const sym = widened.getAliasSymbol() ?? widened.getSymbol();
1100
+ if (sym && isParseArgsDynTypeName(sym.name) &&
1101
+ L.checker.declarationsOf(sym).some(declarationBelongs)) {
1102
+ return true;
1103
+ }
1104
+ // A discriminant check erases the token alias and leaves one anonymous
1105
+ // object arm. Its properties still point into the parseArgs alias, which
1106
+ // is the same stable signal the dotted-member bridge uses.
1107
+ return L.checker.getPropertiesOfType(widened).some((p) => L.checker.declarationsOf(p).some(declarationBelongs));
1108
+ }
1075
1109
  /** Destructuring declarations, desugared as sugar over indexed/field
1076
1110
  * reads: the initializer evaluates ONCE into a hidden temp, then each
1077
1111
  * bound name declares (or assigns its pre-registered module global) from
@@ -1102,6 +1136,7 @@ export function lowerDestructuringDecl(L, decl, isLet) {
1102
1136
  return tokenBound;
1103
1137
  }
1104
1138
  let init = L.lowerExpr(decl.initializer);
1139
+ const parseArgsDynObject = init.type.kind === "dyn" && isParseArgsDynCheckerType(L, L.typeOf(decl.initializer));
1105
1140
  // A TS `any`-origin source whose lowered value is NOT a destructurable
1106
1141
  // shape (`var { x } = <any>0` — the cast erases to the f64; a dyn
1107
1142
  // value — the checked-dynamic tree has no destructure): JS reads the properties off
@@ -1236,12 +1271,12 @@ export function lowerDestructuringDecl(L, decl, isLet) {
1236
1271
  : ts.isCallExpression(src) && ts.isIdentifier(src.expression)
1237
1272
  ? `${src.expression.text} is not a function or its return value is not iterable`
1238
1273
  : undefined;
1239
- L.lowerBindingPattern(decl.name, () => ({ kind: "varRef", localId: tmp.id, type: init.type, loc }), init.type, isLet, out, dynSpell);
1274
+ L.lowerBindingPattern(decl.name, () => ({ kind: "varRef", localId: tmp.id, type: init.type, loc }), init.type, isLet, out, dynSpell, parseArgsDynObject);
1240
1275
  return out;
1241
1276
  }
1242
1277
  /** One pattern level: emits a declaration (or global assignment) per
1243
1278
  * bound name, recursing through hidden temps for nested patterns. */
1244
- export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dynSpell) {
1279
+ export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dynSpell, allowDynObject = false) {
1245
1280
  if (ts.isArrayBindingPattern(pattern)) {
1246
1281
  L.fenceStaticHeadersIteration(pattern);
1247
1282
  // Tuple sources: each position is a field read of the tuple's record
@@ -1534,8 +1569,12 @@ export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dyn
1534
1569
  // default applied exactly when the read answers undefined (lazily,
1535
1570
  // like a defaulted parameter). Bindings are dyn (the checker's `any`),
1536
1571
  // nested object patterns recurse through this same branch. TS files
1537
- // keep the fence — annotations exist there.
1538
- if (srcType.kind === "dyn" && isJsSourceFile(pattern.getSourceFile())) {
1572
+ // keep the fence — annotations exist there. node:util.parseArgs is the
1573
+ // scoped TypeScript exception: its declared result/token types are
1574
+ // deliberately carried by the checked-dynamic tree, so their ordinary
1575
+ // object patterns use the same exact keyed-read desugar.
1576
+ if (srcType.kind === "dyn" &&
1577
+ (isJsSourceFile(pattern.getSourceFile()) || allowDynObject)) {
1539
1578
  for (const el of pattern.elements) {
1540
1579
  if (el.name === undefined)
1541
1580
  continue;
@@ -1572,7 +1611,7 @@ export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dyn
1572
1611
  loc,
1573
1612
  };
1574
1613
  }
1575
- L.bindPatternTarget(el.name, value, isLet, out);
1614
+ L.bindPatternTarget(el.name, value, isLet, out, allowDynObject);
1576
1615
  }
1577
1616
  return;
1578
1617
  }
@@ -2665,7 +2704,7 @@ export function lowerJsvalBindingPattern(L, pattern, srcRef, isLet, out) {
2665
2704
  function jsvalFlavoredType(t) {
2666
2705
  return t.kind === "jsval" || (t.kind === "array" && t.elem.kind === "jsval");
2667
2706
  }
2668
- export function bindPatternTarget(L, name, value, isLet, out) {
2707
+ export function bindPatternTarget(L, name, value, isLet, out, allowDynObject = false) {
2669
2708
  const loc = value.loc;
2670
2709
  if (ts.isIdentifier(name)) {
2671
2710
  const symbol = L.checker.getSymbolAtLocation(name);
@@ -2709,7 +2748,7 @@ export function bindPatternTarget(L, name, value, isLet, out) {
2709
2748
  }
2710
2749
  const tmp = L.declareHiddenLocal("%destr", value.type);
2711
2750
  out.push({ kind: "varDecl", localId: tmp.id, init: value, loc });
2712
- L.lowerBindingPattern(name, () => ({ kind: "varRef", localId: tmp.id, type: value.type, loc }), value.type, isLet, out);
2751
+ L.lowerBindingPattern(name, () => ({ kind: "varRef", localId: tmp.id, type: value.type, loc }), value.type, isLet, out, undefined, allowDynObject);
2713
2752
  }
2714
2753
  /** For-loop initializers. let/const stay restricted to ONE declarator (JS
2715
2754
  * per-iteration binding copies for several captured loop variables are
@@ -2867,8 +2906,8 @@ export function lowerVarDecl(L, decl, isLet) {
2867
2906
  // alias plumbing (see stdlibGlobalAliasDecl), no storage, no code.
2868
2907
  if (!isLet && stdlibGlobalAliasDecl(L, decl.name, decl.initializer))
2869
2908
  return null;
2870
- // `const encoder = new TextEncoder()` and the default TextDecoder
2871
- // twin: the codec has no general value representation, but calls
2909
+ // `const encoder = new TextEncoder()` and a statically-labelled
2910
+ // TextDecoder twin: the codec has no general value representation, but calls
2872
2911
  // through this stable binding resolve back to the initializer. The
2873
2912
  // supported constructors are effect-free, so the declaration itself
2874
2913
  // is compile-time alias plumbing with no storage or code.
@@ -3920,7 +3959,7 @@ export function lowerExprStatement(L, expr) {
3920
3959
  }
3921
3960
  }
3922
3961
  }
3923
- if (isJsSourceFile(sf) && !ts.isExternalModule(sf)) {
3962
+ if (isCjsJsFile(sf)) {
3924
3963
  const init = L.requireInitStmt(spec, expr);
3925
3964
  if (init)
3926
3965
  return init;