@scriptc/compiler 0.0.25 → 0.0.27

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 (69) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +15 -7
  2. package/dist/backend/cc.d.ts +22 -0
  3. package/dist/backend/cc.js +128 -10
  4. package/dist/backend/cc.js.map +1 -1
  5. package/dist/backend/emission/emit-exprs.js +81 -10
  6. package/dist/backend/emission/emit-exprs.js.map +1 -1
  7. package/dist/backend/emission/emitter.d.ts +14 -1
  8. package/dist/backend/emission/emitter.js +126 -13
  9. package/dist/backend/emission/emitter.js.map +1 -1
  10. package/dist/backend/emission/may-throw.js +11 -1
  11. package/dist/backend/emission/may-throw.js.map +1 -1
  12. package/dist/backend/ffi-callbacks.d.ts +11 -0
  13. package/dist/backend/ffi-callbacks.js +33 -0
  14. package/dist/backend/ffi-callbacks.js.map +1 -0
  15. package/dist/backend/llvm/classes.js +21 -21
  16. package/dist/backend/llvm/classes.js.map +1 -1
  17. package/dist/backend/llvm/dyn.d.ts +7 -4
  18. package/dist/backend/llvm/dyn.js +145 -141
  19. package/dist/backend/llvm/dyn.js.map +1 -1
  20. package/dist/backend/llvm/emitter.d.ts +7 -1
  21. package/dist/backend/llvm/emitter.js +961 -303
  22. package/dist/backend/llvm/emitter.js.map +1 -1
  23. package/dist/backend/llvm/shapes.d.ts +4 -0
  24. package/dist/backend/llvm/shapes.js +26 -24
  25. package/dist/backend/llvm/shapes.js.map +1 -1
  26. package/dist/backend/llvm/unsupported.js +1 -1
  27. package/dist/backend/llvm/unsupported.js.map +1 -1
  28. package/dist/backend/llvm/walkers.d.ts +2 -0
  29. package/dist/backend/llvm/walkers.js +50 -46
  30. package/dist/backend/llvm/walkers.js.map +1 -1
  31. package/dist/coverage/surface-manifest.js +1 -1
  32. package/dist/coverage/surface-manifest.js.map +1 -1
  33. package/dist/diagnostics/diagnostic.d.ts +1 -1
  34. package/dist/diagnostics/diagnostic.js +3 -2
  35. package/dist/diagnostics/diagnostic.js.map +1 -1
  36. package/dist/ffi/profile.d.ts +20 -2
  37. package/dist/ffi/profile.js +130 -6
  38. package/dist/ffi/profile.js.map +1 -1
  39. package/dist/frontend/lowering/lower-calls.js +58 -22
  40. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  41. package/dist/frontend/lowering/lower-exprs.js +17 -7
  42. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  43. package/dist/frontend/lowering/lower-server.d.ts +5 -0
  44. package/dist/frontend/lowering/lower-server.js +129 -37
  45. package/dist/frontend/lowering/lower-server.js.map +1 -1
  46. package/dist/frontend/lowering/lower-stmts.js +8 -1
  47. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  48. package/dist/frontend/lowering/surfaces.d.ts +3 -2
  49. package/dist/frontend/lowering/surfaces.js +4 -3
  50. package/dist/frontend/lowering/surfaces.js.map +1 -1
  51. package/dist/frontend/npm.d.ts +16 -0
  52. package/dist/frontend/npm.js +257 -0
  53. package/dist/frontend/npm.js.map +1 -1
  54. package/dist/index.d.ts +7 -4
  55. package/dist/index.js +188 -5
  56. package/dist/index.js.map +1 -1
  57. package/dist/ir/nodes.d.ts +54 -13
  58. package/dist/ir/nodes.js +49 -7
  59. package/dist/ir/nodes.js.map +1 -1
  60. package/dist/ir/validate.js +10 -22
  61. package/dist/ir/validate.js.map +1 -1
  62. package/dist/library/profile.d.ts +11 -0
  63. package/dist/library/profile.js +74 -2
  64. package/dist/library/profile.js.map +1 -1
  65. package/dist/wasi-paths.d.ts +5 -0
  66. package/dist/wasi-paths.js +22 -0
  67. package/dist/wasi-paths.js.map +1 -0
  68. package/package.json +2 -2
  69. package/surface-manifest.json +2 -2
