@scriptc/compiler 0.0.23 → 0.0.25

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 (65) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +100 -11
  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 +31 -1
  7. package/dist/backend/emission/emit-async.js.map +1 -1
  8. package/dist/backend/emission/emit-exprs.js +147 -14
  9. package/dist/backend/emission/emit-exprs.js.map +1 -1
  10. package/dist/backend/emission/emit-shapes.js +1 -0
  11. package/dist/backend/emission/emit-shapes.js.map +1 -1
  12. package/dist/backend/emission/emit-stmts.js +24 -5
  13. package/dist/backend/emission/emit-stmts.js.map +1 -1
  14. package/dist/backend/emission/emit-types.js +10 -0
  15. package/dist/backend/emission/emit-types.js.map +1 -1
  16. package/dist/backend/emission/emitter.d.ts +10 -2
  17. package/dist/backend/emission/emitter.js +49 -30
  18. package/dist/backend/emission/emitter.js.map +1 -1
  19. package/dist/backend/llvm/emitter.js +284 -25
  20. package/dist/backend/llvm/emitter.js.map +1 -1
  21. package/dist/backend/llvm/shapes.js +9 -1
  22. package/dist/backend/llvm/shapes.js.map +1 -1
  23. package/dist/backend/mangle.d.ts +3 -0
  24. package/dist/backend/mangle.js +5 -0
  25. package/dist/backend/mangle.js.map +1 -1
  26. package/dist/frontend/lowering/lower-builtins.d.ts +14 -9
  27. package/dist/frontend/lowering/lower-builtins.js +737 -62
  28. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  29. package/dist/frontend/lowering/lower-calls.js +2 -1
  30. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  31. package/dist/frontend/lowering/lower-containers.d.ts +2 -1
  32. package/dist/frontend/lowering/lower-containers.js +99 -32
  33. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  34. package/dist/frontend/lowering/lower-exprs.js +53 -2
  35. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  36. package/dist/frontend/lowering/lower-inspect.js +59 -1
  37. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  38. package/dist/frontend/lowering/lower-server.d.ts +5 -0
  39. package/dist/frontend/lowering/lower-server.js +1 -1
  40. package/dist/frontend/lowering/lower-server.js.map +1 -1
  41. package/dist/frontend/lowering/lower-stmts.d.ts +6 -2
  42. package/dist/frontend/lowering/lower-stmts.js +45 -10
  43. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  44. package/dist/frontend/lowering/lowerer.d.ts +2 -2
  45. package/dist/frontend/lowering/lowerer.js +11 -6
  46. package/dist/frontend/lowering/lowerer.js.map +1 -1
  47. package/dist/frontend/lowering/surfaces.js +65 -13
  48. package/dist/frontend/lowering/surfaces.js.map +1 -1
  49. package/dist/frontend/types.d.ts +3 -0
  50. package/dist/frontend/types.js +78 -0
  51. package/dist/frontend/types.js.map +1 -1
  52. package/dist/index.js +8 -1
  53. package/dist/index.js.map +1 -1
  54. package/dist/ir/integer-loops.d.ts +23 -0
  55. package/dist/ir/integer-loops.js +82 -0
  56. package/dist/ir/integer-loops.js.map +1 -0
  57. package/dist/ir/nodes.d.ts +84 -21
  58. package/dist/ir/nodes.js +84 -1
  59. package/dist/ir/nodes.js.map +1 -1
  60. package/dist/ir/validate.js +92 -18
  61. package/dist/ir/validate.js.map +1 -1
  62. package/dist/library/fence-eval.js +4 -3
  63. package/dist/library/fence-eval.js.map +1 -1
  64. package/package.json +2 -2
  65. package/surface-manifest.json +50 -2
@@ -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
@@ -1076,6 +1076,36 @@ function lowerMatchAllDrainDecl(L, decl, isConst) {
1076
1076
  },
1077
1077
  ];
1078
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
+ }
1079
1109
  /** Destructuring declarations, desugared as sugar over indexed/field
1080
1110
  * reads: the initializer evaluates ONCE into a hidden temp, then each
1081
1111
  * bound name declares (or assigns its pre-registered module global) from
@@ -1106,6 +1136,7 @@ export function lowerDestructuringDecl(L, decl, isLet) {
1106
1136
  return tokenBound;
1107
1137
  }
1108
1138
  let init = L.lowerExpr(decl.initializer);
1139
+ const parseArgsDynObject = init.type.kind === "dyn" && isParseArgsDynCheckerType(L, L.typeOf(decl.initializer));
1109
1140
  // A TS `any`-origin source whose lowered value is NOT a destructurable
1110
1141
  // shape (`var { x } = <any>0` — the cast erases to the f64; a dyn
1111
1142
  // value — the checked-dynamic tree has no destructure): JS reads the properties off
@@ -1240,12 +1271,12 @@ export function lowerDestructuringDecl(L, decl, isLet) {
1240
1271
  : ts.isCallExpression(src) && ts.isIdentifier(src.expression)
1241
1272
  ? `${src.expression.text} is not a function or its return value is not iterable`
1242
1273
  : undefined;
1243
- 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);
1244
1275
  return out;
1245
1276
  }
1246
1277
  /** One pattern level: emits a declaration (or global assignment) per
1247
1278
  * bound name, recursing through hidden temps for nested patterns. */
1248
- export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dynSpell) {
1279
+ export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dynSpell, allowDynObject = false) {
1249
1280
  if (ts.isArrayBindingPattern(pattern)) {
1250
1281
  L.fenceStaticHeadersIteration(pattern);
1251
1282
  // Tuple sources: each position is a field read of the tuple's record
@@ -1538,8 +1569,12 @@ export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dyn
1538
1569
  // default applied exactly when the read answers undefined (lazily,
1539
1570
  // like a defaulted parameter). Bindings are dyn (the checker's `any`),
1540
1571
  // nested object patterns recurse through this same branch. TS files
1541
- // keep the fence — annotations exist there.
1542
- 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)) {
1543
1578
  for (const el of pattern.elements) {
1544
1579
  if (el.name === undefined)
1545
1580
  continue;
@@ -1576,7 +1611,7 @@ export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out, dyn
1576
1611
  loc,
1577
1612
  };
1578
1613
  }
1579
- L.bindPatternTarget(el.name, value, isLet, out);
1614
+ L.bindPatternTarget(el.name, value, isLet, out, allowDynObject);
1580
1615
  }
1581
1616
  return;
1582
1617
  }
@@ -2669,7 +2704,7 @@ export function lowerJsvalBindingPattern(L, pattern, srcRef, isLet, out) {
2669
2704
  function jsvalFlavoredType(t) {
2670
2705
  return t.kind === "jsval" || (t.kind === "array" && t.elem.kind === "jsval");
2671
2706
  }
2672
- export function bindPatternTarget(L, name, value, isLet, out) {
2707
+ export function bindPatternTarget(L, name, value, isLet, out, allowDynObject = false) {
2673
2708
  const loc = value.loc;
2674
2709
  if (ts.isIdentifier(name)) {
2675
2710
  const symbol = L.checker.getSymbolAtLocation(name);
@@ -2713,7 +2748,7 @@ export function bindPatternTarget(L, name, value, isLet, out) {
2713
2748
  }
2714
2749
  const tmp = L.declareHiddenLocal("%destr", value.type);
2715
2750
  out.push({ kind: "varDecl", localId: tmp.id, init: value, loc });
2716
- 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);
2717
2752
  }
2718
2753
  /** For-loop initializers. let/const stay restricted to ONE declarator (JS
2719
2754
  * per-iteration binding copies for several captured loop variables are
@@ -2871,8 +2906,8 @@ export function lowerVarDecl(L, decl, isLet) {
2871
2906
  // alias plumbing (see stdlibGlobalAliasDecl), no storage, no code.
2872
2907
  if (!isLet && stdlibGlobalAliasDecl(L, decl.name, decl.initializer))
2873
2908
  return null;
2874
- // `const encoder = new TextEncoder()` and the default TextDecoder
2875
- // 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
2876
2911
  // through this stable binding resolve back to the initializer. The
2877
2912
  // supported constructors are effect-free, so the declaration itself
2878
2913
  // is compile-time alias plumbing with no storage or code.