@@ -5,7 +5,8 @@
5
5
  * ToBoolean/ToString coercion helpers, and field/element reads and writes
6
6
  * (FieldTarget). */
7
7
  import * as ts from "../ts7/adapter.js";
8
- import { dirname } from "node:path";
8
+ import { dirname, posix } from "node:path";
9
+ import { wasiGuestPath } from "../../wasi-paths.js";
9
10
  import { BOOL, CAUGHT, DYN, DYN_HANDLE_KINDS, F64, JSVAL, NULL_T, REF_TRUTHY_KINDS, REGEX, RUNTIME_ERROR_CLASSES, SEARCH_PARAMS_T, STRING, UNDEFINED_T, VOID, arrayOf, canAdaptDynFuncTo, canBoxFuncIntoDyn, canDynCheckTo, funcOf, isJsonSafeType, isUnitType, jsOpResultKind, shapeHasAccessorSlots, typeEquals, typeKey, unionFuncSetArmsOk } from "../../ir/nodes.js";
10
11
  import { cjsClassExprWholeExportOf, cjsExportAssignmentOf, cjsExportDiscardReason, isCjsExportTableLiteral, isCjsJsFile, isJsSourceFile, isModuleExportsAccess, isNodeEsmFile, locOf } from "../program.js";
11
12
  import { ARRAY_METHODS, builtinConstLit, builtinFenceHintOf, builtinModuleConstOf, builtinModulesArrayLit, builtinModuleFnOf, ISLAND_SURFACE, isChildSurfaceMember, MAP_METHODS, NARROW_FIRST, SET_METHODS, STR_METHODS, UNSUPPORTED_EXPR, sideEffectFreeOptionValue, stdlibGlobalNameOf } from "./surfaces.js";
@@ -675,18 +676,27 @@ function lowerExprInner(L, expr) {
675
676
  return { kind: "unitLit", unit: "undefined", type: UNDEFINED_T, loc };
676
677
  }
677
678
  // `__dirname` / `__filename` — the CommonJS module globals: per-
678
- // MODULE compile-time constants, the containing file's REAL
679
- // location (Node's exact values when the same tree runs in place;
680
- // locals shadowing the names resolved above). In a file with ESM
681
- // syntax Node never defines them (ReferenceError) — fence rather
682
- // than invent a value there.
679
+ // MODULE compile-time constants, the containing file's location
680
+ // (Node's exact values when the same tree runs in place; WASI uses
681
+ // the equivalent guest-visible path; locals shadowing the names
682
+ // resolved above). In a file with ESM syntax Node never defines them
683
+ // (ReferenceError) — fence rather than invent a value there.
683
684
  if ((expr.text === "__dirname" || expr.text === "__filename") &&
684
685
  L.isStdlibGlobal(expr, expr.text)) {
685
686
  const sf = expr.getSourceFile();
686
687
  if (isNodeEsmFile(sf)) {
687
688
  L.unsupported("SC1090", expr, `'${expr.text}' in an ES module (Node defines the CJS module globals only in CommonJS modules)`);
688
689
  }
689
- const value = expr.text === "__dirname" ? dirname(sf.fileName) : sf.fileName;
690
+ // The WASI runner mounts the host cwd at guest `/` and the host temp
691
+ // directory at `/tmp`. Bake the matching GUEST spelling so resource
692
+ // lookups relative to these CommonJS globals stay inside the exposed
693
+ // capability instead of naming an unreachable host-absolute path.
694
+ const fileName = L.targetPlatform === "wasi"
695
+ ? wasiGuestPath(sf.fileName) ?? sf.fileName.replace(/\\/g, "/")
696
+ : sf.fileName;
697
+ const value = expr.text === "__dirname"
698
+ ? (L.targetPlatform === "wasi" ? posix.dirname(fileName) : dirname(fileName))
699
+ : fileName;
690
700
  return { kind: "strLit", value, type: STRING, loc };
691
701
  }
692
702
  const sig = L.fnSigOf(expr);